/// <summary> /// проверка активности сенсоров /// </summary> public void CheckActivitySensor() { try { CoreICSM.Logs.CLogs.WriteInfo(ELogsWhat.Unknown, "CheckActivitySensor "); ClassDBGetSensor gsd = new ClassDBGetSensor(); BusManager <Sensor> busManager = new BusManager <Sensor>(); ClassDBGetSensor DB = new ClassDBGetSensor(); List <Sensor> L_S = DB.LoadObjectAllSensor(); DB.Dispose(); if (L_S != null) { if (L_S.Count > 0) { foreach (Sensor message in L_S.ToArray()) { busManager.SendDataObject(message, GlobalInit.Template_Event_CheckActivitySensor_Req + message.Name + message.Equipment.TechId, XMLLibrary.BaseXMLConfiguration.xml_conf._TimeExpirationTemp.ToString()); } } } { foreach (Sensor message in GlobalInit.SensorListSDRNS.ToArray()) { if (GlobalInit.Lst_timers.Find(t => t.se.Name == message.Name && t.se.Equipment.TechId == message.Equipment.TechId) == null) { Mdx RW = new Mdx(message); GlobalInit.Lst_timers.Add(RW); } } foreach (Mdx se in GlobalInit.Lst_timers.ToArray()) { if (ClassStaticBus.bus.Advanced.IsConnected) { uint MessCount = busManager.GetMessageCount(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId); for (int i = 0; i < MessCount; i++) { var message_x = busManager.GetDataObject(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId); if (message_x != null) { if ((message_x as Sensor).Name == se.se.Name && (message_x as Sensor).Equipment.TechId == se.se.Equipment.TechId) { se.Cnt_sensor_New++; se.Cnt_timer = 0; se.Cnt_all_time = 0; Sensor f = GlobalInit.SensorListSDRNS.Find(t => t.Name == se.se.Name && t.Equipment.TechId == se.se.Equipment.TechId); if (f != null) { se.Cnt_sensor_New++; f.Status = "A"; se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_Old = 0; se.BZ.Close(); se.BZ.Start(); gsd.UpdateStatusSensor(f); } else { se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_New = 0; } } } else { break; } } /* * GlobalInit.Lds_Activity_Sensor_Receiver.Add(ClassStaticBus.bus.Receive(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId, x => x * .Add<Sensor>(message_x => * { * if (message_x.Name == se.se.Name && message_x.Equipment.TechId == se.se.Equipment.TechId) { * se.Cnt_sensor_New++; se.Cnt_timer = 0; se.Cnt_all_time = 0; * Sensor f = GlobalInit.SensorListSDRNS.Find(t => t.Name == se.se.Name && t.Equipment.TechId == se.se.Equipment.TechId); * if (f != null) { * se.Cnt_sensor_New++; f.Status = "A"; se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_Old = 0; se.BZ.Close(); se.BZ.Start(); gsd.UpdateStatusSensor(f); * } * else { * se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_New = 0; * } * } * }))); */ } else { ClassStaticBus.bus.Dispose(); GC.SuppressFinalize(ClassStaticBus.bus); ClassStaticBus.bus = RabbitHutch.CreateBus(GlobalInit.MainRabbitMQServices); CoreICSM.Logs.CLogs.WriteInfo(CoreICSM.Logs.ELogsWhat.Unknown, "-> Bus dispose... "); } Sensor fc = GlobalInit.SensorListSDRNS.Find(t => t.Name == se.se.Name && t.Equipment.TechId == se.se.Equipment.TechId); if (fc != null) { if ((se.Cnt_timer >= BaseXMLConfiguration.xml_conf._CheckActivitySensor) && (se.Cnt_all_time < BaseXMLConfiguration.xml_conf._MaxTimeNotActivateStatusSensor)) { if (ClassStaticBus.bus.Advanced.IsConnected) { busManager.SendDataObject(se.se, GlobalInit.Template_Event_CheckActivitySensor_Req + se.se.Name + se.se.Equipment.TechId, XMLLibrary.BaseXMLConfiguration.xml_conf._TimeExpirationTask.ToString()); uint MessCount = busManager.GetMessageCount(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId); for (int i = 0; i < MessCount; i++) { var message_x = busManager.GetDataObject(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId); if (message_x != null) { if ((message_x as Sensor).Name == se.se.Name && (message_x as Sensor).Equipment.TechId == se.se.Equipment.TechId) { se.Cnt_sensor_New++; se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_Old = 0; se.BZ.Close(); se.BZ.Start(); } else { break; } } } /* * GlobalInit.Lds_Activity_Sensor_Receiver.Add(ClassStaticBus.bus.Receive(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId, x => x * .Add<Sensor>(message_x => * { * if (message_x.Name == se.se.Name && message_x.Equipment.TechId == se.se.Equipment.TechId) { * se.Cnt_sensor_New++; * se.Cnt_timer = 0; * se.Cnt_all_time = 0; * se.Cnt_sensor_Old = 0; * se.BZ.Close(); * se.BZ.Start(); * * } * }))); */ } else { ClassStaticBus.bus.Dispose(); GC.SuppressFinalize(ClassStaticBus.bus); ClassStaticBus.bus = RabbitHutch.CreateBus(GlobalInit.MainRabbitMQServices); CoreICSM.Logs.CLogs.WriteInfo(CoreICSM.Logs.ELogsWhat.Unknown, "-> Bus dispose... "); } fc.Status = AllStatusSensor.F.ToString(); se.Cnt_timer = 0; se.Cnt_sensor_New = 0; gsd.UpdateStatusSensor(fc); } else if ((se.Cnt_all_time >= BaseXMLConfiguration.xml_conf._MaxTimeNotActivateStatusSensor)) { bool isCheck = false; if (ClassStaticBus.bus.Advanced.IsConnected) { busManager.SendDataObject(se.se, GlobalInit.Template_Event_CheckActivitySensor_Req + se.se.Name + se.se.Equipment.TechId, XMLLibrary.BaseXMLConfiguration.xml_conf._TimeExpirationTask.ToString()); uint MessCount = busManager.GetMessageCount(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId); for (int i = 0; i < MessCount; i++) { var message_x = busManager.GetDataObject(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId); if (message_x != null) { if ((message_x as Sensor).Name == se.se.Name && (message_x as Sensor).Equipment.TechId == se.se.Equipment.TechId) { se.Cnt_sensor_New++; se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_Old = 0; se.BZ.Close(); se.BZ.Start(); isCheck = true; } else { break; } } } /* * GlobalInit.Lds_Activity_Sensor_Receiver.Add(ClassStaticBus.bus.Receive(GlobalInit.Template_Event_CheckActivitySensor_Resp + se.se.Name + se.se.Equipment.TechId, x => x * .Add<Sensor>(message_x => * { * if (message_x.Name == se.se.Name && message_x.Equipment.TechId == se.se.Equipment.TechId) { * se.Cnt_sensor_New++; se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_Old = 0; se.BZ.Close(); se.BZ.Start(); * isCheck = true; * } * }))); */ } else { ClassStaticBus.bus.Dispose(); GC.SuppressFinalize(ClassStaticBus.bus); ClassStaticBus.bus = RabbitHutch.CreateBus(GlobalInit.MainRabbitMQServices); CoreICSM.Logs.CLogs.WriteInfo(CoreICSM.Logs.ELogsWhat.Unknown, "-> Bus dispose... "); } if (!isCheck) { busManager.DeleteQueue(GlobalInit.Template_Event_CheckActivitySensor_Req + se.se.Name + se.se.Equipment.TechId); } if (!isCheck) { se.Cnt_sensor_Old++; } if ((se.Cnt_sensor_New == 0) || (se.Cnt_sensor_Old > 2)) { //------------ ДАННЫЙ МЕХАНИЗМ ПОКА ДЕАКТИВИРУЕМ (ПО ПРИЧИНЕ ИСПОЛЬЗОВАНИЯ СЕРВЕРА СТОРОННЕЙ ОРГАНИЗАЦИЕЙ) ---------------------- //------------ т.е. сенсор не должен удаляться из БД (он может быть активен или неактивен) //fc.Status = AllStatusSensor.Z.ToString(); se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_New = 0; se.Cnt_sensor_Old = 0; //gsd.UpdateStatusSensor(fc); //GlobalInit.SensorListSDRNS.RemoveAll(t => t.Name == fc.Name && t.Equipment.TechId == fc.Equipment.TechId); //se.BZ.Stop(); //---------------------------------- se.Cnt_timer = 0; se.Cnt_all_time = 0; se.Cnt_sensor_New = 0; se.Cnt_sensor_Old = 0; se.BZ.Stop(); busManager.DeleteQueue(GlobalInit.Template_Event_CheckActivitySensor_Req + se.se.Name + se.se.Equipment.TechId); } } } } } gsd.Dispose(); } catch (Exception ex) { Console.WriteLine("--> Error execute proc CheckActivitySensor " + ex.Message); } }
/// <summary> /// Метод, выполняющий проверку наличия данных о сенсорах в БД /// Если сенсоры в БД обнаружены - выполняется добавление данных в глобальный список SensorListSDRNS /// В случае, если в очереди GlobalInit.Template_SENSORS_List_ обнаружены сообщения, выполняется пересохранение объекта Sensor в БД /// Также, после обновления данных о сенсоре в БД осуществляется отправка уведомления(в виде объекта Sensor) на SDR /// /// </summary> public void ReceiveAllSensorList() { BusManager <Sensor> busManager = new BusManager <Sensor>(); //try { Task tsk = new Task(() => { if (GlobalInit.SensorListSDRNS.Count == 0) { ClassDBGetSensor DB = new ClassDBGetSensor(); List <Sensor> L_S = DB.LoadObjectSensor(); DB.Dispose(); if (L_S != null) { foreach (Sensor stx in L_S.ToArray()) { Sensor fnd = GlobalInit.SensorListSDRNS.Find(t => t.Name == stx.Name && t.Equipment.TechId == stx.Equipment.TechId); if (fnd != null) { GlobalInit.SensorListSDRNS.ReplaceAll <Sensor>(fnd, stx); } else { GlobalInit.SensorListSDRNS.Add(stx); } } } } if (ClassStaticBus.bus.Advanced.IsConnected) { uint cnt = busManager.GetMessageCount(GlobalInit.Template_SENSORS_List_); for (int i = 0; i < cnt; i++) { var message = busManager.GetDataObject(GlobalInit.Template_SENSORS_List_); if (message != null) { ClassDBGetSensor DB = new ClassDBGetSensor(); Sensor fnd_s = GlobalInit.SensorListSDRNS.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId); if (fnd_s == null) { bool isFindInDB = false; List <Sensor> L_S = DB.LoadObjectSensor((message as Sensor).Name, (message as Sensor).Equipment.TechId, "Z"); if (L_S != null) { if (L_S.Count > 0) { if (L_S[0].Name == (message as Sensor).Name) { if (L_S[0].Equipment != null) { if (L_S[0].Equipment.TechId == (message as Sensor).Equipment.TechId) { isFindInDB = true; GlobalInit.SensorListSDRNS.Add(L_S[0]); L_S[0].Status = "A"; DB.UpdateStatusSensorWithArchive(L_S[0]); } } } } } if (isFindInDB == false) { DB.CreateNewObjectSensor((message as Sensor)); //Отправка на SDR уведомления о приеме сообщения busManager.SendDataObject((message as Sensor), GlobalInit.Template_Event_Confirm_SENSORS_Send_ + (message as Sensor).Name + (message as Sensor).Equipment.TechId, XMLLibrary.BaseXMLConfiguration.xml_conf._TimeExpirationTask.ToString()); L_S = DB.LoadObjectSensor(); if (L_S.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId) != null) { Sensor fnd = GlobalInit.SensorListSDRNS.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId); if (fnd != null) { GlobalInit.SensorListSDRNS.ReplaceAll <Sensor>(fnd, L_S.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId)); } else { GlobalInit.SensorListSDRNS.Add(L_S.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId)); } } } } else { //Отправка на SDR уведомления о приеме сообщения DB.SaveLocationCoordSensor((message as Sensor)); busManager.SendDataObject((message as Sensor), GlobalInit.Template_Event_Confirm_SENSORS_Send_ + (message as Sensor).Name + (message as Sensor).Equipment.TechId, XMLLibrary.BaseXMLConfiguration.xml_conf._TimeExpirationTask.ToString()); List <Sensor> L_S = DB.LoadObjectSensor(); if (L_S.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId) != null) { Sensor fnd = GlobalInit.SensorListSDRNS.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId); if (fnd != null) { GlobalInit.SensorListSDRNS.ReplaceAll <Sensor>(fnd, L_S.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId)); } else { GlobalInit.SensorListSDRNS.Add(L_S.Find(t => t.Name == (message as Sensor).Name && t.Equipment.TechId == (message as Sensor).Equipment.TechId)); } } } DB.Dispose(); GC.Collect(); } else { break; } } } /* * GlobalInit.Lds_Activity_Sensor_List.Add(ClassStaticBus.bus.Receive<Sensor>(GlobalInit.Template_SENSORS_List_, * message => * { * ClassDBGetSensor DB = new ClassDBGetSensor(); * Sensor fnd_s = GlobalInit.SensorListSDRNS.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId); * if (fnd_s == null) * { * bool isFindInDB = false; * List<Sensor> L_S = DB.LoadObjectSensor(message.Name, message.Equipment.TechId, "Z"); * if (L_S != null) * { * if (L_S.Count > 0) * { * if (L_S[0].Name == message.Name) * { * if (L_S[0].Equipment != null) * { * if (L_S[0].Equipment.TechId == message.Equipment.TechId) * { * isFindInDB = true; * GlobalInit.SensorListSDRNS.Add(L_S[0]); * L_S[0].Status = "A"; * DB.UpdateStatusSensorWithArchive(L_S[0]); * } * } * } * } * } * if (isFindInDB == false) * { * DB.CreateNewObjectSensor(message); * //Отправка на SDR уведомления о приеме сообщения * BusManager<Sensor> busManager = new BusManager<Sensor>(); * busManager.SendDataObject(message, GlobalInit.Template_Event_Confirm_SENSORS_Send_ + message.Name + message.Equipment.TechId, XMLLibrary.BaseXMLConfiguration.xml_conf._TimeExpirationTask.ToString()); * L_S = DB.LoadObjectSensor(); * if (L_S.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId) != null) * { * Sensor fnd = GlobalInit.SensorListSDRNS.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId); * if (fnd != null) * GlobalInit.SensorListSDRNS.ReplaceAll<Sensor>(fnd, L_S.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId)); * else GlobalInit.SensorListSDRNS.Add(L_S.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId)); * } * } * } * else * { * //Отправка на SDR уведомления о приеме сообщения * DB.SaveLocationCoordSensor(message); * BusManager<Sensor> busManager = new BusManager<Sensor>(); * busManager.SendDataObject(message, GlobalInit.Template_Event_Confirm_SENSORS_Send_ + message.Name + message.Equipment.TechId, XMLLibrary.BaseXMLConfiguration.xml_conf._TimeExpirationTask.ToString()); * List<Sensor> L_S = DB.LoadObjectSensor(); * if (L_S.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId) != null) * { * Sensor fnd = GlobalInit.SensorListSDRNS.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId); * if (fnd != null) * GlobalInit.SensorListSDRNS.ReplaceAll<Sensor>(fnd, L_S.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId)); * else GlobalInit.SensorListSDRNS.Add(L_S.Find(t => t.Name == message.Name && t.Equipment.TechId == message.Equipment.TechId)); * } * } * DB.Dispose(); * })); */ else { ClassStaticBus.bus.Dispose(); GC.SuppressFinalize(ClassStaticBus.bus); ClassStaticBus.bus = RabbitHutch.CreateBus(GlobalInit.MainRabbitMQServices); CoreICSM.Logs.CLogs.WriteInfo(CoreICSM.Logs.ELogsWhat.Unknown, "-> Bus dispose... "); } }); tsk.Start(); //tsk.Wait(); //} //catch (Exception ex) { //CoreICSM.Logs.CLogs.WriteError(ELogsWhat.Unknown, "[ReceiveAllSensorList]:" + ex.Message); //} }