예제 #1
0
        private void ReadWCPFile(Thread process)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Recent);
            openFileDialog.Filter           = "wcp files (*.wcp)|*.wcp";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect      = false;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string          Path             = openFileDialog.FileName;
                string          text             = File.ReadAllText(Path);
                string[]        stringSeparators = new string[] { "\r\n" };
                string[]        res   = text.Split(stringSeparators, StringSplitOptions.None);//根据换行符进行拆分
                List <UrlLNode> nodes = new List <UrlLNode> {
                };
                bool StartRecord      = false;
                int  CheckNum         = 0;
                for (int i = 0; i <= res.Length; i++)
                {
                    if (res[i] != "[TOPICS]" && !StartRecord)
                    {
                        continue;
                    }
                    if (res[i] == "[TOPICS]")
                    {
                        StartRecord = true;
                        CheckNum    = Convert.ToInt32(res[i + 1].Split('=')[1]);
                        i          += 1;
                        continue;
                    }
                    UrlLNode urlLNode = new UrlLNode();
                    urlLNode.SetValue(res[i].Split('=')[1], res[i + 1].Split('=')[1], res[i + 2].Split('=')[1], res[i + 3].Split('=')[1], res[i + 4].Split('=')[1], res[i + 5].Split('=')[1], res[i + 6].Split('=')[1], res[i + 7].Split('=')[1], res[i + 8].Split('=')[1], res[i + 9].Split('=')[1]);
                    i += 9;
                    nodes.Add(urlLNode);
                    if (nodes.Count == CheckNum)
                    {
                        break;
                    }
                }
                UpdataXml(nodes, process);
            }
            else
            {
                //用户取消了文件选择
                return;
            }
        }
예제 #2
0
        public XElement WriteXmlRecord(UrlLNode urlLNodes, XElement xDocument)
        {
            XElement xElement = new XElement("ID_" + GenerateId());

            xElement.SetElementValue("Title", urlLNodes.Title);
            xElement.SetElementValue("Level", urlLNodes.Level);
            xElement.SetElementValue("Url", urlLNodes.Url);
            xElement.SetElementValue("Icon", urlLNodes.Icon);
            xElement.SetElementValue("Status", urlLNodes.Status);
            xElement.SetElementValue("Keywords", urlLNodes.Keywords);
            xElement.SetElementValue("ContextNumber", urlLNodes.ContextNumber);
            xElement.SetElementValue("ApplyTemp", urlLNodes.ApplyTemp);
            xElement.SetElementValue("Expanded", urlLNodes.Expanded);
            xElement.SetElementValue("Kind", urlLNodes.Kind);
            xDocument.Add(xElement);
            return(xElement);
        }