예제 #1
0
 public L5XComparer(string baseFilePath, string compareFilePath)
 {
     BaseFilePath = baseFilePath;
     BaseFile = new L5XFile(BaseFilePath);
     CompareFilePath = compareFilePath;
     CompareFile = new L5XFile(compareFilePath);
 }
예제 #2
0
        async private void Button_Click(object sender, RoutedEventArgs e)
        {
            var f1 = new L5XFile(@"f:\users\PLRADSLI\Documents\Work\PROJECTS\ford kentucky\_SW\CT_319102.L5X");
            var f2 = new L5XFile(@"f:\users\PLRADSLI\Documents\Work\PROJECTS\ford kentucky\_SW\CT_319102_spioch.L5X");

            var compare = new L5XComparer(f1, f2);
            List<L5XPair> rungs = await Task.Run<List<L5XPair>>(() => { return compare.GetRungs(); });
            List<L5XPair> tags = await Task.Run<List<L5XPair>>(() => { return compare.GetTags(); });

            System.IO.File.WriteAllLines("runglog.txt", compare.LogRungs.ToArray());
            System.IO.File.WriteAllLines("taglog.txt", compare.LogTags.ToArray());

            await this.ShowMessageAsync("Job done!", "Rung and tags compared!");

            dupa.ItemsSource = tags;

        }
예제 #3
0
        async private void button1_Click(object sender, EventArgs e)
        {
            f1 = new L5XFile(@"f:\users\PLRADSLI\Documents\Work\PROJECTS\ford kentucky\_SW\CT_319102.L5X");
            f2 = new L5XFile(@"f:\users\PLRADSLI\Documents\Work\PROJECTS\ford kentucky\_SW\CT_319102_spioch.L5X");

            var compare = new L5XComparer(f1, f2);
            rungs = await Task.Run<List<L5XPair>>(() => { return compare.GetRungs(); });
            tags = await Task.Run<List<L5XPair>>(() => { return compare.GetTags(); });

            System.IO.File.WriteAllLines("runglog.txt", compare.LogRungs.ToArray());
            System.IO.File.WriteAllLines("taglog.txt", compare.LogTags.ToArray());

            MessageBox.Show("Done!");

            src_rungs = new BindingSource();
            src_rungs.DataSource = rungs;
            dgv_rungs.DataSource = src_rungs;

            src_tags = new BindingSource();
            src_tags.DataSource = tags;
            dgv_tags.DataSource = src_tags;

            //System.Diagnostics.Debugger.Break();
        }
예제 #4
0
 public L5XComparer(L5XFile baseFile, L5XFile compareFile)
 {
     BaseFile = baseFile;
     CompareFile = compareFile;
 }
예제 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentExceptions"></exception>
        public List<L5XPair> GetTags(L5XFile baseFile, L5XFile compareFile)
        {
            if (baseFile == null || compareFile == null)
                throw new ArgumentNullException("One or both files are not parsed!");
            //tags

            List<L5XPair> list = new List<L5XPair>();

            if (baseFile.Tags.Count != compareFile.Tags.Count)
            {
                throw new Exception("Different tag count!");
            }
            else
            {
                LogTags.Add(string.Format("tag\tbase file description\tcompare file description"));
                for (int i = 0; i < baseFile.Tags.Count; i++)
                {
                    var desc1 = baseFile.Tags[i].Element("Description");
                    var desc2 = compareFile.Tags[i].Element("Description");

                    if (desc1 != null && desc2 != null)
                    {
                        if (desc1.Value != desc2.Value)
                        {
                            //System.Diagnostics.Debugger.Break();
                            var pair = new L5XPair(baseFile.Tags[i],desc1, desc2);
                            list.Add(pair);
                            var msg = string.Format("{0}\t{1}\t{2}", baseFile.Tags[i].FirstAttribute.Value, desc1.Value.Replace('\n', ' '), desc2.Value).Replace('\n', ' ');
                            LogTags.Add(msg);
                        }
                    }
                    else if (desc1 == null && desc2 != null)
                    {
                        //System.Diagnostics.Debugger.Break();
                        baseFile.Tags[i].AddFirst(desc2);
                        var msg = string.Format("{0}\t\t{1}", baseFile.Tags[i].FirstAttribute.Value, desc2.Value.Replace('\n', ' '));
                        LogTags.Add(msg);
                    }
                    else if (desc1 != null && desc2 == null)
                    {
                        //System.Diagnostics.Debugger.Break();
                        var msg = string.Format("{0}\t{1}\t", baseFile.Tags[i].FirstAttribute.Value, desc1.Value.Replace('\n', ' '));
                        LogTags.Add(msg);
                    }
                }
            }
            return list;
        }
예제 #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentExceptions"></exception>
        public List<L5XPair> GetRungs(L5XFile baseFile, L5XFile compareFile)
        {
            if (baseFile == null || compareFile == null)
                throw new ArgumentNullException("One or both files are not parsed!");
            //rungs
            List<L5XPair> list = new List<L5XPair>();

            if (baseFile.Rungs.Count != compareFile.Rungs.Count)
            {
                throw new ArgumentException("Different rung count!");
            }
            else
            {
                LogRungs.Add(string.Format("routine\trung\tbase file comment\tcompare file comment"));
                for (int i = 0; i < baseFile.Rungs.Count; i++)
                {
                    if (baseFile.Rungs[i].Parent.Parent.FirstAttribute.Value == compareFile.Rungs[i].Parent.Parent.FirstAttribute.Value)
                    {
                        if (baseFile.Rungs[i].FirstAttribute.Value == compareFile.Rungs[i].FirstAttribute.Value)
                        {
                            if (baseFile.Rungs[i].Element("Comment") == null && compareFile.Rungs[i].Element("Comment") == null)
                                continue;
                            if (baseFile.Rungs[i].Element("Comment") != null && compareFile.Rungs[i].Element("Comment") == null)
                            {
                                //System.Diagnostics.Debugger.Break();
                                var msg = string.Format("{0}\t{1}\t{2}\t",
                                    baseFile.Rungs[i].Parent.Parent.FirstAttribute.Value,
                                    baseFile.Rungs[i].FirstAttribute.Value,
                                    baseFile.Rungs[i].Element("Comment").Value.Replace('\n', ' ')
                                    );
                                LogRungs.Add(msg);
                                continue;
                            }
                            if (baseFile.Rungs[i].Element("Comment") == null && compareFile.Rungs[i].Element("Comment") != null)
                            {
                                //System.Diagnostics.Debugger.Break();
                                baseFile.Rungs[i].AddFirst(compareFile.Rungs[i].Element("Comment"));
                                var msg = string.Format("{0}\t{1}\t\t{2}",
                                    baseFile.Rungs[i].Parent.Parent.FirstAttribute.Value,
                                    baseFile.Rungs[i].FirstAttribute.Value,
                                    compareFile.Rungs[i].Element("Comment").Value.Replace('\n', ' ')
                                    );
                                LogRungs.Add(msg);
                                continue;
                            }
                            if (baseFile.Rungs[i].Element("Comment").Value != compareFile.Rungs[i].Element("Comment").Value)
                            {
                                //System.Diagnostics.Debugger.Break();
                                var pair = new L5XPair(baseFile.Rungs[i], baseFile.Rungs[i].Element("Comment"), compareFile.Rungs[i].Element("Comment"));
                                list.Add(pair);
                                var msg = string.Format("{0}\t{1}\t{2}\t{3}",
                                    baseFile.Rungs[i].Parent.Parent.FirstAttribute.Value,
                                    baseFile.Rungs[i].FirstAttribute.Value,
                                    baseFile.Rungs[i].Element("Comment").Value.Replace('\n', ' '),
                                    compareFile.Rungs[i].Element("Comment").Value.Replace('\n', ' ')
                                    );
                                LogRungs.Add(msg);
                                continue;
                            }
                        }
                    }
                }
            }
            return list;
        }
예제 #7
0
 private void ParseL5K(string filepath)
 {
     var ext = Path.GetExtension(filepath).ToUpper();
     switch (ext)
     {
         case ".L5X":
             L5XFile f = new L5XFile(filepath);
             tags = GetTags(f);
             estop = GetEstop(f);
             networks = (from r in f.Rungs
                         select r.Value).ToList();
             break;
         case ".L5K":
             string fileinmemory = File.ReadAllText(filepath);
             tags = GetTags(fileinmemory);
             estop = GetEstop(fileinmemory);
             networks = GetNetworks(fileinmemory);
             break;
         default:
             break;
     }
     fltlist = GetFltList(networks);
     msglist = GetMsgList(networks);
     bitlist = GetBitList(networks);
     ExportToFile(Path.GetDirectoryName(filepath), Path.GetFileNameWithoutExtension(filepath), ext + ".xls");
 }
예제 #8
0
 private Dictionary<string, string> GetTags(L5XFile fileinmemory)
 {
     string name, description;
     var dict = new Dictionary<string, string>();
     foreach (var item in fileinmemory.Tags)
     {
         var desc = item.Element("Description");
         if (desc != null)
         {
             name = desc.Parent.FirstAttribute.Value;
             description = desc.Value;
             dict.Add(name, description);
         }
     }
     return dict;
 }
예제 #9
0
 private Dictionary<string, string> GetEstop(L5XFile fileinmemory)
 {
     var dict = new Dictionary<string, string>();
     var estop = fileinmemory.Datatypes.First(d => d.FirstAttribute.Value == "ud_EStop");
     var bits = estop.Descendants("Member").Where(m => m.Attribute("DataType").Value == "BIT").ToList();
     foreach (var item in bits)
     {
         var desc = item.Element("Description").Value;
         var name = item.FirstAttribute.Value;
         dict.Add(name, desc);
     }
     return dict;
 }