public string ReadBooks()
        {
            var readCommandInfo = new ReadCommandInfo {
                DataSource = "Bookstore.Book", ReadTotalCount = true
            };
            var result = processingEngine.Execute(readCommandInfo);

            return($"{result.TotalCount} books.");
        }
예제 #2
0
        private object[] ReadEntity(string dataSource, FilterCriteria[] genericFilter = null)
        {
            var processingResult = _processingEngine.Execute(new[] {
                new QueryDataSourceCommandInfo
                {
                    DataSource    = dataSource,
                    GenericFilter = genericFilter
                }
            });

            ThrowExceptionOnError(processingResult);

            var queryResult = (Rhetos.XmlSerialization.XmlBasicData <QueryDataSourceCommandResult>)processingResult.CommandResults[0].Data;

            return(queryResult.Data.Records);
        }
예제 #3
0
        public ServerProcessingResult Execute(params ServerCommandInfo[] commands)
        {
            var totalTime = Stopwatch.StartNew();

            try
            {
                var stopwatch = Stopwatch.StartNew();

                if (_commandsByName == null)
                {
                    PrepareCommandByName();
                }

                if (commands == null || commands.Length == 0)
                {
                    return new ServerProcessingResult {
                               SystemMessage = "Commands missing", Success = false
                    }
                }
                ;

                _performanceLogger.Write(stopwatch, "RhetosService.Execute: Server initialization done.");

                var processingCommandsOrError = Deserialize(commands);
                if (processingCommandsOrError.IsError)
                {
                    return new ServerProcessingResult
                           {
                               Success       = false,
                               SystemMessage = processingCommandsOrError.Error
                           }
                }
                ;
                var processingCommands = processingCommandsOrError.Value;

                _performanceLogger.Write(stopwatch, "RhetosService.Execute: Commands deserialized.");

                var result = _processingEngine.Execute(processingCommands);

                _performanceLogger.Write(stopwatch, "RhetosService.Execute: Commands executed.");

                var convertedResult = ConvertResult(result);

                _performanceLogger.Write(stopwatch, "RhetosService.Execute: Result converted.");

                return(convertedResult);
            }
            finally
            {
                _performanceLogger.Write(totalTime, "RhetosService: Executed " + string.Join(",", commands.Select(c => c.CommandName)) + ".");
            }
        }
예제 #4
0
        private static ExecuteResult Execute <TInput>(
            IProcessingEngine engine,
            IServerCommandDescription <TInput>[] commands,
            IRequestContext request,
            IResponseContext response)
        {
            var result = engine.Execute <TInput, object>(commands, request.Principal);
            var first  = result.ExecutedCommandResults != null?result.ExecutedCommandResults.FirstOrDefault() : null;

            response.StatusCode = first != null && first.Result != null
                                ? first.Result.Status
                                : result.Status;

            if (result.Status == HttpStatusCode.ServiceUnavailable)
            {
                HttpRuntime.UnloadAppDomain();
            }

            var noResult = first == null || first.Result == null || first.Result.Data == null;

            if ((int)result.Status >= 300 && noResult)
            {
                return new ExecuteResult {
                           Error = response.ReturnError(result.Message, result.Status)
                }
            }
            ;
            if (first == null)
            {
                return new ExecuteResult {
                           Error = response.ReturnError("Missing result", HttpStatusCode.InternalServerError)
                }
            }
            ;
            if ((int)first.Result.Status >= 300 && noResult)
            {
                return new ExecuteResult {
                           Error = response.ReturnError(first.Result.Message, first.Result.Status)
                }
            }
            ;

            foreach (var ar in result.ExecutedCommandResults.Skip(1))
            {
                response.AddHeader(ar.RequestID, ar.Result.Data.ToString());
            }

            return(new ExecuteResult {
                Result = first.Result.Data
            });
        }
예제 #5
0
        private ReadCommandResult ExecuteReadCommand(ReadCommandInfo commandInfo)
        {
            var result = _processingEngine.Execute(new[] { commandInfo });

            CheckForErrors(result);
            var resultData = (ReadCommandResult)(((Rhetos.XmlSerialization.XmlBasicData <ReadCommandResult>)(result.CommandResults.Single().Data)).Value);

            return(resultData);
        }
예제 #6
0
        private static async Task <ExecuteResult> Execute <TInput>(
            IProcessingEngine engine,
            IServerCommandDescription <TInput>[] commands,
            IPrincipal principal,
            HttpResponse response)
        {
            //TODO: make it truly async. as a temporary workaroung just call engine in a thread
            var result = await Task.Run(() => engine.Execute <TInput, object>(commands, principal));

            var first = result.ExecutedCommandResults != null?result.ExecutedCommandResults.FirstOrDefault() : null;

            response.StatusCode = (int)(first != null && first.Result != null
                                ? first.Result.Status
                                : result.Status);

            var noResult = first == null || first.Result == null || first.Result.Data == null;

            if ((int)result.Status >= 300 && noResult)
            {
                return new ExecuteResult {
                           Error = result.Message
                }
            }
            ;
            if (first == null)
            {
                return new ExecuteResult {
                           Error = "Missing result"
                }
            }
            ;
            if ((int)first.Result.Status >= 300 && noResult)
            {
                return new ExecuteResult {
                           Error = first.Result.Message
                }
            }
            ;

            foreach (var ar in result.ExecutedCommandResults.Skip(1))
            {
                response.Headers.Add(ar.RequestID, ar.Result.Data.ToString());
            }

            return(new ExecuteResult {
                Result = first.Result.Data
            });
        }
예제 #7
0
        private static ExecuteResult Execute <TInput>(
            IProcessingEngine engine,
            IServerCommandDescription <TInput>[] commands,
            IPrincipal principal,
            HttpResponse response)
        {
            var result = engine.Execute <TInput, object>(commands, principal);
            var first  = result.ExecutedCommandResults != null?result.ExecutedCommandResults.FirstOrDefault() : null;

            response.StatusCode = (int)(first != null && first.Result != null
                                ? first.Result.Status
                                : result.Status);

            //if (result.Status == HttpStatusCode.ServiceUnavailable)
            //HttpRuntime.UnloadAppDomain();

            if ((int)result.Status >= 300)
            {
                return new ExecuteResult {
                           Error = result.Message
                }
            }
            ;
            else if (first == null)
            {
                return new ExecuteResult {
                           Error = "Missing result"
                }
            }
            ;
            else if ((int)first.Result.Status >= 300)
            {
                return new ExecuteResult {
                           Error = first.Result.Message
                }
            }
            ;

            foreach (var ar in result.ExecutedCommandResults.Skip(1))
            {
                response.Headers.Add(ar.RequestID, ar.Result.Data.ToString());
            }

            return(new ExecuteResult {
                Result = first.Result.Data
            });
        }
예제 #8
0
        private static ExecuteResult <TOutput> Execute <TInput, TOutput>(IProcessingEngine engine, IServerCommandDescription <TInput> command)
        {
            var result    = engine.Execute <TInput, TOutput>(new[] { command });
            var subresult = result.ExecutedCommandResults != null?result.ExecutedCommandResults.FirstOrDefault() : null;

            ThreadContext.Response.StatusCode = subresult != null && subresult.Result != null
                                ? subresult.Result.Status
                                : result.Status;

            if (result.Status == HttpStatusCode.ServiceUnavailable)
            {
                HttpRuntime.UnloadAppDomain();
            }

            ThreadContext.Response.Headers.Add("X-Duration", result.Duration.ToString());

            if ((int)result.Status >= 300)
            {
                return new ExecuteResult <TOutput> {
                           Error = Utility.ReturnError(result.Message, result.Status)
                }
            }
            ;

            var first = result.ExecutedCommandResults.FirstOrDefault();

            if (first == null)
            {
                return new ExecuteResult <TOutput> {
                           Error = Utility.ReturnError("Missing result", HttpStatusCode.InternalServerError)
                }
            }
            ;

            if ((int)first.Result.Status >= 300)
            {
                return new ExecuteResult <TOutput> {
                           Error = Utility.ReturnError(first.Result.Message, first.Result.Status)
                }
            }
            ;

            return(new ExecuteResult <TOutput> {
                Result = first.Result.Data
            });
        }
        private ReadCommandResult ExecuteReadCommand(ReadCommandInfo commandInfo)
        {
            var sw = Stopwatch.StartNew();

            var result = _processingEngine.Execute(new[] { commandInfo });

            CheckForErrors(result);
            var resultData = (ReadCommandResult)(((Rhetos.XmlSerialization.XmlBasicData <ReadCommandResult>)(result.CommandResults.Single().Data)).Value);

            _performanceLogger.Write(sw, "RestService: ExecuteReadCommand(" + commandInfo.DataSource + ") Executed.");
            return(resultData);
        }
예제 #10
0
        private ServerProcessingResult ExecuteInner(ServerCommandInfo[] commands)
        {
            var stopwatch = Stopwatch.StartNew();

            if (_commandsByName == null)
            {
                PrepareCommandByName();
            }

            if (commands == null || commands.Length == 0)
            {
                return new ServerProcessingResult {
                           SystemMessage = "Commands missing", Success = false
                }
            }
            ;

            _performanceLogger.Write(stopwatch, "RhetosService.ExecuteInner: Server initialization done.");

            var processingCommandsOrError = Deserialize(commands);

            if (processingCommandsOrError.IsError)
            {
                return new ServerProcessingResult
                       {
                           Success       = false,
                           SystemMessage = processingCommandsOrError.Error
                       }
            }
            ;
            var processingCommands = processingCommandsOrError.Value;

            _performanceLogger.Write(stopwatch, "RhetosService.ExecuteInner: Commands deserialized.");

            var result = _processingEngine.Execute(processingCommands);

            _performanceLogger.Write(stopwatch, "RhetosService.ExecuteInner: Commands executed.");

            var convertedResult = ConvertResult(result);

            _performanceLogger.Write(stopwatch, "RhetosService.ExecuteInner: Result converted.");

            return(convertedResult);
        }
예제 #11
0
        public SoapResultDescription Execute(SoapCommandDescription[] soapCommands)
        {
            IServerCommandDescription <XElement>[] processingCommands;
            if (soapCommands == null || soapCommands.Length == 0)
            {
                throw new FaultException("SOAP commands missing.");
            }

            if (soapCommands.Where(sc => sc.CommandName == null ||
                                   ServerCommands.Find(sc.CommandName) == null).Any())
            {
                var unknownCommand =
                    (from sc in soapCommands
                     where sc.CommandName == null ||
                     ServerCommands.Find(sc.CommandName) == null
                     select sc.CommandName)
                    .First();

                throw new FaultException("Unknown command: " + unknownCommand);
            }

            processingCommands = PrepareCommands(soapCommands).ToArray();

            var result = ProcessingEngine.Execute <XElement, XElement>(processingCommands, Thread.CurrentPrincipal);

            if (result.Status == HttpStatusCode.ServiceUnavailable)
            {
                HttpRuntime.UnloadAppDomain();
            }
            if (result.Status == HttpStatusCode.InternalServerError || result.ExecutedCommandResults == null)
            {
                throw new FrameworkException(result.Message);
            }
            if ((int)result.Status >= 300)
            {
                throw new FaultException(result.Message);
            }

            return(ConvertToSoapResult(result));
        }
예제 #12
0
 public static IProcessingResult <TOutput> Execute <TInput, TOutput>(
     this IProcessingEngine engine,
     params IServerCommandDescription <TInput>[] commands)
 {
     return(engine.Execute <TInput, TOutput>(commands, Thread.CurrentPrincipal));
 }