예제 #1
0
        public static Responses.Paged <TResponse> RequestPaged <TResponse>(this Aggregates.Messages.IMessage message) where TResponse : class
        {
            if (message == null || message is Reject)
            {
                var reject = (Reject)message;
                Log.Logger.Warning("Query was rejected - Message: {0}\n", reject?.Message);
                if (reject != null)
                {
                    throw new QueryRejectedException(reject.Message);
                }
                throw new QueryRejectedException();
            }
            if (message is Error)
            {
                var error = (Error)message;
                Log.Logger.Warning("Query raised an error - Message: {0}", error.Message);
                throw new QueryRejectedException(error.Message);
            }

            var package = (PagedReply)message;

            if (package == null)
            {
                throw new QueryRejectedException($"Unexpected response type: {message.GetType().FullName}");
            }

            return(new Responses.Paged <TResponse>()
            {
                ElapsedMs = package.ElapsedMs,
                Total = package.Total,
                Records = package.Records.Cast <TResponse>().ToArray()
            });
        }
예제 #2
0
        public static QueryResponse <TResponse> RequestQuery <TResponse>(this Aggregates.Messages.IMessage message) where TResponse : class
        {
            if (message == null || message is Reject)
            {
                var reject = (Reject)message;
                Log.Logger.Warning("Query was rejected - Message: {0}\n", reject?.Message);
                if (reject != null)
                {
                    throw new QueryRejectedException(reject.Message);
                }
                throw new QueryRejectedException();
            }
            if (message is Error)
            {
                var error = (Error)message;
                Log.Logger.Warning("Query raised an error - Message: {0}", error.Message);
                throw new QueryRejectedException(error.Message);
            }

            var package = (Reply)message;

            if (package == null)
            {
                throw new QueryRejectedException($"Unexpected response type: {message.GetType().FullName}");
            }

            return(new QueryResponse <TResponse>()
            {
                RoundTripMs = package.ElapsedMs,
                Payload = package.Payload as TResponse
            });
        }
예제 #3
0
 private static void CheckResponse(Aggregates.Messages.ICommand command, Aggregates.Messages.IMessage msg)
 {
     if (msg is Reject)
     {
         var reject = (Reject)msg;
         Log.Logger.WarnEvent("Rejection", $"Command was rejected - Message: {reject.Message}");
         throw new RejectedException(command.GetType(), reject.Message, reject.Exception);
     }
     if (msg is Error)
     {
         var error = (Error)msg;
         Log.Logger.WarnEvent("Fault", $"Command Fault!\n{error.Message}");
         throw new RejectedException(command.GetType(), $"Command Fault!\n{error.Message}");
     }
 }