Exemple #1
0
        public async Task <string> ParseAsync <T>(string template, T model, bool isHtml = true)
        {
            var project = new InMemoryRazorLightProject();
            var engine  = new EngineFactory().Create(project);

            return(await engine.CompileRenderAsync <T>(Guid.NewGuid().ToString(), template, model));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestDatabase")
                          .Options;

            // Create and fill database with test data
            var db = new AppDbContext(options);

            FillDatabase(db);


            // Create engine that uses entityFramework to fetch templates from db
            // You can create project that uses your IRepository<T>
            var project = new EntityFrameworkRazorLightProject(db);
            IRazorLightEngine engine = new EngineFactory().Create(project);



            // As our key in database is integer, but engine takes string as a key - pass integer ID as a string
            string templateKey = "2";
            var    model       = new TestViewModel()
            {
                Name = "Johny", Age = 22
            };
            string result = engine.CompileRenderAsync(templateKey, model).Result;

            //Identation will be a bit fuzzy, as we formatted a string for readability
            Console.WriteLine(result);
            db.Dispose();
        }
Exemple #3
0
        async Task <string> ParseAsync <T>(string templateName, string template, T model)
        {
            var project = new InMemoryRazorLightProject();
            var engine  = new EngineFactory().Create(project);

            return(await engine.CompileRenderAsync <T>(templateName, template, model));
        }
Exemple #4
0
        public void RazorLight_Render()
        {
            var engine  = new EngineFactory().ForFileSystem(Path.Combine(Directory.GetCurrentDirectory()));
            var content = engine.CompileRenderAsync("Template.cshtml", Enumerable.Range(0, 9)).Result;

            File.WriteAllText("View.html", content);
        }
        public async Task <string> GetMessage(DumpMetainfo dumpInfo)
        {
            //var engine = new RazorLightEngineBuilder()
            //.UseEmbeddedResourcesProject(typeof(SlackMessageViewModel))
            //.UseMemoryCachingProvider()
            //.Build();
            var engine = new EngineFactory().ForEmbeddedResources(typeof(SlackMessageViewModel));

            return(await engine.CompileRenderAsync("SlackMessage", await GetMessageModel(dumpInfo)));
        }
Exemple #6
0
        public async Task Ensure_Content_Added_To_DynamicTemplates()
        {
            var options = new RazorLightOptions();

            string key     = "key";
            string content = "content";
            var    project = new TestRazorProject();

            project.Value = new TextSourceRazorProjectItem(key, content);

            var engine = new EngineFactory().Create(project, options);

            await engine.CompileRenderAsync(key, content, new object(), typeof(object));

            Assert.NotEmpty(options.DynamicTemplates);
            Assert.Contains(options.DynamicTemplates, t => t.Key == key && t.Value == content);
        }
Exemple #7
0
        public async Task <string> GetMessage(DumpMetainfo dumpInfo)
        {
            var model = new SlackMessageViewModel();

            var res = dumpRepo.GetResult(dumpInfo.BundleId, dumpInfo.DumpId, out string error);

            var engine = new EngineFactory().ForEmbeddedResources(typeof(SlackMessageViewModel));

            model.TopProperties.Add(dumpInfo.DumpType == DumpType.WindowsDump ? "Windows" : "Linux");
            model.DumpFilename = Path.GetFileName(dumpInfo.DumpFileName);
            model.Url          = $"{superDumpUrl}/Home/Report?bundleId={dumpInfo.BundleId}&dumpId={dumpInfo.DumpId}";
            if (res != null)
            {
                model.TopProperties.Add(res.SystemContext.ProcessArchitecture);

                if (res.IsManagedProcess)
                {
                    model.TopProperties.Add(".NET");
                }
                if (res.SystemContext.Modules.Any(x => x.FileName.Contains("jvm.dll")))
                {
                    model.TopProperties.Add("Java");
                }
                if (res.SystemContext.Modules.Any(x => x.FileName.Contains("jvm.so")))
                {
                    model.TopProperties.Add("Java");
                }
                if (res.SystemContext.Modules.Any(x => x.FileName.Contains("iiscore.dll")))
                {
                    model.TopProperties.Add("IIS");
                }
                if (res.SystemContext.Modules.Any(x => x.FileName.Contains("nginx.so")))
                {
                    model.TopProperties.Add("NGINX");
                }
                if (res.SystemContext.Modules.Any(x => x.FileName.Contains("httpd/modules")))
                {
                    model.TopProperties.Add("Apache");
                }
                if (res.SystemContext.Modules.Any(x => x.FileName.Contains("node.exe")))
                {
                    model.TopProperties.Add("Node.js");
                }

                var agentModules = res.SystemContext.Modules.Where(x => x.Tags.Any(t => t.Equals(SDTag.DynatraceAgentTag))).Select(m => m.ToString());
                model.AgentModules = agentModules.ToList();

                model.NumManagedExceptions = res.ThreadInformation.Count(x => x.Value.Tags.Any(t => t.Equals(SDTag.ManagedExceptionTag)));
                model.NumNativeExceptions  = res.ThreadInformation.Count(x => x.Value.Tags.Any(t => t.Equals(SDTag.NativeExceptionTag)));
                model.NumAssertErrors      = res.ThreadInformation.Count(x => x.Value.Tags.Any(t => t.Equals(SDTag.AssertionErrorTag)));

                SDThread       managedExceptionThread = res.ThreadInformation.Values.FirstOrDefault(x => x.Tags.Any(t => t.Equals(SDTag.ManagedExceptionTag)));
                SDClrException clrException           = managedExceptionThread?.LastException;
                if (clrException != null)
                {
                    model.TopException = clrException.Type;
                    model.Stacktrace   = clrException.StackTrace.ToString();
                }

                if (res.LastEvent != null && !res.LastEvent.Description.Contains("Break instruction"))                   // break instruction events are useless
                {
                    model.LastEvent = $"{res.LastEvent.Type}: {res.LastEvent.Description}";
                }
            }

            return(await engine.CompileRenderAsync("SlackMessage", model));
        }