Пример #1
0
        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);
        }
Пример #2
0
        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();
        }
Пример #4
0
        FHXObject NewObject(string type)
        {
            FHXObject o = new FHXObject();

            o.Type = type;
            return(o);
        }
Пример #5
0
        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
        }
Пример #6
0
        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);
        }
Пример #7
0
        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();
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
                }
            }
        }
Пример #11
0
        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);
                    }
                }
            }
        }
Пример #12
0
        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));
                        }
                    }
                }
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        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();
                }
            }
        }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
Пример #17
0
        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();
 }
Пример #19
0
 public static void ToJson(FHXObject root, string file)
 {
     File.WriteAllText(file, ToJsonObject(root).ToString(Formatting.None));
 }
Пример #20
0
 public SearchWindow(FHXObject root)
 {
     InitializeComponent();
     this.root = root;
 }
Пример #21
0
 public ExtractorWindow(FHXObject root)
 {
     this.root = root;
     InitializeComponent();
 }
Пример #22
0
        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);
        }
Пример #23
0
 public ReferenceWindow(FHXObject root)
 {
     this.Root = root;
     InitializeComponent();
     this.Run();
 }
Пример #24
0
        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;
            }
        }
Пример #25
0
 public AffectationWindow(FHXObject root)
 {
     InitializeComponent();
     this.root = root;
 }