예제 #1
0
        private Container()
        {
            _defaultTypeOfExport = x => {
                var types   = new List <Type>();
                var exports = x.GetCustomAttributes(typeof(ExportAttribute), true)
                              .OfType <ExportAttribute>();

                if (exports.Any())
                {
                    foreach (var export in exports)
                    {
                        types.Add(export.Type);
                    }
                }
                else
                {
                    types.Add(x);
                }

                return(types.ToArray());
            };

            var containerBuilder = new ContainerBuilder();

            // load current assembly
            RegisterAssembly(containerBuilder, Assembly.GetExecutingAssembly());

            _container = containerBuilder.Build();
        }
        internal static void CreateOutgoingClients(List <Client> listClient, TypeOfClient soortKlant,
                                                   TypeOfExport typeOfExport, IConfiguration configuration)
        {
            List <T> listOutgClient;

            listOutgClient = ClientFactory.CreateListClients <T>(soortKlant, listClient);
            var soortUitgFile = soortKlant switch
            {
                TypeOfClient.Big => KindOutgoingFile.BigClient,
                TypeOfClient.Small => KindOutgoingFile.SmallClient,
                TypeOfClient.Criminal => KindOutgoingFile.CriminalClient,
                TypeOfClient.WithManyConsults => KindOutgoingFile.ManyConsultsClient,
                _ => throw new InvalidEnumArgumentException(),
            };

            PathsAndFolders.CreateFileNamesAndDirectories
                (soortUitgFile,
                typeOfExport,
                configuration,
                out string fileName,
                out string fullFileName);

            var klantExportFileModel = ClientFactory.CreateKlantExportFileModel(listOutgClient, fileName);

            klantExportFileModel.SerializeToClientFile <T>(fullFileName, typeOfExport);
        }
예제 #3
0
        public void CreateOutgClientFile(TypeOfClient typeOfClient, TypeOfExport typeOfExport)
        {
            Console.WriteLine("Retrieving all Clients from database ---");
            // Dankzij include in repos hebben we per Client ook Country en Doctor (N: 1)
            // Dankzij include in repos hebben we per Client ook al zijn Consults (1:N)
            var listClient = _clientRepository.GetAllWithConsults();

            switch (typeOfClient)
            {
            case TypeOfClient.Big:
                ClientHandler <BigClient> .CreateOutgoingClients(listClient, typeOfClient, typeOfExport, _configuration);

                break;

            case TypeOfClient.Small:
                ClientHandler <SmallClient> .CreateOutgoingClients(listClient, typeOfClient, typeOfExport, _configuration);

                break;

            case TypeOfClient.Criminal:
                ClientHandler <CriminalClient> .CreateOutgoingClients(listClient, typeOfClient, typeOfExport, _configuration);

                break;

            case TypeOfClient.WithManyConsults:
                ClientHandler <WithManyConsultsClient> .CreateOutgoingClients(listClient, typeOfClient, typeOfExport, _configuration);

                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
예제 #4
0
        internal static void CreateOutgInvoices(List <Invoice> listInv, SoortUitgFactuur soortUitgFactuur,
                                                TypeOfExport typeOfExport, IConfiguration configuration)
        {
            // Maak lijst van Small Invoices en vul de BASISVELDEN van ieder element van deze lijst:
            var listOutgInv = InvoiceFactory <SmallInvoice> .CreateListBaseInvoice(listInv);

            // Toevoegen van een paar klant-naw gegevens aan iedere SMALL factuur:
            for (int i = 0; i < listInv.Count; i++)
            {
                listOutgInv[i].OmschrijvingKleineFactuur = $"KLEINE factuur met nummer {listInv[i].InvoiceNumber}";
            }
            ;



            KindOutgoingFile soortUitgFile;

#pragma warning disable IDE0066 // Convert switch statement to expression
            switch (soortUitgFactuur)
#pragma warning restore IDE0066 // Convert switch statement to expression
            {
            case SoortUitgFactuur.Big:
                soortUitgFile = KindOutgoingFile.BigInvoice;
                break;

            case SoortUitgFactuur.Small:
                soortUitgFile = KindOutgoingFile.SmallInvoice;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            PathsAndFolders.CreateFileNamesAndDirectories
                (soortUitgFile,
                typeOfExport,
                configuration,
                out string fileName,
                out string fullFileName);

            var invoiceExportFileModel = InvoiceFactory <SmallInvoice> .CreateInvoiceExportFileModel(listOutgInv, fileName);

            // Onderstaande is vervangen door een extension method op klasse InvoiceExportFileModel<T>.
            // Serializing.SerializeToFile<SmallInvoice>(fullFileNameSmall, invoiceSmallExportFileModel);
            invoiceExportFileModel.SerializeToInvoiceFile <SmallInvoice>(fullFileName, typeOfExport);
        }
        internal static void CreateOutgInvoices(List <Invoice> listInv, SoortUitgFactuur soortUitgFactuur,
                                                TypeOfExport typeOfExport, IConfiguration configuration)
        {
            // Maak lijst van Big Invoices en vul de BASISVELDEN van ieder element van deze lijst:
            var listOutgInv = InvoiceFactory <BigInvoice> .CreateListBaseInvoice(listInv);

            // Toevoegen van alle Client Gegevens aan iedere BIG factuur:
            for (int i = 0; i < listInv.Count; i++)
            {
                listOutgInv[i].Client = listInv[i].Client; // extra bovenop de basis velden (XXX)
                listOutgInv[i].OmschrijvingGroteFaktuur = $"GROTE factuur met nummer {listInv[i].InvoiceNumber}";
            }
            ;

            KindOutgoingFile soortUitgFile;

            switch (soortUitgFactuur)
            {
            case SoortUitgFactuur.Big:
                soortUitgFile = KindOutgoingFile.BigInvoice;
                break;

            case SoortUitgFactuur.Small:
                soortUitgFile = KindOutgoingFile.SmallInvoice;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
            ;


            PathsAndFolders.CreateFileNamesAndDirectories(
                soortUitgFile,
                typeOfExport,
                configuration,
                out string fileName,
                out string fullFileName);
            var invoiceExportFileModel = InvoiceFactory <BigInvoice> .CreateInvoiceExportFileModel(listOutgInv, fileName);

            // Onderstaande is vervangen door een extension method op klasse InvoiceExportFileModel<T>.
            // Serializing.SerializeToFile<BigInvoice>(fullFileNameBig, invoiceBigExportFileModel);
            invoiceExportFileModel.SerializeToInvoiceFile <BigInvoice>(fullFileName, typeOfExport);
        }
예제 #6
0
        //-------------------------------------------------

        public void CreateOutgInvoiceFile(SoortUitgFactuur soortUitgFactuur, TypeOfExport typeOfExport)
        {
            Console.WriteLine("Retrieving all NotSend Invoices from database ---");
            var listInv = _invoiceRepository.GetAllNotSend(); // Dankzij include in repos hebben we ook client en country

            switch (soortUitgFactuur)
            {
            case SoortUitgFactuur.Big:
                BigInvoiceHandler.CreateOutgInvoices(listInv, soortUitgFactuur, typeOfExport, _configuration);
                break;

            case SoortUitgFactuur.Small:
                SmallInvoiceHandler.CreateOutgInvoices(listInv, soortUitgFactuur, typeOfExport, _configuration);
                break;

            default:
                break;
            }
        }
        internal static void SerializeToClientFile <T>(this KlantExportFileModel <T> klantExportFileModel,
                                                       string fullFileName, TypeOfExport typeOfExport)
            where T : BaseClient, IAuditFields
        {
            switch (typeOfExport)
            {
            case TypeOfExport.XML:
                ProcessExportFileModel <KlantExportFileModel <T> >(klantExportFileModel, fullFileName, typeOfExport);
                break;

            case TypeOfExport.JSON:
                ProcessExportFileModel(klantExportFileModel, fullFileName, typeOfExport);     // deze syntax kan ook
                break;

            case TypeOfExport.CSV:
                var listClientsExport = klantExportFileModel.KlantLijst;
                ProcessListOfItemsToCSV(listClientsExport, fullFileName);
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
예제 #8
0
        /// <summary>
        /// Maak files en directories
        /// </summary>
        /// <param name="soortUitgFactuur"></param>
        /// <param name="configuration"></param>
        /// <param name="fileName"></param>
        /// <param name="fullFileName"></param>
        public static void CreateFileNamesAndDirectories
            (KindOutgoingFile soortUitgFile,
            TypeOfExport typeOfExport,
            IConfiguration configuration,
            out string fileName,
            out string fullFileName)
        {
            // Haal settings uit appsettings.json, de opvolger van web.config

            var mainFolderExport = configuration.GetSection("AppSettings")["MainFolderExport"];

            string fileNamePrefix;
            string subFolderExport;

            switch (soortUitgFile)
            {
            case KindOutgoingFile.BigInvoice:
                subFolderExport = configuration.GetSection("AppSettings")["SubFolderInvoices"];
                fileNamePrefix  = configuration.GetSection("AppSettings")["PrefixBigInvoiceFile"];
                break;

            case KindOutgoingFile.SmallInvoice:
                subFolderExport = configuration.GetSection("AppSettings")["SubFolderInvoices"];
                fileNamePrefix  = configuration.GetSection("AppSettings")["PrefixSmallInvoiceFile"];
                break;

            case KindOutgoingFile.BigClient:
                subFolderExport = configuration.GetSection("AppSettings")["SubFolderClients"];
                fileNamePrefix  = configuration.GetSection("AppSettings")["PrefixBigClientFile"];
                break;

            case KindOutgoingFile.SmallClient:
                subFolderExport = configuration.GetSection("AppSettings")["SubFolderClients"];
                fileNamePrefix  = configuration.GetSection("AppSettings")["PrefixSmallClientFile"];
                break;

            case KindOutgoingFile.CriminalClient:
                subFolderExport = configuration.GetSection("AppSettings")["SubFolderClients"];
                fileNamePrefix  = configuration.GetSection("AppSettings")["PrefixCriminalClientFile"];
                break;

            case KindOutgoingFile.ManyConsultsClient:
                subFolderExport = configuration.GetSection("AppSettings")["SubFolderClients"];
                fileNamePrefix  = configuration.GetSection("AppSettings")["PrefixManyConsultsClientFile"];
                break;

            default:
                throw new Exception();
            }

            string extension;

            switch (typeOfExport)
            {
            case TypeOfExport.XML:
                extension = ".xml";
                break;

            case TypeOfExport.JSON:
                extension = ".json";
                break;

            case TypeOfExport.CSV:
                extension = ".csv";
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            fileName = fileNamePrefix + " " + DateTime.Now.ToString("yyyyMMdd-HHmmss") + extension;  // (XXX)

            // Combine zorgt ervoor dat er geen verwarring ontstaat
            // bij het verbinden van folder-paden (soms zijn er wel of geen extra slashes aanwezig)

            var pathString = Path.Combine(mainFolderExport, subFolderExport);

            fullFileName = Path.Combine(pathString, fileName);
            if (!Directory.Exists(pathString))
            {
                Directory.CreateDirectory(pathString);
                Console.WriteLine($"Dir \"{pathString}\" created");
            }
            else
            {
                Console.WriteLine($"Directory \"{pathString}\" already exists");
            }
        }
        private static void ProcessExportFileModel <U>(U exportFileModel, string fullFileName, TypeOfExport typeOfExport)
        {
            StreamWriter file;
            string       jsonString;

            switch (typeOfExport)
            {
            case TypeOfExport.XML:
                using (file = new StreamWriter(fullFileName))
                {
                    var xmlWriter = new XmlSerializer(exportFileModel.GetType());
                    xmlWriter.Serialize(file, exportFileModel);
                }
                break;

            case TypeOfExport.JSON:
                using (file = new StreamWriter(fullFileName))
                {
                    jsonString = JsonSerializer.Serialize(exportFileModel);
                    file.WriteLine(jsonString);
                }
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
        // Extension Method koppelen aan Generic class InvoiceExportFileModel<T>:
        // Zo blijft InvoiceExportFileModel<T> alleen maar properties bevatten (en krijgt dit model geen methods)

        // Best practice: Gebruik bij een generic bijna altijd een Where, en maak T zo specifiek mogelijk
        // Daarmee voorkomt je dat deze generic misbruikt wordt voor andere classes dan Invoices.
        internal static void SerializeToInvoiceFile <T>(this FactuurExportFileModel <T> invoiceExportFileModel, string fullFileName, TypeOfExport typeOfExport)
            where T : BaseInvoice, IAuditFields
        {
            // Beide syntaxen hieronder zijn OK:
            // ProcessExportFileModel<FactuurExportFileModel<T>>(invoiceExportFileModel, fullFileName, typeOfExport);

            switch (typeOfExport)
            {
            case TypeOfExport.XML:
                ProcessExportFileModel <FactuurExportFileModel <T> >(invoiceExportFileModel, fullFileName, typeOfExport);
                break;

            case TypeOfExport.JSON:
                ProcessExportFileModel(invoiceExportFileModel, fullFileName, typeOfExport);     // deze syntax kan ook
                break;

            case TypeOfExport.CSV:
                var listInvoicesExport = invoiceExportFileModel.FactuurLijst;
                ProcessListOfItemsToCSV(listInvoicesExport, fullFileName);
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
예제 #11
0
 public ExportCustomsFluent TypeOfExport(TypeOfExport typeOfExport)
 {
     _model.TypeOfExport = typeOfExport;
     return(this);
 }