コード例 #1
0
        public async Task HandleAsync(Event @event)
        {
            _context.KeepAlive();
            await _handler.HandleAsync(_context, _serializer.Deserialize(@event));

            _context.KeepAlive();
        }
コード例 #2
0
        public async Task Execute(Action <ExecutionConfiguration> configurator = null)
        {
            var id            = EndpointId.Generate();
            var configuration = new ExecutionConfiguration();

            configurator?.Invoke(configuration);

            using (var hubClient = _hubClientFactory.Create(id))
            {
                var listeners = new List <IListener>();
                try
                {
                    listeners.AddRange((from dynamic handler in _handlers
                                        select hubClient.ListenFor(handler)).Cast <IListener>());

                    var startTime = DateTime.Now;
                    _context.KeepAlive();
                    await hubClient.PublishAsync(new Event <TAction>(_action, id), _publishSettings);

                    _context.KeepAlive();

                    while (listeners.Any() && !_context.Handled)
                    {
                        var currentTime = DateTime.Now;
                        if ((startTime.Add(configuration.ActionTimeout) < currentTime) ||
                            (_context.Usage.GetValueOrDefault().Add(configuration.EventTimeout) < currentTime))
                        {
                            if (_timeoutHandler != null)
                            {
                                await _timeoutHandler.HandleAsync();
                            }

                            break;
                        }

                        await Task.Delay(configuration.Tick);
                    }
                }
                finally
                {
                    foreach (var listener in listeners)
                    {
                        listener.Dispose();
                    }
                }
            }
        }