void onSensorActiveStateChanged(object sender, EventArgs args) { SensorUserCtrl sender_ref = (SensorUserCtrl)sender; if (!sender_ref.Active && sender_ref.Fired) { if (speechAble) { string full_message = null; try { full_message = messages.Single(m => m.Contains(sender_ref.Message)); } catch (Exception) { } if (full_message != null) { try { speaker.SpeakAsyncCancelAll(); } catch (Exception) { } timer.Stop(); messages.Remove(full_message); timer.Start(); } } else { timer.Stop(); } } }
void BuildDevicesControls() { string xmlpath = ConfigurationManager.AppSettings["XMLConfigName"]; d = XDocument.Load(xmlpath); IEnumerable <XElement> l = d.Element("Devices").Elements("DeviceGroup"); foreach (XElement dg in l) { string pagekey = dg.Attribute("code").Value; string rname = dg.Attribute("name").Value; string dname = dg.Attribute("desciption").Value; bool local = Convert.ToBoolean(dg.Attribute("local").Value); bool dtmf = Convert.ToBoolean(dg.Attribute("dtmf").Value); bool pport = Convert.ToBoolean(dg.Attribute("pport").Value); Uri dtmf_add = null; Uri pport_add = null; try { if (local) { dtmf_add = new Uri(dg.Attribute("dtmf_address").Value); pport_add = new Uri(dg.Attribute("pport_address").Value); } }catch (Exception) { MessageBox.Show("Dirección de red no valida.\nVerifique el fichero de configuracion Devices.xml", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } TAB_alarmGroup.TabPages.Add(pagekey, rname, dname); int index = TAB_alarmGroup.TabPages.IndexOfKey(pagekey); var sg = new SensorGroupCtrl(pagekey, rname, dname, local, dtmf, pport, pport_add, dtmf_add); sg.lastContact = DateTime.Now; sg.Dock = DockStyle.Fill; sg.AutoScroll = true; ls.Add(sg); TAB_alarmGroup.TabPages[index].Controls.Add(sg); foreach (XElement x in dg.Elements("Device")) { var s = new SensorUserCtrl { Name = x.Attribute("name").Value, Active = (bool)x.Attribute("active"), Code = x.Attribute("code").Value, Message = x.Attribute("message").Value, DeviceType = x.Attribute("type").Value }; s.onActiveChange += onSensorActiveStateChanged; sg.AddSensor(s); } } }
public void AddSensor(SensorUserCtrl sensor) { this.FL_sensorContainer.Controls.Add(sensor); this.Sensors.Add(sensor); }
void OnRecive(string event_name, Uri sender, EventData[] data) { lock (reciv_lock) { SensorUserCtrl sens = null; SensorGroupCtrl g = ls.SingleOrDefault(sg => sender.ToString().Contains(sg.Code)); Action a; if (g != null) { g.lastContact = DateTime.Now; } else { return; } switch (event_name) { case "DTMF": sens = g.Sensors.SingleOrDefault(sns => sns.Code == data[1].Data_Val.ToString() && sns.DeviceType == "DTMF"); if (sens != null) { if (!sens.Fired && sens.Active) { RegisterEvent((DateTime)data[0].Data_Val, sens.Message, sens.Code, g, "DTMF", false); a = () => sens.Fired = true; this.Invoke(a); } else { RegisterEvent((DateTime)data[0].Data_Val, sens.Message, sens.Code, g, "DTMF", true); } } break; case "PSC": List <SensorUserCtrl> l = g.Sensors.Where(sns => sns.DeviceType == "PSC").ToList(); foreach (var s in l) { sens = s; string[] values = s.Code.Split(';'); int port = Math.Abs(888 - Convert.ToInt32(values[0].Substring("port:".Length, values[0].Length - "port:".Length))); int value = Convert.ToInt16(values[1].Substring("mask:".Length, values[1].Length - "mask:".Length)); int rest = Convert.ToInt16(values[2].Substring("rest:".Length, values[2].Length - "rest:".Length)); int incomingVal = (Convert.ToInt16(data[port + 1].Data_Val)); if (((incomingVal & value) / value) != rest) { if (!sens.Fired && sens.Active) { a = () => sens.Fired = true; this.Invoke(a); RegisterEvent((DateTime)data[0].Data_Val, sens.Message, sens.Code, g, "PSC", false); } else { RegisterEvent((DateTime)data[0].Data_Val, sens.Message, sens.Code, g, "PSC", true); } } else { if (sens.Fired && sens.Active) { a = () => sens.Fired = false; this.Invoke(a); RegisterEvent((DateTime)data[0].Data_Val, "Sensor " + sens.Name + " normalizado", sens.Code, g, "PSC", false); } } } break; case "ENDOR": a = () => g.Sensors.ForEach(s => s.Fired = true); this.Invoke(a); RegisterEvent((DateTime)data[0].Data_Val, "Detector Comprometido", sender.ToString(), g, "", false); break; } } }