private void TAB_alarmGroup_SelectedIndexChanged(object sender, EventArgs e) { String name = TAB_alarmGroup.SelectedTab.Name; SensorGroupCtrl sg = ls.Single(g => g.Code == name); if (sg.isLocal) { if (sg.IsDTMFActive) { LB_dtmfStatus.Text = "Sensores DTMF: Conectados."; } else { LB_dtmfStatus.Text = "Sensores DTMF: Desconectados."; } if (sg.IsPPortActive) { LB_PPortStatus.Text = "Sensores Puerto Paralelo: Conectados."; } else { LB_PPortStatus.Text = "Sensores Puerto Paralelo: Desconectados."; } } else { LB_dtmfStatus.Text = "Sensores DTMF: Remoto."; LB_PPortStatus.Text = "Sensores Puerto Paralelo: Remoto."; } }
private void RegisterEvent(DateTime sendTime, String Message, String Code, SensorGroupCtrl g, String Type, bool registerOnly) { EventsController c; lock (dbcontext) { try { c = new EventsController(dbcontext); c.RegisterNewEvent(new Event { Send_Date = sendTime, Reciv_Date = DateTime.Now, Messaje = Message, Code = Code, DeviceType = Type, SensorsInfo = d.Element("Devices").Elements("DeviceGroup").Single(x => x.Attribute("code").Value == g.Code).ToString(SaveOptions.DisableFormatting), SensorsGroup = new SensorsGroup { Name = g.CodeName, Address = g.Code, DescriptiveName = g.DesciptiveName } }, EventType.EventType_Detection); } catch (Exception e) { string s = e.Message; } } if (registerOnly) { return; } Action update = () => { TAB_alarmGroup.SelectedTab = TAB_alarmGroup.TabPages[g.Code]; TA_logArea.AppendText(g.DesciptiveName + ": " + DateTime.Now.ToShortTimeString() + " -->" + Message + ".Hora de Envío: " + sendTime.ToLongTimeString() + "\n"); }; this.Invoke(update); messages.Add(Message + ". Instancia, " + g.DesciptiveName); if (speechAble) { try { speaker.SpeakAsyncCancelAll(); speaker.SpeakAsync(Message + ". Instancia, " + g.DesciptiveName); } catch (Exception) { speechAble = false; } } if (!eventDetected) { eventDetected = true; if (doCall) { CAllProcedure(); calltimer.Enabled = true; calltimer.Start(); } } timer.Start(); }
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); } } }
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; } } }