Esempio n. 1
0
        /// <summary>
        ///     Renders the specified ASP Session variable and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">
        ///     The <see cref="StringBuilder" /> to append the rendered data to.
        /// </param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            var session = AspHelper.GetSessionObject();

            if (session != null)
            {
                if (Variable != null)
                {
                    var variableValue = session.GetValue(Variable);
                    builder.Append(Convert.ToString(variableValue, CultureInfo.InvariantCulture));
                }

                Marshal.ReleaseComObject(session);
            }
        }
        /// <summary>
        /// Renders the specified ASP Application variable and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            AspHelper.IApplicationObject app = AspHelper.GetApplicationObject();
            if (app != null)
            {
                if (this.Variable != null)
                {
                    object variableValue = app.GetValue(this.Variable);

                    builder.Append(Convert.ToString(variableValue, CultureInfo.InvariantCulture));
                }

                Marshal.ReleaseComObject(app);
            }
        }
        public async Task RenderAsync(ViewContext context)
        {
            CompiledPage cpage = null;

            if (_scriptCache.ContainsKey(Path))
            {
                cpage = _scriptCache[Path];
                if (cpage.CompileTime < File.GetLastWriteTime(Path))
                {
                    cpage = null;
                }
            }
            if (cpage == null)
            {
                try
                {
                    cpage = aspHost.ProcessPageFromFile(Path);
                    _scriptCache[Path] = cpage;
                }
                catch (VBScriptCompilerException ex)
                {
                    AspHelper.RenderError(context, ex);
                    return;
                }
            }

            ScriptScope responseScope = aspHost.CreateScope();
            HttpContext httpContext   = context.HttpContext;

            responseScope.SetVariable("request", httpContext.RequestServices.GetService <IAspRequest>());
            responseScope.SetVariable("session", httpContext.RequestServices.GetService <IAspSession>());
            responseScope.SetVariable("application", httpContext.RequestServices.GetService <IAspApplication>());
            responseScope.SetVariable("writer", context.Writer);
            IAspResponse aspResponse = httpContext.RequestServices.GetService <IAspResponse>();

            responseScope.SetVariable("response", aspResponse);

            responseScope.SetVariable("model", context.ViewData.Model);
            responseScope.SetVariable("viewdata", context.ViewData);
            responseScope.SetVariable("viewbag", context.ViewBag);

            responseScope.SetVariable("literals", cpage.Literals);

            object o = cpage.Code.Execute(responseScope);

            aspResponse.Flush();
        }
Esempio n. 4
0
        /// <summary>
        /// Outputs the rendered logging event through the <c>OutputDebugString()</c> Win32 API.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        protected override void Write(LogEventInfo logEvent)
        {
            AspHelper.IResponse response = AspHelper.GetResponseObject();
            if (response != null)
            {
                if (this.AddComments)
                {
                    response.Write("<!-- " + this.Layout.Render(logEvent) + "-->");
                }
                else
                {
                    response.Write(this.Layout.Render(logEvent));
                }

                Marshal.ReleaseComObject(response);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Renders the specified ASP Request variable and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">
        ///     The <see cref="StringBuilder" /> to append the rendered data to.
        /// </param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            var request = AspHelper.GetRequestObject();

            if (request != null)
            {
                if (QueryString != null)
                {
                    builder.Append(GetItem(request.GetQueryString(), QueryString));
                }
                else if (Form != null)
                {
                    builder.Append(GetItem(request.GetForm(), Form));
                }
                else if (Cookie != null)
                {
                    var cookie = request.GetCookies().GetItem(Cookie);
                    builder.Append(Convert.ToString(AspHelper.GetComDefaultProperty(cookie), CultureInfo.InvariantCulture));
                }
                else if (ServerVariable != null)
                {
                    builder.Append(GetItem(request.GetServerVariables(), ServerVariable));
                }
                else if (Item != null)
                {
                    var o  = request.GetItem(Item);
                    var sl = o as AspHelper.IStringList;
                    if (sl != null)
                    {
                        if (sl.GetCount() > 0)
                        {
                            builder.Append(sl.GetItem(1));
                        }

                        Marshal.ReleaseComObject(sl);
                    }
                }

                Marshal.ReleaseComObject(request);
            }
        }
Esempio n. 6
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            string pagePath = viewContext.HttpContext.Server.MapPath(this.ViewPath);

            CompiledPage cpage = null;

            if (_scriptCache.ContainsKey(pagePath))
            {
                cpage = _scriptCache[pagePath];
                //don't use it if updated
                if (cpage.CompileTime < File.GetLastWriteTime(pagePath))
                {
                    cpage = null;
                }
            }

            if (cpage == null)
            {
                try
                {
                    cpage = aspHost.ProcessPageFromFile(pagePath);
                    _scriptCache[pagePath] = cpage;
                }
                catch (VBScriptCompilerException ex)
                {
                    AspHelper.RenderError(writer, ex);
                    return;
                }
            }

            ScriptScope responseScope = aspHost.CreateScope();
            HttpContext context       = HttpContext.Current;

            responseScope.SetVariable("context", context);
            responseScope.SetVariable("request", context.Request);
            responseScope.SetVariable("session", context.Session);
            responseScope.SetVariable("server", context.Server);
            responseScope.SetVariable("application", context.Application);
            //responseScope.SetVariable("response", new AspResponse(context));

            responseScope.SetVariable("writer", writer);
            responseScope.SetVariable("response", writer);

            responseScope.SetVariable("viewcontext", viewContext);
            responseScope.SetVariable("tempdata", viewContext.TempData);

            ViewDataDictionary viewData = viewContext.ViewData;

            responseScope.SetVariable("viewdata", viewData);
            responseScope.SetVariable("model", viewData.Model);

            ViewDataContainer viewDataContainer = new ViewDataContainer(viewData);

            responseScope.SetVariable("ajax", new AjaxHelper(viewContext, viewDataContainer));
            responseScope.SetVariable("html", new HtmlHelper(viewContext, viewDataContainer));
            responseScope.SetVariable("url", new UrlHelper(viewContext.RequestContext));

            //responseScope.SetVariable("err", new Microsoft.VisualBasic.ErrObject());
            //Used to get the literals
            responseScope.SetVariable("literals", cpage.Literals);

            try
            {
                object o = cpage.Code.Execute(responseScope);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }