Exemplo n.º 1
0
        ExtInfo Extract(XElement foundItem)
        {
            string element              = XmlStruct.element;
            string eName                = XmlStruct.eName;
            string eTypeFile            = XmlStruct.eTypeFile;
            string eRusDescription      = XmlStruct.eRusDescription;
            string eEngDescription      = XmlStruct.eEngDescription;
            string eDetailedDescription = XmlStruct.eDetailedDescription;
            string eInfoHeaderFile      = XmlStruct.eInfoHeaderFile;
            string eWhatOpenWindows     = XmlStruct.eWhatOpenWindows;
            string eWhatOpenLinux       = XmlStruct.eWhatOpenLinux;
            string eWhatOpenMac         = XmlStruct.eWhatOpenMac;

            ExtInfo extInfo = new ExtInfo()
            {
                Name                = foundItem.Attribute(eName).Value,
                TypeFile            = foundItem.Attribute(eTypeFile).Value,
                RusDescription      = foundItem.Attribute(eRusDescription).Value,
                EngDescription      = foundItem.Attribute(eEngDescription).Value,
                DetailedDescription = foundItem.Attribute(eDetailedDescription).Value
            };
            XElement xElem = foundItem.Element(eInfoHeaderFile);

            if (xElem != null)
            {
                extInfo.InfoHeaderFile = new List <string>();
                foreach (var item in xElem.Elements(element))
                {
                    extInfo.InfoHeaderFile.Add(item.Value);
                }
            }
            xElem = foundItem.Element(eWhatOpenWindows);
            if (xElem != null)
            {
                extInfo.WhatOpenWindows = new List <string>();
                foreach (var item in xElem.Elements(element))
                {
                    extInfo.WhatOpenWindows.Add(item.Value);
                }
            }
            xElem = foundItem.Element(eWhatOpenLinux);
            if (xElem != null)
            {
                extInfo.WhatOpenLinux = new List <string>();
                foreach (var item in xElem.Elements(element))
                {
                    extInfo.WhatOpenLinux.Add(item.Value);
                }
            }
            xElem = foundItem.Element(eWhatOpenMac);
            if (xElem != null)
            {
                extInfo.WhatOpenMac = new List <string>();
                foreach (var item in xElem.Elements(element))
                {
                    extInfo.WhatOpenMac.Add(item.Value);
                }
            }
            return(extInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Добавляет новый элемент в xml
        /// </summary>
        /// <param name="itemExt"></param>
        /// <param name="xmlTWriter"></param>
        void AddNewExtension(ExtInfo itemExt, XmlWriter xmlTWriter)
        {
            string element              = XmlStruct.element;
            string eName                = XmlStruct.eName;
            string eTypeFile            = XmlStruct.eTypeFile;
            string eRusDescription      = XmlStruct.eRusDescription;
            string eEngDescription      = XmlStruct.eEngDescription;
            string eDetailedDescription = XmlStruct.eDetailedDescription;
            string eInfoHeaderFile      = XmlStruct.eInfoHeaderFile;
            string eWhatOpenWindows     = XmlStruct.eWhatOpenWindows;
            string eWhatOpenLinux       = XmlStruct.eWhatOpenLinux;
            string eWhatOpenMac         = XmlStruct.eWhatOpenMac;

            xmlTWriter.WriteStartElement("ext");
            {
                xmlTWriter.WriteAttributeString(eName, itemExt.Name);
                xmlTWriter.WriteAttributeString(eTypeFile, itemExt.TypeFile);
                xmlTWriter.WriteAttributeString(eRusDescription, itemExt.RusDescription);
                xmlTWriter.WriteAttributeString(eEngDescription, itemExt.EngDescription);
                xmlTWriter.WriteAttributeString(eDetailedDescription, itemExt.DetailedDescription);

                if (itemExt.InfoHeaderFile.Count > 0)
                {
                    xmlTWriter.WriteStartElement(eInfoHeaderFile);
                    foreach (var item in itemExt.InfoHeaderFile)
                    {
                        xmlTWriter.WriteElementString(element, item);
                    }
                    xmlTWriter.WriteEndElement();
                }
                if (itemExt.WhatOpenWindows.Count > 0)
                {
                    xmlTWriter.WriteStartElement(eWhatOpenWindows);
                    foreach (var item in itemExt.WhatOpenWindows)
                    {
                        xmlTWriter.WriteElementString(element, item);
                    }
                    xmlTWriter.WriteEndElement();
                }
                if (itemExt.WhatOpenLinux.Count > 0)
                {
                    xmlTWriter.WriteStartElement(eWhatOpenLinux);
                    foreach (var item in itemExt.WhatOpenLinux)
                    {
                        xmlTWriter.WriteElementString(element, item);
                    }
                    xmlTWriter.WriteEndElement();
                }
                if (itemExt.WhatOpenMac.Count > 0)
                {
                    xmlTWriter.WriteStartElement(eWhatOpenMac);
                    foreach (var item in itemExt.WhatOpenMac)
                    {
                        xmlTWriter.WriteElementString(element, item);
                    }
                    xmlTWriter.WriteEndElement();
                }
            }
            xmlTWriter.WriteEndElement();
        }
Exemplo n.º 3
0
 protected void OnComplete(ExtInfo ext)
 {
     if (CompleteExtractEvent != null)
     {
         CompleteExtractEvent(ext);
     }
 }
Exemplo n.º 4
0
        private List <ExtInfo> BeginFillList(Dictionary <string, List <string> > AllLink)
        {
            int count = 0;

            foreach (KeyValuePair <string, List <string> > item in AllLink)
            {
                count += item.Value.Count;
            }

            OnMaxValueExtParse(count);
            BlockingCollection <ExtInfo> extListSafe = new BlockingCollection <ExtInfo>(count);
            Stopwatch sw1 = new Stopwatch();

            sw1.Start();
            ParallelLoopResult loopResult = Parallel.ForEach(AllLink, (item) =>
            {
                foreach (string link in item.Value)
                {
                    //ExtInfo ext = GetDescriptionExtension(item.Value[i]);
                    ExtInfo ext = GetDescriptionExtension(link);
                    extListSafe.Add(ext);
                    OnChangeValueExtParse();
                }
            }
                                                             );

            sw1.Stop();
            MessageBox.Show(String.Format("Параллельно выполняемый цикл: " +
                                          "{0} Seconds", sw1.Elapsed.TotalSeconds));

            return(extListSafe.ToList());
        }
Exemplo n.º 5
0
        private List <ExtInfo> FillList(Dictionary <string, List <string> > AllLink)
        {
            int count = 0;

            foreach (KeyValuePair <string, List <string> > item in AllLink)
            {
                count += item.Value.Count;
            }
            OnMaxValueExtParse(count);
            List <ExtInfo> extList = new List <ExtInfo>(count);

            System.Diagnostics.Stopwatch sw1 = new System.Diagnostics.Stopwatch();
            sw1.Start();
            foreach (KeyValuePair <string, List <string> > item in AllLink)
            {
                foreach (string link in item.Value)
                //for( int i = 0; i < 5; i++ )
                {
                    //ExtInfo ext = GetDescriptionExtension(item.Value[i]);
                    ExtInfo ext = GetDescriptionExtension(link);
                    extList.Add(ext);
                    OnChangeValueExtParse();
                }
            }
            sw1.Stop();
            MessageBox.Show(String.Format("Последовательно выполняемый цикл: " +
                                          "{0} Seconds", sw1.Elapsed.TotalSeconds));
            return(extList);
        }
Exemplo n.º 6
0
 ////////////////////////////////////////////////////////////////
 private void XmlE_CompleteExtractEvent(ExtInfo obj)
 {
     mainWindow.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                       (Action) delegate
     {
         ShowResult(obj);
     });
 }
Exemplo n.º 7
0
        void BindProp(ListBox lb, ExtInfo currentExt, string property)
        {
            Binding bind = new Binding();

            bind.Source = currentExt;
            bind.Path   = new PropertyPath(property);
            bind.Mode   = BindingMode.OneWay;
            lb.SetBinding(ListBox.ItemsSourceProperty, bind);
        }
Exemplo n.º 8
0
        void BindProp(TextBlock tb, ExtInfo currentExt, string property)
        {
            Binding bind = new Binding();

            bind.Source = currentExt;
            bind.Path   = new PropertyPath(property);
            bind.Mode   = BindingMode.OneWay;
            tb.SetBinding(TextBlock.TextProperty, bind);
        }
Exemplo n.º 9
0
        public static ExtInfo operator +(ExtInfo left, ExtInfo right)
        {
            ExtInfo temp = new ExtInfo();

            temp.Name = right.Name;

            if (left.TypeFile != string.Empty)
            {
                temp.TypeFile = left.TypeFile + ", " + right.TypeFile.TrimStart();
            }
            else
            {
                temp.TypeFile = right.TypeFile;
            }

            if (left.EngDescription != string.Empty)
            {
                temp.EngDescription = left.EngDescription + "\n" + right.EngDescription.TrimStart();
            }
            else
            {
                temp.EngDescription = right.EngDescription;
            }

            if (left.RusDescription != string.Empty)
            {
                temp.RusDescription = left.RusDescription + "\n" + right.RusDescription.TrimStart();
            }
            else
            {
                temp.RusDescription = right.RusDescription;
            }

            if (left.DetailedDescription != string.Empty)
            {
                temp.DetailedDescription = left.DetailedDescription + "\n" + right.DetailedDescription.TrimStart();
            }
            else
            {
                temp.DetailedDescription = right.DetailedDescription;
            }

            temp.InfoHeaderFile.AddRange(left.InfoHeaderFile);
            temp.InfoHeaderFile.AddRange(right.InfoHeaderFile);

            temp.WhatOpenWindows.AddRange(left.WhatOpenWindows);
            temp.WhatOpenWindows.AddRange(right.WhatOpenWindows);

            temp.WhatOpenLinux.AddRange(left.WhatOpenLinux);
            temp.WhatOpenLinux.AddRange(right.WhatOpenLinux);

            temp.WhatOpenMac.AddRange(left.WhatOpenMac);
            temp.WhatOpenMac.AddRange(right.WhatOpenMac);

            return(temp);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Проверяет xml аттрибут с данными в объекте,
        /// если отличаются то добавляются новые данные
        /// </summary>
        /// <param name="itemExt">объект с данными</param>
        /// <param name="element">элемент с именем как в объекте</param>
        void AddInfoExtension(ExtInfo itemExt, XElement element)
        {
            XAttribute attr;
            bool       coincidence;

            attr        = element.Attribute(XmlStruct.eDetailedDescription);
            coincidence = attr.Value == itemExt.DetailedDescription;
            if (!coincidence)
            {
                attr.Value = itemExt.DetailedDescription;
            }
        }
Exemplo n.º 11
0
 void ShowResult(ExtInfo currentExt)
 {
     BindProp(mainWindow.tb_formatfile, currentExt, "Name");
     BindProp(mainWindow.tb_descripEng, currentExt, "EngDescription");
     BindProp(mainWindow.tb_descripRus, currentExt, "RusDescription");
     BindProp(mainWindow.tb_typefile, currentExt, "TypeFile");
     BindProp(mainWindow.tb_FullDescrip, currentExt, "DetailedDescription");
     BindProp(mainWindow.lb_InfoHeaderFile, currentExt, "InfoHeaderFile");
     BindProp(mainWindow.lb_WhatOpenWindows, currentExt, "WhatOpenWindows");
     BindProp(mainWindow.lb_WhatOpenLinux, currentExt, "WhatOpenLinux");
     BindProp(mainWindow.lb_WhatOpenMac, currentExt, "WhatOpenMac");
 }
Exemplo n.º 12
0
        public void AddToCategory(ExtInfo itemExt)
        {
            if (itemExt.TypeFile == null)
            {
                return;
            }
            foreach (KeyValuePair <string, string> cat in Category.categoryes2)
            {
                // если найдена категория из словаря
                if (itemExt.TypeFile.Contains(cat.Value))
                {
                    // то ищем ее в xml
                    XElement category = root.Element(cat.Key);

                    XmlWriter xmlTWriter;
                    // категория найдена?
                    if (category != null)
                    {
                        // ищем в xml полученое разрешение
                        foreach (var item in category.Elements(XmlStruct.eExt))
                        {
                            bool coincidence = item.Attribute(XmlStruct.eName).Value == itemExt.Name;
                            // если xml уже есть такое расширение
                            if (coincidence)
                            {
                                AddInfoExtension(itemExt, item);
                                return;
                            }
                        }

                        xmlTWriter = category.CreateWriter();
                        AddNewExtension(itemExt, xmlTWriter);
                    }
                    else
                    {
                        xmlTWriter = root.CreateWriter();

                        xmlTWriter.WriteStartElement(cat.Key);
                        AddNewExtension(itemExt, xmlTWriter);
                        xmlTWriter.WriteEndElement();
                    }
                    xmlTWriter.Close();
                    break;
                }
            }
        }
Exemplo n.º 13
0
        private void Parser_CompleteConvertEvent(ExtInfo obj)
        {
            mainWindow.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                              (Action) delegate
            {
                //mainWindow.listBox.Items.Add(obj.Name);
                //mainWindow.listBox.Items.Add(obj.Header);
                //mainWindow.listBox.Items.Add(obj.TypeFile);

                //mainWindow.listBox.Items.Add(obj.RusDescription);
                //mainWindow.listBox.Items.Add(obj.EngDescription);

                //mainWindow.listBox.Items.Add(obj.InfoHeaderFile);
                //foreach( var item in obj.WhatOpenWindows )
                //{
                //    mainWindow.listBox.Items.Add(item);
                //}
            });
        }
Exemplo n.º 14
0
        public void ExtractExt(string word)
        {
            if (!isReady)
            {
                return;
            }
            List <XElement> foundItems = new List <XElement>();

            foreach (KeyValuePair <string, string> cat in Category.categoryes2)
            {
                XElement category = root.Element(cat.Key);
                foreach (XElement item in category.Elements(XmlStruct.eExt))
                {
                    bool condit = item.Attribute(XmlStruct.eName).Value == word;
                    if (condit)
                    {
                        foundItems.Add(item);
                    }
                }
            }

            if (foundItems.Count > 0)
            {
                ExtInfo extInfo = new ExtInfo();
                foreach (XElement foundItem in foundItems)
                {
                    extInfo += Extract(foundItem);
                }

                OnComplete(extInfo);
            }
            else
            {
                MessageBox.Show("Расширение " + word + " не найдено");
            }
        }
Exemplo n.º 15
0
        private ExtInfo GetDescriptionExtension(string link)
        {
            ExtInfo      ext         = new ExtInfo();
            HtmlDocument allHTML     = new HtmlDocument();
            HtmlDocument currentHTML = new HtmlDocument();
            string       siteAddress = "";

            if (link.Contains(this.siteAddress))
            {
                siteAddress = link;
            }
            else
            {
                siteAddress = this.siteAddress + link;
            }
            ext.Link        = siteAddress;
            fileTempAddress = siteAddress.Replace("http://open-file.ru/types/", "");
            fileTempAddress = "types\\" + fileTempAddress + ".txt";
            if (File.Exists(fileTempAddress))
            {
                allHTML.LoadHtml(HtmlToString.ReadCacheFile(fileTempAddress, encoding));
            }
            else
            {
                string s = HtmlToString.Read(siteAddress, encoding, fileTempAddress);
                if (s == "")
                {
                    return(ext);
                }
                allHTML.LoadHtml(s);
            }
            //xPathQuery
            //table class="desc"
            HtmlNodeCollection TableNodes;
            HtmlNodeCollection TableHaderNodes;

            string xpq_allWorks  = "//table[@class=\"desc\"]/*/*/*/td|//table[@class=\"desc\"]/*/*/td|//table[@class=\"desc\"]/*/td|//table[@class=\"desc\"]/td|//table[@class=\"desc\"]/th";
            string xpq_HeaderExt = "//table[@class=\"desc\"]/td|//table[@class=\"desc\"]/th";

            TableNodes      = allHTML.DocumentNode.SelectNodes(xpq_allWorks);
            TableHaderNodes = allHTML.DocumentNode.SelectNodes(xpq_HeaderExt);
            if (TableNodes == null)
            {
                //MessageBox.Show("Ошибка - " + link);
                return(null);
            }
            string key = null;

            key = TableHaderNodes[0].InnerText;
            if (key.Contains("Формат"))
            {
                Match m = Regex.Match(key, @"\.[a-zа-я0-9]*");
                if (m.Value != string.Empty)
                {
                    ext.Name = m.Value.Remove(0, 1);
                }
            }
            else
            {
                MessageBox.Show("Заголовок таблицы: " + key);
            }

            foreach (var tdNode in TableNodes)
            {
                key = null;
                key = tdNode.InnerText;
                key = key.Replace("&lt;", "<");
                key = key.Replace("&nbsp;", " ");

                int index = TableNodes.IndexOf(tdNode);

                if (key.Contains("Тип файла"))
                {
                    if (ext.TypeFile == string.Empty)
                    {
                        ext.TypeFile = TableNodes[index + 1].InnerText;
                    }
                    else
                    {
                        ext.TypeFile += ",\n" + TableNodes[index + 1].InnerText;
                    }
                }
                else if (key.Contains("на русском"))
                {
                    if (ext.RusDescription == string.Empty)
                    {
                        ext.RusDescription = TableNodes[index + 1].InnerText;
                    }
                    else
                    {
                        ext.RusDescription += ",\n" + TableNodes[index + 1].InnerText;
                    }
                }
                else if (key.Contains("на английском"))
                {
                    if (ext.EngDescription == string.Empty)
                    {
                        ext.EngDescription = TableNodes[index + 1].InnerText;
                    }
                    else
                    {
                        ext.EngDescription += ",\n" + TableNodes[index + 1].InnerText;
                    }
                }
                else if (key.Contains("Подробное описание"))
                {
                    string description = TableNodes[index + 1].InnerText;
                    description = description.Replace("&lt;", "<");
                    description = description.Replace("&gt;", ">");
                    description = description.Replace("&nbsp;", " ");

                    if (ext.DetailedDescription == string.Empty)
                    {
                        ext.DetailedDescription = description;
                    }
                    else
                    {
                        ext.DetailedDescription += ",\n " + description;
                    }
                }
                else if (key.Contains("ASCII:"))
                {
                    ext.InfoHeaderFile.Add(key);
                }
                else if (key.Contains("HEX:"))
                {
                    ext.InfoHeaderFile.Add(key);
                }
                else if (key == " Windows" || key == "Windows")
                {
                    ext.WhatOpen = TableNodes[index + 1].InnerText;

                    HtmlNodeCollection li_s = TableNodes[index + 1].SelectNodes("*/li|*/*/li");
                    foreach (HtmlNode li in li_s)
                    {
                        ext.WhatOpenWindows.Add(li.InnerText);
                    }
                }
                else if (key == " Linux" || key == "Linux")
                {
                    ext.WhatOpen += TableNodes[index + 1].InnerText;
                    HtmlNodeCollection li_s = TableNodes[index + 1].SelectNodes("*/li");

                    foreach (HtmlNode li in li_s)
                    {
                        ext.WhatOpenLinux.Add(li.InnerText);
                    }
                }
                else if (key == " MacOS")
                {
                    ext.WhatOpen += TableNodes[index + 1].InnerText;
                    HtmlNodeCollection li_s = TableNodes[index + 1].SelectNodes("*/li");
                    foreach (HtmlNode li in li_s)
                    {
                        ext.WhatOpenMac.Add(li.InnerText);
                    }
                }
            }
            if (ext.EngDescription == null ||
                ext.RusDescription == null ||
                ext.Name == null ||
                ext.TypeFile == null ||
                ext.Link == null
                )
            {
                MessageBox.Show("Не найдены данные");
            }

            return(ext);
        }