示例#1
0
        public string Serialize(IReportStrategy strategy = null)
        {
            string str = "";

            try
            {
                if (strategy == null)
                {
                    strategy = new ReportDefaultStrategy();
                }

                str = strategy.Serialize(this);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(str);
        }
示例#2
0
        public void Deserialize(string str, IReportStrategy strategy = null)
        {
            try
            {
                if (strategy == null)
                {
                    strategy = new ReportDefaultStrategy();
                }

                Reporter reporter = strategy.Deserialize(str);

                ReportBy  = reporter.ReportBy;
                WrittenTo = reporter.WrittenTo;
                Results   = reporter.Results;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
        static void Execute(ArgumentInfo arginfo)
        {
            string disp_se      = ResultStatus.SyntaxError.DisplayName();
            string disp_fa      = ResultStatus.Assert.DisplayName();
            string disp_sr      = ResultStatus.Report.DisplayName();
            string reportheader = $"{disp_se} | {disp_fa} | {disp_sr}";
            string reportborder = new string('-', reportheader.Length);

            Console.ForegroundColor = ConsoleColor.Gray;

            SchemaDocument doc = null;

            try
            {
                doc = new SchemaDocument();

                doc.Open(arginfo.SchFile.FullName);
                doc.Compile(arginfo.Phase);

                ResultCollection results = new ResultCollection();
                foreach (FileInfo xmlfile in arginfo.XmlFiles)
                {
                    Console.WriteLine("");
                    Console.WriteLine($"> Validation Start of '{xmlfile.Name}' by '{doc.SchemaTmp.Name}'");

                    ResultCollection file_results = doc.Validation(xmlfile.FullName);

                    string se = String.Format("{0, " + disp_se.Length + "}", file_results.TotalSyntaxError);
                    string fa = String.Format("{0, " + disp_fa.Length + "}", file_results.TotalAssert);
                    string sr = String.Format("{0, " + disp_sr.Length + "}", file_results.TotalReport);
                    Console.WriteLine("  " + reportborder);
                    Console.WriteLine("  " + reportheader);
                    Console.WriteLine($"  {se} | {fa} | {sr}");
                    Console.WriteLine("  " + reportborder);

                    Console.WriteLine("> End of Validation");

                    results.AddRange(file_results);
                }
                if (results.Count > 0 && arginfo.OutFile != null)
                {
                    Reporter report = new Reporter();
                    report.Results = results;
                    IReportStrategy strategy = EmbeddReportStrategies.Find(arginfo.OutFormat);
                    if (strategy == null)
                    {
                        strategy = new ReportDefaultStrategy();
                    }

                    report.Write(arginfo.OutFile.FullName, strategy);
                }
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("");
                Console.WriteLine("COMPLETE!");
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("");
                Console.WriteLine("ERROR!");
                Console.WriteLine(ex.Message);
            }
            finally
            {
                doc?.Dispose();
            }
        }