Ejemplo n.º 1
0
        /// <summary>
        /// Invokes next processing body be it the next filter or handler (when all filters are iterated through).
        /// The filter implementors must call this method to pass WorkContext processing along the line.
        /// Does nothing if work is Aborted or Handled
        /// </summary>
        protected void InvokeNextWorker(WorkContext work, IList <WorkFilter> filters, int thisFilterIndex)
        {
            if (work == null)
            {
                return;
            }
            if (work.Aborted || work.Handled)
            {
                return;
            }

            var idxNext = thisFilterIndex + 1;

            if (idxNext < filters.Count)
            {
                filters[idxNext].FilterWork(work, filters, idxNext);
            }
            else
            {
                WorkHandler handler = m_Handler;

                if (handler != null)//if we are under Handler already then call the handler directly
                {
                    handler.HandleWork(work);
                }
                else //if we are under dispatcher then call dipatcher to locate and invoke the matching handler
                {
                    m_Dispatcher.InvokeHandler(work, out handler);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unregisters handler and returns true if the named instance has been removed
        /// Note: it is possible to call this method on active server that is - remove handlers while serving requests
        /// </summary>
        public bool UnRegisterHandler(WorkHandler handler)
        {
            if (handler == null)
            {
                return(false);
            }
            if (handler.Dispatcher != this)
            {
                throw new WaveException(StringConsts.WRONG_DISPATCHER_HANDLER_UNREGISTRATION_ERROR.Args(handler));
            }

            return(m_Handlers.Unregister(handler));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Finds appropriate handler and invokes it. Returns the appropriate handler or null if work was aborted or already handled.
        /// Throws if appropriate handler was not found
        /// </summary>
        public virtual void InvokeHandler(WorkContext work, out WorkHandler handler)
        {
            if (!work.Aborted && !work.Handled)
            {
                handler = GetWorkHandler(work);

                if (handler == null)
                {
                    throw HTTPStatusException.NotFound_404(StringConsts.NO_HANDLER_FOR_WORK_ERROR.Args(work.About));
                }

                handler.FilterAndHandleWork(work);
                return;
            }
            handler = null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles processing exception by calling ErrorFilter.HandleException(work, error).
        /// All parameters except ERROR can be null - which indicates error that happened during WorkContext dispose
        /// </summary>
        public virtual void HandleException(WorkContext work, WorkFilter filter, WorkHandler handler, Exception error)
        {
            try
            {
                if (m_InstrumentationEnabled)
                {
                    Interlocked.Increment(ref m_stat_ServerHandleException);
                }

                //work may be null (when WorkContext is already disposed)
                if (work != null)
                {
                    ErrorFilter.HandleException(work, error, m_ErrorShowDumpMatches, m_ErrorLogMatches);
                }
                else
                {
                    Log(MessageType.Error,
                        StringConsts.SERVER_DEFAULT_ERROR_WC_NULL_ERROR + error.ToMessageWithType(),
                        "HandleException()",
                        error);
                }
            }
            catch (Exception error2)
            {
                if (m_LogHandleExceptionErrors)
                {
                    try
                    {
                        Log(MessageType.Error,
                            StringConsts.SERVER_DEFAULT_ERROR_HANDLER_ERROR + error2.ToMessageWithType(),
                            "HandleException.catch()",
                            error2,
                            pars: new
                        {
                            OriginalError = error.ToMessageWithType()
                        }.ToJSON()
                            );
                    }
                    catch {}
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Dispatches work into appropriate handler passing through filters.
        /// The default implementation processes requests on the calling thread and disposes WorkContext deterministically
        /// </summary>
        public virtual void Dispatch(WorkContext work)
        {
            WorkFilter  filter  = null;
            WorkHandler handler = null;

            try
            {
                var filters = m_Filters.OrderedValues.ToList().AsReadOnly();//captures context
                filter = filters.FirstOrDefault();
                if (filter != null)
                {
                    filter.FilterWork(work, filters, 0);
                }
                else
                {
                    InvokeHandler(work, out handler);
                }
            }
            catch (Exception error)
            {
                work.LastError = error;
                HandleException(work, filter, handler, error);
            }
            finally
            {
                try
                {
                    if (!work.NoDefaultAutoClose)
                    {
                        work.Dispose();
                    }
                }
                catch (Exception error)
                {
                    HandleException(null, null, null, error);
                }
            }
        }
Ejemplo n.º 6
0
 private WorkHandler m_ParentHandler; internal void ___setParentHandler(WorkHandler parent) { m_ParentHandler = parent;}
Ejemplo n.º 7
0
      /// <summary>
      /// Handles processing exception by calling ErrorFilter.HandleException(work, error).
      /// All parameters except ERROR can be null - which indicates error that happened during WorkContext dispose
      /// </summary>
      public virtual void HandleException(WorkContext work, WorkFilter filter, WorkHandler handler, Exception error)
      {
         try
         {
            if (m_InstrumentationEnabled) Interlocked.Increment(ref m_Stat_ServerHandleException);

            //work may be null (when WorkContext is already disposed)
            if (work!=null)
              ErrorFilter.HandleException(work, error, m_ErrorShowDumpMatches, m_ErrorLogMatches);
            else
             Log(MessageType.Error,
                 StringConsts.SERVER_DEFAULT_ERROR_WC_NULL_ERROR + error.ToMessageWithType(),
                 "HandleException()",
                 error);
         }
         catch(Exception error2)
         {
            if (m_LogHandleExceptionErrors)
              try
              {
                Log(MessageType.Error,
                     StringConsts.SERVER_DEFAULT_ERROR_HANDLER_ERROR + error2.ToMessageWithType(),
                     "HandleException.catch()",
                     error2,
                     pars: new
                      {
                        OriginalError = error.ToMessageWithType() 
                      }.ToJSON()
                     );
              }
              catch{}
         }
      }
Ejemplo n.º 8
0
 private WorkHandler m_ParentHandler; internal void ___setParentHandler(WorkHandler parent)
 {
     m_ParentHandler = parent;
 }
Ejemplo n.º 9
0
 public CustomFilter(WorkHandler handler, IConfigSectionNode confNode)
     : base(handler, confNode)
 {
     configureMatches(confNode);
 }
Ejemplo n.º 10
0
 public CustomFilter(WorkHandler handler, string name, int order)
     : base(handler, name, order)
 {
 }
Ejemplo n.º 11
0
 protected WorkFilter(WorkHandler handler, IConfigSectionNode confNode)
     : this(handler.NonNull(text: ".ctor(handler==null)").Dispatcher, confNode)
 {
     m_Handler = handler;
     this.__setComponentDirector(handler);
 }
Ejemplo n.º 12
0
 protected WorkFilter(WorkHandler handler, string name, int order)
     : this(handler.NonNull(text: ".ctor(handler==null)").Dispatcher, name, order)
 {
     m_Handler = handler;
     this.__setComponentDirector(handler);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Handles processing exception - this implementation uses server-wide behavior.
 /// All parameters except ERROR can be null - which indicates error that happened during WorkContext dispose
 /// </summary>
 public virtual void HandleException(WorkContext work, WorkFilter filter, WorkHandler handler, Exception error)
 {
     ComponentDirector.HandleException(work, filter, handler, error);
 }
Ejemplo n.º 14
0
 protected WorkFilter(WorkHandler handler, IConfigSectionNode confNode) : this(handler.NonNull(text : ".ctor(handler==null)").Dispatcher, confNode)
 {
     m_Handler = handler;
     this.__setComponentDirector(handler);
 }
Ejemplo n.º 15
0
 protected WorkFilter(WorkHandler handler, string name, int order) : this(handler.NonNull(text : ".ctor(handler==null)").Dispatcher, name, order)
 {
     m_Handler = handler;
     this.__setComponentDirector(handler);
 }