// 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()); }
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(); }
private void declencherTestProfil(String jobName, String[] branchesAttendues, String[] erreursAttendues, Boolean bWithWarns = false) { StreamWriter streamWriter = null; 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.setDataFile(control.dataFile); rpc.controlProfileFile(profileFile); { streamWriter.WriteLine("-------------------------------"); streamWriter.WriteLine("Arbre des unités documentaires."); StringCollection arbre = rpc.getTreeList(); if (arbre != null && arbre.Count != 0) { int numBranche = 1; foreach (String str in arbre) { streamWriter.WriteLine(String.Format("{0,3:G}\t", numBranche) + str); ++numBranche; } } streamWriter.WriteLine("-----------------"); streamWriter.WriteLine("-----------------"); streamWriter.WriteLine("Liste des erreurs."); StringCollection erreurs = rpc.getErrorsList(); if (erreurs != null && erreurs.Count != 0) { int numErreur = 1; foreach (String str in erreurs) { streamWriter.WriteLine(String.Format("{0,3:G}\t", numErreur) + str); ++numErreur; } } streamWriter.WriteLine("-----------------"); } streamWriter.Flush(); 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"); 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(); }
static int Main(string[] args) { StreamWriter streamWriter = null; String jobName; if (args.Length < 1) { System.Console.WriteLine("Syntaxe attendue : RngProfileControllerLauncher 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 profil a la forme :"); System.Console.WriteLine("[profile-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(""); 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; 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.setDataFile(control.dataFile); 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 expectedTagsList = rpc.getExpectedTagsList(); if (expectedTagsList != null && expectedTagsList.Count != 0) { Console.WriteLine("\nTags attendus par le profil.\n"); foreach (String str in expectedTagsList) { 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); }
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); }