Example #1
0
        private void ConfrontationDonneesEtProfil(String testAExecuter, String[] erreursAttendues, Boolean bWithWarns = false)
        {
            StreamWriter      streamWriter = null;
            DataControlConfig control      = configLoader(testAExecuter);
            String            traceFile    = control.traceFile;
            String            profileFile  = control.profileFile;
            String            dataFile     = control.dataFile;

            Action <Exception, String> eh = (ex, str) => {
                Console.WriteLine(ex.GetType().Name + " while trying to use trace file: " + traceFile + ". Complementary message: " + str);
                throw ex;
            };

            try {
                streamWriter = new StreamWriter(traceFile);
            } catch (IOException e) { eh(e, "Mauvaise syntaxe de nom de fichier"); } catch (UnauthorizedAccessException e) { eh(e, "Droits d'accès à corriger"); } catch (System.Security.SecurityException e) { eh(e, "Droits d'accès à corriger"); }

            BusinessDataController bc = new BusinessDataController();

            bc.setTracesWriter(streamWriter);
            StringCollection erreurs = bc.controlMatchingBetweenDataAndProfile(dataFile, profileFile);

            foreach (String err in erreurs)
            {
                streamWriter.WriteLine(err);
            }
            streamWriter.Flush();

            int erreur = 0;

            if (erreurs != null && erreurs.Count != 0)
            {
                foreach (String str in erreurs)
                {
                    if (bWithWarns)
                    {
                        if (erreursAttendues.Length > erreur)
                        {
                            StringAssert.StartsWith(str, erreursAttendues[erreur], "Comparaison des erreurs");
                        }
                        erreur++;
                    }
                    else
                    {
                        if (str.StartsWith("(--) ") == false)
                        {
                            if (erreursAttendues.Length > erreur)
                            {
                                StringAssert.StartsWith(str, erreursAttendues[erreur], "Comparaison des erreurs");
                            }
                            erreur++;
                        }
                    }
                }
            }
            Assert.AreEqual(erreursAttendues.Length, erreur, "Le nombre d'erreurs attendues et obtenues diffère");
        }
Example #2
0
        void declencherControleDonnees(String jobName, String[] erreursAttendues)
        {
            StreamWriter      streamWriter = null;
            DataControlConfig control      = configLoader(jobName);
            String            traceFile    = control.traceFile;
            String            profileFile  = control.profileFile;
            String            dataFile     = control.dataFile;

            Action <Exception, String> eh = (ex, str) => {
                Console.WriteLine(ex.GetType().Name + " while trying to use trace file: " + traceFile + ". Complementary message: " + str);
                throw ex;
            };

            try {
                streamWriter = new StreamWriter(traceFile);
            } catch (IOException e) { eh(e, "Mauvaise syntaxe de nom de fichier"); } catch (UnauthorizedAccessException e) { eh(e, "Droits d'accès à corriger"); } catch (System.Security.SecurityException e) { eh(e, "Droits d'accès à corriger"); }

            BusinessDataController bdc = new BusinessDataController();

            bdc.setTracesWriter(streamWriter);

            StringCollection erreurs = bdc.controlDataFormat(dataFile);

            {
                streamWriter.WriteLine("-----------------");
                streamWriter.WriteLine("Liste des erreurs.");
                if (erreurs != null && erreurs.Count != 0)
                {
                    foreach (String str in erreurs)
                    {
                        streamWriter.WriteLine(str);
                    }
                }
                streamWriter.WriteLine("-----------------");
            }
            streamWriter.Flush();

            if (erreursAttendues != null)
            {
                int erreur = 0;
                if (erreurs != null && erreurs.Count != 0)
                {
                    foreach (String str in erreurs)
                    {
                        if (erreursAttendues.Length > erreur)
                        {
                            StringAssert.StartsWith(str, erreursAttendues[erreur], "Comparaison des erreurs");
                        }
                        erreur++;
                    }
                }

                Assert.AreEqual(erreursAttendues.Length, erreurs.Count, "Le nombre d'erreurs attendues et obtenues diffère");
            }

            streamWriter.Close();
        }
Example #3
0
        protected void doSection()
        {
            if (inSection)
            {
                switch (section)
                {
                case "accord-versement":
                    AccordVersementConfig paccord = new AccordVersementConfig();
                    paccord.accordVersement        = sectionName;
                    paccord.SAE_Serveur            = SAE_Serveur;
                    paccord.TransferIdPrefix       = TransferIdPrefix;
                    paccord.SAE_ProfilArchivage    = SAE_ProfilArchivage;
                    paccord.TransferringAgencyId   = TransferringAgencyId;
                    paccord.TransferringAgencyName = TransferringAgencyName;
                    paccord.TransferringAgencyDesc = TransferringAgencyDesc;
                    paccord.ArchivalAgencyId       = ArchivalAgencyId;
                    paccord.ArchivalAgencyName     = ArchivalAgencyName;
                    paccord.ArchivalAgencyDesc     = ArchivalAgencyDesc;
                    accordVersementConfigList.Add(paccord);
                    break;

                case "profile-control":
                    ProfileControlConfig pcontrol = new ProfileControlConfig();
                    pcontrol.nomJob      = sectionName;
                    pcontrol.traceFile   = traceFile;
                    pcontrol.profileFile = profileFile;
                    pcontrol.dataFile    = dataFile;
                    profilecontrolList.Add(pcontrol);
                    break;

                case "data-control":
                    DataControlConfig dcontrol = new DataControlConfig();
                    dcontrol.nomJob      = sectionName;
                    dcontrol.traceFile   = traceFile;
                    dcontrol.profileFile = profileFile;
                    dcontrol.dataFile    = dataFile;
                    datacontrolList.Add(dcontrol);
                    break;

                case "generator":
                    GeneratorConfig generator = new GeneratorConfig();
                    generator.nomJob          = sectionName;
                    generator.traceFile       = traceFile;
                    generator.accordVersement = accordVersement;
                    generator.dataFile        = dataFile;
                    generator.repDocuments    = repDocuments;
                    generator.baseURI         = baseURI;
                    generator.bordereauFile   = bordereauFile;
                    generatorList.Add(generator);
                    break;
                }
            }
        }
Example #4
0
        void declencherAnalyseProfil(String jobName, String[] erreursAttendues, String[] tagsAttendus, Boolean bWithWarns = false)
        {
            StreamWriter      streamWriter = null;
            DataControlConfig control      = configLoader(jobName);
            String            traceFile    = control.traceFile;
            String            profileFile  = control.profileFile;
            String            dataFile     = control.dataFile;

            Action <Exception, String> eh = (ex, str) => {
                Console.WriteLine(ex.GetType().Name + " while trying to use trace file: " + traceFile + ". Complementary message: " + str);
                throw ex;
            };

            try {
                streamWriter = new StreamWriter(traceFile);
            } catch (IOException e) { eh(e, "Mauvaise syntaxe de nom de fichier"); } catch (UnauthorizedAccessException e) { eh(e, "Droits d'accès à corriger"); } catch (System.Security.SecurityException e) { eh(e, "Droits d'accès à corriger"); }

            RngProfileController rpc = new RngProfileController();

            rpc.setTracesWriter(streamWriter);
            rpc.controlProfileFile(profileFile);

            StringCollection erreurs = rpc.getErrorsList();

            {
                streamWriter.WriteLine("-----------------");
                streamWriter.WriteLine("Liste des erreurs.");
                if (erreurs != null && erreurs.Count != 0)
                {
                    foreach (String str in erreurs)
                    {
                        streamWriter.WriteLine(str);
                    }
                }
                streamWriter.WriteLine("-----------------");
            }
            streamWriter.Flush();

            if (erreursAttendues != null)
            {
                /*
                 * int erreur = 0;
                 * if (erreurs != null && erreurs.Count != 0) {
                 *  foreach (String str in erreurs) {
                 *      if (erreursAttendues.Length > erreur)
                 *          StringAssert.StartsWith(str, erreursAttendues[erreur], "Comparaison des erreurs");
                 *      erreur++;
                 *  }
                 * }
                 *
                 * Assert.AreEqual(erreursAttendues.Length, erreurs.Count, "Le nombre d'erreurs attendues et obtenues diffère");
                 * */
                StringCollection errors = rpc.getErrorsList();
                int erreur = 0;
                if (errors != null && errors.Count != 0)
                {
                    foreach (String str in errors)
                    {
                        if (bWithWarns)
                        {
                            if (erreursAttendues.Length > erreur)
                            {
                                StringAssert.StartsWith(str, erreursAttendues[erreur], "Comparaison des erreurs");
                            }
                            erreur++;
                        }
                        else
                        {
                            if (str.StartsWith("(--) ") == false)
                            {
                                if (erreursAttendues.Length > erreur)
                                {
                                    StringAssert.StartsWith(str, erreursAttendues[erreur], "Comparaison des erreurs");
                                }
                                erreur++;
                            }
                        }
                    }
                }
                Assert.AreEqual(erreursAttendues.Length, erreur, "Le nombre d'erreurs attendues et obtenues diffère");
            }

            StringCollection tags = rpc.getExpectedTagsListList();

            {
                streamWriter.WriteLine("-----------------");
                streamWriter.WriteLine("Liste des tags.");
                if (tags != null && tags.Count != 0)
                {
                    foreach (String str in tags)
                    {
                        streamWriter.WriteLine(str);
                    }
                }
                streamWriter.WriteLine("-----------------");
            }
            streamWriter.Flush();

            if (erreursAttendues != null)
            {
                int tag = 0;
                if (tags != null && tags.Count != 0)
                {
                    foreach (String str in tags)
                    {
                        if (tagsAttendus.Length > tag)
                        {
                            StringAssert.StartsWith(str, tagsAttendus[tag], "Comparaison des tags");
                        }
                        tag++;
                    }
                }

                Assert.AreEqual(tagsAttendus.Length, tags.Count, "Le nombre de tags attendus et obtenus diffère");
            }


            streamWriter.Close();
        }
Example #5
0
        /*
         *
         * */
        public void H04_TestContenuFichierDonnees()
        {
            String[] tagsListeClesAttendus =
            {
                "#Comment",
                "#TransferName",
                "#CustodialHistory",
                "#ContentDescription.Description",
                "#OriginatingAgency.BusinessType",
                "#OriginatingAgency.Description",
                "#OriginatingAgency.LegalClassification",
                "#OriginatingAgency.Name",
                "#OriginatingAgency.Identification",
                "#KeywordContent[{KW_COMMUNE}]",
                "#KeywordContent[{KW_EVT}[#1]]",
                "#ContainsName[ENRSON[#1]]",
                "#CustodialHistory[ENRSON[#1]]",
                "#ContentDescription.Description[ENRSON[#1]]",
                "#KeywordContent[ENRSON[#1]{KW1}]",
                "#ContainsName[ENRSON[#1]//SAMPLES[#1]]",
                "#ContentDescription.Description[ENRSON[#1]//SAMPLES[#1]]",
                "#KeywordContent[ENRSON[#1]//SAMPLES[#1]{KW2}[#1]]",
                "#ContainsName[ENRSON[#1]//SAMPLES[#1]//DESCRIPTION]",
                "#ContentDescription.Description[ENRSON[#1]//SAMPLES[#1]//DESCRIPTION]",
                "#KeywordContent[ENRSON[#1]//SAMPLES[#1]//DESCRIPTION{KW3}]",
                "#ContainsName[ENRSON[#1]//SAMPLES[#1]//ANNEXE]",
                "#ContentDescription.Description[ENRSON[#1]//SAMPLES[#1]//ANNEXE]",
                "#KeywordContent[ENRSON[#1]//SAMPLES[#1]//ANNEXE{KW4}]",
            };
            String[] tagsListeDocumentsAttendus =
            {
                "ENRSON[#1]{PDF}",
                "ENRSON[#1]{MP3}",
                "ENRSON[#1]{WAV}",
                "ENRSON[#1]//SAMPLES[#1]",
                "ENRSON[#1]//SAMPLES[#1]//DESCRIPTION",
                "ENRSON[#1]//SAMPLES[#1]//ANNEXE",
            };

            DataControlConfig control = configLoader("tags_profil_complet_donnees");

            StreamWriter streamWriter     = null;
            Action <Exception, String> eh = (ex, str) => {
                Console.WriteLine(ex.GetType().Name + " while trying to use trace file: " + control.traceFile + ". Complementary message: " + str);
                throw ex;
            };

            try {
                streamWriter = new StreamWriter(control.traceFile);
            } catch (IOException e) { eh(e, "Mauvaise syntaxe de nom de fichier"); } catch (UnauthorizedAccessException e) { eh(e, "Droits d'accès à corriger"); } catch (System.Security.SecurityException e) { eh(e, "Droits d'accès à corriger"); }

            CsvArchiveDocuments ad = new CsvArchiveDocuments();

            ad.setTracesWriter(streamWriter);
            ad.loadFile(control.dataFile);

            StringCollection adErrors = ad.getErrorsList();

            streamWriter.WriteLine("\nErreurs dans la lecture du fichier de données");
            foreach (String str in adErrors)
            {
                streamWriter.WriteLine(str);
            }
            streamWriter.Flush();

            Assert.AreEqual(0, adErrors.Count, "Aucune erreur n'était attendue");

            StringCollection listForKeys      = ad.getTagsListForKeys();
            StringCollection listForDocuments = ad.getTagsListForDocuments();

            int key = 0;

            if (listForKeys != null && listForKeys.Count != 0)
            {
                streamWriter.WriteLine("\nListe des clés lues");
                foreach (String str in listForKeys)
                {
                    streamWriter.WriteLine(str);
                }
                streamWriter.Flush();
                foreach (String str in listForKeys)
                {
                    if (tagsListeClesAttendus.Length > key)
                    {
                        StringAssert.StartsWith(str, tagsListeClesAttendus[key], "Comparaison des tags de clés");
                    }
                    key++;
                }
            }

            Assert.AreEqual(tagsListeClesAttendus.Length, listForKeys.Count, "Le nombre de clés attendues et obtenues diffère");

            key = 0;
            if (listForDocuments != null && listForDocuments.Count != 0)
            {
                streamWriter.WriteLine("\nListe des documents lus");
                foreach (String str in listForDocuments)
                {
                    streamWriter.WriteLine(str);
                }
                streamWriter.Flush();
                foreach (String str in listForDocuments)
                {
                    if (tagsListeClesAttendus.Length > key)
                    {
                        StringAssert.StartsWith(str, tagsListeDocumentsAttendus[key], "Comparaison des tags de documents");
                    }
                    key++;
                }
            }

            Assert.AreEqual(tagsListeDocumentsAttendus.Length, listForDocuments.Count, "Le nombre de documents attendus et obtenus diffère");

            streamWriter.Flush();
            streamWriter.Close();
        }
Example #6
0
        static int Main(string[] args)
        {
            System.IO.StreamWriter streamWriter = null;

            String jobName;

            if (args.Length < 1)
            {
                System.Console.WriteLine("Syntaxe attendue : BusinessDataControllerLauncher nom-job-controle");
                System.Console.WriteLine("nom-job-controle est une section dans le fichier job.config");
                System.Console.WriteLine("Une section de contrôle de données métier a la forme :");
                System.Console.WriteLine("[data-control : nom-job-controle]");
                System.Console.WriteLine("  trace = chemin/vers/fichier-de-trace.txt");
                System.Console.WriteLine("  profil = chemin/vers/fichier-de-profil.rng");
                System.Console.WriteLine("  data = chemin/vers/fichier-de-donnees-metier.txt");
                System.Console.WriteLine("");
                System.Console.WriteLine("Aucun job demandé, le premier job sera exécuté");
                System.Console.WriteLine("");
                jobName = String.Empty;
            }
            else
            {
                jobName = args[0];
            }

            SimpleConfig config = new SimpleConfig();
            String       erreur = config.loadFile("./job.config");

            if (erreur != String.Empty) // on tient compte du fait qu'en environnement de développement, l'exe est dans bin/Release
            {
                erreur = config.loadFile("../../job.config");
            }

            if (erreur != String.Empty)
            {
                System.Console.WriteLine(erreur);
                System.Environment.Exit(-1);
            }

            DataControlConfig datacontrol = config.getDatacontrolConfig(jobName);

            if (datacontrol == null)
            {
                System.Console.WriteLine("Aucun job 'data-control: " + jobName + "' trouvé dans le fichier job.config. Vérifiez la syntaxe ou créez une tâche.");
                System.Environment.Exit(-1);
            }

            System.Console.WriteLine("Contrôle métier du job '" + datacontrol.nomJob + "' : '" + datacontrol.dataFile + "' avec le profil '" + datacontrol.profileFile + "'");

            Action <Exception, String> eh = (ex, str) => {
                Console.WriteLine(ex.GetType().Name + " while trying to use trace file: " + datacontrol.traceFile + ". Complementary message: " + str);
                System.Environment.Exit(-1);
            };

            try {
                streamWriter = new System.IO.StreamWriter(datacontrol.traceFile);
            } catch (System.IO.IOException e) { eh(e, "Mauvaise syntaxe de nom de fichier"); } catch (UnauthorizedAccessException e) { eh(e, "Droits d'accès à corriger"); } catch (System.Security.SecurityException e) { eh(e, "Droits d'accès à corriger"); }

            BusinessDataController bdc = new BusinessDataController();

            bdc.setTracesWriter(streamWriter);
            StringCollection errors = bdc.controlDataFormat(datacontrol.dataFile);

            StringCollection erreursCorrespondance =
                bdc.controlMatchingBetweenDataAndProfile(datacontrol.dataFile, datacontrol.profileFile);

            int nbErreurs = 0;

            if (errors.Count > 0)
            {
                nbErreurs += errors.Count;
            }
            if (erreursCorrespondance != null && erreursCorrespondance.Count != 0)
            {
                nbErreurs += erreursCorrespondance.Count;
            }
            if (nbErreurs > 0)
            {
                System.Console.WriteLine("\nDes erreurs ont été rencontrées\n");
            }

            if (errors.Count > 0)
            {
                System.Console.WriteLine("\nErreurs dans les données :\n");
                foreach (String str in errors)
                {
                    System.Console.WriteLine(str);
                    streamWriter.WriteLine(str);
                }
                System.Console.WriteLine("\n");
                streamWriter.WriteLine("\n");
            }

            if (erreursCorrespondance != null && erreursCorrespondance.Count != 0)
            {
                System.Console.WriteLine("\nErreurs de correspondance entre les données et le profil :\n");
                foreach (String err in erreursCorrespondance)
                {
                    Console.WriteLine(err);
                    streamWriter.WriteLine(err);
                }
                System.Console.WriteLine("\n");
                streamWriter.WriteLine("\n");
            }
            streamWriter.Flush();

            return(nbErreurs);
        }