Beispiel #1
0
        static void Main(string[] args)
        {
            Console.Write("Enter the name of the report: ");
            String reportName = Console.ReadLine();

            IReportStrategy rs = ReportFactory.GetReport(reportName);

            if (rs != null)
            {
                Console.WriteLine(rs.GetColumnHeaders());

                int numRecs = rs.GetNumberOfRows();
                for (int i = 0; i < numRecs; i++)
                {
                    Console.WriteLine(rs.GetData(i));
                }
            }
            else
            {
                Console.WriteLine("Report {0} not found.", reportName);
            }

            Console.Write("\n\nPress Enter to quit...");
            Console.ReadLine();
        }
        public Stream ToStream(IReportStrategy strategy = null)
        {
            MemoryStream stream = null;
            StreamWriter writer = null;
            string       str    = "";

            try
            {
                str    = Serialize(strategy);
                stream = new MemoryStream();
                writer = new StreamWriter(stream);
                writer.Write(str);
                writer.Flush();
                stream.Position = 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                writer?.Close();
                writer?.Dispose();
            }
            return(stream);
        }
        public void Write(string path, IReportStrategy strategy = null)
        {
            try
            {
                string str = Serialize(strategy);

                File.WriteAllText(path, str, Encoding.UTF8);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Read(string path, IReportStrategy strategy = null)
        {
            try
            {
                string str = File.ReadAllText(path, Encoding.UTF8);

                Deserialize(str, strategy);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static IReportStrategy GetReport(String rptName)
        {
            IReportStrategy strat = null;

            if (rptName.Equals("Report1"))
            {
                strat = new Report1();
            }
            else if (rptName.Equals("Report2"))
            {
                strat = new Report2();
            }

            return(strat);
        }
        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);
        }
        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;
            }
        }
        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();
            }
        }
Beispiel #9
0
 protected override void OnPreLoad(EventArgs e)
 {
     Reporter = new ParteReportStrategy(DAOFactory);
     base.OnPreLoad(e);
 }