/// <summary> /// Initializes a new instance of the <see cref="AlertViewModel"/> class. /// </summary> /// <param name="alertMessageInfo">The alert message information.</param> public AlertViewModel(AlertMessageInfo alertMessageInfo) { this.Body = alertMessageInfo.AlertMessage.Body; this.CreatedBy = alertMessageInfo.AlertMessage.CreatedBy?.Key.Value ?? Guid.Empty; this.Flags = alertMessageInfo.AlertMessage.Flags; this.From = alertMessageInfo.AlertMessage.From; this.Id = alertMessageInfo.Id; this.Subject = alertMessageInfo.AlertMessage.Subject; this.Time = alertMessageInfo.AlertMessage.CreationTime.DateTime; this.To = alertMessageInfo.AlertMessage.To; }
/// <summary> /// Creates an alert. /// </summary> /// <param name="alertMessageInfo">The alert message to be created.</param> /// <returns>Returns the created alert.</returns> public AlertMessageInfo CreateAlert(AlertMessageInfo alertMessageInfo) { var alertRepositoryService = ApplicationContext.Current.GetService <IAlertRepositoryService>(); if (alertRepositoryService == null) { throw new InvalidOperationException($"{nameof(IAlertRepositoryService)} not found"); } var createdAlert = alertRepositoryService.Insert(alertMessageInfo.AlertMessage); return(new AlertMessageInfo(createdAlert)); }
public void Initialize() { this.alertMessageInfo = new AlertMessageInfo(new OpenIZ.Core.Alert.Alerting.AlertMessage { Body = "this is some body text of an alert message", CreatedBy = new OpenIZ.Core.Model.Security.SecurityUser { Key = Guid.Parse("3B4A85D4-9D4E-4D4F-A027-32B69648A6A9") }, CreationTime = new DateTimeOffset(1970, 01, 01, 00, 00, 00, TimeSpan.FromHours(5)), Flags = OpenIZ.Core.Alert.Alerting.AlertMessageFlags.Alert, From = "_UNIT_TEST_SYSTEM", Key = Guid.Parse("B20878A9-1DF6-4687-81AA-B8AF7B695423"), RcptTo = new List <OpenIZ.Core.Model.Security.SecurityUser> { new OpenIZ.Core.Model.Security.SecurityUser { Key = Guid.Parse("E3C8D2CA-2646-4075-B054-EF36631CF24D"), UserName = "******" }, new OpenIZ.Core.Model.Security.SecurityUser { Key = Guid.Parse("A5E510E6-6484-48BF-898C-1902C6C3919A"), UserName = "******" } }, Subject = "UNIT TEST ALERT", TimeStamp = new DateTimeOffset(new DateTime(1970, 01, 01)), To = "administrator" }); this.alertViewModel = new AlertViewModel { Body = "body", CreatedBy = Guid.Parse("BCE8DC56-BCC5-4CBF-8649-C24F14606BF7"), Flags = AlertMessageFlags.Acknowledged, From = "from", Id = Guid.Parse("12186EC5-C5A7-4D6E-94B5-0F77C152790A"), Subject = "subject", Time = new DateTime(1970, 01, 01), To = "to" }; }
/// <summary> /// Updates an alert. /// </summary> /// <param name="alertId">The id of the alert to be updated.</param> /// <param name="alert">The alert containing the updated information.</param> /// <returns>Returns the updated alert.</returns> public AlertMessageInfo UpdateAlert(string alertId, AlertMessageInfo alert) { Guid key = Guid.Empty; if (!Guid.TryParse(alertId, out key)) { throw new ArgumentException($"{nameof(alertId)} must be a valid GUID"); } var alertRepository = ApplicationContext.Current.GetService <IAlertRepositoryService>(); if (alertRepository == null) { throw new InvalidOperationException($"{nameof(IAlertRepositoryService)} not found"); } var updatedAlert = alertRepository.Save(alert.AlertMessage); return(new AlertMessageInfo(updatedAlert)); }
/// <summary> /// Converts an alert model to an alert message info. /// </summary> /// <param name="model">The create alert model.</param> /// <param name="user">The <see cref="IPrincipal"/> instance.</param> /// <returns>Returns the converted alert message info.</returns> private AlertMessageInfo ToAlertMessageInfo(CreateAlertModel model, IPrincipal user) { var alertMessageInfo = new AlertMessageInfo { AlertMessage = new AlertMessage { Body = model.Message, CreatedBy = new SecurityUser { Key = Guid.Parse(user.Identity.GetUserId()) }, Flags = (AlertMessageFlags)model.Priority } }; alertMessageInfo.AlertMessage.From = user.Identity.GetUserName(); var securityUser = this.AmiClient.GetUser(model.To).User; alertMessageInfo.AlertMessage.RcptTo = new List <SecurityUser> { securityUser }; switch (alertMessageInfo.AlertMessage.Flags) { case AlertMessageFlags.System: alertMessageInfo.AlertMessage.To = "everyone"; break; default: alertMessageInfo.AlertMessage.To = securityUser.UserName; break; } alertMessageInfo.AlertMessage.Subject = model.Subject; alertMessageInfo.AlertMessage.TimeStamp = DateTimeOffset.Now; return(alertMessageInfo); }
/// <summary> /// Creates an alert message. /// </summary> /// <param name="alertMessageInfo">The alert message to be created.</param> /// <returns>Returns the created alert message.</returns> public AlertMessageInfo CreateAlert(AlertMessageInfo alertMessageInfo) { return(this.Client.Post <AlertMessageInfo, AlertMessageInfo>("alert", this.Client.Accept, alertMessageInfo)); }
/// <summary> /// Updates an alert. /// </summary> /// <param name="alertId">The id of the alert to be updated.</param> /// <param name="alertMessageInfo">The alert message info containing the updated information.</param> /// <returns>Returns the updated alert.</returns> public AlertMessageInfo UpdateAlert(string alertId, AlertMessageInfo alertMessageInfo) { return(this.Client.Put <AlertMessageInfo, AlertMessageInfo>($"alert/{alertId}", this.Client.Accept, alertMessageInfo)); }
public void Cleanup() { this.alertMessageInfo = null; this.alertViewModel = null; }