示例#1
0
        public void Export(ExportFormat format, string filePath, ChatLog log)
        {
            // Create template loader
            var loader = new TemplateLoader();

            // Get template
            var templateCode = loader.Load(format);
            var template     = Template.Parse(templateCode);

            // Create template context
            var context = new TemplateContext
            {
                TemplateLoader  = loader,
                MemberRenamer   = m => m.Name,
                MemberFilter    = m => true,
                LoopLimit       = int.MaxValue,
                StrictVariables = true
            };

            // Create template model
            var templateModel = new TemplateModel(format, log, _settingsService.DateFormat);

            context.PushGlobal(templateModel.GetScriptObject());

            // Render output
            using (var output = File.CreateText(filePath))
            {
                // Configure output
                context.PushOutput(new TextWriterOutput(output));

                // Render template
                template.Render(context);
            }
        }
示例#2
0
        private void ExportChatLogSingle(ChatLog chatLog, string filePath, ExportFormat format)
        {
            // Create template loader
            var loader = new TemplateLoader();

            // Get template
            var templateCode = loader.Load(format);
            var template     = Template.Parse(templateCode);

            // Create template context
            var context = new TemplateContext
            {
                TemplateLoader  = loader,
                MemberRenamer   = m => m.Name,
                MemberFilter    = m => true,
                LoopLimit       = int.MaxValue,
                StrictVariables = true
            };

            // Create template model
            var templateModel = new TemplateModel(format, chatLog,
                                                  _settingsService.DateFormat, _settingsService.MessageGroupLimit);

            context.PushGlobal(templateModel.GetScriptObject());

            // Create directory
            var dirPath = Path.GetDirectoryName(filePath);

            if (dirPath.IsNotBlank())
            {
                Directory.CreateDirectory(dirPath);
            }

            // Render output
            using (var output = File.CreateText(filePath))
            {
                // Configure output
                context.PushOutput(new TextWriterOutput(output));

                // Render output
                context.Evaluate(template.Page);
            }
        }