Ejemplo n.º 1
0
        public XmlValidationRule(IXmlDocumentProvider docProvider, XmlNode node, XmlNamespaceManager nsmgr)
        {
            if (node.Attributes["name"] != null)
            {
                Name = node.Attributes["name"].Value;
            }
            if (node.Attributes["file"] != null)
            {
                File = node.Attributes["file"].Value;
            }

            if (!string.IsNullOrEmpty(File))
            {
                XmlDocument doc = docProvider.Load(File);
                if (doc != null)
                {
                    List <ITest> tests = new List <ITest>();

                    string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation");
                    foreach (XmlNode passNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":pass", nsmgr))
                    {
                        tests.Add(new XmlCalendarTest(passNode, nsmgr));
                    }
                    foreach (XmlNode failNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":fail", nsmgr))
                    {
                        tests.Add(new XmlCalendarTest(failNode, nsmgr));
                    }

                    Tests = tests.ToArray();
                }
            }
        }
Ejemplo n.º 2
0
        public XmlValidationRule(IXmlDocumentProvider docProvider, XmlNode node, XmlNamespaceManager nsmgr)
        {
            if (node.Attributes["name"] != null)
                Name = node.Attributes["name"].Value;
            if (node.Attributes["file"] != null)
                File = node.Attributes["file"].Value;

            if (!string.IsNullOrEmpty(File))
            {
                try
                {
                    XmlDocument doc = docProvider.Load(File);
                    if (doc != null)
                    {
                        List<ITest> tests = new List<ITest>();

                        string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation");
                        foreach (XmlNode passNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":pass", nsmgr))
                            tests.Add(new XmlCalendarTest(passNode, nsmgr));
                        foreach (XmlNode failNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":fail", nsmgr))
                            tests.Add(new XmlCalendarTest(failNode, nsmgr));

                        Tests = tests.ToArray();
                    }
                    else throw new ValidationRuleLoadException("The file could not be found at the following path: '" + File + "'.", this);
                }
                catch (ValidationRuleLoadException) { throw; }
                catch
                {
                    throw new ValidationRuleLoadException(this);
                }
            }
        }
Ejemplo n.º 3
0
        static private bool EnsureXmlDocument()
        {
            if (_XmlDocument == null)
            {
                _XmlDocument = null;
                _Nsmgr       = null;
                _Prefix      = null;

                foreach (string id in _LanguageIdentifiers)
                {
                    _XmlDocument = _XmlDocumentProvider.Load("languages/" + id + ".xml");
                    if (_XmlDocument != null)
                    {
                        _CurrentLanguageIdentifier = id;
                        break;
                    }
                }

                if (_XmlDocument != null)
                {
                    _Nsmgr  = new XmlNamespaceManager(_XmlDocument.NameTable);
                    _Prefix = _Nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation");
                    if (_Prefix == null)
                    {
                        _Nsmgr.AddNamespace("v", "http://icalvalid.wikidot.com/validation");
                        _Prefix = "v";
                    }
                }
            }

            return(_XmlDocument != null);
        }
        public IValidationRuleset[] Load()
        {
            XmlDocument xmlDoc = _DocumentProvider.Load("rulesets.xml");

            if (xmlDoc != null)
            {
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
                nsmgr.AddNamespace("v", "http://icalvalid.wikidot.com/validation");

                // Build a list of rulesets
                List <IValidationRuleset> rulesets = new List <IValidationRuleset>();
                foreach (XmlNode node in xmlDoc.SelectNodes("/v:rulesets/v:ruleset", nsmgr))
                {
                    rulesets.Add(new XmlValidationRuleset(_DocumentProvider, node, nsmgr));
                }

                return(rulesets.ToArray());
            }
            return(null);
        }
Ejemplo n.º 5
0
        public XmlValidationRule(IXmlDocumentProvider docProvider, XmlNode node, XmlNamespaceManager nsmgr)
        {
            if (node.Attributes["name"] != null)
                Name = node.Attributes["name"].Value;
            if (node.Attributes["file"] != null)
                File = node.Attributes["file"].Value;

            if (!string.IsNullOrEmpty(File))
            {
                XmlDocument doc = docProvider.Load(File);
                if (doc != null)
                {
                    List<ITest> tests = new List<ITest>();

                    string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation");
                    foreach (XmlNode passNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":pass", nsmgr))
                        tests.Add(new XmlCalendarTest(passNode, nsmgr));
                    foreach (XmlNode failNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":fail", nsmgr))
                        tests.Add(new XmlCalendarTest(failNode, nsmgr));

                    Tests = tests.ToArray();
                }
            }            
        }
Ejemplo n.º 6
0
        static void LanguageKeyValidation(IXmlDocumentProvider docProvider)
        {
            Console.Write(Environment.NewLine + "Validating language files for missing entries...");
            try
            {
                List <string> languageFiles = new List <string>();
                foreach (string path in docProvider)
                {
                    if (path.Contains("languages"))
                    {
                        languageFiles.Add(path);
                    }
                }

                List <string> masterEntries = new List <string>();
                Dictionary <string, List <string> > entries = new Dictionary <string, List <string> >();
                foreach (string xmlPath in languageFiles)
                {
                    XmlDocument         doc   = docProvider.Load(xmlPath);
                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

                    string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation");
                    if (string.IsNullOrEmpty(prefix))
                    {
                        prefix = "v";
                        nsmgr.AddNamespace("v", "http://icalvalid.wikidot.com/validation");
                    }

                    entries[xmlPath] = new List <string>();
                    foreach (XmlNode str in doc.SelectNodes("/" + prefix + ":language/" + prefix + ":string", nsmgr))
                    {
                        string name = str.Attributes["name"].Value;
                        entries[xmlPath].Add("string/" + name);
                        if (!masterEntries.Contains("string/" + name))
                        {
                            masterEntries.Add("string/" + name);
                        }
                    }
                    foreach (XmlNode str in doc.SelectNodes("/" + prefix + ":language/" + prefix + ":errors/" + prefix + ":error", nsmgr))
                    {
                        string name = str.Attributes["name"].Value;
                        entries[xmlPath].Add("error/" + name);
                        if (!masterEntries.Contains("error/" + name))
                        {
                            masterEntries.Add("error/" + name);
                        }
                    }
                    foreach (XmlNode str in doc.SelectNodes("/" + prefix + ":language/" + prefix + ":resolutions/" + prefix + ":resolution", nsmgr))
                    {
                        string name = str.Attributes["error"].Value;
                        entries[xmlPath].Add("resolution/" + name);
                        if (!masterEntries.Contains("resolution/" + name))
                        {
                            masterEntries.Add("resolution/" + name);
                        }
                    }
                }

                foreach (KeyValuePair <string, List <string> > kvp in entries)
                {
                    Console.Write(Environment.NewLine + "Validating '" + kvp.Key + "'...");
                    List <string> missingEntries = new List <string>();
                    foreach (string masterEntry in masterEntries)
                    {
                        if (!kvp.Value.Contains(masterEntry))
                        {
                            missingEntries.Add(masterEntry);
                        }
                    }

                    if (missingEntries.Count > 0)
                    {
                        Console.Write("Missing " + missingEntries.Count + " entries!");
                        foreach (string me in missingEntries)
                        {
                            Console.Write(Environment.NewLine + "'" + me + "'");
                        }
                    }
                    else
                    {
                        Console.Write("OK");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine();
        }
Ejemplo n.º 7
0
        static void LanguageKeyValidation(IXmlDocumentProvider docProvider)
        {
            Console.Write(Environment.NewLine + "Validating language files for missing entries...");
            try
            {
                List<string> languageFiles = new List<string>();
                foreach (string path in docProvider)
                {
                    if (path.Contains("languages") && path.EndsWith(".xml"))
                        languageFiles.Add(path);
                }

                List<string> masterEntries = new List<string>();
                Dictionary<string, List<string>> entries = new Dictionary<string, List<string>>();
                foreach (string xmlPath in languageFiles)
                {
                    XmlDocument doc = docProvider.Load(xmlPath);
                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

                    string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation");
                    if (string.IsNullOrEmpty(prefix))
                    {
                        prefix = "v";
                        nsmgr.AddNamespace("v", "http://icalvalid.wikidot.com/validation");
                    }

                    entries[xmlPath] = new List<string>();
                    foreach (XmlNode str in doc.SelectNodes("/" + prefix + ":language/" + prefix + ":string", nsmgr))
                    {
                        string name = str.Attributes["name"].Value;
                        entries[xmlPath].Add("string/" + name);
                        if (!masterEntries.Contains("string/" + name))
                            masterEntries.Add("string/" + name);
                    }
                    foreach (XmlNode str in doc.SelectNodes("/" + prefix + ":language/" + prefix + ":errors/" + prefix + ":error", nsmgr))
                    {
                        string name = str.Attributes["name"].Value;
                        entries[xmlPath].Add("error/" + name);
                        if (!masterEntries.Contains("error/" + name))
                            masterEntries.Add("error/" + name);
                    }
                    foreach (XmlNode str in doc.SelectNodes("/" + prefix + ":language/" + prefix + ":resolutions/" + prefix + ":resolution", nsmgr))
                    {
                        string name = str.Attributes["error"].Value;
                        entries[xmlPath].Add("resolution/" + name);
                        if (!masterEntries.Contains("resolution/" + name))
                            masterEntries.Add("resolution/" + name);
                    }
                }

                foreach (KeyValuePair<string, List<string>> kvp in entries)
                {
                    Console.Write(Environment.NewLine + "Validating '" + kvp.Key + "'...");
                    List<string> missingEntries = new List<string>();
                    foreach (string masterEntry in masterEntries)
                    {
                        if (!kvp.Value.Contains(masterEntry))
                            missingEntries.Add(masterEntry);
                    }

                    if (missingEntries.Count > 0)
                    {
                        Console.Write("Missing " + missingEntries.Count + " entries!");
                        foreach (string me in missingEntries)
                            Console.Write(Environment.NewLine + "'" + me + "'");
                    }
                    else Console.Write("OK");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine();
        }