Exemplo n.º 1
0
        private void go_Click(object sender, EventArgs e)
        {
            try
            {
                if (!PathIsValid(inputPath.Text, "input", true))
                {
                    return;
                }

                if (!PathIsValid(outputPath.Text, "output", false))
                {
                    return;
                }

                DirectoryInfo inputDir = new DirectoryInfo(inputPath.Text);

                Directory.CreateDirectory(outputPath.Text);

                var xmlFiles = inputDir.EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly).Where(p => DredmorInfo.XmlFilesToValidate.Any(q => q == p.Name.ToLower()));

                var count = xmlFiles.Count();

                if (count > 0)
                {
                    foreach (var xmlFile in xmlFiles)
                    {
                        string newContents;

                        using (StreamReader fileStream = xmlFile.OpenText())
                        {
                            newContents = CapitalizationFixer.Fix(fileStream.ReadToEnd());
                        }

                        File.WriteAllText(Path.Combine(outputPath.Text, xmlFile.Name), newContents);
                    }

                    MessageBox.Show(String.Format("{0} files transformed", count), "Done", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("No transformable XML files found.", "Done", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Validates each file, optionally ignoring the case of elements, attributes, and enumerated attribute values.
        /// </summary>
        /// <param name="filesToValidate"></param>
        /// <param name="ignoreCase">If true, uses the CapitalizationFixer.Fix method to fix the capitalization of the file before validating.</param>
        /// <returns></returns>
        public List <XmlFileValidationErrorList> Validate(IEnumerable <ContentFile> filesToValidate, bool ignoreCase)
        {
            List <XmlFileValidationErrorList> result = new List <XmlFileValidationErrorList>();

            foreach (var file in filesToValidate)
            {
                try
                {
                    using (StreamReader fileStream = file.OpenText())
                    {
                        using (TextReader xmlTextReader = (ignoreCase) ? (TextReader) new StringReader(CapitalizationFixer.Fix(fileStream.ReadToEnd())) : (TextReader)fileStream)
                        {
                            var errors = ValidateFile(xmlTextReader, ignoreCase);

                            if (errors.Count > 0)
                            {
                                result.Add(
                                    new XmlFileValidationErrorList
                                {
                                    Path   = file.FullName,
                                    Errors = errors
                                }
                                    );
                            }
                        }
                    }
                }
                catch (XmlException ex)
                {
                    result.Add(new XmlFileValidationErrorList(file.FullName, ex));
                }
            }

            return(result);
        }