Exemplo n.º 1
0
 /// <summary>
 /// This method is called when an incoming request cannot be matched to a command within the Microservice.
 /// </summary>
 /// <param name="args">The error arguments.</param>
 internal virtual void OnProcessRequestUnresolved(DispatcherRequestUnresolvedEventArgs args)
 {
     try
     {
         ProcessRequestUnresolved?.Invoke(this, args);
     }
     catch (Exception ex)
     {
         mDataCollection?.LogException("ProcessRequestUnresolved event / external exception thrown on event", ex);
     }
 }
        /// <summary>
        /// This method processes an unhandled payload.
        /// </summary>
        /// <param name="policy">The action policy.</param>
        /// <param name="reason">The unhandled reason.</param>
        /// <param name="payload">The payload.</param>
        protected virtual void ProcessUnhandledPayload(DispatcherUnhandledAction policy
                                                       , DispatcherRequestUnresolvedReason reason
                                                       , TransmissionPayload payload)
        {
            //OK, we have an problem. We log this as an error and get out of here.
            mDataCollection.DispatcherPayloadUnresolved(payload, reason);

            var args = new DispatcherRequestUnresolvedEventArgs(payload, reason, policy);

            //Raise an event for the unresolved wrapper
            mEventsWrapper.OnProcessRequestUnresolved(args);

            //Process the policy. Note this can be changed in the response.
            switch (args.Policy)
            {
            case DispatcherUnhandledAction.Ignore:
                break;

            case DispatcherUnhandledAction.AttemptResponseFailMessage:
                if (!payload.CanRespond())
                {
                    break;
                }

                var response = payload.ToResponse();
                response.Message.StatusSet(501, args.Reason.ToString());
                response.Message.ChannelPriority = -1;
                Dispatch.Process(response);
                //request.IsSuccess = true;
                break;

            case DispatcherUnhandledAction.Exception:
                //request.IsSuccess = true;
                break;
            }
        }