private void RadarFailureAlarm(AlarmData alarmData) { _synchContext.Post(a => { try { RadarAlarm radarAlarm = new RadarAlarm(); bool isalarm = radarAlarm.ProcessAlarm(alarmData); if (isalarm) { if (报警声音ToolStripMenuItem.Checked && _isCollect) { _soundAlarm.StartAlarm(AppDomain.CurrentDomain.BaseDirectory + "Alarm.wav"); } toolStripStatusLabel1.Image = Resources.red_light; Activate(); } else { toolStripStatusLabel1.Image = Resources.green_light; } } catch (Exception ex) { CommonLogHelper.GetInstance("LogError").Error(@"雷达故障报警过程出错", ex); } }, null); }
public JsonResult Get(AlarmData alarmData) { IAlarm alarmService; var alarmData2 = alarmData; if (alarmData2.AlarmId == Guid.Parse("aafea53a-3705-42ea-885a-e9bdf308ae31")) { alarmService = Mocks.For.AlarmSerice; alarmData2 = new AlarmData { AlarmId = Guid.NewGuid(), ArrivalTime = new DateTime(2018, 6, 8, 9, 30, 0), FromLat = 51.525246, FromLong = 0.084672, ToLat = 51.559098, ToLong = 0.074503 }; } else { alarmService = new AlarmService(new CityMapperClient()); } var alarmRequest = alarmService.CreateAlarm(alarmData2); return(new JsonResult(alarmRequest)); }
bool AcceptAdd() { if (AlarmToAddMarker == null) { ShowToast(Resource.String.click_on_map_to_set_alarm); return(false); } else if (string.IsNullOrEmpty(_alarmNameEditText.Text)) { _alarmNameEditText.RequestFocus(); _alarmNameEditText.SetError(Html.FromHtml(string.Format("<font color='#9933cc'>{0}</font>", Resources.GetString(Resource.String.enter_alarm_name))), null); return(false); } else { var radius = Constants.AlarmRadiusValues [_alarmRadiusSpinner.SelectedItemPosition]; var newAlarm = new AlarmData() { Latitude = AlarmToAddMarker.Position.Latitude, Longitude = AlarmToAddMarker.Position.Longitude, Radius = radius, Name = _alarmNameEditText.Text, Enabled = true, RequestId = string.Format("{0};{1}_{2}", AlarmToAddMarker.Position.Latitude, AlarmToAddMarker.Position.Longitude, random.NextDouble()) }; AddGeofence(newAlarm); return(true); } }
void Start() { //Screen.fullScreen = false; instance = this; EditingAlarmParam = new AlarmParam(); m_iPagePre = 0; string key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwoEtQFcqjLFQJ0wXu8mkFjowH8t4I7tcG1G6Ais7Vx8qZWYidwNPzdp2pvPCQS4/BZDgtRyk1+FsPbaCOndof2e4OlVmdlGUXVQOtJl5hT40xxmlotliBG9IzO1A5Huvy0tjv2pQ6Et0g72k1qxJPFI1O/L7mzQDHPzawYEqHv47U/yGD1GTE6jHK0u1apgxUI89UJsiYIhVlwdZ40390LGWAR8+LrUhk+q//NYjxfKBd3fotgV4QZecNPQks1fz9bk5oWOwOpOz2pQ3aZ62RInlueAk8ttsfow6+M4rmdfBDVGOkVKgScwhBjeCAcsXQaO+qwWdr1GhLPNuYck39wIDAQAB"; GoogleIAB.init(key); if (m_AlarmData == null) { m_AlarmData = new AlarmData(); } reserveTimeReset(); kvs_data.Load(KvsData.FILE_NAME); int iTest = kvs_data.ReadInt("test"); iTest += 1; kvs_data.WriteInt("test", iTest); kvs_data.Save(); m_PageNow = m_PageBaseList [m_iPagePre]; InitPage(m_PageNow); }
public void SetAlarms(DataTable AlarmsTable) { this.alarmData.Clear(); foreach (DataRow row in AlarmsTable.Rows) { var newData = new AlarmData(); newData.Alarm0 = Convert.ToString(AlarmsTable.Rows[currentRow]["Alarm0"]);
//static AlarmData oldData = null; private void MyEvent(object sender) { try { if (sender == null) { return; } byte[] date = sender as byte[]; string strMsg = Encoding.Default.GetString(date, 0, date.Length);// 将接受到的字节数据转化成字符串; //SuperFramework.SuperFile.FileRWHelper<VibrationOpticalFibersHKYR>.AppendText("c:\\123.txt", strMsg); strMsg = strMsg.Replace("\n", ""); AlarmData data = SuperFramework.SuperConvert.JSONHelper.JsonToObject <AlarmData>(strMsg); if (data != null) { //if (oldData != null) //{ // if (oldData.section != data.section && oldData.action != data.action) // Alarm?.Invoke(data); //} //else Alarm?.Invoke(data); } //oldData = data; } catch (Exception) { } checkTime = DateTime.Now; }
public MainClass() { _handler += new MainClass.EventHandler(Handler); AppDomain.CurrentDomain.ProcessExit += (s, e) => { OnProcessExit(s, new EventType { msg = "Quit" }); }; SetConsoleCtrlHandler(_handler, true); settings = new SettingsData(); controller = new Controller(settings); Sheet = new GSheet(controller); RigEx.WriteLineColors($"servise:\tGoogle Sheet\t- {Sheet != null}".AddTimeStamp(), Sheet != null ? ConsoleColor.DarkGreen : ConsoleColor.Red); bool initBiosDone = controller.TelegramUser.Any() && controller.ServerList.Any(); RigEx.WriteLineColors($"servise:\tGoogle Reader\t- {initBiosDone}".AddTimeStamp(), initBiosDone ? ConsoleColor.DarkGreen : ConsoleColor.Red); sensors = new SensorService(controller); RigEx.WriteLineColors($"servise:\tSensors\t\t- {sensors != null}".AddTimeStamp(), sensors != null ? ConsoleColor.DarkGreen : ConsoleColor.Red); alarmSensors = new AlarmData(controller); RigEx.WriteLineColors($"servise:\tAlarmSensors\t- {alarmSensors != null}".AddTimeStamp(), alarmSensors != null ? ConsoleColor.DarkGreen : ConsoleColor.Red); tbot = new TelegramBot(controller); RigEx.WriteLineColors($"servise:\tTelegramBot\t- {tbot != null}".AddTimeStamp(), tbot != null ? ConsoleColor.DarkGreen : ConsoleColor.Red); difficulty = new MineDifficulty(controller); RigEx.WriteLineColors($"servise:\tWhat To Mine\t- {difficulty != null}".AddTimeStamp(), difficulty != null ? ConsoleColor.DarkGreen : ConsoleColor.Red); miner = new Miner(controller); RigEx.WriteLineColors($"servise:\tMiner \t- {miner != null}".AddTimeStamp(), miner != null ? ConsoleColor.DarkGreen : ConsoleColor.Red); }
private async Task SendAlarmWithThrottling(AlarmData alarmData) { if (alarmData.lastUpdated.Elapsed >= deviceStateUpdateInterval) { Trace.WriteLine($"[{cameraName}]Refreshing alarm {alarmData.CameraContruct.Id} in HS as {alarmData.lastUpdated.Elapsed} passed"); await SendAlarm(alarmData.CameraContruct, alarmData).ConfigureAwait(false); } }
public void ClockDataCollectionTest_SortByClosestRingingMoment() { // Arrange var f = new MainForm(); var td1 = new TimerData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "t1", GroupName = "test", CurrentTimeSpan = TimeSpan.FromMinutes(60) }; var td2 = new TimerData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "t2", CurrentTimeSpan = TimeSpan.FromMinutes(50) }; var td3 = new TimerData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "t3", CurrentTimeSpan = TimeSpan.FromMinutes(20) }; var ad4 = new AlarmData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "a4", CurrentDateTime = DateTime.Now + TimeSpan.FromMinutes(40) }; var ad5 = new AlarmData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "a5", CurrentDateTime = DateTime.Now + TimeSpan.FromMinutes(1000) }; // Act f.MyDataFile.ClockMCollection.IsUnsavedLocked = true; f.MyDataFile.ClockMCollection.AddClocks(td1, td2, td3, ad4, ad5); f.MyDataFile.ClockMCollection.IsUnsavedLocked = false; td1.StartOrStop(); td2.StartOrStop(); td3.StartOrStop(); ad4.ActivateOrDeactivate(); f.MyDataFile.ClockMCollection.AutosortMode = AutosortMode.ClosestRingingMoment; f.MyDataFile.ClockMCollection.SortByClosestRingingMoment(); // order changed Assert.AreEqual(td3, f.MyDataFile.ClockMCollection.Ms[0]); Assert.AreEqual(ad4, f.MyDataFile.ClockMCollection.Ms[1]); Assert.AreEqual(td2, f.MyDataFile.ClockMCollection.Ms[2]); Assert.AreEqual(td1, f.MyDataFile.ClockMCollection.Ms[3]); Assert.AreEqual(ad5, f.MyDataFile.ClockMCollection.Ms[4]); Assert.IsTrue(f.MyDataFile.ClockMCollection.IsUnsaved); }
public void CopyToAlarmData(AlarmData alarmData) { alarmData.id = id; alarmData.ErrorCode = ErrorCode; alarmData.ErrorDes = ErrorDes; alarmData.DeviceInfo = DeviceInfo; alarmData.CreateDate = CreateDate; alarmData.CreateTime = CreateTime; alarmData.HasHandle = HasHandle; }
public void LoadAlarm() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(PATH, FileMode.Open); AlarmData data = (AlarmData)bf.Deserialize(file); Alarmes.wActive = data.wActive; Alarmes.aActive = data.aActive; file.Close(); }
public void AlarmDataTest_ctor() { // Arrange var f = new MainForm(); var ad = new AlarmData(f.MyDataFile, f.MyDataFile.MultiAudioPlayer); // Assert Assert.IsFalse(ad.IsUnsavedLocked); Assert.IsFalse(ad.IsUnsaved); }
private Task SyncHistoryAlarm() { return(Task.Run(async() => { logger.Polling.Info($"Start Sync History Alarm"); var existAlarmData = new List <AlarmData>(); var existEnclosureAlarmData = EnclosureConnector.Instance.GetExistAlarmDatas(this.FusionDirectorIp); var existServerAlarmData = ServerConnector.Instance.GetExistAlarmDatas(this.FusionDirectorIp); existAlarmData.AddRange(existEnclosureAlarmData); existAlarmData.AddRange(existServerAlarmData); logger.Polling.Info($"Get exist events success:[Enclosure:{existAlarmData.Count}] Server:{existServerAlarmData.Count}"); int totalPage = 1; int startPage = 0; var allVaildEvent = new List <EventSummary>(); while (startPage < totalPage) { try { startPage++; var filter = "(EventView='CurrentAlert')"; //"(EventOrder='FirstOccurTime desc')" var result = await eventService.GetEventListCollectionAsync(100, (startPage - 1) * 100, filter, "(EventOrder=First_Occur_Time asc)"); totalPage = (result.MembersCount - result.MembersCount % 100) / 100 + 1; var validList = result.Members.Where(x => x.EventCategory == "BMC" || x.EventCategory == "Enclosure").ToList(); allVaildEvent.AddRange(validList); logger.Polling.Info($"SyncHistoryAlarm Success:[TotalCount:{result.Members.Count}] VaildCount:{validList.Count} Enclosure:{validList.Count(x => x.EventCategory == "Enclosure")} BMC:{validList.Count(x => x.EventCategory == "BMC")} Switch:{validList.Count(x => x.EventCategory == "Switch")} "); foreach (var eventSummary in validList) { try { var alarm = new AlarmData(eventSummary); var existAlarm = existAlarmData.FirstOrDefault(x => x.Sn == alarm.Sn); //对比本次列表中的告警和已存在的告警,如果不同再去插入 if (existAlarm == null || !CompareAlarmData(alarm, existAlarm)) { var info = await eventService.GetEventsInfoAsync(eventSummary.SerialNumber.ToString()); AlarmDatas.Enqueue(new AlarmData(info)); } } catch (Exception e) { OnPollingError($"GetEventsInfoAsync Error. EventID:{eventSummary.EventID}.", e); } } } catch (Exception ex) { OnPollingError($"SyncHistoryAlarm Error.pageNo:{startPage}.", ex); } } //检查未关闭的告警,在本次历史告警查询中是否存在,不存在则关闭 EnclosureConnector.Instance.CheckUnclosedAlert(this.FusionDirectorIp, allVaildEvent.Select(x => x.SerialNumber.ToString()).ToList()); ServerConnector.Instance.CheckUnclosedAlert(this.FusionDirectorIp, allVaildEvent.Select(x => x.SerialNumber.ToString()).ToList()); })); }
public void SetData(AlarmData data, int index, Action <int> clickAction) { MiniSlotTitle.text = data.Title; MiniSlotDate.text = data.DateStr; SlotIndex = index; ClickAction = clickAction; CommonFunc.SetImageFile(TextureCacheManager.Instance.GetTexture(data.ContentURL), ref BigSlotImg); RefreshSlot(); }
public void ClockDataCollectionTest_Equals() { // Arrange var f = new MainForm(); var td1 = new TimerData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "t1", GroupName = "test", CurrentTimeSpan = TimeSpan.FromMinutes(60) }; var td2 = new TimerData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "t2", CurrentTimeSpan = TimeSpan.FromMinutes(50) }; var td3 = new TimerData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "t3", CurrentTimeSpan = TimeSpan.FromMinutes(20) }; var ad4 = new AlarmData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "a4", CurrentDateTime = DateTime.Now + TimeSpan.FromMinutes(40) }; var ad5 = new AlarmData(f.MyDataFile, f.MultiAudioPlayer) { Tag = "a5", CurrentDateTime = DateTime.Now + TimeSpan.FromMinutes(1000) }; // Act f.MyDataFile.ClockMCollection.IsUnsavedLocked = true; f.MyDataFile.ClockMCollection.AddClocks(td1, td2, td3, ad4, ad5); f.MyDataFile.ClockMCollection.IsUnsavedLocked = false; var cc = new ClockMCollection(f.MyDataFile); cc.Groups = f.MyDataFile.ClockMCollection.Groups; cc.AddClocks(td1, td2, td3, ad4, ad5); Assert.AreEqual(f.MyDataFile.ClockMCollection, cc); cc.RemoveAllClocks(); cc.Groups = f.MyDataFile.ClockMCollection.Groups; cc.AddClocks(td2, td1, td3, ad4, ad5); Assert.AreNotEqual(f.MyDataFile.ClockMCollection, cc); }
public void AlarmDataTest_CurrentDateTime_change() { // Arrange var f = new MainForm(); var ad = new AlarmData(f.MyDataFile, f.MyDataFile.MultiAudioPlayer); object val = ad.CurrentDateTime; // Assert Assert.AreEqual(ad.CurrentDateTime, ad.CurrentValue); }
protected void AddGeofence(AlarmData alarm) { Log.Debug(TAG, "AddGeofence"); lock (_changesToProceed) { _changesToProceed.Add(Tuple.Create(ActionOnAlarm.Add, alarm)); } ProcessNextChange(); }
protected void AddGeofence(AlarmData alarm) { Log.Debug(TAG, "AddGeofence"); lock (_changesToProceed) { _changesToProceed.Add(Tuple.Create(ActionOnAlarm.Add, alarm)); } ProcessNextChange(); }
public void AlarmDataTest_EnableOrDisable() { // Arrange var f = new MainForm(); var ad = new AlarmData(f.MyDataFile, f.MyDataFile.MultiAudioPlayer); ad.Enabled = false; ad.EnableOrDisable(); // Assert Assert.IsTrue(ad.Enabled); }
protected void EnableAlarm(AlarmData alarm, bool enabled) { alarm.Enabled = enabled; if (enabled) { AddGeofence(alarm); } else { RemoveGeofence(alarm, ActionOnAlarm.Disable); } }
public List <AlarmData> GetHisDatabases() { List <AlarmData> fake = new List <AlarmData>(); List <AlramInfoModel> hisDataBaseModels = BodSqliteHelp.SelectAlramInfo(); foreach (var item in hisDataBaseModels) { AlarmData hisDatabase = new AlarmData(); item.CopyToAlarmData(hisDatabase); fake.Add(hisDatabase); } return(fake); }
public void SaveAlarm() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(PATH); AlarmData data = new AlarmData { wActive = Alarmes.wActive, aActive = Alarmes.aActive, }; bf.Serialize(file, data); file.Close(); }
/// <summary> /// Tests the update task. /// </summary> /// <param name="data">The data.</param> public void TestUpdateTask(AlarmData data) { var fdList = FusionDirectorDal.Instance.GetList(); if (fdList != null) { this.OnLog($"fdList Count :{fdList.Count}"); foreach (var x in fdList) { var instance = this.FindInstance(x); instance.DealNewAlarm(data); } } }
public void DeleteAlarm (AlarmData alarmData) { List<AlarmData> newAlarms = null; using (var connection = CreateConnection ()) { lock (_lockObject) { var alarm = connection.Table<AlarmData> ().FirstOrDefault (a => a.Latitude == alarmData.Latitude && a.Longitude == alarmData.Longitude); connection.Delete (alarm); newAlarms = connection.Table<AlarmData> ().ToList (); } } OnDataUpdated (newAlarms); }
public void DeleteAlarm(AlarmData alarmData) { List <AlarmData> newAlarms = null; using (var connection = CreateConnection()) { lock (_lockObject) { var alarm = connection.Table <AlarmData> ().FirstOrDefault(a => a.Latitude == alarmData.Latitude && a.Longitude == alarmData.Longitude); connection.Delete(alarm); newAlarms = connection.Table <AlarmData> ().ToList(); } } OnDataUpdated(newAlarms); }
public static void GatherAlarmData(SAlarmEvent almEV, short clientNo) { AlarmData alm = new AlarmData(); alm.time = DateTime.Now; alm.isOnOff = almEV.begin; alm.alarmNo = almEV.alarmNo; alm.alarmTxt = System.Text.Encoding.Default.GetString(almEV.alarmText).Trim('\0'); LineDevice.CNC result = MainForm.cnclist.Find( delegate(LineDevice.CNC temp) { return(temp.HCNCShareData.sysData.clientNo == clientNo); } ); if (result != null) { if (MainForm.m_CheckHander != null && MainForm.m_CheckHander.AlarmSendDataEvenHandle != null) { EquipmentCheck.AlarmSendData SendMeg = new EquipmentCheck.AlarmSendData(); // SendMeg.alardat = new ScadaHncData.AlarmData(); SendMeg.NeedFindTeX = false; SendMeg.BujianID = result.BujianID; SendMeg.alardat = alm; MainForm.m_CheckHander.AlarmSendDataEvenHandle.BeginInvoke(null, SendMeg, null, null); } if (result.HCNCShareData.alarmList.Count == result.HCNCShareData.AlmLstLen) { result.HCNCShareData.alarmList.RemoveRange(0, result.HCNCShareData.AlmLstLen / 2); } UpdateCurrentAlarmLst(result.HCNCShareData, alm); } else if (PLCDataShare.m_plclist != null && PLCDataShare.m_plclist.Count > 0 && PLCDataShare.m_plclist[0].m_hncPLCCollector != null && clientNo == Collector.CollectHNCPLC.m_clientNo)//HNC8 PLC报警 { if (MainForm.m_CheckHander != null && MainForm.m_CheckHander.AlarmSendDataEvenHandle != null) { EquipmentCheck.AlarmSendData SendMeg = new EquipmentCheck.AlarmSendData(); // SendMeg.alardat = new ScadaHncData.AlarmData(); SendMeg.NeedFindTeX = false; SendMeg.BujianID = PLCDataShare.m_plclist[0].m_hncPLCCollector.EQUIP_CODE; SendMeg.alardat = alm; MainForm.m_CheckHander.AlarmSendDataEvenHandle.BeginInvoke(null, SendMeg, null, null); } } }
/// <summary> /// The insert event. /// </summary> /// <param name="alarmData">The alarm data.</param> public void InsertEvent(AlarmData alarmData) { Task.Run(() => { try { var serverType = this.GetServerType(alarmData.NeDN); HWLogger.NOTIFICATION_PROCESS.Info($"Start InsertEvent {alarmData.NeDN}"); var alertModel = new EventData(alarmData); switch (serverType) { case ServerTypeEnum.Blade: BladeConnector.Instance.InsertEvent(alertModel); break; case ServerTypeEnum.ChildBlade: BladeConnector.Instance.InsertChildBladeEvent(alertModel); break; case ServerTypeEnum.Highdensity: HighdensityConnector.Instance.InsertEvent(alertModel); break; case ServerTypeEnum.ChildHighdensity: HighdensityConnector.Instance.InsertChildBladeEvent(alertModel); break; case ServerTypeEnum.Rack: RackConnector.Instance.InsertEvent(alertModel); break; case ServerTypeEnum.KunLun: KunLunConnector.Instance.InsertEvent(alertModel); break; } HWLogger.NOTIFICATION_PROCESS.Info($"End InsertEvent {alarmData.NeDN}"); } catch (Exception ex) { HWLogger.UI.Error("InsertEvent Error: ", ex); } }); }
// 기타알림 정보 파이어베이스에서 로드 public void GetAlarmData() { Debug.Log("GetAlarmData Start"); mDatabaseRef.Child("Alarm").OrderByKey().LimitToLast(4) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { // Handle the error... } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; if (snapshot != null && snapshot.Exists) { foreach (var tempChild in snapshot.Children) { int tempIndex = Convert.ToInt32(tempChild.Key); var tempData = tempChild.Value as Dictionary <string, object>; var tempTitle = tempData["Title"].ToString(); var tempContent = tempData["Content"].ToString(); var tempDate = tempData["Date"].ToString(); DateTime date = new DateTime(); if (DateTime.TryParseExact(tempDate, "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out date)) { AlarmData alarmData = new AlarmData(tempTitle, date, tempContent); DataManager.Instance.AddAlarmData(alarmData); TextureCacheManager.Instance.AddLoadImageURL(tempContent); } else { Debug.LogFormat("GetAlarmData 날짜 형식이 맞지 않습니다 {0}", tempDate); } } } else { } Debug.Log("GetAlarmData End"); AddFirstLoadingComplete(); } } ); }
public void SetAlarmClock(string id, DateTime tarDate, Action cb) { for (int i = 0; i < alarmClock.Count; i++) { if (alarmClock[i].id == id) { alarmClock[i].date = tarDate; alarmClock[i].cb = cb; return; } } AlarmData alarm = new AlarmData(); alarm.id = id; alarm.date = tarDate; alarm.cb = cb; alarmClock.Add(alarm); }
public void AlarmDataTest_Enabled_change() { var f = new MainForm(); var ad = new AlarmData(f.MyDataFile, f.MyDataFile.MultiAudioPlayer); ad.Enabled = false; bool pass = false; ad.EnabledChanged += delegate(object sender, ClockEventArgs e) { pass = e.Clock.Enabled; }; ad.Enabled = true; Assert.IsTrue(pass); }
protected void RemoveGeofence(AlarmData alarm, ActionOnAlarm action) { Log.Debug(TAG, "RemoveGeofence"); lock (_changesToProceed) { // if alarm in queue to be added should be removed var alarmFromQueueToAdd = _changesToProceed.FirstOrDefault(a => a.Item1 == ActionOnAlarm.Add && a.Item2.Latitude == alarm.Latitude && a.Item2.Longitude == alarm.Longitude); if (alarmFromQueueToAdd != null && (!_isProcessing || _changesToProceed.IndexOf(alarmFromQueueToAdd) > 0)) { _changesToProceed.Remove(alarmFromQueueToAdd); return; } _changesToProceed.Add(Tuple.Create(action, alarm)); } ProcessNextChange(); }
protected void RemoveGeofence(AlarmData alarm, ActionOnAlarm action) { Log.Debug(TAG, "RemoveGeofence"); lock (_changesToProceed) { // if alarm in queue to be added should be removed var alarmFromQueueToAdd = _changesToProceed.FirstOrDefault(a => a.Item1 == ActionOnAlarm.Add && a.Item2.Latitude == alarm.Latitude && a.Item2.Longitude == alarm.Longitude); if (alarmFromQueueToAdd != null && (!_isProcessing || _changesToProceed.IndexOf(alarmFromQueueToAdd) > 0)) { _changesToProceed.Remove(alarmFromQueueToAdd); return; } _changesToProceed.Add(Tuple.Create(action, alarm)); } ProcessNextChange(); }
void ShowNotification(AlarmData alarm) { var builder = new NotificationCompat.Builder(this); builder.SetSmallIcon(Resource.Drawable.marker_violet) .SetContentTitle(alarm.Name) .SetContentText(GetString(Resource.String.app_name)) .SetAutoCancel(false) .AddAction(Resource.Drawable.ic_action_volume_muted, GetString(Resource.String.stop_noise), PendingIntent.GetService(this, 0, new Intent(this, typeof(UIWhileRingingIntentService)).SetAction(StopAlarmAction), 0)); var intent = new Intent(this, typeof(AlarmScreen)) .SetFlags(ActivityFlags.NewTask) .PutExtra(Constants.AlarmsData_Extra, JsonConvert.SerializeObject(alarm)); builder.SetContentIntent(PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent)); StartForeground(_notificationId, builder.Build()); }
public void AddAlarm (AlarmData alarm) { List<AlarmData> newAlarms = null; using (var connection = CreateConnection ()) { lock (_lockObject) { var existingAlarm = connection.Table<AlarmData> ().FirstOrDefault (a => a.RequestId.Equals (alarm.RequestId)); if (existingAlarm == null) { connection.Insert (alarm); } else { existingAlarm.Enabled = alarm.Enabled; connection.Update (existingAlarm); } newAlarms = connection.Table<AlarmData> ().ToList (); } } OnDataUpdated (newAlarms); }
public Task<object> AddCCTVAsync(string url,string username,string pasword,AlarmData adata) { slSecure.Controls.CCTVLock1 cctv = new Controls.CCTVLock1(url, username, pasword,true) { Width = 320, Height = 240, Margin = new Thickness(10) }; //new slSecure.Controls.CCTVLock(new Random().Next(1,40)) { Width = 250, Height =200, Margin = new Thickness(10) }; System.Threading.Tasks.TaskCompletionSource<object> source = new TaskCompletionSource<object>(); cctv.DataContext = adata; cctv.Click += cctv_Click; //Dispatcher.BeginInvoke(() => // { this.lstCCTVLock.Children.Insert(0, cctv); //}); source.SetResult(new object()); return source.Task; }
void item_ItemDegreeChanged(Item sender, int? NewValue) { SecureDBEntities1 db = new SecureDBEntities1(); if (NewValue == 2 && sender.AlarmMode=="Y") { AlarmData data=new AlarmData() { TimeStamp = DateTime.Now, AlarmType = AlarmType.RTU, ColorString = "Red", Description = sender.ItemConfig.ItemName+"警報", PlaneID = sender.PlaneID, IsForkCCTVEvent = false, PlaneName =Global.GetPlaneNameByPlaneID(sender.PlaneID) // CCTVBindingData =cctv.ToBindingData( }; if(!(sender.ItemConfig.Suppress??false)) Program.MyServiceObject.DispatchAlarmEvent(data); int typecode = 0; switch(sender.ItemType) { case "AI": typecode=3; break; case "DI": typecode=0; break; } tblAlarmLog tblalarmlog = new tblAlarmLog() { ControlID = sender.ItemConfig.ControlID, ItemID = sender.ItemID, Timestamp = DateTime.Now, TypeID = 5, TypeCode = (short)typecode, Value = sender.Value }; db.tblAlarmLog.Add(tblalarmlog); } else if (NewValue == 1 && sender.ItemType == "AI" && sender.AlarmMode == "Y") { int typecode = 0; switch (sender.ItemType) { case "AI": typecode = 2; break; //case "DI": // typecode = 1; // break; } tblAlarmLog tblalarmlog = new tblAlarmLog() { ControlID = sender.ItemConfig.ControlID, ItemID = sender.ItemID, Timestamp = DateTime.Now, TypeID = 5, TypeCode = (short)typecode, Value = sender.Value }; db.tblAlarmLog.Add(tblalarmlog); } if (NewValue == 0) { sender.ItemConfig.Suppress = false; tblItemConfig item = db.tblItemConfig.Where(n => n.ItemID == sender.ItemID).FirstOrDefault(); if (item != null) item.Suppress = false; } if( NewValue==0 && sender.AlarmMode=="Y") { int typecode=0; switch(sender.ItemType) { case "AI": typecode=4; break; case "DI": typecode=1; break; } tblAlarmLog tblalarmlog = new tblAlarmLog() { ControlID = sender.ItemConfig.ControlID, ItemID = sender.ItemID, Timestamp = DateTime.Now, TypeID = 5, TypeCode = (short)typecode, Value = sender.Value }; db.tblAlarmLog.Add(tblalarmlog); } tblItemConfig tbl = db.tblItemConfig.Where(n => n.ItemID == sender.ItemID).FirstOrDefault(); if (tbl != null) { tbl.Degree = NewValue; } db.SaveChanges(); db.Dispose(); }
public void SecureAlarm(AlarmData alarmdata) { throw new NotImplementedException(); }
void cardreader_OnStatusChanged(ICardReader reader, CardReaderEventReport rpt) { try { if (rpt.Status == (int)CardReaderStatusEnum.卡號連續錯誤 && this.EventInvalidCardAlarm || rpt.Status == (int)CardReaderStatusEnum.外力破壞 && this.EventExternalForceAlarm || rpt.Status == (int)CardReaderStatusEnum.異常入侵 && this.EventIntrusionAlarm || rpt.Status == (int)CardReaderStatusEnum.開門超時 && this.EventDoorOpenOverTimeAlarm || rpt.Status == (int)CardReaderStatusEnum.開鎖 && this.EventDoorOpenAlarm || rpt.Status == (int)CardReaderStatusEnum.號碼錯誤 && this.R23InvalidCardAlarm ) { if (this.OnAlarmEvent != null) { ICCTV cctv = (ICCTV)SecureService.cctv_mgr[reader.TriggerCCTVID]; AlarmData data = new AlarmData() { TimeStamp = DateTime.Now, AlarmType = AlarmType.Secure, ColorString = "Red", Description = reader.ControllerID + "," + rpt.StatusString, PlaneID = reader.PlaneID, IsForkCCTVEvent = true, PlaneName = Global.GetPlaneNameByPlaneID(reader.PlaneID), CCTVBindingData = cctv!=null?cctv.ToBindingData():null }; this.OnAlarmEvent(reader, data); } } if (rpt.Status == (int)CardReaderStatusEnum.開鎖 || rpt.Status == (int)CardReaderStatusEnum.按鈕開門 || rpt.Status == (int)CardReaderStatusEnum.密碼開門 || rpt.Status == (int)CardReaderStatusEnum.系統開門 || rpt.Status == (int)CardReaderStatusEnum.異常入侵 || rpt.Status == (int)CardReaderStatusEnum.開門超時) { SecureDBEntities1 db = new SecureDBEntities1(); tblEngineRoomLog log = new tblEngineRoomLog() { ControlID = reader.ControllerID, ABA = rpt.CardNo.ToString(), StartTime = DateTime.Now, TypeID = 8, Memo = rpt.StatusString, TypeCode = (short)rpt.Status, ERNo = reader.PlaneID.ToString() }; db.tblEngineRoomLog.Add( log ); db.SaveChanges(); //開門錄影 if (rpt.Status == (int)CardReaderStatusEnum.開鎖 || rpt.Status == (int)CardReaderStatusEnum.按鈕開門 || rpt.Status == (int)CardReaderStatusEnum.密碼開門 || rpt.Status == (int)CardReaderStatusEnum.系統開門) { if (reader.NVRID == -1) return; #region 擷取錄影 #if R23 #else Task task = Task.Factory.StartNew(() => { DateTime dt = DateTime.Now; System.Threading.Thread.Sleep(1000 * 20); long flowid = log.FlowID; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("nvrid:" + reader.NVRID); try { NVR.INVR nvr = SecureService.nvr_mgr[reader.NVRID]; if (nvr == null) { Console.WriteLine(reader.NVRID + " is null"); return; } bool success = nvr.SaveRecord( // reader.NVRChNo, dt.AddSeconds(-10), dt.AddSeconds(10), @"C:\web\Secure\ClientBin\VideoRecord\" + flowid + ".avi"); reader.NVRChNo, dt.AddSeconds(-10), dt.AddSeconds(10), @"E:\web\Secure\ClientBin\VideoRecord\" + flowid + ".avi"); //bool success = nvr.SaveRecord( //reader.NVRChNo, dt.AddSeconds(-10), dt.AddSeconds(10), @"D:\" + flowid + ".avi"); log.NVRFile = flowid + ".wmv"; db.SaveChanges(); Console.WriteLine(success); } catch (Exception ex) { Console.WriteLine(ex.Message + "," + ex.StackTrace); } finally { Console.ResetColor(); } }); #endif #endregion } if (this.serivce != null && reader.TriggerCCTVID != 0) { if (InOperationCCTV.Where(n => n == reader.TriggerCCTVID).Count() > 0) { Task.Factory.StartNew(() => { try { Console.WriteLine("Trigger " + reader.TriggerCCTVID); SecureService.cctv_mgr[reader.TriggerCCTVID].Preset(2); System.Threading.Thread.Sleep(1000 * 10); SecureService.cctv_mgr[reader.TriggerCCTVID].Preset(1); } catch (Exception ex) { Console.WriteLine("May be trigger cctv not found" + ex.Message + "," + ex.StackTrace); } InOperationCCTV.Remove(reader.TriggerCCTVID); }); } } } if (rpt.Status == (int)CardReaderStatusEnum.號碼錯誤 || rpt.Status == (int)CardReaderStatusEnum.卡號連續錯誤 || rpt.Status == (int)CardReaderStatusEnum.外力破壞 ) { SecureDBEntities1 db = new SecureDBEntities1(); db.tblEngineRoomLog.Add( new tblEngineRoomLog() { ControlID = reader.ControllerID, ABA = rpt.CardNo.ToString(), StartTime = DateTime.Now, TypeID = 8, Memo = rpt.StatusString, TypeCode = (short)rpt.Status, ERNo = reader.PlaneID.ToString() } ); db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine("CardManager OnStatus Change:" + ex.Message + "," + ex.StackTrace); } }
//void cardreader_OnAlarmEvent(CardReader reder, AlarmData alarmdata) //{ // if (this.OnAlarmEvent != null) // this.OnAlarmEvent(reder, alarmdata); //} void cardreader_OnDoorEvent(ICardReader reader, DoorEventType enumEventType) { if (this.OnDoorEvent != null) { try { this.OnDoorEvent(reader, enumEventType); } catch { ;} } if (enumEventType == DoorEventType.Connected) { SecureDBEntities1 db = new SecureDBEntities1(); tblControllerConfig config = db.tblControllerConfig.Where(n => n.ControlID == reader.ControllerID).FirstOrDefault(); if (config != null) config.Comm_state = 1; tblEngineRoomLog log = new tblEngineRoomLog() { ControlID = reader.ControllerID, ABA = "0", StartTime = DateTime.Now, TypeID = 8, TypeCode = 31, Result = 1 }; db.tblEngineRoomLog.Add(log); db.SaveChanges(); db.Dispose(); AlarmData data = new AlarmData() { TimeStamp = DateTime.Now, AlarmType = AlarmType.Secure, ColorString = "Green", Description = reader.ControllerID + "復線", PlaneID = reader.PlaneID, IsForkCCTVEvent = false, PlaneName = Global.GetPlaneNameByPlaneID(reader.PlaneID) // CCTVBindingData =cctv.ToBindingData( }; Program.MyServiceObject.DispatchAlarmEvent(data); this.DownloadSuperPassword(reader.ControllerID); } if (enumEventType == DoorEventType.DisConnected) { SecureDBEntities1 db = new SecureDBEntities1(); tblControllerConfig config = db.tblControllerConfig.Where(n => n.ControlID == reader.ControllerID).FirstOrDefault(); if (config != null) config.Comm_state = 0; tblEngineRoomLog log=new tblEngineRoomLog(){ ControlID=reader.ControllerID, ABA="0", StartTime=DateTime.Now, TypeID=8, TypeCode=30, Result=0}; db.tblEngineRoomLog.Add(log); db.SaveChanges(); db.Dispose(); AlarmData data = new AlarmData() { TimeStamp = DateTime.Now, AlarmType = AlarmType.Secure, ColorString = "Red", Description = reader.ControllerID + "斷線警報", PlaneID = reader.PlaneID, IsForkCCTVEvent = false, PlaneName = Global.GetPlaneNameByPlaneID(reader.PlaneID) // CCTVBindingData =cctv.ToBindingData( }; Program.MyServiceObject.DispatchAlarmEvent(data); } }
public void SecureAlarm(AlarmData alarmdata) { if (this.OnAlarm != null) this.OnAlarm(alarmdata); }
public void Upsert(AlarmData.ChannelAlarmSummaryRow dataRow) { UpsertQuery(dataRow.ChannelID, dataRow.AlarmTypeID, dataRow.Date, dataRow.AlarmPoints); }
public void Upsert(AlarmData.MeterAlarmSummaryRow dataRow) { UpsertQuery(dataRow.MeterID, dataRow.AlarmTypeID, dataRow.Date, dataRow.AlarmPoints); }
void ShowNotification (AlarmData alarm) { var builder = new NotificationCompat.Builder (this); builder.SetSmallIcon (Resource.Drawable.marker_violet) .SetContentTitle (alarm.Name) .SetContentText (GetString (Resource.String.app_name)) .SetAutoCancel (false) .AddAction (Resource.Drawable.ic_action_volume_muted, GetString (Resource.String.stop_noise), PendingIntent.GetService (this, 0, new Intent (this, typeof(UIWhileRingingIntentService)).SetAction (StopAlarmAction), 0)); var intent = new Intent (this, typeof(AlarmScreen)) .SetFlags (ActivityFlags.NewTask) .PutExtra (Constants.AlarmsData_Extra, JsonConvert.SerializeObject (alarm)); builder.SetContentIntent (PendingIntent.GetActivity (this, 0, intent, PendingIntentFlags.UpdateCurrent)); StartForeground (_notificationId, builder.Build ()); }
void OneHourTmr_OnElapsed(object sender) { // throw new NotImplementedException(); foreach (Meter.R23PowerMeter meter in list) { try { SecureDBEntities1 db = new SecureDBEntities1(); if (!meter.IsValid) continue; tblPowerMeter tbl = db.tblPowerMeter.Where(n => n.ERID == meter.ERID).FirstOrDefault(); if (tbl != null) { DateTime dt=DateTime.Now; // DateTime lastbeg=DateTime.Now.Subtract(TimeSpan.FromHours(24 )); tblPowerMeter1HourLog lastlog= db.tblPowerMeter1HourLog.Where(n=>n.ERID==tbl.ERID).OrderByDescending(n=>n.Timestamp).Take(1).FirstOrDefault(); double? wateCurrent = (tbl.CumulateValue - lastlog.CumulateValue); double? PowerCurrent = ((tbl.kWh ?? 0) - (lastlog.kWh ?? 0)); bool IsModify = false; if (wateCurrent <-1|| wateCurrent > 100) { wateCurrent = lastlog.WaterConsume; tbl.CumulateValue=lastlog.CumulateValue + lastlog.WaterConsume; IsModify = true; } if (PowerCurrent < 0 || PowerCurrent > 5000) { PowerCurrent = lastlog.PowerConsume; tbl.kWh = lastlog.kWh + lastlog.PowerConsume; IsModify = true; } double? PowerBase = GetPowerBase(tbl.ERID); //db.tblPowerMeter1HourLog.Where(n =>/* n.Timestamp >= lastbeg && */ n.ERID==tbl.ERID ).Average(n => n.KW); double? WaterBase = GetWaterBase(tbl.ERID);//db.tblPowerMeter1HourLog.Where(n => /*n.Timestamp >= lastbeg && */ n.ERID==tbl.ERID ).Average(n => n.WaterConsume); double? Kwh24Hour= db.tblPowerMeter1HourLog.Where(n=>n.ERID==tbl.ERID).OrderByDescending(n => n.Timestamp ).Take(23).Sum(n=>n.PowerConsume)+PowerCurrent; //db.tblPowerMeter1HourLog.Where(n=>n.ERID==tbl.ERID).OrderByDescending(n => n.Timestamp ).Take(24).Average(n=>n.KW); double? water24Hour = db.tblPowerMeter1HourLog.Where(n => n.ERID == tbl.ERID).OrderByDescending(n => n.Timestamp).Take(23).Sum(n => n.WaterConsume)+wateCurrent; double? PowerLastDayBase = GetLastDayPowerBase(tbl.ERID); double? PowerLastHourBase = GetLastHourPowerBase(tbl.ERID); bool PowerAlarm = false, WaterAlarm = false, PowerLastDayAlarm = false, PowerLastHourAlarm = false ; //if(PowerAvg!=null && (tbl.KW> PowerAvg*(1+tbl.PowerAlarmUpper/100) || tbl.KW< PowerAvg*(1-tbl.PowerAlarmLower/100 )) ) if (PowerBase != null && (Kwh24Hour > PowerBase * (1 + tbl.PowerAlarmUpper / 100) || Kwh24Hour < PowerBase * (1 - tbl.PowerAlarmLower / 100))) PowerAlarm=true; if (WaterBase != null && (water24Hour > WaterBase * (1 + tbl.WaterAlarmUpper / 100) /* || wateCurrent< WaterAvg*(1-tbl.WaterAlarmLower/100 )*/)) WaterAlarm=true; if(PowerLastDayBase!=null && (Kwh24Hour > PowerLastDayBase * (1 + tbl.PowerAlarmUpper / 100) || Kwh24Hour < PowerLastDayBase * (1 - tbl.PowerAlarmLower / 100))) PowerLastDayAlarm=true; if (PowerLastHourBase != null && (PowerCurrent > PowerLastHourBase * (1 + tbl.PowerAlarmUpper / 100) || PowerCurrent < PowerLastHourBase * (1 - tbl.PowerAlarmLower / 100))) PowerLastHourAlarm = true; tbl.PowerAlarm = PowerAlarm; tbl.WaterAlarm = WaterAlarm; bool PowerAlarmChanged, WaterAlarmChanged; PowerAlarmChanged = (tbl.PowerAlarm ?? false) ^ PowerAlarm; WaterAlarmChanged = (tbl.WaterAlarm ?? false) ^ WaterAlarm; // tbl.KW24Avg = Kw24avg; tblPowerMeter1HourLog log = new tblPowerMeter1HourLog() { ERID = tbl.ERID, KW = tbl.KW, Timestamp = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, 0, 0), CumulateValue = tbl.CumulateValue, //(lastlog==null)?tbl.CumulateValue:tbl.CumulateValue-lastlog.CumulateValue, WaterAlarm = WaterAlarm, PowerAlarm = (PowerLastDayAlarm || PowerLastHourAlarm || PowerAlarm), // PowerAlarm = PowerAlarm, // PowerAlarmAvg = PowerAvg ?? tbl.KW, // WaterAlarmAvg = WaterAvg ?? ((lastlog == null) ? tbl.CumulateValue : tbl.CumulateValue - lastlog.CumulateValue), WaterConsume = wateCurrent,//(lastlog == null) ? tbl.CumulateValue : tbl.CumulateValue - lastlog.CumulateValue, //KW24Avg=Kw24avg, PowerConsume =PowerCurrent, //(lastlog == null) ? tbl.PowerConsume: tbl.kWh - (lastlog.PowerConsume??0), PowerAlarm_LastHour=(short)(PowerLastHourAlarm?(PowerCurrent>PowerLastHourBase?2:1):0), PowerAlarm_LastYear = (short)(PowerAlarm ? (Kwh24Hour > PowerBase ? 2 : 1):0), PowerAlarm_Yesterday=(short)(PowerLastDayAlarm ? (Kwh24Hour > PowerLastDayBase ? 2 : 1):0), Power24Consume=Kwh24Hour, kWh=tbl.kWh, PowerAlarmBaseValue_LastHour=PowerLastHourBase, PowerAlarmBaseValue_LastYear=PowerBase, PowerAlarmBaseValue_Yesterday=PowerLastDayBase, WaterAlarmBaseValue_LastYear=WaterBase, WaterAlarm_LastYear=(short)(WaterAlarm ? (water24Hour > WaterBase ? 2 : 1):0), Water24Consume=water24Hour, Memo=(IsModify?"Modify":null) }; db.tblPowerMeter1HourLog.Add(log); tbl.WaterConsume = log.WaterConsume; tbl.WaterAlarm_LastYear = log.WaterAlarm_LastYear; tbl.Water24Consume = log.Water24Consume; tbl.WaterAlarmBaseValue_LastYear = log.WaterAlarmBaseValue_LastYear; tbl.WaterAlarmAvg = log.WaterAlarmAvg; tbl.PowerAlarmAvg = log.PowerAlarmAvg; tbl.Power24Consume = log.Power24Consume; tbl.PowerAlarm = log.PowerAlarm; tbl.PowerAlarm_LastHour = log.PowerAlarm_LastHour; tbl.PowerAlarm_LastYear = log.PowerAlarm_LastYear; tbl.PowerAlarm_Yesterday = log.PowerAlarm_Yesterday; tbl.PowerAlarmBaseValue_LastHour = log.PowerAlarmBaseValue_LastHour; tbl.PowerAlarmBaseValue_LastYear = log.PowerAlarmBaseValue_LastYear; tbl.PowerAlarmBaseValue_Yesterday = log.PowerAlarmBaseValue_Yesterday; tbl.PowerConsume = log.PowerConsume; if ((log.PowerAlarm ?? false) && (log.PowerAlarm_LastHour == 2 || log.PowerAlarm_LastYear == 2 || log.PowerAlarm_Yesterday == 2)) tbl.PowerAlarmDesc = "用電量過高"; else if ((log.PowerAlarm ?? false) && (log.PowerAlarm_LastHour == 1 || log.PowerAlarm_LastYear == 1 || log.PowerAlarm_Yesterday == 1)) tbl.PowerAlarmDesc = "用電量過低"; if ((log.WaterAlarm ?? false) && log.WaterAlarm_LastYear==2) tbl.WaterAlarmDesc = "用水量過高"; else if ((log.WaterAlarm ?? false) && log.WaterAlarm_LastYear==1) tbl.WaterAlarmDesc = "用水量過低 "; //if ((log.PowerAlarm ?? false) && log.KW > log.PowerAlarmAvg) // tbl.PowerAlarmDesc = "用電量過高"; //else if ((log.PowerAlarm ?? false) && log.KW <= log.PowerAlarmAvg) // tbl.PowerAlarmDesc = "用電量過低 "; //if ((log.WaterAlarm ?? false) && log.WaterConsume > log.WaterAlarmAvg) // tbl.WaterAlarmDesc = "用水量過高"; //else if ((log.WaterAlarm ?? false) && log.WaterConsume <= log.WaterAlarmAvg) // tbl.WaterAlarmDesc = "用水量過低 "; if (!(log.PowerAlarm ?? false)) tbl.PowerAlarmDesc = ""; if (!(log.WaterAlarm ?? false)) tbl.WaterAlarmDesc = ""; db.SaveChanges(); if (PowerAlarm /*&& PowerAlarmChanged*/) { AlarmData data = new AlarmData() { AlarmType = AlarmType.PowerMeter, ColorString = "Red", TimeStamp = DateTime.Now, PlaneName = tbl.ERName, TimeStampString = string.Format("HH:mm"), IsForkCCTVEvent=false, Description=tbl.PowerAlarmDesc }; Program.MyServiceObject.DispatchAlarmEvent(data); } if (WaterAlarm /*&& WaterAlarmChanged*/) { AlarmData data = new AlarmData() { AlarmType = AlarmType.WaterMeter, ColorString = "Red", TimeStamp = DateTime.Now, PlaneName = tbl.ERName, TimeStampString = string.Format("HH:mm"), IsForkCCTVEvent=false, Description=tbl.WaterAlarmDesc }; Program.MyServiceObject.DispatchAlarmEvent(data); } //tbl.VA = meter.VA; //tbl.VB = meter.VB; //tbl.VC = meter.VC; //tbl.AVGV = meter.AVGV; //tbl.IA = meter.IA; //tbl.IB = meter.IB; //tbl.IC = meter.IC; //tbl.AVGI = meter.AVGI; //tbl.KW = meter.KW; //tbl.PF = meter.PF; //tbl.CumulateValue = meter.CumulateValue; //tbl.InstantaneousValue = meter.InstantaneousValue; //tbl.UpdateDate = DateTime.Now; //db.SaveChanges(); //db.Dispose(); } } catch (Exception ex) { Console.WriteLine(ex.Message + "," + ex.StackTrace); } } }
void CheckDataChange(byte[] temp) { string description=""; if (data[0] == temp[0] && data[1] == temp[1]) { // Console.WriteLine("沒變化!"); return; } Console.WriteLine(this.PDName); SecureDBEntities1 db = new SecureDBEntities1(); tblPDConfig tblpd= db.tblPDConfig.Where(n=>n.PDName==this.PDName).FirstOrDefault(); if(tblpd==null) return; PDStatus d= new PDStatus(data); PDStatus t = new PDStatus(temp); if(tblPDConfig.R0!=-1) if (d.R0 != t.R0 ) { tblpd.R0 = t.R0; if (t.R0 == 0) //normal { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "R0", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1}; db.tblPDAlarmLog.Add(log); } else //abnormal { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "R0", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, Memo = GetPDStatusDescription(0, tblpd), UserMemo=tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "R0 "+GetPDStatusDescription(0, tblpd); } } if (tblPDConfig.S0 != -1) if (d.S0 != t.S0) { tblpd.S0 = t.S0; if (t.S0 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "S0", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "S0", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, Memo = GetPDStatusDescription(0, tblpd), UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "S0 " + GetPDStatusDescription(0, tblpd); ; } } if (tblPDConfig.T0 != -1) if (d.T0 != t.T0 ) { tblpd.T0 =t.T0; if (t.T0 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "T0", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "T0", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, Memo = GetPDStatusDescription(0, tblpd), UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "T0 " + GetPDStatusDescription(0, tblpd); ; } } if (d.R1 != t.R1) { tblpd.R1 = t.R1; if (t.R1 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "R1", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "R1", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, Memo = GetPDStatusDescription(1, tblpd), UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "R1 "+GetPDStatusDescription(1, tblpd); } } if (d.S1 != t.S1) { tblpd.S1 = t.S1; if (t.S1 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "S1", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "S1", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, Memo = GetPDStatusDescription(1, tblpd), UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "S1 " + GetPDStatusDescription(1, tblpd); } } if (d.T1 != t.T1) { tblpd.T1 = t.T1; if (t.T1 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "T1", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "T1", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, Memo = GetPDStatusDescription(1, tblpd), UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "T1 " + GetPDStatusDescription(1, tblpd); } } if(tblPDConfig.L0!=-1) if (d.L0 != t.L0 ) { tblpd.L0 = t.L0; if (t.L0 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L0", Timestamp = DateTime.Now, PDName = this.PDName,Status=1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L0", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "L0 "; } } if (tblPDConfig.L1 != -1) if (d.L1 != t.L1) { tblpd.L1 = t.L1; if (t.L1 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L1", Timestamp = DateTime.Now, PDName = this.PDName,Status=1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L1", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "L1 "; } } if (tblPDConfig.L2 != -1) if (d.L2 != t.L2) { tblpd.L2 = t.L2; if (t.L2 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L2", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L2", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "L2 "; } } if (tblPDConfig.L3 != -1) if (d.L3 != t.L3) { tblpd.L3 = t.L3; if (t.L3 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L3", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L3", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "L3 "; } } if (tblPDConfig.L4 != -1) if (d.L4 != t.L4) { tblpd.L4 = t.L4; if (t.L4 == 0) { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L4", Timestamp = DateTime.Now, PDName = this.PDName, Status = 1 }; db.tblPDAlarmLog.Add(log); } else { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "L4", Timestamp = DateTime.Now, PDName = this.PDName, Status = 0, UserMemo = tblpd.Memo }; db.tblPDAlarmLog.Add(log); description += "L4 "; } } if (d.Cabinet != t.Cabinet) { tblpd.Cabinet = t.Cabinet; if (t.Cabinet == 1) //close { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "Cabinet", Timestamp = DateTime.Now, PDName = this.PDName, Memo = "箱門關閉", Status = 1 }; db.tblPDAlarmLog.Add(log); } else //open { tblPDAlarmLog log = new tblPDAlarmLog() { PDItem = "Cabinet", Timestamp = DateTime.Now, PDName = this.PDName, Memo = "箱門開啟", Status = 0 }; db.tblPDAlarmLog.Add(log); if(description !="") description += "異常 " + "箱門開啟 "; else description += "箱門開啟 "; } } if (!description.Contains("箱門") && description != "") description += "異常"; if (description != "") { AlarmData alarmdata = new AlarmData() { TimeStamp = DateTime.Now, AlarmType = AlarmType.PD, ColorString = "Red", Description = description, // PlaneID = sender.PlaneID, IsForkCCTVEvent = false, PlaneName = this.tblPDConfig.PDName//Global.GetPlaneNameByPlaneID(this.PDName) }; try { Program.MyServiceObject.DispatchAlarmEvent(alarmdata); } catch { ;} } // Console.WriteLine("save change"); db.SaveChanges(); db.Dispose(); }
bool AcceptAdd () { if (AlarmToAddMarker == null) { ShowToast (Resource.String.click_on_map_to_set_alarm); return false; } else if (string.IsNullOrEmpty (_alarmNameEditText.Text)) { _alarmNameEditText.RequestFocus (); _alarmNameEditText.SetError (Html.FromHtml (string.Format ("<font color='#9933cc'>{0}</font>", Resources.GetString (Resource.String.enter_alarm_name))), null); return false; } else { var radius = Constants.AlarmRadiusValues [_alarmRadiusSpinner.SelectedItemPosition]; var newAlarm = new AlarmData () { Latitude = AlarmToAddMarker.Position.Latitude, Longitude = AlarmToAddMarker.Position.Longitude, Radius = radius, Name = _alarmNameEditText.Text, Enabled = true, RequestId = string.Format ("{0};{1}_{2}", AlarmToAddMarker.Position.Latitude, AlarmToAddMarker.Position.Longitude, random.NextDouble ()) }; AddGeofence (newAlarm); return true; } }
protected void EnableAlarm (AlarmData alarm, bool enabled) { alarm.Enabled = enabled; if (enabled) { AddGeofence (alarm); } else { RemoveGeofence (alarm, ActionOnAlarm.Disable); } }