Ejemplo n.º 1
0
        void RenderViewImpl(ViewContext viewContext, Func <XcstTemplateEvaluator, XcstOutputter> getOutputter, object instance)
        {
            if (viewContext is null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }
            if (instance is null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            XcstViewPage viewPage = instance as XcstViewPage
                                    ?? throw new InvalidOperationException($"The view at '{ViewPath}' must derive from {nameof(XcstViewPage)}, or {nameof(XcstViewPage)}<TModel>.");

            viewPage.ViewContext = viewContext;

            AddFileDependencies(instance, viewContext.HttpContext.Response);

            XcstEvaluator evaluator = XcstEvaluator.Using((object)viewPage);

            foreach (var item in viewContext.ViewData)
            {
                evaluator.WithParam(item.Key, item.Value);
            }

            getOutputter(evaluator.CallInitialTemplate())
            .Run();
        }
Ejemplo n.º 2
0
 protected virtual void RenderPage(XcstPage page, HttpContextBase context)
 {
     XcstEvaluator.Using((object)page)
     .CallInitialTemplate()
     .OutputTo(context.Response.Output)
     .Run();
 }
Ejemplo n.º 3
0
 RenderPage(XcstPage page, HttpContext context)
 {
     XcstEvaluator.Using((object)page)
     .CallInitialTemplate()
     .OutputTo(context.Response.BodyWriter.AsStream())
     .Run();
 }
Ejemplo n.º 4
0
        static void SimplyRun(Type packageType, Uri packageUri)
        {
            XcstViewPage package = CreatePackage(packageType);

            XcstEvaluator.Using((object)package)
            .CallInitialTemplate()
            .OutputTo(TextWriter.Null)
            .WithBaseUri(packageUri)
            .WithBaseOutputUri(packageUri)
            .Run();
        }
Ejemplo n.º 5
0
 protected override void RenderViewPage(XcstViewPage page, HttpContextBase context)
 {
     if (page is IPageInit pInit)
     {
         XcstEvaluator.Using(pInit)
         .CallFunction(p => p.Init())
         .Run();
     }
     else
     {
         base.RenderViewPage(page, context);
     }
 }
Ejemplo n.º 6
0
            protected override void RenderViewPage(XcstViewPage page, HttpContext context)
            {
                context.Response.ContentType = "text/html";

                if (page is IPageInit pInit)
                {
                    XcstEvaluator.Using(pInit)
                    .CallFunction(p => p.Init())
                    .Run();
                }
                else
                {
                    base.RenderViewPage(page, context);
                }
            }
Ejemplo n.º 7
0
        static bool OutputEqualsToExpected(Type packageType, Uri packageUri, bool printCode)
        {
            XcstViewPage package = CreatePackage(packageType);

            var expectedDoc = new XDocument();
            var actualDoc   = new XDocument();

            XcstEvaluator evaluator = XcstEvaluator.Using((object)package);

            using (XmlWriter actualWriter = actualDoc.CreateWriter()) {
                evaluator.CallInitialTemplate()
                .OutputTo(actualWriter)
                .WithBaseUri(packageUri)
                .WithBaseOutputUri(packageUri)
                .Run();
            }

            using (XmlWriter expectedWriter = expectedDoc.CreateWriter()) {
                evaluator.CallTemplate(_expectedName)
                .OutputTo(expectedWriter)
                .Run();
            }

            XDocument normalizedExpected = XDocumentNormalizer.Normalize(expectedDoc);
            XDocument normalizedActual   = XDocumentNormalizer.Normalize(actualDoc);
            bool      equals             = XNode.DeepEquals(normalizedExpected, normalizedActual);

            if (printCode || !equals)
            {
                Console.WriteLine("/*");
                Console.WriteLine("<!-- expected -->");
                Console.WriteLine(normalizedExpected.ToString());
                Console.WriteLine();
                Console.WriteLine("<!-- actual -->");
                Console.WriteLine(normalizedActual.ToString());
                Console.WriteLine("*/");
            }

            return(equals);
        }