コード例 #1
0
        // retourne des erreurs s'il s'en produit
        // sinon retourne une chaîne vide
        public string checkProfileFile(String filename)
        {
            StreamWriter streamWriter = null;
            DateTime date = DateTime.Now;
            String stdate = date.ToString();
            String traceFile = "D:/DEV_PPE/traces/trace-control-WS-" +  DateTime.Now.ToString() + ".txt";

            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);

            streamWriter.WriteLine("Appel de rpc.controlProfileFile(filename)");

            rpc.controlProfileFile(filename);

            StringCollection errors = rpc.getErrorsList();
            StringBuilder Response = new StringBuilder();

            if (errors != null && errors.Count != 0) {
                Console.WriteLine("Il y a eu des erreurs.");
                foreach (String str in errors) {
                    Console.WriteLine(str);
                    streamWriter.WriteLine(str);
                    Response.Append(str);
                    Response.Append("\n");
                }
            }
            Console.WriteLine("Fin de la liste des erreurs du programme de contrôle du profil");

            streamWriter.Close();

            return Response.ToString();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: PatPercot/Seda-Generator
        static int Main(string[] args)
        {
            StreamWriter streamWriter = null;

            String jobName;
            if (args.Length < 1) {
                System.Console.WriteLine("Syntaxe attendue : BusinessDataController nom-job-controle");
                System.Console.WriteLine("nom-job-controle est une section dans le fichier job.config");
                System.Console.WriteLine("Une section 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);
            }

            ProfileControlConfig control = config.getProfileConfig(jobName);
            if (control == null) {
                System.Console.WriteLine("Aucun job 'profile-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 profil du job '" + control.nomJob +  "' du profil '" + control.profileFile + "'");

            String profileFile = control.profileFile;
            String traceFile = control.traceFile;

            // String traceFile = @"D:\DEV_PPE\devel\gw-quimper\trace-control.txt";
            // String profileFile = @"D:\DEV_PPE\devel\gw-quimper\repetition_une_unite_deux_documents_schema.rng";

            //String profileFile = @"D:\DEV_PPE\tests\marches\20150619Profil_avec_doc_falcultatif_donne_avant_engagement\EMEG_PROFIL_MP_0002_schema.rng";
            //String profileFile = @"D:\DEV_PPE\tests\marches\repetition_une_unite-1-v1_0_schema.rng";

            //String profileFile = @"D:\DEV_PPE\tests\marches\repetition_une_unite-trois_documents-optionnels_schema.rng";

            //String profileFile = @"D:\DEV_PPE\tests\CGI\Test_MARCHES-V5bis\EMEG_PROFIL_MP_0002-PPE_schema.rng";

            //String profileFile = @"D:\DEV_PPE\tests\marches\repetition_une_unite_schema.rng";
            //String profileFile = @"D:\DEV_PPE\tests\marches\repetition_une_unite_avec_sous_unites_schema.rng";
            //String profileFile = @"D:\DEV_PPE\tests\marches\repetition_deux_unites_avec_sous_unites_schema.rng";

            //String profileFile = @"\\cg56.fr\dfs2\BW\DEVT\ArcEspCo\DATA\CG56_PROFIL_PES_0001_v1_schema-duplication.rng";
            //String profileFile = "D:/DEV_PPE/devel/RNG/esco-ad/SAE-INT-PROFIL-ESPACE-CO_schema.rng";
            //String profileFile = @"\\vm-devshare\d$\DEV_PPE\devel\CG56_PES-transfert-manuel\CG56_PROFIL_PES_0001_v1_schema.rng";

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

            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 arbre = rpc.getTreeList();

            if (arbre != null && arbre.Count != 0) {
                Console.WriteLine("\nArbre des unités documentaires.\n");
                Console.WriteLine("Les unités répétées sont présentées sous la forme UNITE[#1].");
                foreach (String str in arbre) {
                    Console.WriteLine(str);
                    streamWriter.WriteLine(str);
                }
            }

            StringCollection errors = rpc.getErrorsList();

            if (errors != null && errors.Count != 0) {
                Console.WriteLine("\n!!!!!!!!!!!!!!!!!!!!!!\nIl y a eu des erreurs.\n");
                foreach (String str in errors) {
                    Console.WriteLine(str);
                    streamWriter.WriteLine(str);
                }
            } else {
                Console.WriteLine("\nAucune erreur détectée\n");
            }

            streamWriter.Close();

            return errors.Count;
        }
コード例 #3
0
        void declencherAnalyseProfil(String jobName, String[] erreursAttendues, String[] tagsAttendus)
        {
            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 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();
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        void declencherTestProfil(String jobName, String[] branchesAttendues, String[] erreursAttendues)
        {
            StreamWriter streamWriter = null;
            ProfileControlConfig control = configLoader(jobName);
            String traceFile = control.traceFile;
            String profileFile = control.profileFile;

            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);
            {
                streamWriter.WriteLine("-------------------------------");
                streamWriter.WriteLine("Arbre des unités documentaires.");
                StringCollection arbre = rpc.getTreeList();
                if (arbre != null && arbre.Count != 0) {
                    foreach (String str in arbre) {
                        streamWriter.WriteLine(str);
                    }
                }
                streamWriter.WriteLine("-----------------");

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

            if (erreursAttendues != null) {
                StringCollection errors = rpc.getErrorsList();

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

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

            if (branchesAttendues != null) {
                StringCollection arbre = rpc.getTreeList();

                int branche = 0;
                if (arbre != null && arbre.Count != 0) {
                    foreach (String str in arbre) {
                        if (branchesAttendues.Length > branche)
                            Assert.AreEqual(branchesAttendues[branche], str, "Comparaison du nom des branches");
                        branche++;
                    }
                }

                Assert.AreEqual(branchesAttendues.Length, arbre.Count, "La taille des arbres diffère");
            }

            streamWriter.Close();
        }