Пример #1
0
 public ScriptContext(IMiddlerContext middlerContext, ScriptContextMethods scriptContextMethods)
 {
     _middlerContext       = middlerContext;
     _scriptContextMethods = scriptContextMethods;
     Request  = new ScriptContextRequest(middlerContext.Request);
     Response = new ScriptContextResponse(middlerContext.Response);
 }
Пример #2
0
        public void ExecuteRequest(IMiddlerContext middlerContext, IActionHelper actionHelper)
        {
            var rewriteTo  = actionHelper.BuildPathFromRoutData(Parameters.RewriteTo);
            var isAbsolute = Uri.IsWellFormedUriString(rewriteTo, UriKind.Absolute);

            if (isAbsolute)
            {
                middlerContext.Request.Uri = new Uri(rewriteTo);
            }
            else
            {
                var builder = new UriBuilder(middlerContext.Request.Uri);
                builder.Query = null;
                if (rewriteTo.Contains("?"))
                {
                    builder.Path  = rewriteTo.Split("?")[0];
                    builder.Query = rewriteTo.Split("?")[1];
                }
                else
                {
                    builder.Path = rewriteTo;
                }


                middlerContext.Request.Uri = builder.Uri;
            }



            //middlerContext.ForwardBody();

            //var nUrl = new UriBuilder(Parameters.RewriteTo);
            //builder.Path = Parameters.RewriteTo;
        }
Пример #3
0
        public void ExecuteRequest(IMiddlerContext middlerContext, IActionHelper actionHelper)
        {
            var uri = new Uri(actionHelper.BuildPathFromRoutData(Parameters.RedirectTo));

            if (Parameters.PreserveMethod)
            {
                middlerContext.Response.StatusCode = Parameters.Permanent ? StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
            }
            else
            {
                middlerContext.Response.StatusCode = Parameters.Permanent ? StatusCodes.Status301MovedPermanently : StatusCodes.Status302Found;
            }

            middlerContext.Response.Headers["Location"] = uri.AbsoluteUri;
        }
Пример #4
0
        public async Task ExecuteRequestAsync(IMiddlerContext middlerContext)
        {
            IScriptEngine scriptEngine = _serviceProvider.GetRequiredNamedService <IScriptEngine>(Parameters.Language);

            var compile = scriptEngine.NeedsCompiledScript && (!string.IsNullOrEmpty(Parameters.SourceCode) &&
                                                               string.IsNullOrWhiteSpace(Parameters.CompiledCode));


            if (compile)
            {
                CompileScriptIfNeeded();
            }

            var scriptContextMethods = new ScriptContextMethods();
            //scriptContextMethods.SendResponse = () =>
            //{
            //    Console.WriteLine("Test von Action");
            //    scriptEngine.Stop();
            //};

            var scriptContext = new ScriptContext(middlerContext, scriptContextMethods);

            scriptContext.Terminating = Terminating;


            scriptEngine.SetValue("context", scriptContext);

            //scriptEngine.SetValue("m", new Environment(middlerContext.RequestServices.GetService<IVariablesRepository>()));


            try
            {
                await scriptEngine.ExecuteAsync(scriptEngine.NeedsCompiledScript?Parameters.CompiledCode : Parameters.SourceCode);

                //SendResponse(middlerContext.Response, scriptContext);
            }
            catch (Exception e)
            {
                throw e;
                //await httpContext.BadRequest(e.GetBaseException().Message);
            }

            Terminating = scriptContext.Terminating;
        }
Пример #5
0
        public async Task ExecuteRequestAsync(IMiddlerContext middlerContext)
        {
            IScriptEngine scriptEngine = GetScriptEngine();



            var scriptContextMethods = new ScriptContextMethods();

            scriptContextMethods.SendResponse = () =>
            {
                Console.WriteLine("Test von Action");
                scriptEngine.Stop();
            };

            var scriptContext = new ScriptContext(middlerContext, scriptContextMethods);

            scriptContext.Terminating = Terminating;

            scriptEngine.Initialize();
            scriptEngine.SetValue("context", scriptContext);

            scriptEngine.SetValue("m", new Environment(middlerContext.RequestServices.GetService <VariableStore>()));


            try
            {
                await scriptEngine.Execute(scriptEngine.NeedsCompiledScript?Parameters.CompiledCode : Parameters.SourceCode);

                //SendResponse(middlerContext.Response, scriptContext);
            }
            catch (Exception e)
            {
                throw e;
                //await httpContext.BadRequest(e.GetBaseException().Message);
            }

            Terminating = scriptContext.Terminating;
        }
Пример #6
0
 public void ExecuteResponse(IMiddlerContext middlerContext)
 {
     middlerContext.Response.Headers["TestHeader"] = "irgendwas";
 }