/// <summary> /// Constructs a new instance of the form /// </summary> public ValidatePluginForm() { InitializeComponent(); InitializeCommandManager(); this.hlpProvider.HelpNamespace = Properties.Resources.FileHelpName; this.ValidationType = XmlKindEnum.Plugin; }
/// <summary> /// Constructs a new instance of the form /// </summary> public ValidatePluginForm(XmlKindEnum ValidationType) : this() { this.ValidationType = ValidationType; if (this.ValidationType == XmlKindEnum.SnippitInstl) { this.hlpProvider.SetHelpKeyword(this, @"23"); } else { this.hlpProvider.SetHelpKeyword(this, @"24"); } }
/// <summary> /// Gets a <see cref="ValidationResult"/> with information a specified xml string is valid /// </summary> /// <param name="xmlData">The xml string to validate</param> /// <returns> /// Returns <see cref="ValidationResult"/> instance. If any errors are prsent thne <see cref="ValidationResult.HasErrors"/> will be set to true. /// Alos if there are errors <see cref="ValidationResult.Errors"/> will contain information about the errors. /// </returns> /// <remarks> /// This method will automatically determine if the xml file is a snippit install, Plugin or Profile and validate depending on type and version. /// </remarks> public static ValidationResult ValidateXmlString(string xmlData) { ValidationResult result = new ValidationResult(); if (string.IsNullOrWhiteSpace(xmlData)) { result.Errors.Add(Properties.Resources.ErrorEmptyXmlString); return(result); } try { ValidationResult SubResult = null; XDocument custDoc = XDocument.Parse(xmlData); XmlKindEnum XmlKind = ValidateXml.GetXmlType(custDoc.Root); switch (XmlKind) { case XmlKindEnum.SnippitInstl: SubResult = ValidateXml.ValidateSnipitInstalDoc(custDoc); break; case XmlKindEnum.Plugin: SubResult = ValidateXml.ValidatePluginDoc(custDoc); break; case XmlKindEnum.Profile: SubResult = ValidateXml.ValidateProfileDoc(custDoc); break; default: SubResult = new ValidationResult(); break; } if (SubResult.HasErrors) { result.Errors.AddRange(SubResult.Errors); } } catch (Exception err) { result.Errors.Add(err.Message); } return(result); }
/// <summary> /// Gets a <see cref="ValidationResult"/> with information a specified xml file is valid /// </summary> /// <param name="xmlFile">The path to the xml file to validate</param> /// <returns> /// Returns <see cref="ValidationResult"/> instance. If any errors are prsent thne <see cref="ValidationResult.HasErrors"/> will be set to true. /// Alos if there are errors <see cref="ValidationResult.Errors"/> will contain information about the errors. /// </returns> /// <remarks> /// This method will automatically determine if the xml file is a snippit install, Plugin or Profile and validate depending on type and version. /// </remarks> public static ValidationResult ValidateXmlFile(string xmlFile) { ValidationResult result = new ValidationResult(); if (!File.Exists(xmlFile)) { result.Errors.Add(Properties.Resources.ErrorFileNotExist); return(result); } try { ValidationResult SubResult = null; XDocument custDoc = XDocument.Load(xmlFile); XmlKindEnum XmlKind = ValidateXml.GetXmlType(custDoc.Root); switch (XmlKind) { case XmlKindEnum.SnippitInstl: SubResult = ValidateXml.ValidateSnipitInstalDoc(custDoc); break; case XmlKindEnum.Plugin: SubResult = ValidateXml.ValidatePluginDoc(custDoc); break; case XmlKindEnum.Profile: SubResult = ValidateXml.ValidateProfileDoc(custDoc); break; default: SubResult = new ValidationResult(); break; } if (SubResult.HasErrors) { result.Errors.AddRange(SubResult.Errors); } } catch (Exception err) { result.Errors.Add(err.Message); } return(result); }