Пример #1
0
        public Stream PassThrough <TCommand, TArgument>(TArgument argument, string accept, AdditionalCommand[] additionalCommands)
        {
            var request   = ThreadContext.Request;
            var response  = ThreadContext.Response;
            var start     = Stopwatch.GetTimestamp();
            var engine    = ProcessingEngine;
            var sessionID = request.GetHeaderLowercase("x-revenj-session-id");

            if (sessionID != null)
            {
                var scope = ObjectFactory.FindScope(sessionID);
                if (scope == null)
                {
                    return(response.ReturnError("Unknown session: " + sessionID, HttpStatusCode.BadRequest));
                }
                engine = scope.Resolve <IProcessingEngine>();
            }
            var commands = new ObjectCommandDescription[1 + (additionalCommands != null ? additionalCommands.Length : 0)];

            commands[0] = new ObjectCommandDescription {
                Data = argument, CommandType = typeof(TCommand)
            };
            for (int i = 1; i < commands.Length; i++)
            {
                var ac = additionalCommands[i - 1];
                commands[i] = new ObjectCommandDescription {
                    RequestID = ac.ToHeader, CommandType = ac.CommandType, Data = ac.Argument
                };
            }
            var stream  = RestApplication.ExecuteCommands <object>(engine, Serialization, commands, request, response, accept);
            var elapsed = (decimal)(Stopwatch.GetTimestamp() - start) / TimeSpan.TicksPerMillisecond;

            response.AddHeader("X-Duration", elapsed.ToString(CultureInfo.InvariantCulture));
            return(stream);
        }
Пример #2
0
        public Stream PassThrough <TCommand, TArgument>(TArgument argument, string accept)
        {
            var sessionID = ThreadContext.Request.GetHeader("X-NGS-Session-ID") ?? string.Empty;
            var scope     = ObjectFactory.FindScope(sessionID);

            if (!string.IsNullOrEmpty(sessionID) && scope == null)
            {
                return(Utility.ReturnError("Unknown session: " + sessionID, HttpStatusCode.BadRequest));
            }
            var engine = scope != null?scope.Resolve <IProcessingEngine>() : ProcessingEngine;

            return
                (RestApplication.ExecuteCommand <object>(
                     engine,
                     Serialization,
                     new ObjectCommandDescription {
                Data = argument, CommandType = typeof(TCommand)
            },
                     accept));
        }