Esempio n. 1
0
        private static string onSearchClicked(BulkWindow.BulkCommunicator bc, ICollection <string> files, object userObject)
        {
            bc.ReportProgress(string.Format("Found {0} files to pretty print", files.Count));

            StringBuilder errorlog = new StringBuilder();

            foreach (string file in files)
            {
                try
                {
                    string newFileName = Path.ChangeExtension(file, ".pretty.xml");
                    bc.ReportProgress("Prettyprinting file: " + file);
                    string xml = File.ReadAllText(file);
                    string res = PrettyPrint.Execute(xml, true, false);
                    File.WriteAllText(newFileName, res);
                }
                catch (Exception e)
                {
                    errorlog.AppendLine("Error while prettyprinting " + file + ": " + e.Message);
                }
            }

            errorlog.AppendLine("Prettyprinting completed");
            return(errorlog.ToString());
        }
Esempio n. 2
0
        private static string onSearchClicked(BulkWindow.BulkCommunicator bc, ICollection <string> files, object userObject)
        {
            bc.ReportProgress(string.Format("Found {0} files to scan", files.Count));

            StringBuilder edtResult = new StringBuilder();

            try
            {
                XPathExpression expr = XPathExpression.Compile(userObject.ToString());

                foreach (string file in files)
                {
                    try
                    {
                        bc.ReportProgress("Scanning file: " + file);
                        edtResult.AppendLine("Result of file: " + file);

                        XPathDocument doc = new XPathDocument(file);
                        var           nav = doc.CreateNavigator();

                        var result = nav.Evaluate(expr);
                        if (result is Boolean || result is Double || result is string)
                        {
                            edtResult.AppendFormat("{0}\n", result);
                        }
                        else if (result is XPathNodeIterator)
                        {
                            DisplayNavigator((XPathNodeIterator)result, edtResult);
                        }
                        else
                        {
                            Debug.Fail("result is " + result.GetType());
                        }
                    }
                    catch (Exception e)
                    {
                        edtResult.AppendLine("Error while scanning " + file + ": " + e.Message);
                    }
                }

                edtResult.AppendLine("Scanning completed");
            }
            catch (Exception e)
            {
                edtResult.AppendLine("Error: " + e.Message);
            }
            return(edtResult.ToString());
        }
Esempio n. 3
0
        private static string onSearchClicked(BulkWindow.BulkCommunicator bc, ICollection <string> files, object userObject)
        {
            bc.ReportProgress(string.Format("Found {0} files to scan", files.Count));

            StringBuilder edtResult = new StringBuilder();
            int           countFiles = 0, countWarnings = 0, countErrors = 0, countSuccess = 0;

            try
            {
                foreach (string file in files)
                {
                    try
                    {
                        bc.ReportProgress("Scanning file: " + file);
                        edtResult.Append("Result of file: " + file + " ...");

                        try
                        {
                            countFiles++;

                            XmlDocument xmldoc = File.ReadAllText(file).ToXmlDocument();

                            XsdValidationResult result = XsdValidationHelper.Instance.ValidateInstance(
                                userObject.ToString(), File.ReadAllText(file));
                            switch (result.State)
                            {
                            case ValidationState.Success:
                                edtResult.Append(" valid");
                                countSuccess++;
                                break;

                            case ValidationState.Warning:
                                edtResult.Append(" warning");
                                countWarnings++;
                                break;

                            case ValidationState.ValidationError:
                                edtResult.Append(" error");
                                countErrors++;
                                break;

                            case ValidationState.OtherError:
                                edtResult.Append(" other error");
                                countErrors++;
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            edtResult.Append(ex.Message);
                            countErrors++;
                        }
                        edtResult.AppendLine();
                    }
                    catch (Exception e)
                    {
                        edtResult.AppendLine("Error while scanning " + file + ": " + e.Message);
                    }
                }

                edtResult.AppendLine();
                edtResult.AppendFormat("{0} files, {1} valid, {2} valid with warnings, {3} errors",
                                       countFiles, countSuccess, countWarnings, countErrors);
                edtResult.AppendLine();
                edtResult.AppendLine("Scanning completed");
            }
            catch (Exception e)
            {
                edtResult.AppendLine("Error: " + e.Message);
            }
            return(edtResult.ToString());
        }