public static Notification Notify(NotificationDto notificationDto, string sendingApplicationName) { var dataContext = new FoghornEntities(); var sendingApplication = dataContext.SendingApplications.FirstOrDefault(x => x.SendingApplicationName == sendingApplicationName); if (sendingApplication == null) { var exception = new ArgumentException("sendingApplicationName must match a previously registered SendingApplication", "sendingApplicationName"); Logger.ErrorException(FailureMessage, exception); throw exception; } if (notificationDto == null) { var exception = new ArgumentException("notification must not be null", "notificationDto"); Logger.ErrorException(FailureMessage, exception); throw exception; } if (notificationDto.Priority > 2) notificationDto.Priority = 2; if (notificationDto.Priority < -2) notificationDto.Priority = -2; var growlNotification = new Growl.Connector.Notification(sendingApplication.SendingApplicationName, notificationDto.NotificationTypeName, notificationDto.NotificationId.ToString( CultureInfo.InvariantCulture), notificationDto.NotificationTitle, notificationDto.NotificationMessage) { Sticky = notificationDto.Sticky, Priority = (Priority) notificationDto.Priority }; var notification = notificationDto.ToEntity(); foreach (var subscriber in sendingApplication.Subscribers) { var port = subscriber.Port.HasValue ? subscriber.Port.Value : Settings.Default.GrowlDefaultPort; var growlConnector = new GrowlConnector(subscriber.Password, subscriber.HostName, port); growlConnector.Notify(growlNotification); subscriber.NotificationsSent.Add(notification); } notification.SentDateTime = DateTime.UtcNow; notification.NotificationType = dataContext.NotificationTypes.FirstOrDefault( x => x.NotificationTypeName == notificationDto.NotificationTypeName); dataContext.Notifications.Add(notification); dataContext.SaveChanges(); return notification; }
private void DeleteTestApplications(FoghornEntities dataContext) { var testApplications = dataContext.SendingApplications.Where(x => x.SendingApplicationName.StartsWith(ApplicationTestName)); foreach (var sendingApplication in testApplications) { var subscribersToRemove = sendingApplication.Subscribers; foreach (var subscriber in subscribersToRemove) { var notifications = subscriber.NotificationsSent.ToList(); foreach (var notification in notifications) { dataContext.Notifications.Remove(notification); } } dataContext.SendingApplications.Remove(sendingApplication); } dataContext.SaveChanges(); _testApplicationId = 0; }