/// <summary> /// Converts this instance of <see cref="Subscriber"/> to an instance of <see cref="SubscriberDto"/>. /// </summary> /// <param name="entity"><see cref="Subscriber"/> to convert.</param> public static SubscriberDto ToDto(this Subscriber entity) { if (entity == null) { return(null); } var dto = new SubscriberDto(); dto.SubscriberId = entity.SubscriberId; dto.SubscriberName = entity.SubscriberName; dto.Port = entity.Port; dto.HostName = entity.HostName; dto.Password = entity.Password; entity.OnDto(dto); return(dto); }
/// <summary> /// Converts this instance of <see cref="SubscriberDto"/> to an instance of <see cref="Subscriber"/>. /// </summary> /// <param name="dto"><see cref="SubscriberDto"/> to convert.</param> public static Subscriber ToEntity(this SubscriberDto dto) { if (dto == null) { return(null); } var entity = new Subscriber(); entity.SubscriberId = dto.SubscriberId; entity.SubscriberName = dto.SubscriberName; entity.Port = dto.Port; entity.HostName = dto.HostName; entity.Password = dto.Password; dto.OnEntity(entity); return(entity); }
public void TestRegisterSubscription_ApplicationExists_SubscriberRegistered() { var foghornClient = new ChannelFactory<IFoghornService>(new BasicHttpBinding(), new EndpointAddress(ServiceUrl)).CreateChannel(); var subscriberDto = new SubscriberDto {HostName = "localhost", Password = "******", SubscriberName = "jbloggs"}; foghornClient.RegisterSubscription(subscriberDto, ApplicationTestName); //TODO: Add Assertions }
/// <summary> /// Invoked when <see cref="ToEntity"/> operation is about to return. /// </summary> /// <param name="dto"><see cref="SubscriberDto"/> converted from <see cref="Subscriber"/>.</param> /// <param name="entity"><see cref="Subscriber"/> converted from <see cref="SubscriberDto"/>.</param> static partial void OnEntity(this SubscriberDto dto, Subscriber entity);
/// <summary> /// Invoked when <see cref="ToDto"/> operation is about to return. /// </summary> /// <param name="dto"><see cref="SubscriberDto"/> converted from <see cref="Subscriber"/>.</param> /// <param name="entity"><see cref="Subscriber"/> converted from <see cref="SubscriberDto"/>.</param> static partial void OnDto(this Subscriber entity, SubscriberDto dto);
/// <summary> /// Invoked when <see cref="ToDto"/> operation is about to return. /// </summary> /// <param name="dto"><see cref="SubscriberDto"/> converted from <see cref="Subscriber"/>.</param> /// <param name="entity"><see cref="Subscriber"/> converted from <see cref="SubscriberDto"/>.</param> partial static void OnDto(this Subscriber entity, SubscriberDto dto);
/// <summary> /// Converts this instance of <see cref="Subscriber"/> to an instance of <see cref="SubscriberDto"/>. /// </summary> /// <param name="entity"><see cref="Subscriber"/> to convert.</param> public static SubscriberDto ToDto(this Subscriber entity) { if (entity == null) return null; var dto = new SubscriberDto(); dto.SubscriberId = entity.SubscriberId; dto.SubscriberName = entity.SubscriberName; dto.Port = entity.Port; dto.HostName = entity.HostName; dto.Password = entity.Password; entity.OnDto(dto); return dto; }
public Guid RegisterSubscription(SubscriberDto subscriberDto, string sendingApplicationName) { var sendingApplication = DataContext.SendingApplications.FirstOrDefault(x => x.SendingApplicationName == sendingApplicationName); if (sendingApplication == null) { var exception = new Exception("Cannot register a subscription for a SendingApplication that is not registered."); Logger.ErrorException(FailureMessage, exception); throw exception; } Subscriber subscriber; if (subscriberDto.SubscriberId != Guid.Empty) { subscriber = DataContext.Subscribers.FirstOrDefault(x => x.SubscriberId == subscriberDto.SubscriberId); } else { subscriber = subscriberDto.ToEntity(); subscriber.SubscriberId = Guid.NewGuid(); DataContext.Subscribers.Add(subscriber); } var port = subscriberDto.Port.HasValue ? subscriberDto.Port.Value : Settings.Default.GrowlDefaultPort; var growlConnector = new GrowlConnector(subscriberDto.Password, subscriberDto.HostName, port); var growlNotificationTypes = new List<Growl.Connector.NotificationType>(); foreach (var notificationType in sendingApplication.NotificationTypes) { var growlNotificationType = new Growl.Connector.NotificationType(notificationType.NotificationTypeName, notificationType.NotificationTypeDisplayName); if (notificationType.NotificationTypeIcon != null && notificationType.NotificationTypeIcon.Length > 0) { growlNotificationType.Icon = new BinaryData(notificationType.NotificationTypeIcon); } growlNotificationTypes.Add(growlNotificationType); } var growlApplication = new Application(sendingApplicationName); if (sendingApplication.SendingApplicationIcon != null && sendingApplication.SendingApplicationIcon.Length > 0) { growlApplication.Icon = new BinaryData(sendingApplication.SendingApplicationIcon); } growlConnector.Register(growlApplication, growlNotificationTypes.ToArray()); if (sendingApplication.Subscribers.Contains(subscriber)) return Guid.Empty; Debug.Assert(subscriber != null, "subscriber != null"); subscriber.SendingApplication = sendingApplication; DataContext.SaveChanges(); return subscriber.SubscriberId; }
public void TestRegisterSubscription_ApplicationExists_SubscriberRegistered() { var service = new FoghornService(); if (_testApplicationId <= 0) { RegisterTestApplication(service); } var subscriberDto = new SubscriberDto { HostName = "localhost", Password = "******", SubscriberName = ApplicationTestName + "TestSubscriber", }; var subscriberId = service.RegisterSubscription(subscriberDto, ApplicationTestName); var dataContext = new FoghornEntities(); var subscriber = dataContext.Subscribers.FirstOrDefault(x => x.SubscriberId == subscriberId); Assert.NotNull(subscriber); }