コード例 #1
0
 internal static void TemplateOptimizerStarting(
     this IProfilerScope ps,
     string codeProvider,
     bool usingOptimizer)
 {
     ps.AddMetric("codeProvider", codeProvider);
     ps.AddMetric("usingOptimizer", usingOptimizer);
 }
コード例 #2
0
 internal static void EndParsing(
     this IProfilerScope ps,
     string name,
     int contentLength)
 {
     ps.MarkEnd();
     ps.AddMetric("templateName", name);
     ps.AddMetric("templateLength", contentLength);
 }
コード例 #3
0
 internal static void SourceCodeMetrics(
     this IProfilerScope ps,
     bool completelyInlined,
     int domNodeCount,
     int generatedCodeLength,
     int renderIslandCount,
     int variableCount)
 {
     // TODO Currently unsupported in HTML lib - ps.AddMetric("documentNodeCount", this.SourceDocument.Descendents.Count());
     ps.AddMetric("generatedCodeLength", generatedCodeLength);
     ps.AddMetric("nodeCount", domNodeCount);
     ps.AddMetric("renderIslandCount", renderIslandCount);
     ps.AddMetric("variableCount", variableCount);
     ps.AddMetric("completelyInlined", completelyInlined);
     ps.MarkEnd();
 }
コード例 #4
0
        private bool IsCompletelyInlined(DomContainer document, IProfilerScope scope)
        {
            if (document.ChildNodes.Count != 1)
            {
                return(false);
            }

            var hxlRenderElement = document.ChildNodes[0] as HxlRenderWorkElement;

            if (hxlRenderElement == null || hxlRenderElement.ChildNodes.Count > 0)
            {
                return(false);
            }

            scope.AddMetric("completelyInlined", true);
            CSTemplateGenerator g = new CSTemplateGenerator();

            ApplySettings(template, g);
            g.TransformTextCore =
                string.Join(Environment.NewLine, hxlRenderElement.PreLines)
                + string.Join(Environment.NewLine, hxlRenderElement.PostLines);

            g.HasDocument = false;

            string code = g.TransformText();

            output.WriteLine(code);

            if (Metrics.EnableAdvancedParserMetrics)
            {
                scope.SourceCodeMetrics(true,
                                        1,
                                        code.Length,
                                        0,
                                        0);
            }

            return(true);
        }
コード例 #5
0
        public void WriteCode(IProfilerScope scope)
        {
            var result = this.template.PreparedDocument;

            if (IsCompletelyInlined(result, scope))
            {
                return;
            }

            // We buffer this output so that we can present variables upfront for readability
            var buffer  = new StringWriter();
            var visitor = new GenerateInitTextVisitor(buffer, this.template);

            visitor.Visit(result);

            CSTemplateGenerator g = new CSTemplateGenerator();

            ApplySettings(template, g);
            g.DomNodeVariables    = visitor.AllDomNodeVariables;
            g.DomObjectVariables  = visitor.AllDomObjectVariables;
            g.InitializeComponent = buffer.ToString();
            g.RenderIslands       = visitor.RenderIslands;
            g.HasDocument         = true;
            g.Accessibility       = "public";

            string code = g.TransformText();

            output.WriteLine(code);

            if (Metrics.EnableAdvancedParserMetrics)
            {
                scope.SourceCodeMetrics(false,
                                        this.template.PreparedDocument.DescendantNodes.Count(),
                                        code.Length,
                                        visitor.RenderIslandCount,
                                        g.DomNodeVariables.Count + g.DomNodeVariables.Count);
            }
        }
コード例 #6
0
ファイル: ParsedTemplate.cs プロジェクト: Carbonfrost/f-hxl
        public ParsedTemplate(string text, string name, HxlCompilerSettings settings)
        {
            _metrics = Metrics.ForTemplateParsing();
            _metrics.StartParsing();
            _sourceDocument = HtmlDocumentFragment.Parse(text, new HtmlReaderSettings {
                Mode = HtmlTreeBuilderMode.Xml
            });
            _metrics.EndParsing(name, text.Length);

            _settings    = settings;
            _nodeFactory = DomNodeFactory.Compose(
                HxlDomNodeFactory.Compiler,
                _settings.NodeFactories,
                new InvalidFactory());

            Signature = string.Concat(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(text))
                                      .Take(8)
                                      .Select(b => b.ToString("x2"))
                                      );

            if (string.IsNullOrEmpty(name))
            {
                this.TemplateName = "Template" + this.Signature;
            }
            else
            {
                this.TemplateName = CodeUtility.Slug(name);
            }

            this.Namespace = "Generated";
            this.ClassName = this.TemplateName;

            using (UsingNamespaceResolver()) {
                this._preparedDocument = PrepareDocument();
            }
        }
コード例 #7
0
 internal static void EndOptimizer(
     this IProfilerScope ps)
 {
     ps.MarkEnd();
     // TODO Compute optimizer efficiency
 }
コード例 #8
0
 internal static void StartOptimizer(
     this IProfilerScope ps)
 {
     ps.MarkStart("optimizerTime");
 }
コード例 #9
0
 internal static void EndSourceGenerator(
     this IProfilerScope ps)
 {
     ps.MarkEnd();
 }
コード例 #10
0
 internal static void StartSourceGenerator(
     this IProfilerScope ps)
 {
     ps.MarkStart("sourceGeneratorTime");
 }
コード例 #11
0
 internal static void StartParsing(
     this IProfilerScope ps)
 {
     ps.MarkStart("parserTime");
 }
コード例 #12
0
 internal static void EndPreprocessor(
     this IProfilerScope ps)
 {
     ps.MarkEnd();
 }
コード例 #13
0
 internal static void StartPreprocessor(
     this IProfilerScope ps)
 {
     ps.MarkStart("preprocessorTime");
 }
コード例 #14
0
 internal static IDisposable NewTiming(IProfilerScope self, string name)
 {
     self.MarkStart(name);
     return(new DisposableAction(self.MarkEnd));
 }