Exemplo n.º 1
0
        public override void Interpret()
        {
            if (File.Exists(context.Request.PhysicalPathFile))
            {
                using (FileStream fs = new FileStream(context.Request.PhysicalPathFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    // calculamos el hashcode para
                    string hashcode      = Conversion.CalculateHashCode(fs);
                    string mainClassName = "CodeRender_" + Path.GetFileNameWithoutExtension(context.Request.PhysicalPathFile);

                    Assembly asam = cache.Get(hashcode) as Assembly;

                    if (asam == null)
                    {
                        StreamReader reader = new StreamReader(fs, Encoding.Default, true, 4096);
                        parser             = new AspParser(context.Request.PhysicalPathFile, reader);
                        parser.TagParsed  += new TagParsedHandler(parser_TagParsed);
                        parser.TextParsed += new TextParsedHandler(parser_TextParsed);
                        parser.Error      += new ParseErrorHandler(parser_Error);

                        eb = new EvaluatorBuilder();

                        eb.BeginCompile("ASP");
                        eb.AppendNameSpace("System");
                        eb.AppendNameSpace("System.Web");

                        CodeTypeDeclaration c = eb.AppendClass(mainClassName, typeof(DinamicPage));

                        // eb.CreatePropertyGetForObject(c, context.App.GetType(), "App", "Context.App");
                        // eb.CreatePropertyGetForObject(c, context.SessionRequest == null ? typeof(Object) : context.SessionRequest.GetType(), "SessionRequest", "Context.SessionRequest");

                        m = eb.AppendMethod(c, "Render", MemberAttributes.Override);

                        parser.Parse();

                        asam = eb.EndCompile();

                        // añadimos al cache
                        cache.Add(hashcode, asam);
                    }

                    DinamicPage page = asam.CreateInstance("ASP." + mainClassName)
                                       as DinamicPage;

                    page.Me              = this;
                    page.Context         = context;
                    page.OutStream       = new StringBuilder();
                    context.Reply.Render = page;

                    try
                    {
                        page.Render();
                    }
                    catch (Exception err)
                    {
                        page.OutStream.AppendFormat("Error: {0}\n{1}", err.Message, err.StackTrace);
                    }

                    // forzar descarga de archivo
                    if (!context.Reply.ForcedFileDownload && !context.Reply.LoadedStream)
                    {
                        context.Reply.LoadText(page.OutStream.ToString());
                    }
                }
            }
            else
            {
                context.Reply.Code = Codes.NOT_FOUND;
            }
        }
Exemplo n.º 2
0
 public void Parser()
 {
     parser.Parse();
 }