public ManifestPageGenerator(ITemplateGenerator templateGenerator, IPageDefinition pageDefinitionService, IFr8Account fr8AccountService, IUnitOfWorkFactory uowFactory)
 {
     _templateGenerator     = templateGenerator;
     _pageDefinitionService = pageDefinitionService;
     _fr8AccountService     = fr8AccountService;
     _uowFactory            = uowFactory;
 }
Exemple #2
0
        public void Initialize()
        {
            _documentTypeRepositoryMock      = DocumentTypeRepositoryMock.GetDocumentTypeRepositoryMock();
            _generatedDocumentRepositoryMock = GeneratedDocumentRepositoryMock.GetGeneratedDocumentRepositoryMock();
            jsonContent   = new GenerateDocumentRequest();
            htmlContent   = new GenerateDocumentRequest();
            nsiContext    = new NsiContext();
            htmlGenerator = new NSI.DocumentGenerator.Implementations.HtmlGenerator(new NSI.DocumentGenerator.Implementations.Helpers.HtmlGeneratorHelper());
            pdfGenerator  = new NSI.DocumentGenerator.Implementations.PdfGenerator();

            _docxGeneratorMock = DocxGeneratorMock.GetDocxGeneratorMock();
            _odtGeneratorMock  = OdtGeneratorMock.GetOdtGeneratorMock();

            generatedDocumentLogger = new NSI.DocumentGenerator.Implementations.Helpers.GeneratedDocumentLogger(_generatedDocumentRepositoryMock.Object);
            templateGenerator       = new TemplateGenerator(new NSI.DocumentGenerator.Implementations.PdfGenerator(), new NSI.DocumentGenerator.Implementations.HtmlGenerator(new NSI.DocumentGenerator.Implementations.Helpers.HtmlGeneratorHelper()));
            documentGenerator       = new NSI.DocumentGenerator.Implementations.Generators.DocumentGenerator(_documentTypeRepositoryMock.Object, generatedDocumentLogger, htmlGenerator, pdfGenerator, _odtGeneratorMock.Object, _docxGeneratorMock.Object, templateGenerator);
            jsonDocumentTypeDomain  = new DocumentTypeDomain()
            {
                Name     = "json",
                Code     = "json",
                Version  = "1.0",
                Encoding = "utf-8"
            };
            htmlDocumentTypeDomain = new DocumentTypeDomain()
            {
                Name     = "html",
                Code     = "html",
                Version  = "1.0",
                Encoding = "utf-8"
            };
        }
 public EmailService(IEmailConfiguration emailConfiguration,
                     IHostingEnvironment env,
                     ITemplateGenerator generator)
 {
     _emailConfiguration = emailConfiguration;
     _env       = env;
     _generator = generator;
 }
        /// <summary>
        /// Unregisters the specified factory.
        /// </summary>
        /// <param name="generator">The factory.</param>
        /// <exception cref="System.ArgumentNullException">factory</exception>
        public static void Unregister(ITemplateGenerator generator)
        {
            if (generator == null) throw new ArgumentNullException("generator");

            lock (ThisLock)
            {
                Generators.Remove(generator);
            }
        }
Exemple #5
0
        public PlanTemplateDetailsGenerator(ITemplateGenerator templateGenerator)
        {
            if (templateGenerator == null)
            {
                throw new ArgumentNullException(nameof(templateGenerator));
            }

            _templateGenerator = templateGenerator;
        }
Exemple #6
0
 public RandomArticleInteractor(
     IArticleGateway articleGateway,
     ITemplateGenerator templateGenerator,
     IOutputBoundary outputBoundary)
 {
     this.ArticleGateway = articleGateway;
     this.TemplateGenerator = templateGenerator;
     this.OutputBoundary = outputBoundary;
 }
Exemple #7
0
        /// <summary>
        /// Invokes the given template generator safely. The generator will be prepared on the calling thread, and run from
        /// a task. This methods will catch and log all exceptions occurring during the template generation.
        /// </summary>
        /// <param name="generator">The template generator to run.</param>
        /// <param name="parameters">The parameters for the template generator.</param>
        /// <param name="workProgress">The view model used to report progress.</param>
        /// <returns>A task that completes when the template generator has finished to run.</returns>
        internal static async Task <bool> RunTemplateGeneratorSafe <TParameters>(ITemplateGenerator <TParameters> generator, TParameters parameters, WorkProgressViewModel workProgress) where TParameters : TemplateGeneratorParameters
        {
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            var success = false;

            try
            {
                success = await generator.PrepareForRun(parameters);

                if (!success)
                {
                    // If the preparation failed without error, it means that the user cancelled the operation.
                    if (!parameters.Logger.HasErrors)
                    {
                        parameters.Logger.Info(Tr._p("Log", "Operation cancelled."));
                    }

                    return(false);
                }
            }
            catch (Exception e)
            {
                parameters.Logger.Error(Tr._p("Log", "An exception occurred while generating the template."), e);
            }

            if (parameters.Logger.HasErrors || !success)
            {
                workProgress?.ServiceProvider.Get <IEditorDialogService>().ShowProgressWindow(workProgress, 0);
                return(false);
            }

            workProgress?.ServiceProvider.Get <IEditorDialogService>().ShowProgressWindow(workProgress, 500);

            var result = await Task.Run(() =>
            {
                try
                {
                    return(generator.Run(parameters));
                }
                catch (Exception e)
                {
                    parameters.Logger.Error(Tr._p("Log", "An exception occurred while generating the template."), e);
                    return(false);
                }
            });

            return(result && !parameters.Logger.HasErrors);
        }
 public WebservicesPageGenerator(
     IPageDefinition pageDefinitionService,
     IPlanTemplate planTemplateService,
     ITemplateGenerator templateGenerator,
     ITagGenerator tagGenerator)
 {
     _pageDefinitionService = pageDefinitionService;
     _planTemplateService   = planTemplateService;
     _templateGenerator     = templateGenerator;
     _tagGenerator          = tagGenerator;
 }
        /// <summary>
        /// Registers the specified factory.
        /// </summary>
        /// <param name="generator">The factory.</param>
        /// <exception cref="System.ArgumentNullException">factory</exception>
        public static void Register(ITemplateGenerator generator)
        {
            if (generator == null) throw new ArgumentNullException("generator");

            lock (ThisLock)
            {
                if (!Generators.Contains(generator))
                {
                    Generators.Add(generator);
                }
            }
        }
        /// <summary>
        /// Add a template generator
        /// </summary>
        /// <param name="fileExtension">File extension without the dot.</param>
        /// <param name="generator">Generator to handle the extension</param>
        /// <exception cref="InvalidOperationException">If the generator already exists.</exception>
        /// <exception cref="ArgumentException">If file extension is incorrect</exception>
        /// <exception cref="ArgumentNullException">If generator is not specified.</exception>
        /// <example>
        /// <code>
        /// cache.Add("haml", new HamlGenerator());
        /// </code>
        /// </example>
        public void Add(string fileExtension, ITemplateGenerator generator)
        {
            if (string.IsNullOrEmpty(fileExtension) || fileExtension.Contains("."))
                throw new ArgumentException("Invalid file extension.");
            if (generator == null)
                throw new ArgumentNullException("generator");

            if (_generators.ContainsKey(fileExtension))
                throw new InvalidOperationException("A generator already exists for " + fileExtension);

            _generators.Add(fileExtension, generator);
        }
Exemple #11
0
        /// <summary>
        /// Unregisters the specified factory.
        /// </summary>
        /// <param name="generator">The factory.</param>
        /// <exception cref="System.ArgumentNullException">factory</exception>
        public static void Unregister(ITemplateGenerator generator)
        {
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }

            lock (ThisLock)
            {
                Generators.Remove(generator);
            }
        }
 public Notifier(ITemplateGenerator templateGenerator,
                 OmnitureNotificationContext context,
                 Func <NotificationTypes, INotificationHandler> notificationHandlers,
                 INotificationQueue notificationQueue,
                 OmnitureConfiguration config)
 {
     _templateGenerator    = templateGenerator;
     _context              = context;
     _config               = config;
     _notificationHandlers = notificationHandlers;
     _notificationQueue    = notificationQueue;
 }
Exemple #13
0
        /// <summary>
        /// Registers the specified factory.
        /// </summary>
        /// <param name="generator">The factory.</param>
        /// <exception cref="System.ArgumentNullException">factory</exception>
        public static void Register(ITemplateGenerator generator)
        {
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }

            lock (ThisLock)
            {
                if (!Generators.Contains(generator))
                {
                    Generators.Add(generator);
                }
            }
        }
Exemple #14
0
 public EmailGenerator(SrvPdfGenerator srvPdfGenerator, IAssetsRepository assetsRepository,
                       IPersonalDataRepository personalDataRepository, TemplateGenerator localTemplateGenerator,
                       BaseSettings settings, ITemplateGenerator templateGenerator, EmailGeneratorSettings emailGeneratorSettings,
                       IQrCodeGenerator qrCodeGenerator, IBackupQrRepository backupQrRepository)
 {
     _srvPdfGenerator        = srvPdfGenerator;
     _assetsRepository       = assetsRepository;
     _personalDataRepository = personalDataRepository;
     _settings               = settings;
     _templateGenerator      = templateGenerator;
     _emailGeneratorSettings = emailGeneratorSettings;
     _qrCodeGenerator        = qrCodeGenerator;
     _backupQrRepository     = backupQrRepository;
     _localTemplateGenerator = localTemplateGenerator;
 }
        private void TestGetGeneratorForWildCard()
        {
            string resource = "rendering\\resourcetest.*";

            Add("haml", new HamlGenerator());
            Add("tiny", new Tiny.TinyGenerator());
            _templateLoaders.Clear();
            ResourceTemplateLoader loader = new ResourceTemplateLoader();

            loader.LoadTemplates("rendering/", loader.GetType().Assembly, "HttpServer.Rendering");
            _templateLoaders.Add(loader);
            ITemplateGenerator gen = GetGeneratorForWildCard(ref resource);

            Assert.NotNull(gen);
            Assert.IsType(typeof(HamlGenerator), gen);
        }
Exemple #16
0
 public DocumentGenerator(
     IDocumentTypeRepository documentTypeRepository,
     IGeneratedDocumentLogger documentLogger,
     IHtmlGenerator htmlGenerator,
     IPdfGenerator pdfGenerator,
     IOdtGenerator odtGenerator,
     IDocxGenerator docxGenerator,
     ITemplateGenerator templateGenerator
     )
 {
     _documentTypeRepository = documentTypeRepository;
     _documentLogger         = documentLogger;
     _htmlGenerator          = htmlGenerator;
     _pdfGenerator           = pdfGenerator;
     _odtGenerator           = odtGenerator;
     _docxGenerator          = docxGenerator;
     _templateGenerator      = templateGenerator;
 }
Exemple #17
0
        /// <summary>
        /// Add a template generator
        /// </summary>
        /// <param name="fileExtension">File extension without the dot.</param>
        /// <param name="generator">Generator to handle the extension</param>
        /// <exception cref="InvalidOperationException">If the generator already exists.</exception>
        /// <exception cref="ArgumentException">If file extension is incorrect</exception>
        /// <exception cref="ArgumentNullException">If generator is not specified.</exception>
        /// <example>
        /// <code>
        /// cache.Add("haml", new HamlGenerator());
        /// </code>
        /// </example>
        public void Add(string fileExtension, ITemplateGenerator generator)
        {
            if (string.IsNullOrEmpty(fileExtension) || fileExtension.Contains("."))
            {
                throw new ArgumentException("Invalid file extension.");
            }
            if (generator == null)
            {
                throw new ArgumentNullException("generator");
            }

            if (_generators.ContainsKey(fileExtension))
            {
                throw new InvalidOperationException("A generator already exists for " + fileExtension);
            }

            _generators.Add(fileExtension, generator);
        }
        public void Initialize()
        {
            _documentTypeRepositoryMock      = DocumentTypeRepositoryMock.GetDocumentTypeRepositoryMock();
            _generatedDocumentRepositoryMock = GeneratedDocumentRepositoryMock.GetGeneratedDocumentRepositoryMock();
            jsonContent        = new GenerateDocumentRequest();
            htmlContent        = new GenerateDocumentRequest();
            htmlGenerator      = new DocumentGenerator.Implementations.HtmlGenerator(new DocumentGenerator.Implementations.Helpers.HtmlGeneratorHelper());
            pdfGenerator       = new DocumentGenerator.Implementations.PdfGenerator();
            _docxGeneratorMock = DocxGeneratorMock.GetDocxGeneratorMock();
            _odtGeneratorMock  = OdtGeneratorMock.GetOdtGeneratorMock();

            generatedDocumentLogger = new DocumentGenerator.Implementations.Helpers.GeneratedDocumentLogger(_generatedDocumentRepositoryMock.Object);
            templateGenerator       = new TemplateGenerator(new DocumentGenerator.Implementations.PdfGenerator(), new DocumentGenerator.Implementations.HtmlGenerator(new DocumentGenerator.Implementations.Helpers.HtmlGeneratorHelper()));
            documentGenerator       = new DocumentGenerator.Implementations.Generators.DocumentGenerator(_documentTypeRepositoryMock.Object, generatedDocumentLogger, htmlGenerator, pdfGenerator, _odtGeneratorMock.Object, _docxGeneratorMock.Object, templateGenerator);
            setJsonContent();
            setHtmlContent();
            controller = new DocumentGeneratorController(documentGenerator, generatedDocumentLogger);
        }
Exemple #19
0
 public EmailService(ITemplateGenerator templateGenerator, IEmailSender emailSender)
 {
     _templateGenerator = templateGenerator;
     _emailSender       = emailSender;
 }
Exemple #20
0
 public EmailGenerator(ITemplateGenerator templateGenerator, TemplateGenerator localTemplateGenerator)
 {
     _templateGenerator      = templateGenerator;
     _localTemplateGenerator = localTemplateGenerator;
 }
Exemple #21
0
 public ConfigRunner(IFileSystemWrapper fileSystem, IConfigProvider configProvider, ITemplateGenerator templateGenerator)
 {
     this.fileSystem = fileSystem;
     this.configProvider = configProvider;
     this.templateGenerator = templateGenerator;
 }
Exemple #22
0
        /// <summary>
        /// Will generate code from the template.
        /// Next step is to compile the code.
        /// </summary>
        /// <param name="path">Path and filename to template.</param>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="InvalidOperationException">If no template generator exists for the specified extension.</exception>
        /// <exception cref="CodeGeneratorException">If parsing/compiling fails</exception>
        /// <see cref="Render(string, TemplateArguments)"/>
        /// <exception cref="FileNotFoundException">Template is not found.</exception>
        private string GenerateCode(ref string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("No filename was specified.");
            }

            int pos = path.LastIndexOf('.');

            if (pos == -1)
            {
                throw new ArgumentException("Filename do not contain a file extension.");
            }
            if (pos == path.Length - 1)
            {
                throw new ArgumentException("Invalid filename '" + path + "', should not end with a dot.");
            }

            string extension = path.Substring(pos + 1);


            lock (_generators)
            {
                ITemplateGenerator generator = null;
                if (extension == "*")
                {
                    generator = GetGeneratorForWildCard(ref path);
                }
                else
                {
                    if (_generators.ContainsKey(extension))
                    {
                        generator = _generators[extension];
                    }
                }

                if (generator == null)
                {
                    throw new InvalidOperationException("No template generator exists for '" + path + "'.");
                }

                TextReader reader = null;
                try
                {
                    foreach (ITemplateLoader loader in _templateLoaders)
                    {
                        reader = loader.LoadTemplate(path);
                        if (reader != null)
                        {
                            break;
                        }
                    }

                    if (reader == null)
                    {
                        throw new FileNotFoundException("Did not find template: " + path);
                    }

                    generator.Parse(reader);
                    reader.Close();
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Dispose();
                    }
                }

                StringBuilder sb = new StringBuilder();
                using (TextWriter writer = new StringWriter(sb))
                {
                    generator.GenerateCode(writer);
                    return(sb.ToString());
                }
            }
        }
Exemple #23
0
 public SmsTextGenerator(ITemplateGenerator templateGenerator)
 {
     _templateGenerator = templateGenerator;
 }
Exemple #24
0
 public EmailService(ITemplateGenerator templateGenerator, IEmailSender emailSender, IClientAccountService clientAccountService)
 {
     _templateGenerator    = templateGenerator;
     _emailSender          = emailSender;
     _clientAccountService = clientAccountService;
 }