public MainWindowViewModel(IStartAddingMoneyCommand addMoneyCommand, IEventNotification <MoneyAddedNotificationToEventAdapter.MoneyAddedEventArgs> moneyAddedEvent) : this() { StartAddMoneyCommand = addMoneyCommand; this.moneyAddedEvent = moneyAddedEvent; this.moneyAddedEvent.NotificationReceived += MoneyAddedEvent_NotificationReceived; }
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); }
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); }
public Task Handle(IEventNotification notification, CancellationToken cancellation) { if (notification is TNotification typedNotification) { return(Handle(typedNotification, cancellation)); } return(Task.CompletedTask); }
protected Task OnEventNotification(IEventNotification notification) { if (notification.Events.Count > 0) { ListenedEvents.AddRange(notification.Events); } return(Task.CompletedTask); }
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); }
public Message CreateMessage(IEventNotification <IEvent> context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var eventName = context.Payload.GetType().Name; return(CreateMessage(eventName, context)); }
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)); }
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); }
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); } }
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, }); }
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); } }
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)); }
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); }
/// <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(); } }); } }
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); }
//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(); }
public HttpResponseMessage PublishEvent(IEventNotification notification) { //TODO: Implementation required return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)); }
/// <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(); } }); } }
public void RemoveDomainEvent(IEventNotification evt) { DomainEvents?.Remove(evt); }
public void AddDomainEvent(IEventNotification evt) { DomainEvents ??= new List <IEventNotification>(); DomainEvents.Add(evt); }