public void AddAlert(IInternalAlert alert) { try { string type = AlertTypeUtils.ToString(alert.Type); string level = alert.Level.ToString(); AlertDocument alertDocument = GetAlertDocument(alert.AlertId); if (alertDocument == null) { AlertDocument alertDocument2 = new AlertDocument(); alertDocument2.AlertId = alert.AlertId; alertDocument2.Type = type; alertDocument2.Level = level; alertDocument = alertDocument2; alerts.Insert(alertDocument); } else { alertDocument.Type = type; alertDocument.Level = level; alerts.Update(alertDocument); } } catch (CorruptionException ex) { databaseCorruptionHandler.HandleCorruption(ex); throw; } }
public void ClearAlerts(IEnumerable <IAlert> alerts, Action <IClearAlertsResult> callback) { try { List <IInternalAlert> list = new List <IInternalAlert>(); foreach (IAlert alert in alerts) { IInternalAlert internalAlert = alert as IInternalAlert; if (internalAlert == null) { logger.Critical("Can't clear unknown alert"); callback(new ClearAlertsResult(success: false)); return; } list.Add(internalAlert); } IWebCall <ClearAlertsRequest, ClearAlertsResponse> webCall = mixWebCallFactory.AlertsClearPut(new ClearAlertsRequest { AlertIds = list.Select((IInternalAlert a) => a.AlertId).Cast <long?>().ToList() }); webCall.OnResponse += delegate(object sender, WebCallEventArgs <ClearAlertsResponse> e) { ClearAlertsResponse response = e.Response; if (NotificationValidator.Validate(response.Notification)) { notificationQueue.Dispatch(response.Notification, delegate { callback(new ClearAlertsResult(success: true)); }, delegate { callback(new ClearAlertsResult(success: false)); }); } else { logger.Critical("Failed to validate clear alerts response: " + JsonParser.ToJson(response)); callback(new ClearAlertsResult(success: false)); } }; webCall.OnError += delegate { callback(new ClearAlertsResult(success: false)); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(new ClearAlertsResult(success: false)); } }