public static JObject ToJsonObject(FHXObject o) { dynamic j = new JObject(); j.Type = o.Type; if (o.Parameters.Count > 0) { JArray a = new JArray(); foreach (FHXParameter p in o.Parameters) { a.Add(ToJsonParameter(p)); } j.Parameters = a; } if (o.Children.Count > 0) { JArray a = new JArray(); foreach (FHXObject c in o.Children) { a.Add(ToJsonObject(c)); } j.Children = a; } return(j); }
public static FHXObject ParseTokens(List <Token> tokens) { Parser p = new TokenListParser(tokens); FHXObject o = p.ParseAll(); return(o); }
public void Load(string file) { var thread = new Thread( () => { FHXObject root = FHXParserWrapper.FromFile(file); FHXParserWrapper.BuildDeltaVHierarchy(root); RootLoaded(root); }); thread.Start(); var thread2 = new Thread( () => { pbPercent.Maximum = 100; pbPercent.Minimum = 0; while (this.IsActive) { pbPercent.Value = FHXParserWrapper.State == "Parsing" ? FHXParserWrapper.ParsingPercent : FHXParserWrapper.BuildingPercent; labelPercent.Content = FHXParserWrapper.ParsingPercent.ToString() + "%"; labelState.Content = FHXParserWrapper.State; Thread.Sleep(100); } }); thread2.Start(); }
FHXObject NewObject(string type) { FHXObject o = new FHXObject(); o.Type = type; return(o); }
private void tvMain_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { TreeViewItem i = (TreeViewItem)e.NewValue; Selected = (FHXObject)i.Tag; this.labelBottom.Content = Selected.Path; this.gridParam.ItemsSource = Selected.Parameters; this.gridParam.Columns[2].Visibility = Visibility.Hidden; //Hides the Parent field }
public static void ToXML(FHXObject root, string file) { XmlDocument xmlDoc = new XmlDocument(); XmlNode rootNode = xmlDoc.CreateElement("root"); xmlDoc.AppendChild(rootNode); ToXML(root, rootNode, xmlDoc); xmlDoc.Save(file); }
private void ChargerFichierXML(string file) { var t = new Thread(() => { this.Root = FHXXMLConverter.FromXML(file); //FHXParserWrapper.BuildDeltaVHierarchy(this.Root); this.tvMain.Dispatcher.BeginInvoke(new Action(delegate { this.tvMain.Items.Add(this.Root.ToTreeViewItem(true, false)); })); }); t.Start(); }
public static FHXObject FromJson(string file) { Stopwatch sw = new Stopwatch(); sw.Start(); dynamic oJson = JsonConvert.DeserializeObject(File.ReadAllText(file)); FHXObject o = FromJsonObject(oJson); sw.Stop(); Console.WriteLine("Loaded {0} in {1}ms", file, sw.ElapsedMilliseconds); return(o); }
public static FHXObject FromXML(string file) { Stopwatch sw = new Stopwatch(); sw.Start(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(file); XmlNode root = xmlDoc.FirstChild; FHXObject o = FromXMLObject(root.FirstChild); sw.Stop(); Console.WriteLine("Loaded {0} in {1}ms", file, sw.ElapsedMilliseconds); return(o); }
public static void ToXML(FHXObject o, XmlNode parentNode, XmlDocument doc) { XmlNode oNode = doc.CreateElement("object"); parentNode.AppendChild(oNode); XmlAttribute attr = doc.CreateAttribute("TYPE"); attr.Value = o.Type; oNode.Attributes.Append(attr); if (o.Parameters.Count > 0) { foreach (FHXParameter p in o.Parameters.Where((i) => i.Mandatory)) { XmlAttribute a = doc.CreateAttribute(p.Name); a.Value = p.Value; oNode.Attributes.Append(a); } if (o.Parameters.Where((i) => i.Mandatory == false).ToList().Count > 0) { XmlNode cNode = doc.CreateElement("parameters"); oNode.AppendChild(cNode); foreach (FHXParameter p in o.Parameters.Where((i) => i.Mandatory == false)) { XmlAttribute a = doc.CreateAttribute(p.Name); a.Value = p.Value; cNode.Attributes.Append(a); } } } if (o.Children.Count > 0) { XmlNode cNode = doc.CreateElement("children"); oNode.AppendChild(cNode); foreach (FHXObject c in o.Children) { ToXML(c, cNode, doc); } } }
public static void SearchAffectations() { string[] affectations = File.ReadAllLines(@"D:\FHX\Affectations.txt"); FHXObject Root = FHXXMLConverter.FromXML(@"D:\FHX\Base LLIC3 19-08-14.xml"); var res = FHXAffectationChecker.CheckAffectations(affectations, Root); Console.WriteLine("{0} / {1}", affectations.Length, res.Keys.Count); foreach (var r in res.Keys) { if (res.Keys.Contains(r)) { if (res[r].Count == 0) { Console.WriteLine(r); } } } }
private void TreeViewItem_Expanded(object sender, RoutedEventArgs e) { TreeViewItem tvi = e.OriginalSource as TreeViewItem; if (tvi != null) { foreach (TreeViewItem tvic in tvi.Items) { if (tvic.Items.Count == 0) { FHXObject o = (FHXObject)tvic.Tag; foreach (FHXObject child in o.Children) { tvic.Items.Add(child.ToTreeViewItem(true, false)); } } } } }
public static FHXObject FromXMLObject(XmlNode node) { FHXObject o = new FHXObject(); foreach (XmlAttribute a in node.Attributes) { if (a.Name == "TYPE") { o.Type = a.Value; } else { o.AddParameter(new FHXParameter(a.Name, a.Value, true)); } } foreach (XmlNode c in node.ChildNodes) { if (c.Name == "parameters") { foreach (XmlAttribute a in c.Attributes) { o.AddParameter(new FHXParameter(a.Name, a.Value, false)); } } else if (c.Name == "children") { foreach (XmlNode cc in c.ChildNodes) { o.AddChild(FromXMLObject(cc)); } } else { Console.WriteLine("Unknown tag : {0}", c.Name); } } return(o); }
private void ConvertJson(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "FHX file (*.fhx)|*.fhx"; if (openFileDialog.ShowDialog() == true) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "JSON file (*.json)|*.json"; if (saveFileDialog.ShowDialog() == true) { var t = new Thread(() => { FHXObject o = FHXParserWrapper.FromFile(openFileDialog.FileName); FHXParserWrapper.BuildDeltaVHierarchy(o); FHXJsonConverter.ToJson(o, saveFileDialog.FileName); MessageBox.Show("Fichier converti"); }); t.Start(); } } }
public static void TestNodes() { //Load File string file = @"D:\FHX\SITE_COMMUNS.fhx"; FHXObject Root = FHXParserWrapper.FromFile(file); FHXParserWrapper.BuildDeltaVHierarchy(Root); //Test Areas FHXStructureHandler h = new FHXStructureHandler(Root); FHXNode r = new FHXNode("Root"); foreach (FHXNode n in h.Areas) { r.Children.Add(n); foreach (FHXNode m in h.ModulesArea(n.Label)) { n.Children.Add(m); } } Console.WriteLine(r.Label); }
public static void TestTokensFile(string input) { Stopwatch sw = new Stopwatch(); sw.Start(); string s = File.ReadAllText(input); sw.Stop(); Console.WriteLine("Reading file took {0} ms", sw.ElapsedMilliseconds); sw.Restart(); List <Token> tokens = TestTokens(s); sw.Stop(); Console.WriteLine("Tokenizing file took {0} ms", sw.ElapsedMilliseconds); TestTokenHierarchy(tokens); sw.Restart(); FHXObject root = ParseTokens(tokens); sw.Stop(); Console.WriteLine("Parsing file took {0} ms", sw.ElapsedMilliseconds); }
public static FHXObject FromJsonObject(dynamic j) { FHXObject o = new FHXObject(); o.Type = j.Type; if (j.Parameters != null) { foreach (dynamic p in j.Parameters) { o.Parameters.Add(FromJsonParameter(p)); } } if (j.Children != null) { foreach (dynamic c in j.Children) { o.Children.Add(FromJsonObject(c)); } } return(o); }
private void RootLoaded(FHXObject root) { this.Root = root; this.Hide(); }
public static void ToJson(FHXObject root, string file) { File.WriteAllText(file, ToJsonObject(root).ToString(Formatting.None)); }
public SearchWindow(FHXObject root) { InitializeComponent(); this.root = root; }
public ExtractorWindow(FHXObject root) { this.root = root; InitializeComponent(); }
public FHXObject ParseAll() { List <FHXObject> objects = new List <FHXObject>(); List <FHXParameter> parameters = new List <FHXParameter>(); FHXObject root = new FHXObject("ROOT", "Project"); objects.Add(root); bool waitingForBody = false; //Flag to see if we started an item and are looking for a bracketed body FHXObject currentObject = root; while (!EOF()) { Token t = Peek(); if (t.Type == TokenType.COMMENT_START) { while (t.Type != TokenType.COMMENT_END) { t = Next(); } t = Next(); // Skip last comment token } else if (t.Type == TokenType.WHITESPACE) { //Skips whitespaces Next(); } else if (t.Type == TokenType.OPEN_BRACKET) { if (waitingForBody) { waitingForBody = false; } else { Console.WriteLine("Brackets without an item identifier"); } Next(); } else if (t.Type == TokenType.CLOSE_BRACKET) { currentObject = currentObject.Parent; Next(); } else if (t.Type == TokenType.TEXT) { string s = Next().Value; if (Peek().Type == TokenType.WHITESPACE) { if (IsHex(s) && s.Length == 2) { //Cas où on a { 00 01 02 ... XX } if (currentObject.HasParameter("VALUE")) { FHXParameter p = currentObject.GetParameter("VALUE"); p.Value = p.Value + " " + s; } else { FHXParameter p = new FHXParameter("VALUE", s); currentObject.AddParameter(p); parameters.Add(p); } } else { //New object FHXObject o = NewObject(s); currentObject.AddChild(o); currentObject = o; objects.Add(o); waitingForBody = true; } } else if (Peek().Type == TokenType.EQUAL) { Next(); //Skips the equal sign if (Peek().Type == TokenType.WHITESPACE) { Next(); FHXObject o = new FHXObject(); o.mName = s; currentObject.AddChild(o); currentObject = o; objects.Add(o); waitingForBody = true; } else { string value = Next().Value; //Retieves the parameter's value FHXParameter p = new FHXParameter(s, value, waitingForBody); currentObject.AddParameter(p); parameters.Add(p); } } else { //Unexpected token Console.WriteLine("Unexpected token while parsing TEXT : {0}", Peek().GetTypeString()); } } else { Console.WriteLine("Unhandled token : {0}", Peek().GetTypeString()); Next(); } } return(root); }
public ReferenceWindow(FHXObject root) { this.Root = root; InitializeComponent(); this.Run(); }
private void Compare(object sender, RoutedEventArgs e) { string n1 = ""; string n2 = ""; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Title = Properties.Resources.OpenFirstFile; if (openFileDialog1.ShowDialog() == true) { n1 = openFileDialog1.FileName; } OpenFileDialog openFileDialog2 = new OpenFileDialog(); openFileDialog2.Title = Properties.Resources.OpenSecondFile; if (openFileDialog2.ShowDialog() == true) { n2 = openFileDialog2.FileName; } if (n1 == "" || n2 == "") { return; } FHXObject a = FHXParserWrapper.FromFile(n1); //a = a.Children.Single(i => i.Type == "MODULE"); FHXObject b = FHXParserWrapper.FromFile(n2); //b = b.Children.Single(i => i.Type == "MODULE"); if (a == null || b == null) { MessageBox.Show(Properties.Resources.ErrorLoading); return; } double coef = 37.0 / 11940138.0; double sec = coef * (double)(a.GetAllParameters().Count *b.GetAllParameters().Count); string unit = "s"; if (sec > 60.0) { sec = sec / 60.0; unit = "m"; } else if (sec > 3600.0) { sec = sec / 3600.0; unit = "h"; } string sMessageBoxText = string.Format("La procédure prendra environ {0}{1}. Continuer ?", sec, unit); string sCaption = "Valider la comparaison"; MessageBoxButton btnMessageBox = MessageBoxButton.YesNoCancel; MessageBoxImage icnMessageBox = MessageBoxImage.Warning; MessageBoxResult rsltMessageBox = MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox); switch (rsltMessageBox) { case MessageBoxResult.Yes: results = FHXComparator.CompareObjects(a, b); this.gridResults.ItemsSource = results.Results; this.gridResults.Columns[1].Visibility = Visibility.Hidden; break; case MessageBoxResult.No: return; case MessageBoxResult.Cancel: return; } }
public AffectationWindow(FHXObject root) { InitializeComponent(); this.root = root; }