Example #1
0
        /// <summary>
        /// Unsubscribes the specified subscriber.
        /// </summary>
        /// <typeparam name="T">The type of message being unsubscribed from</typeparam>
        /// <param name="subscriber">The subscriber.</param>
        public void Unsubscribe <T>(IHandleMessage <T> subscriber)
        {
            IList <WeakReference> subscribers;

            lock (_subscriptions)
            {
                if (!_subscriptions.TryGetValue(typeof(T), out subscribers))
                {
                    return;
                }

                lock (subscribers)
                {
                    for (int i = 0; i < subscribers.Count; i++)
                    {
                        if (object.ReferenceEquals(subscribers[i].Target, subscriber))
                        {
                            subscribers.RemoveAt(i);
                            break;
                        }
                    }

                    if (subscribers.Count == 0)
                    {
                        _subscriptions.Remove(typeof(T));
                    }
                }
            }
        }
Example #2
0
 public RemoveFromReadQueueAspect(IHandleMessage <Message> action, IReadMessageContext context, IBusConfig config, ILogMessages logger)
 {
     _context = context;
     _config  = config;
     _logger  = logger;
     _inner   = action;
 }
 public QueuedHandler(IHandleMessage <Message> handler, string name, int maxCount = 0)
 {
     _handler      = handler;
     _name         = name;
     _maxCount     = maxCount;
     _messageQueue = new ConcurrentQueue <Message>();
     _stopped      = new AutoResetEvent(false);
 }
Example #4
0
        /// <summary>
        /// Subscribes the specified subscriber.
        /// </summary>
        /// <typeparam name="T">The type of message being subscribed to</typeparam>
        /// <param name="subscriber">The subscriber.</param>
        public void Subscribe <T>(IHandleMessage <T> subscriber)
        {
            IList <object> subscribers;

            if (!_subscriptions.TryGetValue(typeof(T), out subscribers))
            {
                subscribers = new List <object>();
                _subscriptions.Add(typeof(T), subscribers);
            }

            subscribers.Add(subscriber);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessMessageAsync"/> class.
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="heartBeatWorkerFactory">The heart beat worker factory.</param>
        /// <param name="messageExceptionHandler">The message exception handler.</param>
        /// <param name="commitMessage">The commit message.</param>
        public ProcessMessageAsync(IHandleMessage handler,
                                   IHeartBeatWorkerFactory heartBeatWorkerFactory,
                                   MessageExceptionHandler messageExceptionHandler,
                                   ICommitMessage commitMessage)
        {
            Guard.NotNull(() => handler, handler);
            Guard.NotNull(() => heartBeatWorkerFactory, heartBeatWorkerFactory);
            Guard.NotNull(() => messageExceptionHandler, messageExceptionHandler);
            Guard.NotNull(() => commitMessage, commitMessage);

            _messageExceptionHandler = messageExceptionHandler;
            _methodToRun             = handler;
            _heartBeatWorkerFactory  = heartBeatWorkerFactory;
            _commitMessage           = commitMessage;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessMessage"/> class.
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="heartBeatWorkerFactory">The heart beat worker factory.</param>
        /// <param name="messageExceptionHandler">The message exception handler.</param>
        /// <param name="commitMessage">The commit message.</param>
        public ProcessMessage(IHandleMessage handler,
            IHeartBeatWorkerFactory heartBeatWorkerFactory,
            MessageExceptionHandler messageExceptionHandler,
            ICommitMessage commitMessage)
        {
            Guard.NotNull(() => handler, handler);
            Guard.NotNull(() => heartBeatWorkerFactory, heartBeatWorkerFactory);
            Guard.NotNull(() => messageExceptionHandler, messageExceptionHandler);
            Guard.NotNull(() => commitMessage, commitMessage);

            _messageExceptionHandler = messageExceptionHandler;
            _methodToRun = handler;
            _heartBeatWorkerFactory = heartBeatWorkerFactory;
            _commitMessage = commitMessage;
        }
Example #7
0
        private void Subscribe <T>(string topic, IHandleMessage <T> handler) where T : Message
        {
            var narrowingHandler = new MessageHandler <T>(handler);

            _topicHandlers.AddOrUpdate(
                topic,
                x => new List <IWrapHandler>()
            {
                narrowingHandler
            },
                (s, list) => new List <IWrapHandler>(list)
            {
                narrowingHandler
            });
        }
Example #8
0
        /// <summary>
        /// Unsubscribes the specified subscriber.
        /// </summary>
        /// <typeparam name="T">The type of message being unsubscribed from</typeparam>
        /// <param name="subscriber">The subscriber.</param>
        public void Unsubscribe <T>(IHandleMessage <T> subscriber)
        {
            IList <object> subscribers;

            if (!_subscriptions.TryGetValue(typeof(T), out subscribers))
            {
                return;
            }

            subscribers.Remove(subscriber);

            if (subscribers.Count == 0)
            {
                _subscriptions.Remove(typeof(T));
            }
        }
Example #9
0
        /// <summary>
        /// Unsubscribes a given IHandleMessage implementation to the channels it returns.
        /// </summary>
        /// <param name="implementation">An instance of IHandleMessage.</param>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if implementation is null</exception>
        public void Unsubscribe(IHandleMessage implementation)
        {
            if (implementation == null)
            {
                throw new ArgumentNullException();
            }

            var tobeRemoved = (IncomingLeadHandler)implementation;

            // if tobeRemoved is already on the subscribed list, remove it from the list
            var existing = SubscribedList.Subscriptions.FirstOrDefault(x => x.Subscriber == tobeRemoved.Subscriber);

            if (existing != null)
            {
                SubscribedList.Subscriptions.Remove(existing);
            }
        }
Example #10
0
        /// <summary>
        /// Subscribes a given IHandleMessage implementation to the channels it returns.
        /// </summary>
        /// <param name="implementation">An instance of IHandleMessage.</param>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if implementation is null</exception>
        public void Subscribe(IHandleMessage implementation)
        {
            if (implementation == null)
            {
                throw new ArgumentNullException();
            }

            var incoming = (IncomingLeadHandler)implementation;

            // if incoming is not on the subscribed list, add it to the list.
            var previouslySubscribed = SubscribedList.Subscriptions.Where(x => x.Subscriber == incoming.Subscriber).ToList().Count;

            if (previouslySubscribed == 0)
            {
                SubscribedList.Subscriptions.Add(incoming);
            }
        }
Example #11
0
        /// <summary>
        /// Subscribes the specified subscriber.
        /// </summary>
        /// <typeparam name="T">The type of message being subscribed to</typeparam>
        /// <param name="subscriber">The subscriber.</param>
        public void Subscribe <T>(IHandleMessage <T> subscriber)
        {
            IList <WeakReference> subscribers;

            lock (_subscriptions)
            {
                if (!_subscriptions.TryGetValue(typeof(T), out subscribers))
                {
                    subscribers = new List <WeakReference>();
                    _subscriptions.Add(typeof(T), subscribers);
                }

                lock (subscribers)
                {
                    subscribers.Add(new WeakReference(subscriber));
                }
            }
        }
Example #12
0
 public UserController(IServiceAppUser serviceAppUser, UserManager <User> userManager, RoleManager <Role> roleManager,
                       SignInManager <User> signInManager,
                       IMapper mapper,
                       IConfiguration config,
                       IServiceAppCompany serviceAppCompany,
                       IServiceAppCompanySubjectIssue serviceAppCompanySubjectIssue,
                       IHandleMessage <UserSummary> handleMessageUserSummary,
                       IServiceAppCompanyRate serviceAppCompanyRate,
                       IHandleMessage <UserDetailsDTO> handleMessageUser)
 {
     _serviceAppUser = serviceAppUser;
     _userManager    = userManager;
     _roleManager    = roleManager;
     _signInManager  = signInManager;
     _mapper         = mapper;
     _config         = config;
     _serviceAppCompanySubjectIssue = serviceAppCompanySubjectIssue;
     _handleMessageUserSummary      = handleMessageUserSummary;
     _handleMessageUser             = handleMessageUser;
     _serviceAppCompany             = serviceAppCompany;
     _serviceAppCompanyRate         = serviceAppCompanyRate;
 }
Example #13
0
 public CompanyController(IHandleMessage <List <CompanyDTO> > handleMessageUser,
                          IHandleMessage <CompanySubjectTellUsDTO> handleMessageCompanySubjectTellUs,
                          IHandleMessage <List <SubjectDTO> > handleMessageSubject,
                          IHandleMessage <List <SubjectIssueDTO> > handleMessageSubjectIssue,
                          IServiceAppCompany serviceAppCompany,
                          IServiceAppCompanyRate serviceAppCompanyRate,
                          IServiceAppSubject serviceAppSubject,
                          IServiceAppSubjectIssue serviceAppSubjectIssue,
                          IServiceAppCompanySubjectIssue serviceAppCompanySubjectIssue,
                          IMapper mapper)
 {
     _handleMessageUser = handleMessageUser;
     _handleMessageCompanySubjectTellUs = handleMessageCompanySubjectTellUs;
     _handleMessageSubject          = handleMessageSubject;
     _handleMessageSubjectIssue     = handleMessageSubjectIssue;
     _serviceAppCompany             = serviceAppCompany;
     _serviceAppCompanyRate         = serviceAppCompanyRate;
     _serviceAppSubject             = serviceAppSubject;
     _serviceAppSubjectIssue        = serviceAppSubjectIssue;
     _serviceAppCompanySubjectIssue = serviceAppCompanySubjectIssue;
     _mapper = mapper;
 }
Example #14
0
 public TimeToLiveHandler(IHandleMessage <Message> handler)
 {
     _handler = handler;
 }
 public static IHandleMessageAsync <TMessage> AsAsync <TMessage>(this IHandleMessage <TMessage> handler)
 {
     return(new SyncAsAsyncHandlerDecorator <TMessage>(handler));
 }
Example #16
0
 public MessageHandler(IHandleMessage <T> handle)
     : base(handle)
 {
     _handle = handle;
 }
 public SyncAsAsyncHandlerDecorator(IHandleMessage <TMessage> handler)
 {
     this.handler = handler;
 }
Example #18
0
 public void Subscribe <T>(IHandleMessage <T> handler) where T : Message
 {
     Subscribe(typeof(T).Name, handler);
 }
 public MoveToErrorQueueAspect(IHandleMessage <Message> action, IReadMessageContext context, ILogMessages logger)
 {
     _context = context;
     _logger  = logger;
     _inner   = action;
 }
Example #20
0
        /// <summary>
        /// Overrides the default comparison logic to properly define the equality for IHandleMessage type.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>Returns true if the current object is equal to the other parameter; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            IHandleMessage handle = obj as IHandleMessage;

            return(handle != null && handle.Subscriber == Subscriber);
        }
 public AlertMonitor(IHandleMessage <Message> handler, IThreshold threshold, IAppBus bus)
 {
     _bus       = bus;
     _threshold = threshold;
     _handler   = handler;
 }
Example #22
0
 public LoggingAspect(IHandleMessage <Message> action, string operation, ILogMessages logger)
 {
     _inner     = action;
     _logger    = logger;
     _operation = operation;
 }
Example #23
0
 public FailFastAspect(IHandleMessage <Message> action, IBusConfig config, ILogMessages logger)
 {
     _inner  = action;
     _config = config;
     _logger = logger;
 }
Example #24
0
 public void RegisterHandler <T>(IHandleMessage <T> handler) where T : IMessage
 {
     m_callbackDict.Add(typeof(T), (message) => handler.Handle((T)message));
 }
 public RegisterMessageHandler(IHandleMessage handler, IProvideServiceBusConnection bus)
 {
     this.handler = handler;
     this.bus     = bus;
 }
Example #26
0
 public RegisterHandler(IHandleMessage <T> handler, IProvideServiceBusConnection <T> bus)
 {
     bus.QueueClient.RegisterMessageHandler(handler.HandleAsync, handler.HandleOption);
 }
Example #27
0
 public NarrowingHandler(IHandleMessage <TDerived> handle)
 {
     _handle = handle;
 }
Example #28
0
 /// <summary>
 /// Takes user-defined message handlers implementing the IHandleMessage
 /// of T interface and stores them to be invoked later when the Receive
 /// method is called.
 /// </summary>
 public void RegisterHandler <T>(IHandleMessage <T> handler)
 {
     _handlers.Add(new Action <T>(handler.Handle));
 }
Example #29
0
 public WideningHandler(IHandleMessage <TBase> handler)
 {
     _handler = handler;
 }
Example #30
0
 public void Subscribe(IHandleMessage handler)
 {
     MessageReceived += handler.Handle;
 }
Example #31
0
 private static UserRule ToUserRule(this IHandleMessage handleMessage)
 {
     return(JsonConvert.DeserializeObject <UserRule>(handleMessage.Message));
 }