/// <summary> /// Gets the specified identification. /// </summary> /// <param name="identification">The identification.</param> /// <returns></returns> public Subscriptor Get(Identification identification) { Subscriptor subscriptor = default(Subscriptor); _subscriptors.TryGetValue(identification, out subscriptor); return(subscriptor); }
/// <summary> /// Sends the specified identification. /// </summary> /// <param name="identification">The identification.</param> /// <param name="messageControl">The message control.</param> public void Send(Identification identification, IControlMessage messageControl) { Subscriptor subscriptor = _subscriptorsRepository.Get(identification); if (subscriptor != null) { subscriptor.ServiceInputControlGateway.Send(messageControl); } }
/// <summary> /// Adds the specified subscriptor. /// </summary> /// <param name="subscriptor">The subscriptor.</param> public void Add(Subscriptor subscriptor) { SubscriptorEntity subscriptorEntity = _repository.FindOne( s => s.Service.Id == subscriptor.Service.Id && s.Service.Type == subscriptor.Service.Type) ?? new SubscriptorEntity(); subscriptorEntity.From(subscriptor); _repository.Save(subscriptorEntity); }
/// <summary> /// Unsubscribes the specified type. /// </summary> /// <param name="subscriptor">The subscriptor.</param> public void Remove(Subscriptor subscriptor) { if (_subscriptors.ContainsKey(subscriptor.Service)) { Subscriptor subs; if (_subscriptors.TryRemove(subscriptor.Service, out subs)) { subs.Dispose(); //_subscriptors.Keys.Remove(subscriptor.Service); Collection Read-Only } } }
/// <summary> /// Unsubscribes the specified type. /// </summary> /// <param name="subscriptorIdentification">The subscriptor identification.</param> public void Remove(Identification subscriptorIdentification) { Subscriptor subscriptor = _subscriptorsRepository.Get(subscriptorIdentification); _subscriptorsRepository.Remove(subscriptor); foreach (SubscriptionKey type in subscriptor.SubcriptionTypes) { ((ISubscriber)Controller.Processor).Unsubscribe(type, subscriptorIdentification, subscriptor.ServiceInputGateway); } _subscriptorsPersister.Remove(subscriptor.Service); subscriptor.Dispose(); }
/// <summary> /// Subscribes the specified type. /// </summary> /// <param name="subscriptor">The subscriptor.</param> public void Add(Subscriptor subscriptor) { LoggerManager.Instance.Debug("Adding Subscriptor"); AddSubscriptor(subscriptor); LoggerManager.Instance.Debug("Persisting Subscriptor"); try { _subscriptorsPersister.Add(subscriptor); } catch (Exception ex) { LoggerManager.Instance.Error("Error Persisting Subscriptor", ex); throw; } }
public void Contains_Susbscriptor() { var identification = new Identification { Id = "A", Type = "B" }; var subscriptor = new Subscriptor { Service = identification, ServiceInputControlGateway = _mockGateWayControl.Object, ServiceInputGateway = _mockGateWayMessageBus.Object }; using (var subject = new MemorySubscriptorsRepository()) { subject.Add(subscriptor); Assert.IsTrue(subject.Contains(identification)); } }
public void Dispose_Susbscriptor() { var identification = new Identification { Id = "A", Type = "B" }; var subscriptor = new Subscriptor { Service = identification, ServiceInputControlGateway = _mockGateWayControl.Object, ServiceInputGateway = _mockGateWayMessageBus.Object }; using (var subject = new MemorySubscriptorsRepository()) { subject.Add(subscriptor); } _mockGateWayMessageBus.Verify(x => x.Dispose()); _mockGateWayControl.Verify(x => x.Dispose()); }
/// <summary> /// Adds the subscriptor. /// </summary> /// <param name="subscriptor">The subscriptor.</param> private void AddSubscriptor(Subscriptor subscriptor) { _subscriptorsRepository.Add(subscriptor); foreach (SubscriptionKey type in subscriptor.SubcriptionTypes) { if (type != null) { LoggerManager.Instance.Debug(string.Format("Adding Subscriptors Types {0}", type.Key)); ((ISubscriber)Controller.Processor).Subscribe(type, subscriptor.Service, subscriptor.ServiceInputGateway); } else { LoggerManager.Instance.Error( string.Format("Type null in subscriptor {0}, check subscription message", subscriptor.Service.Id)); } } }
/// <summary> /// Toes the subscriptor. /// </summary> /// <param name="subscriptorEntity">The subscriptor entity.</param> /// <param name="processor">The processor.</param> /// <returns></returns> public static Subscriptor ToSubscriptor(this SubscriptorEntity subscriptorEntity, Identification processor) { var subscriptor = new Subscriptor { Service = subscriptorEntity.Service, ServiceInputGateway = RouterGatewayFactory.CreateOutputGateway( new Uri(subscriptorEntity.InputGateway.Uri), (TransportType)subscriptorEntity.InputGateway.Transport), ServiceInputControlGateway = AgentGatewayFactory.CreateOutputGateway(processor, new Uri(subscriptorEntity.InputControlGateway.Uri), (TransportType)subscriptorEntity.InputControlGateway.Transport), }; foreach (var subscriptionTypeMessage in subscriptorEntity.SubcriptionTypes) { subscriptor.SubcriptionTypes.Add(subscriptionTypeMessage.ToSubscriptorKey()); } return subscriptor; }
/// <summary> /// Froms the specified subscriptor entity. /// </summary> /// <param name="subscriptorEntity">The subscriptor entity.</param> /// <param name="subscriptor">The subscriptor.</param> public static void From(this SubscriptorEntity subscriptorEntity, Subscriptor subscriptor) { subscriptorEntity.InputGateway = new GatewayEntity { Uri = subscriptor.ServiceInputGateway.EndPoint.Uri.OriginalString, Transport = (int) subscriptor.ServiceInputGateway.EndPoint.Transport }; subscriptorEntity.InputControlGateway = new GatewayEntity { Uri = subscriptor.ServiceInputControlGateway.EndPoint.Uri. OriginalString, Transport = (int) subscriptor.ServiceInputControlGateway.EndPoint. Transport }; subscriptorEntity.Service = subscriptor.Service; subscriptorEntity.SubcriptionTypes = subscriptor.SubcriptionTypes.Where(t => t != null).Select(t => t.ToSubscriptorType()).ToList(); }
public void SetUp() { _subscriptorsRepository = new Mock<ISubscriptorsRepository>(MockBehavior.Strict); _subscriptorPersister = new Mock<ISubscriptorsPersister>(MockBehavior.Strict); _controller = new Mock<IRouterController>(MockBehavior.Strict); _processor = new Mock<IProcessorFake>(MockBehavior.Strict); _outputControlGateway = new Mock<IOutputGateway<IControlMessage>>(MockBehavior.Strict); _outputGateway = new Mock<IOutputGateway<byte[]>>(MockBehavior.Strict); _controller.SetupGet(c => c.Processor).Returns(_processor.Object); _identification = new Identification { Id = "Test", Type = "Test_Type" }; _subscriptionKey = new SubscriptionKey { Key = string.Format("{0},{1}", typeof(string).FullName, typeof(string).Assembly.GetName().Name) }; _subscriptor = new Subscriptor() { Service = new Identification { Id = "Service", Type = "Service" }, ServiceInputControlGateway = _outputControlGateway.Object, ServiceInputGateway = _outputGateway.Object, SubcriptionTypes = new List<SubscriptionKey> { _subscriptionKey } }; _subscriptorsRepository.Setup(r => r.Dispose()); }
/// <summary> /// Subscribes the specified type. /// </summary> /// <param name="subscriptor">The subscriptor.</param> public void Add(Subscriptor subscriptor) { _subscriptors.GetOrAdd(subscriptor.Service, subscriptor); }
public void GetAll_Susbscriptor() { var identification = new Identification { Id = "A", Type = "B" }; var subscriptor = new Subscriptor { Service = identification, ServiceInputControlGateway = _mockGateWayControl.Object, ServiceInputGateway = _mockGateWayMessageBus.Object }; var identification2 = new Identification { Id = "C", Type = "C" }; var subscriptor2 = new Subscriptor { Service = identification2, ServiceInputControlGateway = _mockGateWayControl.Object, ServiceInputGateway = _mockGateWayMessageBus.Object }; using (var subject = new MemorySubscriptorsRepository()) { subject.Add(subscriptor); subject.Add(subscriptor2); var subscriptors = subject.GetAll(); Assert.IsTrue(subscriptors.Count() == 2); } }
/// <summary> /// Adds the subscriptor. /// </summary> /// <param name="subscriptor">The subscriptor.</param> private void AddSubscriptor(Subscriptor subscriptor) { _subscriptorsRepository.Add(subscriptor); foreach (SubscriptionKey type in subscriptor.SubcriptionTypes) { if (type != null) { LoggerManager.Instance.Debug(string.Format("Adding Subscriptors Types {0}", type.Key)); ((ISubscriber) Controller.Processor).Subscribe(type, subscriptor.Service, subscriptor.ServiceInputGateway); } else { LoggerManager.Instance.Error( string.Format("Type null in subscriptor {0}, check subscription message", subscriptor.Service.Id)); } } }