<commit_before>﻿using CsvHelper;
using SO115App.Persistence.File.PDFManagement.TemplateModelForms;
using System;
using System.Globalization;
using System.IO;

namespace SO115App.Persistence.File.CSVManagement
{
    internal sealed class CSVTemplateManager<TemplateModelForm> : ICSVTemplateManager<TemplateModelForm> where TemplateModelForm : class
    {
        private MemoryStream memoryStream; 
        private StreamWriter streamWriter; 
        private CsvWriter csvWriter;

        public CSVTemplateManager() 
        {
            memoryStream = new MemoryStream();
            streamWriter = new StreamWriter(memoryStream);
            csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture);
        }

        public MemoryStream GenerateAndDownload(TemplateModelForm template, string fileName, string requestFolder)
        {
            switch (template)
            {
                case DettaglioChiamataModelForm model: generaDettaglioChiamataCSV(model); break;

                case DettaglioInterventoModelForm model: generaDettaglioInterventoCSV(model); break;

                case RiepilogoInterventiModelForm model: generaRiepilogoInterventoCSV(model); break;

                default: throw new NotImplementedException("Template non gestito");
            }

            csvWriter.Flush();
            
            return memoryStream;
        }

        private void generaDettaglioChiamataCSV(DettaglioChiamataModelForm model)
        {
            csvWriter.WriteRecord(model);
        }

        private void generaDettaglioInterventoCSV(DettaglioInterventoModelForm model)
        {
            csvWriter.WriteRecord(model);
        }

        private void generaRiepilogoInterventoCSV(RiepilogoInterventiModelForm model)
        {
            csvWriter.WriteRecord(model);
        }
    }
}
<commit_msg>fix vari csv<commit_after>﻿using CsvHelper;
using CsvHelper.Configuration;
using SO115App.Persistence.File.PDFManagement.TemplateModelForms;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

namespace SO115App.Persistence.File.CSVManagement
{
    internal sealed class CSVTemplateManager<TemplateModelForm> : ICSVTemplateManager<TemplateModelForm> where TemplateModelForm : class
    {
        private MemoryStream memoryStream; 
        private StreamWriter streamWriter; 
        private CsvWriter csvWriter;

        public CSVTemplateManager() 
        {
            memoryStream = new MemoryStream();
            streamWriter = new StreamWriter(memoryStream);
            csvWriter = new CsvWriter(streamWriter, new CsvConfiguration(CultureInfo.InvariantCulture));
        }

        public MemoryStream GenerateAndDownload(TemplateModelForm template, string fileName, string requestFolder)
        {
            switch (template)
            {
                case DettaglioChiamataModelForm model: generaDettaglioChiamataCSV(model); break;

                case DettaglioInterventoModelForm model: generaDettaglioInterventoCSV(model); break;

                case RiepilogoInterventiModelForm model: generaRiepilogoInterventoCSV(model); break;

                default: throw new NotImplementedException("Template non gestito");
            }

            csvWriter.Flush();
            
            return memoryStream;
        }

        private void generaDettaglioChiamataCSV(DettaglioChiamataModelForm model)
        {
            csvWriter.WriteRecords(new List<DettaglioChiamataModelForm>() { model });
        }

        private void generaDettaglioInterventoCSV(DettaglioInterventoModelForm model)
        {
            csvWriter.WriteRecords(new List<DettaglioInterventoModelForm>() { model });
        }

        private void generaRiepilogoInterventoCSV(RiepilogoInterventiModelForm model)
        {
            csvWriter.WriteRecords(model.lstRiepiloghi);
        }
    }
}

{'fraction_non_alphanumeric': 0.06126126126126126, 'fraction_numerical': 0.003088803088803089, 'mean_word_length': 2.787524366471735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7662166', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1005, 'n_words': 191}