示例#1
0
        /// <summary>
        /// Select proper execution method and handle it
        /// </summary>
        private static JsonValue ExecuteProperMethod(
            ExecutionParameters executionParameters,
            Application app
            )
        {
            switch (executionParameters.Method)
            {
            case "entrypoint-test":
                return(EntrypointTest.Start(
                           executionParameters.MethodParameters,
                           app.Resolve <SpecialValues>()
                           ));

            case "facet-call":
                var kernel     = app.Resolve <FacetCallKernel>();
                var parameters = FacetCallKernel.MethodParameters
                                 .Parse(executionParameters.MethodParameters);
                return(kernel.Handle(parameters));

            default:
                throw new UnisaveException(
                          "UnisaveFramework: Unknown execution method: "
                          + executionParameters.Method
                          );
            }
        }
示例#2
0
        /// <summary>
        /// Main entrypoint to the framework execution
        /// Given executionParameters it starts some action which results.
        /// in a returned value or an exception.
        ///
        /// Input and output are serialized as JSON strings.
        /// </summary>
        public static string Start(
            string executionParametersAsJson,
            Type[] gameAssemblyTypes
            )
        {
            if (someExecutionIsRunning)
            {
                throw new InvalidOperationException(
                          "You cannot start the framework from within the framework."
                          );
            }

            someExecutionIsRunning = true;

            var executionStopwatch = Stopwatch.StartNew();

            try
            {
                PrintGreeting();

                var executionParameters = ExecutionParameters
                                          .Parse(executionParametersAsJson);

                var specialValues = new SpecialValues();

                JsonObject result = HandleExceptionSerialization(
                    specialValues,
                    () => {
                    // NOTE: this place is where a test/emulation
                    // is started. Simply boot the application and
                    // then directly call proper kernel (method handler).

                    var env = EnvStore.Parse(executionParameters.EnvSource);

                    JsonValue methodResult;

                    using (var app = Bootstrap.Boot(
                               gameAssemblyTypes,
                               env,
                               specialValues
                               ))
                    {
                        Facade.SetApplication(app);

                        methodResult = ExecuteProperMethod(
                            executionParameters,
                            app
                            );

                        Facade.SetApplication(null);
                    }

                    return(new JsonObject()
                           .Add("result", "ok")
                           .Add("returned", methodResult)
                           .Add("special", specialValues.ToJsonObject()));
                }
                    );

                executionStopwatch.Stop();
                result["special"].AsJsonObject["executionDuration"]
                    = executionStopwatch.ElapsedMilliseconds / 1000.0;

                return(result.ToString());
            }
            finally
            {
                someExecutionIsRunning = false;
            }
        }