/// <summary>
        /// Starts HTTP services
        /// </summary>
        public async Task Start()
        {
            _httpListener.Start();

            var requests = new HashSet <Task>();

            for (int i = 0; i < MaxConcurrentRequests; i++)
            {
                requests.Add(_httpListener.GetContextAsync());
            }

            while (!_tokenSource.Token.IsCancellationRequested)
            {
                Task t = await Task.WhenAny(requests);

                requests.Remove(t);

                if (t is Task <HttpListenerContext> )
                {
                    var context = (t as Task <HttpListenerContext>).Result;
                    requests.Add(ProcessRequestAsync(context));
                    requests.Add(_httpListener.GetContextAsync());
                }
                else
                {
                    if (t.IsFaulted)
                    {
                        OnUnhandledException?.Invoke(t.Exception);
                    }
                }
            }
        }
        public void Start(params string[] args)
        {
            var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>();

            Task.Run(() =>
            {
                var publishConfirmTimeOut = TimeSpan.FromSeconds(3);
                using (var messagePublisher = messagePublisherFactory.Create("myExchange0"))
                {
                    var confirmed = messagePublisher
                                    .Publish("myMessage",
                                             new TestMessage("Testing sending a message using RabbitMQ"))
                                    .WaitForConfirm(publishConfirmTimeOut, out var timedOut);

                    if (confirmed == false)
                    {
                        throw new InvalidOperationException("Failed waiting for publish confirm.");
                    }

                    if (timedOut)
                    {
                        throw new TimeoutException($"Timed out waiting for confirms. Waited for {publishConfirmTimeOut.TotalSeconds}s.");
                    }

                    messagePublisher
                    .Publish("messageConfirmed",
                             new TestMessage("Test message has been confirmed"));
                }
            }).ContinueWith(task =>
            {
                OnUnhandledException?.Invoke(task.Exception);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
Ejemplo n.º 3
0
        public void Update(DateTime now)
        {
            Now = now;
            while (queue.Count > 0)
            {
                var timer = queue.Top;
                if (timer.IsStopped)
                {
                    queue.Dequeue();
                    continue;
                }
                if (timer.At > Now)
                {
                    break;
                }

                var callback = timer.Callback;
                timer.Stop();
                queue.Dequeue();

                try
                {
                    callback?.Invoke();
                }
                catch (Exception e)
                {
                    OnUnhandledException?.Invoke(e);
                }
            }
        }
Ejemplo n.º 4
0
 public int Start(params string[] args)
 {
     Task.Run(() => _app.Start(args))
     .ContinueWith(task => OnUnhandledException?.Invoke(task.Exception),
                   TaskContinuationOptions.OnlyOnFaulted);
     return(0);
 }
        public void Start(params string[] args)
        {
            var threads = int.Parse(args.First());
            var messageConsumerFactory  = _configurer.Resolve <IMessageConsumerFactory>();
            var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>();

            Task.Run(() =>
            {
                Parallel.For(0, threads, i =>
                {
                    _messageConsumers.Add(messageConsumerFactory.Consume <TestMessage>(
                                              "myExchange" + i % 2,
                                              "queue" + i % 2,
                                              "routing" + i % 2,
                                              message =>
                    {
                        using (var messagePublisher = messagePublisherFactory.Create("myExchange" + i % 2))
                        {
                            messagePublisher.Publish("myMessage",
                                                     new TestMessage(i + ": " + message.Message));
                        }
                    }));
                });
            }).ContinueWith(task =>
            {
                OnUnhandledException?.Invoke(task.Exception);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
Ejemplo n.º 6
0
 public ApplicationWrapper(IApplication app)
 {
     _app = app;
     app.OnUnhandledException += exception =>
     {
         OnUnhandledException?.Invoke(exception);
     };
 }
Ejemplo n.º 7
0
 private static void CaptureUnhandledException(object sender, UnhandledExceptionEventArgs arg)
 {
     OnUnhandledException?.Invoke(sender, arg);
     Logger.Fatal(
         $"Unhandled Mono Exception Thrown '{arg.ExceptionObject.GetType().Name}':\n───────────────\n{arg.ExceptionObject}\n───────────────");
     if (arg.IsTerminating)
     {
         Logger.Fatal("Exception Terminating");
     }
 }
 public void Start(params string[] args)
 {
     Task.Run(() =>
     {
         var connectionFactory = _configurer.Resolve <IConnectionFactory>();
         _connection           = connectionFactory.CreateConnection();
     }).ContinueWith(task =>
     {
         OnUnhandledException?.Invoke(task.Exception);
     }, TaskContinuationOptions.OnlyOnFaulted);
 }
Ejemplo n.º 9
0
 public Task <int> StartAsync(CancellationToken cancellationToken = default, params string[] args)
 {
     try
     {
         var startCode = _app.Start(args);
         return(Task.FromResult(startCode));
     }
     catch (Exception exception)
     {
         OnUnhandledException?.Invoke(exception);
         return(Task.FromResult(-1));
     }
 }
Ejemplo n.º 10
0
 private void Unwind()
 {
     Contract.Requires(CurrentException != null);
     for (var frame = CurrentFrame; frame != null; frame = frame.Caller)
     {
         if (frame.TryHandle(CurrentException))
         {
             CurrentFrame = frame;
             return;
         }
     }
     OnUnhandledException?.Invoke(CurrentException);
     throw new UnhandledExceptionException(CurrentException.ThrownValue.CastToString());
 }
Ejemplo n.º 11
0
        public void Start(params string[] args)
        {
            var messagesToPublish       = int.Parse(args.First());
            var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>();

            Task.Run(() =>
            {
                Parallel.For(0, messagesToPublish, i =>
                {
                    using (var messagePublisher = messagePublisherFactory.Create("myExchange" + i % 2))
                    {
                        messagePublisher.Publish("myMessage",
                                                 new TestMessage("Testing sending a message using RabbitMQ"));
                    }
                });
            }).ContinueWith(task =>
            {
                OnUnhandledException?.Invoke(task.Exception);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
        public int Start(params string[] args)
        {
            var startCode = (int)HostFactory.Run(config =>
            {
                using (config.UseApplicationHostBuilder(args))
                {
                    config.OnException(exception => OnUnhandledException?.Invoke(exception));

                    config.Service <TService>(settings =>
                    {
                        settings.ConstructUsing(hostSettings => _service);
                        settings.WhenStarted((service, control) =>
                        {
                            _control = control;
                            var code = service.Start();
                            return(code == 0);
                        });
                        settings.WhenStopped(service => { service.Stop(); });
                    });
                }
            });

            return(startCode);
        }
Ejemplo n.º 13
0
        private async Task ProcessItemAsync(QueueItem <TItem> queueItem, CancellationToken cancellationToken)
        {
            var holderId = queueItem.HolderId;

            try
            {
                var processed = await _ProcessItemFunc(queueItem.Value, cancellationToken).ConfigureAwait(false);

                if (processed)
                {
                    await _ItemQueue.RemoveQueueItemAsync(queueItem.Id, holderId, cancellationToken).ConfigureAwait(false);

                    return;
                }

                await Task.Delay(_ItemQueueProcessorSettings.ItemRetryDelay, cancellationToken).ConfigureAwait(false);

                await _ItemQueue.ReleaseQueueItemAsync(queueItem.Id, holderId, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                OnUnhandledException?.Invoke(queueItem.Value, e);
            }
        }
Ejemplo n.º 14
0
 private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     OnUnhandledException?.Invoke();
 }
 public TopshelfHostService(TService service)
 {
     _service = service;
     _service.OnUnhandledException += exception => OnUnhandledException?.Invoke(exception);
 }
Ejemplo n.º 16
0
 public void Handle(Exception e)
 {
     OnUnhandledException?.Invoke(this, e);
 }