/// <summary>
 /// Initializes a new instance of the <see cref="PipelineEventArgs"/> class.
 /// </summary>
 /// <param name="message">The pipe message.</param>
 /// <param name="pipeline">The pipeline.</param>
 /// <param name="pipeFilter">The pipe filter.</param>
 /// <param name="exception">The exception.</param>
 public PipelineEventArgs(PipeMessage message, Pipeline pipeline, IPipeFilter pipeFilter, Exception exception = null)
 {
     this.Message        = message;
     this.Pipeline       = pipeline;
     this.PipeFilter     = pipeFilter;
     this.InnerException = exception;
 }
Esempio n. 2
0
        /// <summary>
        /// Method RaiseEvent.
        /// </summary>
        /// <param name="eventHandler">Instance of EventHandler.</param>
        /// <param name="message">The pipe message.</param>
        /// <param name="pipeFilter">The pipe filter.</param>
        /// <param name="exception">The exception.</param>
        private void RaiseEvent(EventHandler <PipelineEventArgs> eventHandler, PipeMessage message, IPipeFilter pipeFilter, Exception exception = null)
        {
            // Copy a reference to the delegate field now into a temporary field for thread safety.
            EventHandler <PipelineEventArgs> temp = Interlocked.CompareExchange(ref eventHandler, null, null);

            if (temp != null)
            {
                temp(this, new PipelineEventArgs(message, this, pipeFilter, exception));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PipeMessage"/> class.
 /// </summary>
 /// <param name="originalMessage">The original message.</param>
 private PipeMessage(PipeMessage originalMessage)
 {
     this.Id           = originalMessage.Id;
     this.CreatedAt    = originalMessage.CreatedAt;
     this.SentAt       = originalMessage.SentAt;
     this.ReceivedAt   = originalMessage.ReceivedAt;
     this.LastPipeline = originalMessage.LastPipeline;
     this.LastFilter   = originalMessage.LastFilter;
     this.Value        = originalMessage.Value;
     this._bodyObject  = originalMessage._bodyObject;
     this._properties  = originalMessage._properties;
 }
Esempio n. 4
0
 /// <summary>
 /// Occurs after the filter processed message.
 /// </summary>
 /// <param name="filter">The filter done processed message.</param>
 /// <param name="message">The output message.</param>
 protected virtual void AfterFilterProcessed(IPipeFilter filter, PipeMessage message)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Occurs before the filter processing message.
 /// </summary>
 /// <param name="filter">The filter going to process message.</param>
 /// <param name="message">The input message.</param>
 protected virtual void BeforeFilterProcessing(IPipeFilter filter, PipeMessage message)
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Occurs after the pipeline processed message.
 /// </summary>
 /// <param name="message">The output message.</param>
 protected virtual void AfterPipelinePumped(PipeMessage message)
 {
 }
Esempio n. 7
0
 /// <summary>
 /// Occurs before the pipeline processing message.
 /// </summary>
 /// <param name="message">The input message.</param>
 protected virtual void BeforePipelinePumping(PipeMessage message)
 {
 }
Esempio n. 8
0
        /// <summary>
        /// Pumps the specified input PipeMessage to the pipeline and start to process.
        /// </summary>
        /// <param name="input">The input PipeMessage.</param>
        /// <returns>The final PipeMessage output.</returns>
        public PipeMessage Pump(PipeMessage input)
        {
            var nextInput = input.Clone();

            nextInput.ReceivedAt   = DateTime.Now;
            nextInput.SentAt       = nextInput.ReceivedAt;
            nextInput.LastPipeline = this.Name;
            nextInput.LastFilter   = null;

            this.RaiseEvent(this.PipelinePumping, nextInput, null);
            this.BeforePipelinePumping(nextInput);

            lock (Utilities.GetSyncRoot(this._filterChain))
            {
                try
                {
                    foreach (var filter in this._filterChain)
                    {
                        try
                        {
                            var receivedAt = DateTime.Now;
                            nextInput.ReceivedAt   = receivedAt;
                            nextInput.LastPipeline = this.Name;

                            this.RaiseEvent(this.FilterProcessing, nextInput, filter);
                            this.BeforeFilterProcessing(filter, nextInput);

                            var output = filter.Process(nextInput);
                            output.ReceivedAt   = receivedAt;
                            output.SentAt       = DateTime.Now;
                            output.LastPipeline = this.Name;
                            output.LastFilter   = filter.Name;

                            this.AfterFilterProcessed(filter, output);

                            nextInput = output.Clone();

                            this.RaiseEvent(this.FilterProcessed, output, filter);
                        }
                        catch (Exception e)
                        {
                            InternalLogger.Log(e);
                            this.RaiseEvent(this.ErrorOccurred, nextInput, filter, e);
                            throw;
                        }
                    }
                }
                catch (Exception e)
                {
                    InternalLogger.Log(e);
                    this.RaiseEvent(this.ErrorOccurred, nextInput, null, e);
                    throw;
                }
            }

            this.AfterPipelinePumped(nextInput);

            var result = nextInput.Clone();

            this.RaiseEvent(this.PipelinePumped, nextInput, null);

            return(result);
        }