Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="article"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        private static void CreerContratsFormationsHtml(Article article, DirectoryInfo repertoire, IHostingEnvironment env)
        {
            DirectoryInfo        repertoireDest      = repertoire.CreateSubdirectory("documents");
            IServiceScopeFactory serviceScopeFactory = InitializeServices();
            ContratFormationView viewModel;

            if (article.HasFinancementDpc)
            {
                viewModel = ContratFormationView.Create(article, Financement.Dpc);
                string cheminFichierCree = CreerContratFormationHtml(serviceScopeFactory, repertoireDest, viewModel, "contrat-formation-dpc", "Contrats/ContratFormationDpcHorsDpc");
                _logger.LogInformation("création fichier:" + Path.GetFileName(cheminFichierCree));
            }
            if (article.HasFinancementHorsDpc)
            {
                viewModel = ContratFormationView.Create(article, Financement.HorsDpc);
                string cheminFichierCree = CreerContratFormationHtml(serviceScopeFactory, repertoireDest, viewModel, "contrat-formation-hors-dpc", "Contrats/ContratFormationDpcHorsDpc");
                _logger.LogInformation("création fichier:" + Path.GetFileName(cheminFichierCree));
            }
            if (article.HasFinancementSalarie)
            {
                viewModel = ContratFormationView.Create(article, Financement.Salarie);
                string cheminFichierCree = CreerContratFormationHtml(serviceScopeFactory, repertoireDest, viewModel, "contrat-formation-salarie", "Contrats/ContratFormationSalarie");
                _logger.LogInformation("création fichier:" + Path.GetFileName(cheminFichierCree));
            }
        }
Exemplo n.º 2
0
        private static string CreerContratFormationHtml(IServiceScopeFactory serviceScopeFactory, DirectoryInfo repertoire, ContratFormationView viewModel, string filename, string template)
        {
            string modeleHtml = "";

            try
            {
                modeleHtml = RenderViewAsync(serviceScopeFactory, viewModel, template).Result;
            }
            catch (Exception ex)
            {
                _logger.LogError($"Erreur sur la création du template HTML: {template}", ex);
            }
            string cheminModeleHtml = $"{repertoire.FullName}/{filename}.html";

            using (StreamWriter DestinationWriter = File.CreateText(cheminModeleHtml))
            {
                try
                {
                    DestinationWriter.Write(modeleHtml);
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Erreur sur la création du template PDF: {cheminModeleHtml}", ex);
                }
            }
            return(cheminModeleHtml);
        }