2 using System.Collections.Generic;
6 using Seci.Definitions;
7 using System.ComponentModel;
9 using System.Xml.Serialization;
11 namespace Seci.Managers
15 private static string PHONE_NUMBERS_FILENAME =
"phone_numbers.xml";
21 public static void SetAlerts(Tools.AlertsBox alerts)
28 PhoneNumbers = numbers;
33 if (Alerts != null && Alerts.BlockLimitsAlerts.ContainsKey(block.BlockName.ToLower()))
35 BlockAlert temp = Alerts.BlockLimitsAlerts[block.BlockName.ToLower()];
40 if (Double.TryParse(block.CurrentValue, out value))
42 if (value <= temp.HighLimit && value >= temp.
LowLimit)
48 temp.TimeWentOutOfRange =
new DateTime();
50 temp.OutOfRange =
false;
56 temp.OutOfRange =
true;
57 temp.TimeWentOutOfRange = DateTime.Now;
61 TimeSpan diff = DateTime.Now - temp.TimeWentOutOfRange;
68 temp.LastMessageSent = DateTime.Now;
69 sendMessage(
"The " + block.BlockName +
" block has gone out of range on " + Seci.Definitions.Status.Instrument.ToUpper());
79 if (Alerts != null && Alerts.WaitingStateAlert != null)
83 if (!Alerts.WaitingStateAlert.OutOfRange)
85 Alerts.WaitingStateAlert.OutOfRange =
true;
86 Alerts.WaitingStateAlert.TimeWentOutOfRange = DateTime.Now;
89 TimeSpan diff = DateTime.Now - Alerts.WaitingStateAlert.TimeWentOutOfRange;
90 if (diff > Alerts.WaitingStateAlert.DelayBeforeSms)
93 if (DateTime.Now - Alerts.WaitingStateAlert.LastMessageSent >
new TimeSpan(1, 0, 0))
96 Alerts.WaitingStateAlert.LastMessageSent = DateTime.Now;
98 sendMessage(
"The " + Seci.Definitions.Status.Instrument.ToUpper() +
" system has been in the WAITING state for longer than the set limit");
104 if (Alerts.WaitingStateAlert.OutOfRange)
107 Alerts.WaitingStateAlert.TimeWentOutOfRange =
new DateTime();
109 Alerts.WaitingStateAlert.OutOfRange =
false;
116 _sender =
new BackgroundWorker();
117 _sender.DoWork +=
new DoWorkEventHandler(_sender_DoWork);
118 _sender.RunWorkerAsync(message);
123 String message = e.Argument.ToString();
125 if (!String.IsNullOrEmpty(message) && PhoneNumbers.Numbers.Count > 0)
127 foreach (Tools.PhoneNumber pn in PhoneNumbers.Numbers)
132 WebRequest request = WebRequest.Create(
"http://www.kapow.co.uk/scripts/sendsms.php");
134 request.Method =
"POST";
136 string postData =
"username=isissms&password=camacdead&mobile=" + pn.Number +
"&sms=" + message;
137 byte[] byteArray = Encoding.UTF8.GetBytes(postData);
139 request.ContentType =
"application/x-www-form-urlencoded";
141 request.ContentLength = byteArray.Length;
143 Stream dataStream = request.GetRequestStream();
145 dataStream.Write(byteArray, 0, byteArray.Length);
149 WebResponse response = request.GetResponse();
153 Seci.Helpers.ErrorLogger.SeciError(
"Alerts Manager", err);
174 Tools.AlertsBox newcopy =
new Tools.AlertsBox();
176 newcopy.WaitingStateAlert = copy.WaitingStateAlert;
179 foreach (String key
in copy.BlockLimitsAlerts.Keys)
182 if (
BlockMgr.
Blocks.
Contains(key) && String.IsNullOrEmpty(Alerts.BlockLimitsAlerts[key].OwningConfiguration))
184 newcopy.AddBlockAlert(copy.BlockLimitsAlerts[key].Blockname, copy.BlockLimitsAlerts[key].BlockType, copy.BlockLimitsAlerts[key].LowLimit, copy.BlockLimitsAlerts[key].HighLimit, copy.BlockLimitsAlerts[key].Enabled);
198 public static void AddComponentBox(Tools.AlertsBox master, Tools.AlertsBox toAdd, String compName)
206 if (toAdd.WaitingStateAlert != null && master.WaitingStateAlert == null)
208 master.WaitingStateAlert = toAdd.WaitingStateAlert;
209 master.WaitingStateAlert.OwningConfiguration = compName;
213 foreach (String key
in toAdd.BlockLimitsAlerts.Keys)
216 if (!master.BlockLimitsAlerts.ContainsKey(key))
218 master.BlockLimitsAlerts.Add(key, toAdd.BlockLimitsAlerts[key]);
219 master.BlockLimitsAlerts[key].OwningConfiguration = compName;
231 FileStream stream =
new FileStream(Seci.Definitions.Status.ConfigDir +
"\\" + PHONE_NUMBERS_FILENAME, FileMode.Create);
236 XmlSerializer serialize =
new XmlSerializer(typeof(Tools.PhoneNumbersList));
237 serialize.Serialize(stream, PhoneNumbers);
253 FileInfo fi =
new FileInfo(Seci.Definitions.Status.ConfigDir +
"\\" + PHONE_NUMBERS_FILENAME);
260 FileStream stream =
new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
264 XmlSerializer deserialize =
new XmlSerializer(typeof(Tools.PhoneNumbersList));
Boolean Contains(String blockName)
Wrapper for standard Dictionary "Contains" All keys are lowercase.
static Tools.PhoneNumbersList GetPhoneNumbersCopy()
static void sendMessage(String message)
static void SetPhoneNumbers(Tools.PhoneNumbersList numbers)
static BlockDictionary Blocks
static void _sender_DoWork(object sender, DoWorkEventArgs e)
static Tools.AlertsBox GetAlertsCopy()
The manager class for Block related stuff.
static void AddComponentBox(Tools.AlertsBox master, Tools.AlertsBox toAdd, String compName)
Method for adding another AlertsBox to the current AlertsBox, i.e. when loading a sub-configuration...
static void SetAlerts(Tools.AlertsBox alerts)
static BackgroundWorker _sender
static Tools.AlertsBox GetAlertsCopyForSaving()
static void ClearAlerts()
static void CheckInWaiting(Boolean waiting)
static void LoadPhoneNumbers()
static void SavePhoneNumbers()
static void CheckBlockInRange(Definitions.BlockInfo block)