// Run the timer for 10 seconds and remove the first alert, double the time if the alert is a Login. // If there are more, remove the next one after 5 seconds. public void StartTimer() { if (this.Alerts.Count == 0) { return; } if (!this.Timer.IsEnabled) { AlertBase alert = this.Alerts[0]; if (alert is LoginAlert) { this.Timer.Interval = new TimeSpan(0, 0, 20); } else { this.Timer.Interval = new TimeSpan(0, 0, 10); } this.Timer.Start(); } else { this.Timer.Interval = new TimeSpan(0, 0, 5); } }
public List <AlertBase> GetUserAlerts(Account account) { List <AlertBase> alerts = new List <AlertBase>(); this.ApiCall.ApiRequest.SessionID = account.SessionID; this.ApiCall.ApiRequest.SessionData = account.SessionData; this.ApiCall.ApiRequest.Version = EbayContext.ClientAlertsApiVersion; this.ApiCall.Execute(); account.SessionData = this.ApiCall.ApiResponse.SessionData; if (this.ApiCall.ApiResponse.ClientAlerts == null) { return(alerts); } foreach (ClientAlertEventType item in this.ApiCall.ApiResponse.ClientAlerts.ClientAlertEvent) { this.Logger.Log(LogLevel.Debug, "Alert type {0}", item.GetType()); AlertBase alert = PopulateAlert(account, item); if (alert != null) { alerts.Add(alert); } else { this.Logger.Log(LogLevel.Info, "Unknown EventType received: {0}.", item.EventType.ToString()); } } return(alerts); }
/// <summary> /// Сохранить оповещение. /// </summary> /// <param name="alert">Сохраняемое оповещение.</param> /// <returns>Сохраненное оповещение с заполненным идентификатором</returns> public Guid Save(AlertBase alert) { using (var uow = CreateUnitOfWork()) { return(uow.AlertRepository.Save(alert)); } }
private void AlertQueueTimer_Tick(object sender, EventArgs e) { try { lock (this.AlertQueue) { this.Logger.Log(LogLevel.Debug, "Queue Timer Tick... Total Alerts {0}.", this.AlertQueue.Count); if (this.AlertQueue.Count > 0) { // Always de-queue only one item. AlertBase alert = this.AlertQueue.Dequeue(); int second = System.DateTime.Now.Second; OnAlertRaised(alert); } if (this.AlertQueue.Count > 0) { this.StartQueueAlertTimer(); } else { this.StopQueueAlertTimer(); } } } catch (Exception ex) { this.Logger.Log(LogLevel.Error, "", ex); } }
public ActionResult Speed(int Id = 0) { SpeedAlert alertModel = new SpeedAlert(); try { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.SpeedAlarm; sVM = new AlertData().GetAlertDetails(sVM, Id); AlertBase alertData = sVM.AlertDatas.FirstOrDefault() as AlertBase; if (alertData == null) { alertData = new AlertBase() { Id = 0, Conditions = new List <Tracker.Common.Condition>(), IsActive = false }; } int SpeedLimit = 50; string SpeedComparer = string.Empty; if (alertData.Conditions.Where(m => m.Operand == "Speed").FirstOrDefault() != null) { SpeedLimit = Convert.ToInt32(alertData.Conditions.Where(m => m.Operand == "Speed").FirstOrDefault().Value); SpeedComparer = Convert.ToString(alertData.Conditions.Where(m => m.Operand == "Speed").FirstOrDefault().Operator); } alertModel = new SpeedAlert() { Id = alertData.Id, Name = alertData.Name, Description = alertData.DescriptionText, IsActive = alertData.IsActive, SpeedLimit = SpeedLimit, SpeedComparer = SpeedComparer, Devices = new List <DeviceDetailSelection>() }; List <DeviceDetailSelection> availableDevices = new AlertData().GetAvailableDevices(); List <string> activeDevices = new AlertData().GetDevicesForAlert(alertData.Id); if (availableDevices != null && availableDevices.Count > 0) { alertModel.Devices = availableDevices.Select(m => new DeviceDetailSelection { DeviceId = m.DeviceId, VehicleId = m.VehicleId, Checked = activeDevices.Contains(m.DeviceId) }).ToList(); } } catch (Exception ex) { } return(View(alertModel)); }
public ActionResult PowerCut(int?Id = null) { PowerCutAlert alertModel = new PowerCutAlert(); try { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.PowerCutAlarm; sVM = new AlertData().GetAlertDetails(sVM, Id); AlertBase alertData = sVM.AlertDatas.FirstOrDefault() as AlertBase; if (alertData == null) { alertData = new AlertBase() { Id = 0, Conditions = new List <Tracker.Common.Condition>(), IsActive = false }; } bool IsOnPowerCut = false; if (alertData.Conditions.Where(m => m.Operand == "OnPowerCut").FirstOrDefault() != null) { IsOnPowerCut = Convert.ToBoolean(Convert.ToInt32(alertData.Conditions.Where(m => m.Operand == "OnPowerCut").FirstOrDefault().Value)); } else { IsOnPowerCut = false; } alertModel = new PowerCutAlert() { Id = alertData.Id, IsActive = alertData.IsActive, IsOnPowerCut = IsOnPowerCut, Devices = new List <DeviceDetailSelection>() }; List <DeviceDetailSelection> availableDevices = new AlertData().GetAvailableDevices(); List <string> activeDevices = new AlertData().GetDevicesForAlert(alertData.Id); if (availableDevices != null && availableDevices.Count > 0) { alertModel.Devices = availableDevices.Select(m => new DeviceDetailSelection { DeviceId = m.DeviceId, VehicleId = m.VehicleId, Checked = activeDevices.Contains(m.DeviceId) }).ToList(); } // TODO: Get from db/old service } catch (Exception ex) { } return(View(alertModel)); }
public ActionResult Fence(FenceAlert alertModel) { { ScheduleViewModel sVM = new ScheduleViewModel(); //sVM.SelectedAlertType = DeviceAlarmType.FenceAlarm; sVM.SelectedAlertType = alertModel.FenceType; sVM.AlertDatas = new List <object>(); AlertBase alertData = new AlertBase() { Id = alertModel.Id, Name = alertModel.Name, DescriptionText = alertModel.Description, IsActive = alertModel.IsActive, FenceListStr = alertModel.PointsStr }; sVM.AlertDatas.Add(alertData); if (new AlertData().SaveAlertData(sVM)) { int updateId = 0; if (int.TryParse(sVM.SelectedAlertId, out updateId)) { alertModel.Id = updateId; try { alertModel.Points = (sVM.AlertDatas[0] as AlertBase).FenceList; } catch (Exception aBEx) { } if (alertModel.Devices != null && alertModel.Devices.Count > 0) { alertModel.Devices.ForEach(d => { try { new AlertData().SaveDevicesForAlert(alertModel.Id, d.DeviceId, !d.Checked); } catch (Exception ex) { } }); } } ViewBag.AlertWriteStatus = "Success"; } else { ViewBag.AlertWriteStatus = "Failed"; } return(View(alertModel)); } }
public ActionResult Speed(SpeedAlert alertModel) { { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.SpeedAlarm; sVM.AlertDatas = new List <object>(); AlertBase alertData = new AlertBase() { Id = alertModel.Id, Name = alertModel.Name, DescriptionText = alertModel.Description, IsActive = alertModel.IsActive, Conditions = new List <Tracker.Common.Condition>() { new Tracker.Common.Condition() { Operand = "Speed", Operator = alertModel.SpeedComparer, Value = alertModel.SpeedLimit.ToString() } } }; sVM.AlertDatas.Add(alertData); if (new AlertData().SaveAlertData(sVM)) { int updateId = 0; if (int.TryParse(sVM.SelectedAlertId, out updateId)) { alertModel.Id = updateId; if (alertModel.Devices != null && alertModel.Devices.Count > 0) { alertModel.Devices.ForEach(d => { try { new AlertData().SaveDevicesForAlert(alertModel.Id, d.DeviceId, !d.Checked); } catch (Exception ex) { } }); } } ViewBag.AlertWriteStatus = "Success"; } else { ViewBag.AlertWriteStatus = "Failed"; } return(View(alertModel)); } }
private void Engine_AlertRaised(object sender, AlertEventArgs args) { if (args.DisplayPopup) { AlertBase alert = args.Alert; this._playSound = args.PlaySound; this.Alerts.Insert(0, alert); this.StartTimer(); } }
public ActionResult Ignition(IgnitionAlert alertModel) { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.AccAlarm; sVM.AlertDatas = new List <object>(); AlertBase alertData = new AlertBase() { Id = alertModel.Id, IsActive = alertModel.IsActive, Conditions = new List <Tracker.Common.Condition>() { new Tracker.Common.Condition() { Operand = "OnAcc", Value = alertModel.IsOnAcc == true ? "1" : "0" } } }; sVM.AlertDatas.Add(alertData); if (new AlertData().SaveAlertData(sVM)) { int updateId = 0; if (int.TryParse(sVM.SelectedAlertId, out updateId)) { alertModel.Id = updateId; if (alertModel.Devices != null && alertModel.Devices.Count > 0) { alertModel.Devices.ForEach(d => { try { new AlertData().SaveDevicesForAlert(alertModel.Id, d.DeviceId, !d.Checked); } catch (Exception ex) { } }); } } ViewBag.AlertWriteStatus = "Success"; } else { ViewBag.AlertWriteStatus = "Failed"; } return(View(alertModel)); }
public ActionResult Fence(int Id = 0) { FenceAlert alertModel = new FenceAlert(); try { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.FenceAlarm; sVM = new AlertData().GetAlertDetails(sVM, Id); AlertBase alertData = sVM.AlertDatas.FirstOrDefault() as AlertBase; if (alertData == null) { alertData = new AlertBase() { Id = 0, Conditions = new List <Tracker.Common.Condition>(), IsActive = false }; } alertModel = new FenceAlert() { Id = alertData.Id, Name = alertData.Name, Description = alertData.DescriptionText, IsActive = alertData.IsActive, FenceType = (Id == 0) ? DeviceAlarmType.FenceInAlarm : sVM.SelectedAlertType, Points = alertData.FenceList, Devices = new List <DeviceDetailSelection>() }; List <DeviceDetailSelection> availableDevices = new AlertData().GetAvailableDevices(); List <string> activeDevices = new AlertData().GetDevicesForAlert(alertData.Id); if (availableDevices != null && availableDevices.Count > 0) { alertModel.Devices = availableDevices.Select(m => new DeviceDetailSelection { DeviceId = m.DeviceId, VehicleId = m.VehicleId, Checked = activeDevices.Contains(m.DeviceId) }).ToList(); } } catch (Exception ex) { } return(View(alertModel)); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { AlertBase alert = item as AlertBase; if (alert == null) { return(this.DefaultAlertTemplate); } if (alert is LoginAlert) { return(LoginTemplate); } if (alert is TickAlert) { return(TickTemplate); } if (alert is ExceptionAlert) { return(ExceptionTemplate); } if (alert is MessageAlert) { return(AskSellerQuestionTemplate); } if (alert is FeedbackReceivedAlert) { return(FeedbackReceivedTemplate); } if (alert is ItemSoldAlert) { return(FixedPriceTransactionTemplate); } return(this.DefaultAlertTemplate); }
/// <summary>This raises an alert to the PopupViewModel so it can display the Alert.</summary> public void OnAlertRaised(AlertBase item) { SchedulerSetting setting = this.Context.Schedule.GetApplicableSetting(DateTime.Now); // TODO: Threading wrap around this... bool displayPopup = (setting == SchedulerSetting.Enabled || setting == SchedulerSetting.PopupOnly); bool playSound = (setting == SchedulerSetting.Enabled); App.Current.Dispatcher.Invoke((Action) delegate { if (AlertRaised != null) { if (!(item is TickAlert)) { this.Context.Alerts.Insert(0, item); } AlertRaised(this, new AlertEventArgs(item, displayPopup, playSound)); } }); }
public ScheduleViewModel GetAlertDetails(ScheduleViewModel svm, int?DeviceAlertId) { DataTable alertsDt = new DataTable(); try { List <SqlParameter> dbParams = new List <SqlParameter>(); dbParams.Add(new SqlParameter("DeviceAlertId", DeviceAlertId)); if (svm.SelectedAlertType != DeviceAlarmType.FenceAlarm) { dbParams.Add(new SqlParameter("AlertType", svm.SelectedAlertType)); } alertsDt = Data.GetData(DataBase.Api, System.Data.CommandType.StoredProcedure, "Master_GetDeviceAlert", dbParams.ToArray()); } catch (Exception ex) { } if (alertsDt != null) { switch (svm.SelectedAlertType) { case DeviceAlarmType.PowerCutAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { alertDatas.Add(new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false) }); } svm.AlertDatas = alertDatas; break; } case DeviceAlarmType.SOSAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { alertDatas.Add(new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false) }); } svm.AlertDatas = alertDatas; break; } case DeviceAlarmType.SpeedAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { alertDatas.Add(new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false) }); } svm.AlertDatas = alertDatas; break; } //case DeviceAlarmType.BreakAlarm: // _AlertData = new BreakAlert(); // break; case DeviceAlarmType.VibrationAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { alertDatas.Add(new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false) }); } svm.AlertDatas = alertDatas; break; } case DeviceAlarmType.FenceAlarm: case DeviceAlarmType.FenceInAlarm: case DeviceAlarmType.FenceOutAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { svm.SelectedAlertType = (DeviceAlarmType)Enum.Parse(typeof(DeviceAlarmType), Convert.ToString(aDt["AlertType"])); var FenceList = new List <ATFPosition>(); try { var fenceListDt = Data.GetData(DataBase.Api, System.Data.CommandType.StoredProcedure, "Master_GetFenceList", new SqlParameter[] { new SqlParameter("DeviceAlertId", aDt["Id"]) }); FenceList = fenceListDt.AsEnumerable().Select(m => new ATFPosition() { Lat = Convert.ToString(m["Latitude"]), Lang = Convert.ToString(m["Longitude"]), Distance = (float)Convert.ToDouble(m["Distance"]), ListOrder = Convert.ToInt32(m["ListOrder"]) }).ToList(); } catch (Exception ex) { } alertDatas.Add(new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false), FenceList = FenceList ?? new List <ATFPosition>() }); } svm.AlertDatas = alertDatas; } break; case DeviceAlarmType.MovingAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { var _aData = new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false) }; _aData.Conditions.RemoveAll(a => a.Operand.ToLower() == "onacc"); alertDatas.Add(_aData); } svm.AlertDatas = alertDatas; break; } case DeviceAlarmType.AcAlarm: case DeviceAlarmType.AccAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { alertDatas.Add(new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false) }); } svm.AlertDatas = alertDatas; break; } case DeviceAlarmType.StopAlarm: { var alertDatas = new List <object>(); foreach (var aDt in alertsDt.AsEnumerable()) { var _aData = new AlertBase() { Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)), Name = Convert.ToString(aDt["Name"]), DescriptionText = Convert.ToString(aDt["DescriptionText"]), Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")), IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false) }; alertDatas.Add(_aData); } svm.AlertDatas = alertDatas; break; } default: break; } } return(svm); }
public Guid Post([FromBody] AlertBase alert) { return(AlertService.Save(alert)); }
public AlertEventArgs(AlertBase alert, bool displayPopup, bool playSound) { this.Alert = alert; this.DisplayPopup = displayPopup; this.PlaySound = playSound; }
public void Init() { alert1 = new RuleBasedAlert(); }