public StringCollection controlDataFormat(String dataFile)
 {
     CsvArchiveDocuments ad = new CsvArchiveDocuments();
     if (traceActions)
         ad.setTracesWriter(tracesWriter);
     return ad.checkFile(dataFile);
 }
        public StringCollection controlDataFormat(String dataFile)
        {
            CsvArchiveDocuments ad = new CsvArchiveDocuments();

            if (traceActions)
            {
                ad.setTracesWriter(tracesWriter);
            }
            return(ad.checkFile(dataFile));
        }
        public void H04_TestContenuFichierDonnees()
        {
            String[] tagsListeClesAttendus =
                {
                "#Comment",
                "#TransferName",
                "#CustodialHistory",
                "#OriginatingAgency.BusinessType",
                "#OriginatingAgency.Description",
                "#OriginatingAgency.LegalClassification",
                "#OriginatingAgency.Name",
                "#OriginatingAgency.Identification",
                "#KeywordContent[#1]",
                "#KeywordContent[#2]",
                "#ContainsName[ENRSON[#1]]",
                "#ContainsDescription[ENRSON[#1]]",
                "#KeywordContent[ENRSON[#1]]",
                "#ContainsName[ENRSON[#1]//SAMPLES[#1]]",
                "#ContainsDescription[ENRSON[#1]//SAMPLES[#1]]",
                "#KeywordContent[ENRSON[#1]//SAMPLES[#1]]",
                "#ContainsName[ENRSON[#1]//SAMPLES[#1]//DESCRIPTION]",
                "#ContainsDescription[ENRSON[#1]//SAMPLES[#1]//DESCRIPTION]",
                "#KeywordContent[ENRSON[#1]//SAMPLES[#1]//DESCRIPTION]",
                "#ContainsName[ENRSON[#1]//SAMPLES[#1]//ANNEXE]",
                "#ContainsDescription[ENRSON[#1]//SAMPLES[#1]//ANNEXE]",
                "#KeywordContent[ENRSON[#1]//SAMPLES[#1]//ANNEXE]",
                };
            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();
        }
        public StringCollection controlMatchingBetweenDataAndProfile(String dataFile, String profileFile)
        {
            StringCollection errors = new StringCollection();
            CsvArchiveDocuments ad = new CsvArchiveDocuments();
            if (traceActions)
                ad.setTracesWriter(tracesWriter);
            ad.loadFile(dataFile);
            /*
            StringCollection erreursDonnees = ad.getErrorsList();
            if (erreursDonnees.Count != 0) {
                foreach (String st in erreursDonnees) {
                    errors.Add(st);
                }
            }
            */
            RngProfileController rpc = new RngProfileController();
            if (traceActions)
                rpc.setTracesWriter(tracesWriter);
            rpc.controlProfileFile(profileFile);
            /*
            StringCollection erreursProfil = rpc.getErrorsList();
            if (erreursProfil.Count != 0) {
                foreach (String st in erreursProfil) {
                    errors.Add(st);
                }
            }
            */
            String str;
            StringCollection tagsForKeys = ad.getTagsListForKeys();
            StringCollection tagsForDocs = ad.getTagsListForDocuments();
            StringCollection expectedTags = rpc.getExpectedTagsListList();

            StringCollection expectedTagsForDocs = new StringCollection();
            foreach (String st in expectedTags) {
                if (st.StartsWith("document: ")) {
                    expectedTagsForDocs.Add(st.Substring(10));
                }
            }
            foreach (String st in expectedTagsForDocs) {
                expectedTags.Remove("document: " + st);
            }

            StringCollection tagsForKeysModified = new StringCollection();
            foreach (String st in tagsForKeys) {
                str = Regex.Replace(st, @"#KeywordContent\[#[0-9]+\]", "#KeywordContent");
                tagsForKeysModified.Add(str);
            }

            StringCollection tagsForDocsModified = new StringCollection();
            foreach (String st in tagsForDocs) {
                str = Regex.Replace(st, @"#KeywordContent(\[[^]]+\])?\[#[0-9]+\]", "#KeywordContent$1");
                tagsForDocsModified.Add(str);
            }

            if (traceActions) {
                if (tagsForKeysModified.Count != 0) {
                    tracesWriter.WriteLine("\ntagsForKeysModified");
                    foreach (String st in tagsForKeysModified) {
                        tracesWriter.WriteLine(st);
                    }
                }
                if (tagsForDocsModified.Count != 0) {
                    tracesWriter.WriteLine("\ntagsForDocsModified");
                    foreach (String st in tagsForDocsModified) {
                        tracesWriter.WriteLine(st);
                    }
                }
                if (expectedTags.Count != 0) {
                    tracesWriter.WriteLine("\nexpectedTags");
                    foreach (String st in expectedTags) {
                        tracesWriter.WriteLine(st);
                    }
                }
                if (expectedTagsForDocs.Count != 0) {
                    tracesWriter.WriteLine("\nexpectedTagsForDocs");
                    foreach (String st in expectedTagsForDocs) {
                        tracesWriter.WriteLine(st);
                    }
                }
                tracesWriter.WriteLine("");
            }

            // Test des clés
            foreach (String st in tagsForKeysModified) {
                str = Regex.Replace(st, @"\[#\d+\]", "[#1]");
                str = Regex.Replace(str, @"#KeywordContent\[#[0-9]+\]", "#KeywordContent");
                if (expectedTags.IndexOf(str) == -1)
                    errors.Add("La clé '" + st + "' fournie par les données métier n'est pas attendue par le profil");
            }

            // Test des documents
            foreach (String st in tagsForDocsModified) {
                str = Regex.Replace(st, @"\[#\d+\]", "[#1]");
                str = Regex.Replace(str, @"#KeywordContent(\[[^]]+\])?\[#[0-9]+\]", "#KeywordContent$1");
                if (expectedTagsForDocs.IndexOf(str) == -1)
                    errors.Add("Le document typé par le tag '" + st + "' n'est pas attendu par le profil");
            }

            // Test du profil
            foreach (String st in expectedTags) {
                if (tagsForKeysModified.IndexOf(st) == -1) {
                    errors.Add("Dans le profil, le tag '" + st + "' ne trouve pas de correspondance dans les données métier");
                }
            }
            foreach (String st in expectedTagsForDocs) {
                if (tagsForDocsModified.IndexOf(st) == -1) {
                    errors.Add("Dans le profil, le tag de document '" + st + "' ne trouve pas de correspondance dans les données métier");
                }
            }
            return errors;
        }
 /*
  * La liste des documents à archiver est définie dans un fichier qui contient
  * les noms des fichiers et leurs métadonnées
  * Les documents sont dans le répertoire documentsFilePath
  * */
 public override void prepareArchiveDocumentsWithFile(String documentsFilePath, String archiveDocumentsFile)
 {
     SAE_FilePath = documentsFilePath;
     archiveDocumentsLoaded = false;
     CsvArchiveDocuments ad = new CsvArchiveDocuments();
     ad.setTracesWriter(tracesWriter);
     try {
         ad.loadFile(archiveDocumentsFile);
         // La variable membre héritée contient la valeur de l'objet créé
         archiveDocuments = ad;
         archiveDocumentsLoaded = true;
     } catch (Exception e) {
         errorsList.Add("Erreur lors de la préparation du fichiers de documents '" + archiveDocumentsFile + "' " + e.GetType().Name);
     }
 }
        public StringCollection controlMatchingBetweenDataAndProfile(String dataFile, String profileFile)
        {
            StringCollection    errors = new StringCollection();
            CsvArchiveDocuments ad     = new CsvArchiveDocuments();

            if (traceActions)
            {
                ad.setTracesWriter(tracesWriter);
            }
            ad.loadFile(dataFile);

            /*
             * StringCollection erreursDonnees = ad.getErrorsList();
             * if (erreursDonnees.Count != 0) {
             *  foreach (String st in erreursDonnees) {
             *      errors.Add(st);
             *  }
             * }
             */
            RngProfileController rpc = new RngProfileController();

            if (traceActions)
            {
                rpc.setTracesWriter(tracesWriter);
            }
            rpc.controlProfileFile(profileFile);

            /*
             * StringCollection erreursProfil = rpc.getErrorsList();
             * if (erreursProfil.Count != 0) {
             *  foreach (String st in erreursProfil) {
             *      errors.Add(st);
             *  }
             * }
             */
            String           str;
            StringCollection tagsForKeys  = ad.getTagsListForKeys();
            StringCollection tagsForDocs  = ad.getTagsListForDocuments();
            StringCollection expectedTags = rpc.getExpectedTagsList();

            StringCollection expectedTagsForDocs = new StringCollection();

            foreach (String st in expectedTags)
            {
                if (st.StartsWith("document: "))
                {
                    expectedTagsForDocs.Add(st.Substring(10));
                }
            }
            foreach (String st in expectedTagsForDocs)
            {
                expectedTags.Remove("document: " + st);
            }

            StringCollection tagsForKeysModified = new StringCollection();

            foreach (String st in tagsForKeys)
            {
                str = Regex.Replace(st, @"#KeywordContent\[#[0-9]+\]", "#KeywordContent");
                tagsForKeysModified.Add(str);
            }

            StringCollection tagsForDocsModified = new StringCollection();

            foreach (String st in tagsForDocs)
            {
                str = Regex.Replace(st, @"#KeywordContent(\[[^]]+\])?\[#[0-9]+\]", "#KeywordContent$1");
                tagsForDocsModified.Add(str);
            }

            if (traceActions)
            {
                if (tagsForKeysModified.Count != 0)
                {
                    tracesWriter.WriteLine("\ntagsForKeysModified");
                    foreach (String st in tagsForKeysModified)
                    {
                        tracesWriter.WriteLine(st);
                    }
                }
                if (tagsForDocsModified.Count != 0)
                {
                    tracesWriter.WriteLine("\ntagsForDocsModified");
                    foreach (String st in tagsForDocsModified)
                    {
                        tracesWriter.WriteLine(st);
                    }
                }
                if (expectedTags.Count != 0)
                {
                    tracesWriter.WriteLine("\nexpectedTags");
                    foreach (String st in expectedTags)
                    {
                        tracesWriter.WriteLine(st);
                    }
                }
                if (expectedTagsForDocs.Count != 0)
                {
                    tracesWriter.WriteLine("\nexpectedTagsForDocs");
                    foreach (String st in expectedTagsForDocs)
                    {
                        tracesWriter.WriteLine(st);
                    }
                }
                tracesWriter.WriteLine("");
            }


            // Test des clés
            foreach (String st in tagsForKeysModified)
            {
                str = Regex.Replace(st, @"\[#\d+\]", "[#1]");
                str = Regex.Replace(str, @"#KeywordContent\[#[0-9]+\]", "#KeywordContent");
                if (expectedTags.IndexOf(str) == -1)
                {
                    errors.Add("La clé '" + st + "' fournie par les données métier n'est pas attendue par le profil");
                }
            }

            // Test des documents
            foreach (String st in tagsForDocsModified)
            {
                str = Regex.Replace(st, @"\[#\d+\]", "[#1]");
                str = Regex.Replace(str, @"#KeywordContent(\[[^]]+\])?\[#[0-9]+\]", "#KeywordContent$1");
                if (expectedTagsForDocs.IndexOf(str) == -1)
                {
                    errors.Add("Le document typé par le tag '" + st + "' n'est pas attendu par le profil");
                }
            }

            // Test du profil
            foreach (String st in expectedTags)
            {
                if (tagsForKeysModified.IndexOf(st) == -1)
                {
                    errors.Add("Dans le profil, le tag '" + st + "' ne trouve pas de correspondance dans les données métier");
                }
            }
            foreach (String st in expectedTagsForDocs)
            {
                if (tagsForDocsModified.IndexOf(st) == -1)
                {
                    errors.Add("Dans le profil, le tag de document '" + st + "' ne trouve pas de correspondance dans les données métier");
                }
            }
            return(errors);
        }