static void Main(string[] args) { string text2 = System.IO.File.ReadAllText(path_script); Console.WriteLine("Création Dictionnaire..."); Dictionary <String, List <String> > PhysicalTableList = CreateDictionnary(text2); Console.WriteLine("Fin création dictionnaire"); /*Lire fichier*/ File.Delete(path_test); if (!File.Exists(path_test)) { string text = System.IO.File.ReadAllText(path_queries); string[] queries = text.Split("________________________________________"); /*Initialisation parser*/ var parser = new TSql130Parser(false); /*Stocke les erreurs liés à la lecture du parser*/ IList <ParseError> errors; /*Iniatilisation*/ MyVisitor myvisitor = new MyVisitor(); VisitorCommonTable myVisitorCommonTable = new VisitorCommonTable(); myvisitor.PhysicalTableList = PhysicalTableList; int i = 0; foreach (String query in queries) { myVisitorCommonTable.id_requete_courante = i; var fragment = parser.Parse(new StringReader(query), out errors); fragment.Accept(myVisitorCommonTable); i = i + 1; } myvisitor.dictTableWith = myVisitorCommonTable.dict; i = 0; /*Pour chaque requête présent dans le fichier, on l'analyse*/ foreach (var query in queries) { /*Sépare chaque query et leur résultat par "______________" pour le fichier de sorti*/ myvisitor.save(query, i.ToString()); //Console.WriteLine(Environment.NewLine+"_____________________________"+query); /*Enregistre la query en cours*/ TSqlFragment fragment = parser.Parse(new StringReader(query), out errors); fragment.Accept(myvisitor); myvisitor.Add(); i++; Console.WriteLine(i); } myvisitor.Imprime(); } PreTraitement preTraitement = new PreTraitement(PhysicalTableList); preTraitement.Process(); }
static void Main(string[] args) { /*Lire fichier*/ File.Delete(@"C:\Users\wilou\source\repos\SqlShareParsing\SqlShareParsing\ressources\fichier_abstraction\test.xml"); string text = System.IO.File.ReadAllText(path); string[] queries = text.Split("________________________________________"); /*Initialisation parser*/ var parser = new TSql130Parser(false); /*Stocke les erreurs liés à la lecture du parser*/ IList <ParseError> errors; /*Iniatilisation*/ string text2 = System.IO.File.ReadAllText(@"C:\Users\wilou\source\repos\SqlShareParsing\SqlShareParsing\ressources\view_script.txt"); Dictionary <String, List <String> > PhysicalTableList = new Dictionary <String, List <String> >(); string[] views = Regex.Split(text2, "________________________________________"); String sDir = @"C:\Users\wilou\Documents\stage_workspace\sqlshare_data_release1\data"; foreach (String view in views) { Regex rx = new Regex(@"\(\[.*\]\)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rx2 = new Regex(@"\[[^\[\]\(\)]*\]\.\[[^\[\]]*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); // Find matches. String matchText = ""; String matchText2 = ""; MatchCollection matches = rx.Matches(view); MatchCollection matches2 = rx2.Matches(view); if (matches.Count > 0) { matchText = matches[0].Groups[0].Value; } if (matches2.Count > 0) { matchText2 = matches2[0].Groups[0].Value; } if (!PhysicalTableList.ContainsKey(matchText2)) { using (StreamWriter sw = File.AppendText(@"C:\Users\wilou\source\repos\SqlShareParsing\SqlShareParsing\ressources\myf.txt")) { sw.WriteLine(matchText2 + " " + matchText.Replace("(", "").Replace(")", "")); } //Console.WriteLine("le match est : " + matchText.Replace("(", "").Replace(")", "") + ", pour la vue nommée : " + matchText2); PhysicalTableList.Add(matchText2, new List <String>(matchText.Replace("(", "").Replace(")", "").Split(','))); } } try { string firstLine; foreach (string d in Directory.GetDirectories(sDir)) { foreach (string f in Directory.GetFiles(d)) { using (StreamReader reader = new StreamReader(f)) { firstLine = reader.ReadLine() ?? ""; } string[] listIdentifier = f.Split('\\'); //Avant-dernière value du chemin de dossier pour récupérer le nom d'utilisateur int pos1 = listIdentifier.Count() - 2; //dernière value .. int pos2 = listIdentifier.Count() - 1; //Console.WriteLine("[" + listIdentifier[pos1] + "].[" + listIdentifier[pos2] + "] = " + firstLine); PhysicalTableList.Add("[" + listIdentifier[pos1] + "].[" + listIdentifier[pos2] + "]", new List <String>(firstLine.Split(','))); } } } catch (System.Exception excpt) { Console.WriteLine(excpt.Message); } MyVisitor myvisitor = new MyVisitor(); VisitorCommonTable myVisitorCommonTable = new VisitorCommonTable(); myvisitor.PhysicalTableList = PhysicalTableList; int i = 0; foreach (String query in queries) { myVisitorCommonTable.id_requete_courante = i; var fragment = parser.Parse(new StringReader(query), out errors); fragment.Accept(myVisitorCommonTable); i = i + 1; } myvisitor.dictTableWith = myVisitorCommonTable.dict; i = 0; /*Pour chaque requête présent dans le fichier, on l'analyse*/ foreach (var query in queries) { /*Sépare chaque query et leur résultat par "______________" pour le fichier de sorti*/ myvisitor.save(query, i.ToString()); //Console.WriteLine(Environment.NewLine+"_____________________________"+query); /*Enregistre la query en cours*/ TSqlFragment fragment = parser.Parse(new StringReader(query), out errors); fragment.Accept(myvisitor); myvisitor.add(); i++; Console.WriteLine(i); } /*Remise à zéro du string pour les clauses présentes dans le FROM, pour éviter les doublons avec le WhereClause*/ Console.WriteLine("FIN"); Console.ReadLine(); myvisitor.Imprime(); }