示例#1
0
            public async Task DispatchAsync(Message message)
            {
                if (message == null) //0 bytes
                {
                    //We have already closed all channels, return. (Couldn't use DoneReceivingInCurrentState())
                    if (_channel.State == CommunicationState.Closed ||
                        _channel.State == CommunicationState.Closing ||
                        _channel.State == CommunicationState.Closed)
                    {
                        return;
                    }
                    else
                    {
                        await _serviceChannelDispatcher.DispatchAsync(message);

                        return;
                    }
                }
                IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(message);

                if (serviceDispatcher == null)
                {
                    ErrorBehavior.ThrowAndCatch(
                        new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, message.Headers.Action)), message);
                    await _demuxer.EndpointNotFoundAsync((IDuplexSessionChannel)_channel, message);

                    return;
                }
                _serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel);

                await _serviceChannelDispatcher.DispatchAsync(message);
            }
        public ISagaStepBuilder <TContext> With_Error_Behavior(ErrorBehavior errorBehavior)
        {
            if (Steps.Any())
            {
                var lastStep = Steps.Last();
                lastStep.OnErrorBehavior = errorBehavior;
            }

            return(this);
        }
示例#3
0
 public void GeneratorSetErrorBehavior(int behaviour)
 {
     if (behaviour == 0)
     {
         errorBehavior = ErrorBehavior.ErrorTile;
     }
     else if (behaviour == 1)
     {
         errorBehavior = ErrorBehavior.Restart;
     }
 }
 /// <summary>
 /// Constructs the step
 /// </summary>
 public ForwardTransportMessageStep(Func <TransportMessage, Task <ForwardAction> > routingFunction, ITransport transport, IRebusLoggerFactory rebusLoggerFactory, string errorQueueName, ErrorBehavior errorBehavior)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _routingFunction = routingFunction ?? throw new ArgumentNullException(nameof(routingFunction));
     _transport       = transport ?? throw new ArgumentNullException(nameof(transport));
     _errorQueueName  = errorQueueName;
     _errorBehavior   = errorBehavior;
     _log             = rebusLoggerFactory.GetLogger <ForwardTransportMessageStep>();
 }
示例#5
0
            public async Task DispatchAsync(RequestContext context)
            {
                // TODO: Find way to avoid instantiating a new ServiceChannelDispatcher each time
                IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(context.RequestMessage);

                if (serviceDispatcher == null)
                {
                    ErrorBehavior.ThrowAndCatch(
                        new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, context.RequestMessage.Headers.Action)), context.RequestMessage);
                }
                // TODO: if serviceDispatcher == null, use the EndpointNotFound code path
                IServiceChannelDispatcher serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel);

                await serviceChannelDispatcher.DispatchAsync(context);
            }
示例#6
0
            private bool IsImpersonatedContext()
            {
                SafeCloseHandle tokenHandle = null;

                if (!System.ServiceModel.ComIntegration.SafeNativeMethods.OpenCurrentThreadToken(System.ServiceModel.ComIntegration.SafeNativeMethods.GetCurrentThread(), TokenAccessLevels.Query, true, out tokenHandle))
                {
                    int error = Marshal.GetLastWin32Error();
                    Utility.CloseInvalidOutSafeHandle(tokenHandle);
                    if (error == 0x3f0)
                    {
                        return(false);
                    }
                    ErrorBehavior.ThrowAndCatch(new Win32Exception(error));
                    return(true);
                }
                tokenHandle.Close();
                return(true);
            }
示例#7
0
    /// <summary>
    /// Adds the given routing function - should return <see cref="ForwardAction.None"/> to do nothing, or another action
    /// available on <see cref="ForwardAction"/> in order to do something to the message
    /// </summary>
    public static void AddTransportMessageForwarder(this StandardConfigurer <IRouter> configurer,
                                                    Func <TransportMessage, Task <ForwardAction> > routingFunction,
                                                    ErrorBehavior errorBehavior)
    {
        configurer.OtherService <IPipeline>()
        .Decorate(c =>
        {
            var pipeline           = c.Get <IPipeline>();
            var transport          = c.Get <ITransport>();
            var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();

            var errorQueueName = c.Has <SimpleRetryStrategySettings>()
                    ? c.Get <SimpleRetryStrategySettings>().ErrorQueueAddress
                    : "error";

            var stepToAdd = new ForwardTransportMessageStep(routingFunction, transport, rebusLoggerFactory, errorQueueName, errorBehavior);

            return(new PipelineStepConcatenator(pipeline)
                   .OnReceive(stepToAdd, PipelineAbsolutePosition.Front));
        });
    }
 protected CommandBase(Delegate @delegate, ErrorBehavior errorBehavior)
 {
     Delegate      = @delegate;
     ErrorBehavior = errorBehavior;
 }
示例#9
0
 public Command(Action execute, Func <bool> canExecute, ErrorBehavior errorBehavior)
     : base(execute, errorBehavior)
 {
     this.execute    = execute;
     this.canExecute = canExecute;
 }
示例#10
0
 /// <summary>
 /// Returns this schema with the given ErrorBehaviour
 /// </summary>
 public static Schema WithErrorBehavior(this Schema schema, ErrorBehavior eb)
 {
     schema.DefaultErrorBehavior = eb;
     return(schema);
 }
示例#11
0
        public static List <SourceReferencingFile> GetSourceReferencingFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive, ErrorBehavior errorBehavior, ref string error, ref string verboseError)
        {
            string fileExtension = FileManager.GetExtension(fileName);

            List <SourceReferencingFile> referencedFiles = null;

            switch (fileExtension)
            {
            case "scnx":
                try
                {
                    SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

                    referencedFiles = ses.GetSourceReferencingReferencedFiles(RelativeType.Absolute);
                }
                catch (Exception e)
                {
                    error           = "Error loading file " + fileName + ": " + e.Message;
                    referencedFiles = new List <SourceReferencingFile>();
                    verboseError    = e.ToString();
                }
                break;

            default:
                referencedFiles = new List <SourceReferencingFile>();
                break;
            }
/**/
            if (topLevelOrRecursive == TopLevelOrRecursive.Recursive)
            {
                //First we need to get a list of all referenced files
                List <string> filesToSearch = new List <string>();

                try
                {
                    // GetFilesReferencedByAsset can throw an error if the file doesn't
                    // exist.  But we don't really care if it's missing if it can't reference
                    // others.  I mean, sure we care, but it's not relevant here.  Other systems
                    // can check for that.
                    if (CanFileReferenceOtherFiles(fileName))
                    {
                        GetFilesReferencedByAsset(fileName, topLevelOrRecursive, filesToSearch);
                    }
                }
                catch (Exception e)
                {
                    if (errorBehavior == ErrorBehavior.ThrowException)
                    {
                        throw e;
                    }
                    else
                    {
                        error += e.Message + "\n";
                    }
                }



                if (filesToSearch != null)
                {
                    for (int i = filesToSearch.Count - 1; i > -1; i--)
                    {
                        string errorForThisFile        = "";
                        string verboseErrorForThisFile = "";
                        List <SourceReferencingFile> subReferencedFiles = GetSourceReferencingFilesReferencedByAsset(filesToSearch[i], topLevelOrRecursive,
                                                                                                                     errorBehavior, ref errorForThisFile, ref verboseErrorForThisFile);
                        // error may have already been set.  If it has already been set, we don't want to dump more errors (which may just be duplicates anyway)
                        if (string.IsNullOrEmpty(error))
                        {
                            error += errorForThisFile;
                        }

                        if (subReferencedFiles != null)
                        {
                            referencedFiles.AddRange(subReferencedFiles);
                        }
                    }
                }
            }
/**/
            return(referencedFiles);
        }
示例#12
0
        private bool ProcessItem(TInnerItem item)
        {
            bool flag;

            try
            {
                Message          message  = this.GetMessage(item);
                IChannelListener listener = null;
                try
                {
                    listener = this.MatchListener(message);
                }
                catch (CommunicationException exception)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                    }
                    return(false);
                }
                catch (MultipleFilterMatchesException exception2)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                    }
                    return(false);
                }
                catch (XmlException exception3)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information);
                    }
                    return(false);
                }
                catch (Exception exception4)
                {
                    if (Fx.IsFatal(exception4))
                    {
                        throw;
                    }
                    this.HandleUnknownException(exception4);
                    return(true);
                }
                if (listener == null)
                {
                    ErrorBehavior.ThrowAndCatch(new EndpointNotFoundException(System.ServiceModel.SR.GetString("UnableToDemuxChannel", new object[] { message.Headers.Action })), message);
                    this.EndpointNotFound(item);
                    item = default(TInnerItem);
                    return(false);
                }
                if (this.onItemDequeued == null)
                {
                    this.onItemDequeued = new Action(this.OnItemDequeued);
                }
                this.EnqueueAndDispatch(listener, item, this.onItemDequeued, false);
                item = default(TInnerItem);
                flag = true;
            }
            finally
            {
                if (item != null)
                {
                    this.AbortItem(item);
                }
            }
            return(flag);
        }
示例#13
0
        /// <inheritdoc />
        protected override async Task <Result <Array <Entity>, IError> > Run(
            IStateMonad stateMonad,
            CancellationToken cancellationToken)
        {
            var entityStream = await EntityStream.Run(stateMonad, cancellationToken);

            if (entityStream.IsFailure)
            {
                return(entityStream.ConvertFailure <Array <Entity> >());
            }

            var schemaEntity = await Schema.Run(stateMonad, cancellationToken);

            if (schemaEntity.IsFailure)
            {
                return(schemaEntity.ConvertFailure <Array <Entity> >());
            }

            var schema = EntityConversionHelpers.TryCreateFromEntity <Schema>(schemaEntity.Value)
                         .MapError(e => e.WithLocation(this));

            if (schema.IsFailure)
            {
                return(schema.ConvertFailure <Array <Entity> >());
            }

            Maybe <ErrorBehavior> errorBehavior;

            if (ErrorBehavior == null)
            {
                errorBehavior = Maybe <ErrorBehavior> .None;
            }
            else
            {
                var errorBehaviorResult = await ErrorBehavior.Run(stateMonad, cancellationToken);

                if (errorBehaviorResult.IsFailure)
                {
                    return(errorBehaviorResult.ConvertFailure <Array <Entity> >());
                }

                errorBehavior = Maybe <ErrorBehavior> .From(errorBehaviorResult.Value);
            }

            var newStream = entityStream.Value.SelectMany(ApplySchema);

            return(newStream);

            async IAsyncEnumerable <Entity> ApplySchema(Entity entity)
            {
                await ValueTask.CompletedTask;
                var result = schema.Value.ApplyToEntity(entity, this, stateMonad, errorBehavior);

                if (result.IsFailure)
                {
                    throw new ErrorException(result.Error.WithLocation(this));
                }

                if (result.Value.HasValue)
                {
                    yield return(result.Value.Value);
                }
            }
        }
        static IBus GetFailingBus(BuiltinHandlerActivator activator, InMemNetwork network, string recipientQueueName, ErrorBehavior errorBehavior)
        {
            var deliveryAttempts = 0;

            var bus = Configure.With(activator)
                      .Transport(t => t.UseInMemoryTransport(network, "forwarder"))
                      .Routing(t =>
            {
                t.AddTransportMessageForwarder(async transportMessage =>
                {
                    deliveryAttempts++;

                    if (deliveryAttempts < 10)
                    {
                        throw new RebusApplicationException("fake an error");
                    }

                    return(ForwardAction.ForwardTo(recipientQueueName));
                }, errorBehavior);
            })
                      .Options(o =>
            {
                o.SetNumberOfWorkers(1);
                o.SetMaxParallelism(1);
            })
                      .Start();

            return(bus);
        }
示例#15
0
 public AsyncCommand(Func <Task> executeAsync, Func <bool> canExecute, ErrorBehavior errorBehavior)
     : base(executeAsync, errorBehavior)
 {
     this.executeAsync = executeAsync;
     this.canExecute   = canExecute;
 }
示例#16
0
        private void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    return;
                }
                this.connectionReaders.Remove(modeReader);
            }
            bool flag = true;

            try
            {
                FramingMode connectionMode;
                try
                {
                    connectionMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType exceptionEventType = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(exceptionEventType))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, exceptionEventType);
                    }
                    return;
                }
                catch (TimeoutException exception2)
                {
                    if (!isCached)
                    {
                        exception2 = new TimeoutException(System.ServiceModel.SR.GetString("ChannelInitializationTimeout", new object[] { this.channelInitializationTimeout }), exception2);
                        ErrorBehavior.ThrowAndCatch(exception2);
                    }
                    TraceEventType type = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(type))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, type);
                    }
                    return;
                }
                switch (connectionMode)
                {
                case FramingMode.Singleton:
                    this.OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                    break;

                case FramingMode.Duplex:
                    this.OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                    break;

                default:
                {
                    Exception innerException = new InvalidDataException(System.ServiceModel.SR.GetString("FramingModeNotSupported", new object[] { connectionMode }));
                    Exception exception4     = new ProtocolException(innerException.Message, innerException);
                    FramingEncodingString.AddFaultString(exception4, "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode");
                    ErrorBehavior.ThrowAndCatch(exception4);
                    return;
                }
                }
                flag = false;
            }
            catch (Exception exception5)
            {
                if (Fx.IsFatal(exception5))
                {
                    throw;
                }
                if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception5))
                {
                    throw;
                }
            }
            finally
            {
                if (flag)
                {
                    modeReader.Dispose();
                }
            }
        }