Esempio n. 1
0
        public static IEnumerable <URLPattern> ReadConfig(string path)
        {
            string            classification = Path.GetFileNameWithoutExtension(path);
            List <URLPattern> urlPatterns    = new List <URLPattern>();
            XmlDocument       doc            = new XmlDocument();

            doc.Load(path);
            XmlNodeList nodelist = doc.SelectNodes("//URLPattern");

            if (nodelist == null)
            {
                return(urlPatterns);
            }

            foreach (XmlNode node in nodelist)
            {
                if (node.Attributes == null)
                {
                    continue;
                }
                XmlAttribute urlX               = node.Attributes["URL"];
                XmlAttribute needValidationX    = node.Attributes["NeedValidation"];
                XmlAttribute necessaryKeywordsX = node.Attributes["NecessaryKeywords"];
                XmlAttribute forbiddenKeywordsX = node.Attributes["ForbiddenKeywords"];
                XmlAttribute enabledX           = node.Attributes["Enabled"];
                if (needValidationX == null || necessaryKeywordsX == null ||
                    forbiddenKeywordsX == null || enabledX == null)
                {
                    continue;
                }
                URLPattern urlPattern = new URLPattern(urlX.Value);
                urlPattern.NeedValidation = Convert.ToBoolean(needValidationX.Value);
                urlPattern.Enabled        = Convert.ToBoolean(enabledX.Value);
                string[] necessaryKeywords = necessaryKeywordsX.Value.Split(new char[] { ',' });
                foreach (string s in necessaryKeywords)
                {
                    urlPattern.NecessaryKeywords.Add(s);
                }
                string[] forbiddenKeywords = forbiddenKeywordsX.Value.Split(new char[] { ',' });
                foreach (string s in forbiddenKeywords)
                {
                    urlPattern.ForbiddenKeywords.Add(s);
                }
                urlPattern.Classification = classification;

                urlPatterns.Add(urlPattern);
            }
            return(urlPatterns);
        }
Esempio n. 2
0
        private void SaveURLPattern()
        {
            List <URLPattern> patterns = new List <URLPattern>();

            foreach (DataRow row in urlPatternTable.Rows)
            {
                URLPattern p        = new URLPattern(row["URLPattern"].ToString());
                string[]   keywords = row["NecessaryKeywords"].ToString().Split(new char[] { ',', ';', ',', ';' });
                p.NecessaryKeywords.AddRange(keywords);

                string[] forbiddenKeywords = row["ForbiddenKeywords"].ToString().Split(new char[] { ',', ';', ',', ';' });
                p.ForbiddenKeywords.AddRange(forbiddenKeywords);

                p.Enabled        = (bool)row["Enabled"];
                p.NeedValidation = (bool)row["NeedValidation"];
                p.Classification = row["Classification"].ToString();
                if (string.IsNullOrEmpty(p.Classification))
                {
                    p.Classification      = "default";
                    row["Classification"] = "default";
                }
                patterns.Add(p);
            }
            ins.PacSetting.Clear();
            ins.PacSetting.LoadURLPatterns(patterns);

            bool success = ins.SaveURLPatterns();

            ResetURLPatterns();
            if (success)
            {
                MessageBox.Show("Done");
            }
            else
            {
                MessageBox.Show("Failed");
            }
        }