コード例 #1
0
        public MainWindowViewModel(IStartAddingMoneyCommand addMoneyCommand, IEventNotification <MoneyAddedNotificationToEventAdapter.MoneyAddedEventArgs> moneyAddedEvent) : this()
        {
            StartAddMoneyCommand = addMoneyCommand;
            this.moneyAddedEvent = moneyAddedEvent;

            this.moneyAddedEvent.NotificationReceived += MoneyAddedEvent_NotificationReceived;
        }
コード例 #2
0
        public void Start_WithoutEnqueuedItem_TaskWillBeTriggered()
        {
            IEventNotification toBeFilled        = null;
            Func <IEventNotification, Task> func = @event =>
            {
                if (toBeFilled == null)
                {
                    toBeFilled = @event;
                }
                return(Task.CompletedTask);
            };

            var subscription = Mock.Of <ISubscription>(s =>
                                                       s.Execution == Mock.Of <IExecution>(e =>
                                                                                           e.Delegate == func &&
                                                                                           e.Interval == TimeSpan.FromMilliseconds(100)) &&
                                                       s.Options == Mock.Of <IOptions>(o =>
                                                                                       o.QueueCapacity == 10)
                                                       );

            var handler = new SubscriptionHandler(subscription);

            handler.Start();

            Assert.True(Common.WaitUntil(() => toBeFilled != null, TimeSpan.FromSeconds(10)));
            Assert.True(toBeFilled.Events.Count == 0);
            Assert.True(toBeFilled.RemainingEventCount == 0);
            Assert.True(toBeFilled.LastExecution == default);
            toBeFilled = null;

            Assert.True(Common.WaitUntil(() => toBeFilled != null, TimeSpan.FromSeconds(10)));
            Assert.True(toBeFilled.LastExecution != default);
        }
コード例 #3
0
        private Hashtable htableSubscribed     = new Hashtable(); //eventName -- Delegate(是一个链表)

        public EventClient(string eventServerUri)
        {
            TcpChannel theChannel = new TcpChannel(0);

            ChannelServices.RegisterChannel(theChannel, false);

            this.eventServer = (IEventNotification)Activator.GetObject(typeof(IEventNotification), eventServerUri);
        }
コード例 #4
0
        public Task Handle(IEventNotification notification, CancellationToken cancellation)
        {
            if (notification is TNotification typedNotification)
            {
                return(Handle(typedNotification, cancellation));
            }

            return(Task.CompletedTask);
        }
コード例 #5
0
        protected Task OnEventNotification(IEventNotification notification)
        {
            if (notification.Events.Count > 0)
            {
                ListenedEvents.AddRange(notification.Events);
            }

            return(Task.CompletedTask);
        }
コード例 #6
0
        public async Task PublishAsync <TEvent>(IEventNotification <TEvent> context, CancellationToken cancellationToken = default) where TEvent : IEvent
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            await _messageSender.SendAsync(context, cancellationToken);
        }
コード例 #7
0
        public Message CreateMessage(IEventNotification <IEvent> context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var eventName = context.Payload.GetType().Name;

            return(CreateMessage(eventName, context));
        }
コード例 #8
0
        public Message CreateMessage <TEvent>(IEventNotification <TEvent> context) where TEvent : IEvent
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var eventName = typeof(TEvent).Name;

            return(CreateMessage(eventName, (IEventNotification <IEvent>)context));
        }
コード例 #9
0
        public async Task SendAsync <TEvent>(IEventNotification <TEvent> context, CancellationToken cancellationToken = default) where TEvent : IEvent
        {
            cancellationToken.ThrowIfCancellationRequested();

            var client = await _topicClientFactory.CreateAsync();

            var message = _messageFactory.CreateMessage(context);

            _logger.LogInformation($"Sending message 1 of 1. Type: '{message.Label}' | Size: '{message.Size}' bytes");

            await client.SendAsync(message);
        }
コード例 #10
0
        public async Task SendAsync<TEvent>(IEventNotification<TEvent> context, CancellationToken cancellationToken = default) where TEvent : IEvent
        {
            if (context == null)
                throw new ArgumentNullException(nameof(context));

            var message = _messageFactory.CreateMessage(context);

            using (var connection = await _connectionFactory.CreateConnectionAsync(cancellationToken))
            {
                await connection.PublishAsync(message, cancellationToken);
            }
        }
コード例 #11
0
        private Message CreateMessage(string eventName, IEventNotification <IEvent> context)
        {
            var @event = context.Payload;
            var body   = Encoding.UTF8.GetBytes(_eventSerializer.Serialize(context.Payload));

            return(new Message
            {
                MessageId = @event.Id,
                Type = eventName,
                CorrelationId = context.CorrelationId,
                CausationId = context.CausationId,
                UserId = context.UserId,
                Body = body,
            });
        }
コード例 #12
0
        public async Task PublishAsync <TEvent>(IEventNotification <TEvent> context, CancellationToken cancellationToken = default) where TEvent : IEvent
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            cancellationToken.ThrowIfCancellationRequested();

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var sender = scope.ServiceProvider.GetRequiredService <IQueueMessageSender>();
                await sender.SendAsync(context, cancellationToken);
            }
        }
コード例 #13
0
        public Message CreateMessage <TEvent>(IEventNotification <TEvent> context) where TEvent : IEvent
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (context.Payload == null)
            {
                throw new ArgumentNullException($"{nameof(context)}.{nameof(context.Payload)}");
            }

            var @event    = context.Payload;
            var eventName = @event.GetType().Name;

            return(CreateMessage(eventName, (IEventNotification <IEvent>)context));
        }
コード例 #14
0
        private async Task <bool> CanSendEvent(IEventNotification e, Type type, CancellationToken cancellationToken)
        {
            if (!_preprocessorsDictionary.TryGetValue(type, out List <IEventPreprocessor> filters))
            {
                return(true);
            }

            foreach (IEventPreprocessor filter in filters)
            {
                // filter is not passed correctly
                if (await filter.Handle(e, cancellationToken) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #15
0
        /// <summary>
        /// Displays an event notification, and then removes the event some time later (user-configurable)
        /// </summary>
        private void DisplayEventNotification(IEventNotification notification, ICollection <IEventNotification> notificationCollection)
        {
            const int SLEEP_TIME = 250;

            if (this.UserData.AreEventNotificationsEnabled &&
                (this.armedEventNotifications[notification.EventId] == true) &&
                !notificationCollection.Any((n) => n.EventId == notification.EventId))
            {
                Task.Factory.StartNew(() =>
                {
                    logger.Info("Displaying notification for \"{0}\"", notification.EventName);
                    Threading.InvokeOnUI(() =>
                    {
                        notificationCollection.Add(notification);
                    });

                    if (this.UserData.NotificationDuration > 0)
                    {
                        // For X seconds, loop and sleep, with checks to see if notifications have been disabled
                        for (int i = 0; i < (this.UserData.NotificationDuration * 1000 / SLEEP_TIME); i++)
                        {
                            System.Threading.Thread.Sleep(SLEEP_TIME);
                            if (!this.UserData.AreEventNotificationsEnabled)
                            {
                                logger.Debug("Removing notification for \"{0}\"", notification.EventName);
                                Threading.InvokeOnUI(() => notificationCollection.Remove(notification));
                            }
                        }

                        logger.Debug("Removing notification for \"{0}\"", notification.EventName);

                        // TODO: I hate having this here, but due to a limitation in WPF, there's no reasonable way around this at this time
                        // This makes it so that the notifications can fade out before they are removed from the notification window
                        Threading.InvokeOnUI(() => notification.IsRemovingNotification = true);
                        System.Threading.Thread.Sleep(SLEEP_TIME);
                        Threading.InvokeOnUI(() =>
                        {
                            notificationCollection.Remove(notification);
                        });
                        notification.Cleanup();
                    }
                });
            }
        }
コード例 #16
0
        private Message CreateMessage(string eventName, IEventNotification <IEvent> context)
        {
            var @event  = context.Payload;
            var body    = _eventSerializer.Serialize(@event);
            var message = new Message
            {
                MessageId      = @event.Id.ToString(),
                Body           = Encoding.UTF8.GetBytes(body),
                Label          = eventName,
                CorrelationId  = context.CorrelationId?.ToString(),
                UserProperties =
                {
                    { nameof(context.StreamId),    context.StreamId?.ToString()    },
                    { nameof(context.CausationId), context.CausationId?.ToString() },
                    { nameof(context.UserId),      context.UserId                  },
                    { nameof(context.Timestamp),   context.Timestamp               },
                },
            };

            return(message);
        }
コード例 #17
0
        //private ILoggerFactory _loggerFactory;

        public MsgService(IConfigLogic configLogic
                          , IMapper mapper
                          , ITokenBrandLogic tokenBrandLogic
                          , IPushTokenBrandService pushTokenBrandService
                          , ISendProcessLogic sendProcessLogic
                          , IPushSendProcessService pushSendProcessService
                          , IEventNotification eventNotification
                          //, ILoggerFactory loggerFactory
                          )
        {
            _configLogic            = configLogic;
            _mapper                 = mapper;
            _tokenBrandLogic        = tokenBrandLogic;
            _pushTokenBrandService  = pushTokenBrandService;
            _sendProcessLogic       = sendProcessLogic;
            _pushSendProcessService = pushSendProcessService;
            _eventNotification      = eventNotification;
            //_loggerFactory = loggerFactory;
            //初始化信号量
            InitSemaphore();
            //初始化队列
            InitQueue();
        }
コード例 #18
0
 public HttpResponseMessage PublishEvent(IEventNotification notification)
 {
     //TODO: Implementation required
     return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
 }
コード例 #19
0
ファイル: EventsController.cs プロジェクト: SamHurne/gw2pao
        /// <summary>
        /// Displays an event notification, and then removes the event some time later (user-configurable)
        /// </summary>
        private void DisplayEventNotification(IEventNotification notification, ICollection<IEventNotification> notificationCollection)
        {
            const int SLEEP_TIME = 250;

            if (this.UserData.AreEventNotificationsEnabled
                && (this.armedEventNotifications[notification.EventId] == true)
                && !notificationCollection.Any((n) => n.EventId == notification.EventId))
            {
                Task.Factory.StartNew(() =>
                {
                    logger.Info("Displaying notification for \"{0}\"", notification.EventName);
                    Threading.InvokeOnUI(() =>
                    {
                        notificationCollection.Add(notification);
                    });

                    if (this.UserData.NotificationDuration > 0)
                    {
                        // For X seconds, loop and sleep, with checks to see if notifications have been disabled
                        for (int i = 0; i < (this.UserData.NotificationDuration * 1000 / SLEEP_TIME); i++)
                        {
                            System.Threading.Thread.Sleep(SLEEP_TIME);
                            if (!this.UserData.AreEventNotificationsEnabled)
                            {
                                logger.Debug("Removing notification for \"{0}\"", notification.EventName);
                                Threading.InvokeOnUI(() => notificationCollection.Remove(notification));
                            }
                        }

                        logger.Debug("Removing notification for \"{0}\"", notification.EventName);

                        // TODO: I hate having this here, but due to a limitation in WPF, there's no reasonable way around this at this time
                        // This makes it so that the notifications can fade out before they are removed from the notification window
                        Threading.InvokeOnUI(() => notification.IsRemovingNotification = true);
                        System.Threading.Thread.Sleep(SLEEP_TIME);
                        Threading.InvokeOnUI(() =>
                        {
                            notificationCollection.Remove(notification);
                        });
                        notification.Cleanup();
                    }
                });
            }
        }
コード例 #20
0
 public void RemoveDomainEvent(IEventNotification evt)
 {
     DomainEvents?.Remove(evt);
 }
コード例 #21
0
 public void AddDomainEvent(IEventNotification evt)
 {
     DomainEvents ??= new List <IEventNotification>();
     DomainEvents.Add(evt);
 }