Esempio n. 1
0
        public void Error(T err)
        {
            if (!_isUnsubscribed)
            {
                try
                {
                    _target.Error(err);
                }
                catch (Exception e)
                {
                    Unsubscribe();
                    throw;
                }
            }

            Unsubscribe();
        }
Esempio n. 2
0
        private Task<CommandExecutionResult> Execute(object cmd, string[] tags, IPrincipal principal, IObserver<LogEntry> log)
        {
            var broker = _context.Broker;

            var ctx = new CommandHandlingContext(tags, principal, log);

            return broker.Handle(cmd, ctx)
                .ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        if (t.Exception != null)
                        {
                            var ex = t.Exception.Flatten();
                            if (ex.InnerExceptions.Count == 0)
                            {
                                log.Error(ex.GetBaseException().ToString());
                            }
                            else
                            {
                                foreach (var child in ex.InnerExceptions)
                                {
                                    log.Error(child.ToString());
                                }
                            }
                            return CommandExecutionResult.Failure(ex.GetBaseException().Message);
                        }
                        else
                        {
                            return CommandExecutionResult.Failure();
                        }
                    }
                    // TODO: Handle cancelled
                    return CommandExecutionResult.Success();
                });
        }