Exemple #1
0
        /// <summary>
        /// Add an error to the SQL table
        /// </summary>
        /// <param name="fileID">The corresponding R file</param>
        /// <param name="errorMessage">The error type</param>
        /// <param name="errorDesc">The full error description</param>
        /// <param name="error">Output of any error messages</param>
        /// <returns>Whether the method was successful</returns>
        public static int AddError(int fileID, string errorMessage, string errorDesc, out string error)
        {
            error = string.Empty;
            if (ConfigurationManager.ConnectionStrings["SaveResults"] == null)
            {
                return(-1);
            }

            string connectionString = string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["SaveResults"].ConnectionString) ?
                                      string.Empty : ConfigurationManager.ConnectionStrings["SaveResults"].ConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                return(-1);
            }


            int errorID = 0;

            try
            {
                SqlParameter _errorID = new SqlParameter("@ErrorID", errorID);
                _errorID.Direction = ParameterDirection.Output;

                if (!String.IsNullOrEmpty(connectionString))
                {
                    using (DataAccess data = new DataAccess(connectionString))
                    {
                        if (data.ExecuteTestConnection())
                        {
                            data.ExecuteNonQuery(CommandType.StoredProcedure, InsertNewError,
                                                 new SqlParameter("@FileID", fileID), new SqlParameter("@Error", errorMessage),
                                                 new SqlParameter("@ErrorDesc", errorDesc), new SqlParameter("@UpdateBaseline", true),
                                                 _errorID);
                        }
                    }
                }

                errorID = Convert.ToInt32(_errorID.Value);
            }

            catch (SqlException ex)
            {
                error = ex.Message;
                RLogger.Error("An SQL exception occured", ex);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                RLogger.Error("An exception occured", ex);
            }

            return(errorID);
        }
Exemple #2
0
        public bool HTML(InstanceReport report, string readFrom, string saveAs)
        {
            bool retval = true;

            try
            {
                string transformFile = RulesEngineUtils.GetResourcePath(RulesEngineUtils.ReportBuilderFolder.Resources, RulesEngineUtils.TransformFile);
                if (!File.Exists(transformFile))
                {
                    Trace.TraceError("Error: Transform File '" + RulesEngineUtils.TransformFile + "' not found at:\n\t" + transformFile + "\nHtml Conversion aborted.");
                    return(false);
                }

                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load(transformFile);

                XsltArgumentList argList = new XsltArgumentList();
                argList.AddParam("asPage", string.Empty, "true");

                using (FileStream fs = new FileStream(saveAs, FileMode.Create, FileAccess.Write))
                {
                    transform.Transform(readFrom, argList, fs);
                }

                string reportDirectory = Path.GetDirectoryName(saveAs);
                string styleSheetTo    = Path.Combine(reportDirectory, RulesEngineUtils.StylesheetFile);
                string stylesheetFrom  = RulesEngineUtils.GetResourcePath(RulesEngineUtils.ReportBuilderFolder.Resources, RulesEngineUtils.StylesheetFile);
                FileUtilities.Copy(stylesheetFrom, styleSheetTo);

                string javascriptTo   = Path.Combine(reportDirectory, RulesEngineUtils.JavascriptFile);
                string javascriptFrom = RulesEngineUtils.GetResourcePath(RulesEngineUtils.ReportBuilderFolder.Resources, RulesEngineUtils.JavascriptFile);
                FileUtilities.Copy(javascriptFrom, javascriptTo);
                return(true);
            }
            catch (IOException ex)
            {
                RLogger.Error(string.Format("An error occured writing the HTML file {0}. Error: {1}", report.ReportName, ex.Message));
                retval = false;
            }
            catch (System.Security.SecurityException ex)
            {
                RLogger.Error(string.Format("An error occured writing the HTML file {0}. Error: {1}", report.ReportName, ex.Message));
                retval = false;
            }
            catch (ArgumentNullException ex)
            {
                RLogger.Error(string.Format("An error occured writing the HTML file {0}. Error: {1}", report.ReportName, ex.Message));
                retval = false;
            }
            return(retval);
        }
Exemple #3
0
        /// <summary>
        /// Inserts a new RFile ID into the SQL database
        /// </summary>
        /// <param name="reportID">The ReportID from the Report table</param>
        /// <param name="rFile">The r file name (R1.xml)</param>
        /// <param name="baseURL">Location of the base HTML</param>
        /// <param name="newURL">Location of the new HTML</param>
        /// <param name="updateBaseline">Whether or not to update the baseline</param>
        /// <param name="error">Output of any error messages</param>
        /// <returns>Returns the R File ID of the inserted record</returns>
        public static int AddFile(int reportID, string rFile,
                                  string baseURL, string newURL, out string error)
        {
            error = string.Empty;
            if (ConfigurationManager.ConnectionStrings["SaveResults"] == null)
            {
                return(-1);
            }

            string connectionString = string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["SaveResults"].ConnectionString) ?
                                      string.Empty : ConfigurationManager.ConnectionStrings["SaveResults"].ConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                return(-1);
            }

            SqlParameter fileID = new SqlParameter("@FileID", 0);

            fileID.Direction = ParameterDirection.Output;

            try
            {
                using (DataAccess data = new DataAccess(connectionString))
                {
                    if (data.ExecuteTestConnection())
                    {
                        data.ExecuteNonQuery(CommandType.StoredProcedure, InsertNewFile,
                                             new SqlParameter("@ReportID", reportID), new SqlParameter("@RFile", rFile),
                                             new SqlParameter("@BaseURL", baseURL), new SqlParameter("@NewURL", newURL),
                                             new SqlParameter("@UpdateBaseline", true), fileID);
                    }
                }
            }

            catch (SqlException ex)
            {
                error = ex.Message;
                RLogger.Error("An SQL exception occured", ex);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                RLogger.Error("An exception occured", ex);
            }

            return(Convert.ToInt32(fileID.Value));
        }
Exemple #4
0
        private bool UnzipMove(DirectoryInfo directory, out string[] files, out string error)
        {
            //Directory passed should be \Reports
            bool retval = true;

            FileInfo[] zipped = directory.GetFiles("*.zip");
            files = null;
            error = string.Empty;
            string fileName = string.Empty;

            try
            {
                foreach (FileInfo zip in zipped)
                {
                    fileName = zip.Name;
                    fileName = fileName.Remove(fileName.Length - 4);
                    ZipUtilities.TryUnzipAndUncompressFiles(zip.FullName,
                                                            zip.Directory.Parent.FullName + "\\Comparison\\" + fileName,
                                                            out files, out error);
                }
            }
            catch (System.Security.SecurityException ex)
            {
                error = "Failed proccess report with the following exception: " + ex.Message;
                RLogger.Error(error, ex);
                retval = false;
            }
            catch (UnauthorizedAccessException ex)
            {
                error = "Failed proccess report with the following exception: " + ex.Message;
                RLogger.Error(error, ex);
                retval = false;
            }
            catch (PathTooLongException ex)
            {
                error = "Failed proccess report with the following exception: " + ex.Message;
                RLogger.Error(error, ex);
                retval = false;
            }
            catch (Exception ex)
            {
                error = "Failed proccess report with the following exception: " + ex.Message;
                RLogger.Error(error, ex);
                retval = false;
            }
            return(retval);
        }
Exemple #5
0
 private void LoadFiles(FileInfo rFile, ref List <InstanceReport> list)
 {
     try
     {
         InstanceReport ir = InstanceReport.LoadXml(rFile.FullName);
         list.Add(ir);
     }
     catch (InvalidOperationException ex)
     {
         RLogger.Error(string.Format("Error on file {0}, file {1}.", reportName, rFile.Name));
         RLogger.Error(string.Format("Unable to deserialize the file: {0}. Error: {1}", rFile.Name, ex.Message));
     }
     catch (Exception ex)
     {
         RLogger.Error(string.Format("An error on file {0}:\n{1}", rFile.Name, ex.Message));
     }
 }
Exemple #6
0
        //Methods

        /// <summary>
        /// Adds a new Report to the sql database
        /// </summary>
        /// <param name="reportName">The name of the report (ReportLongName)</param>
        /// <param name="error">Output of any error messages</param>
        /// <returns>The inserted ID of the SQL record</returns>
        public static int AddReport(string reportName, DateTime reportDate, out string error)
        {
            //String connectionString = String.Empty;
            String connectionString = (!String.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["SaveResults"].ConnectionString)) ? ConfigurationManager.ConnectionStrings["SaveResults"].ConnectionString : String.Empty;

            error = string.Empty;
            SqlParameter _reportID = new SqlParameter("@reportID", 0);

            _reportID.Direction = ParameterDirection.Output;

            try
            {
                if (!String.IsNullOrEmpty(connectionString))
                {
                    using (DataAccess data = new DataAccess(connectionString))
                    {
                        if (data.ExecuteTestConnection())
                        {
                            data.ExecuteNonQuery(CommandType.StoredProcedure, InsertNewReport,
                                                 new SqlParameter("@ReportName", reportName),
                                                 new SqlParameter("@ReportDateTime", reportDate),
                                                 _reportID);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                error = ex.Message;
                RLogger.Error("An SQL exception occured", ex);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                RLogger.Error("An exception occured", ex);
            }

            return(Convert.ToInt32(_reportID.Value));
        }
Exemple #7
0
        public void Compare(bool SkipZip, bool baseHTML, out int totalRFiles, out int failedRFiles)
        {
            //Load list of files:
            string[] files;
            string   error = string.Empty;

            FileInfo[] baseRFiles = null;
            FileInfo[] newRFiles  = null;

            bool reportFailed = false;

            output op = new output(Output);

            totalRFiles  = 0;
            failedRFiles = 0;

            int totalFilings  = 0;
            int failedFilings = 0;

            baseList = new List <InstanceReport>();
            newList  = new List <InstanceReport>();

            //Allows the user to skip this proccess if they're simply rerunning the comparison.
            if (!SkipZip)
            {
                UnzipMove(baseDirs, out files, out error);
                UnzipMove(newDirs, out files, out error);
            }

            baseDirs = new DirectoryInfo(baseDirs.Parent.FullName + "\\Comparison");
            newDirs  = new DirectoryInfo(newDirs.Parent.FullName + "\\Comparison");

            DateTime renderStart = new DateTime();
            DateTime renderEnd   = new DateTime();

            int      renderCount = 0;
            TimeSpan totalRender = GetRenderTime(newDirs, out renderStart, out renderEnd, out renderCount);

            //List of unzipped instance doc directories:
            List <DirectoryInfo> allB = new List <DirectoryInfo>(baseDirs.GetDirectories());
            List <DirectoryInfo> allN = new List <DirectoryInfo>(newDirs.GetDirectories());

            allB.Sort(new CompareFileInfo());
            allN.Sort(new CompareFileInfo());

            //Sync the resources:
            Trace.TraceInformation("Information: Synchronizing resources. . .");
            XBRLReportBuilder.Utilities.RulesEngineUtils.SynchronizeResources();

            int minCount = Math.Min(allB.Count, allN.Count);

            DateTime compareStart = DateTime.Now;

            try
            {
                Trace.TraceInformation("Information: Starting the Comparison loop.");
                for (int i = 0; i <= minCount - 1; i++)
                {
                    reportFailed = false;
                    //Proccess current directory:
                    DirectoryInfo baseDirectory = allB.Find(ab => ab.Name == allN[i].Name);
                    DirectoryInfo newDirectory  = allN[i];

                    if (baseDirectory != null)
                    {
                        //get the Filing summary for the current filing.
                        List <ReportHeader> baseHeaders = returnHeaders(baseDirectory);
                        List <ReportHeader> newHeaders  = returnHeaders(newDirectory);

                        Trace.TraceInformation("Comparing report {0}:\t\t{1} of {2}", baseDirectory.Name, (i + 1).ToString(), minCount);

                        baseRFiles = gFiles(baseDirectory, "R*.xml");
                        newRFiles  = gFiles(newDirectory, "R*.xml");

                        reportName = baseDirectory.Name;
                        baseList.Clear();
                        newList.Clear();

                        try
                        {
                            //Trace.TraceInformation("Loading Files into memory.");
                            //Deserialize, load and sort the r files:
                            foreach (FileInfo file in baseRFiles)
                            {
                                LoadFiles(file, ref baseList);
                            }

                            foreach (FileInfo file in newRFiles)
                            {
                                LoadFiles(file, ref newList);
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceInformation("The following error occured while trying to load the R files for {0}: \n{1}", baseDirectory.Name, ex.Message);
                            RLogger.Error(string.Format("The following error occured while trying to load the R files for {0}: \n{1}", baseDirectory.Name, ex.Message));
                        }

                        //baseList and newList now has the list of the R files:

                        for (int j = 0; j <= baseList.Count - 1; j++)
                        {
                            //Trace.TraceInformation("Starting Instance Report Comparison Inner Loop.");
                            //Compare the actual R Files:
                            swCompare.Reset();
                            swCompare.Start();

                            //find the exact R file.
                            InstanceReport currentBase  = baseList[j];
                            string         baseLongName = WHITE_SPACE.Replace(currentBase.ReportLongName.Trim(), " ");
                            //string baseShortName = WHITE_SPACE.Replace( currentBase.ReportName.Trim(), " " );

                            InstanceReport currentNew = newList.Find(
                                nl =>
                                WHITE_SPACE.Replace(nl.ReportLongName.Trim(), " ") == baseLongName);

                            //try to match by report long name if it's there. If not, try by report name
                            if (currentNew != null)
                            {
                                string newLongName  = WHITE_SPACE.Replace(currentNew.ReportLongName.Trim(), " ");
                                string newShortName = WHITE_SPACE.Replace(currentNew.ReportName.Trim(), " ");
                                if (!string.IsNullOrEmpty(newLongName))
                                {
                                    workingHeader = baseHeaders.Find(
                                        bh =>
                                        WHITE_SPACE.Replace(bh.LongName.Trim(), " ") == newLongName);
                                }

                                if (workingHeader == null)
                                {
                                    workingHeader = baseHeaders.Find(
                                        bh =>
                                        WHITE_SPACE.Replace(bh.ShortName.Trim(), " ") == newShortName);
                                }

                                if (workingHeader != null && baseHTML)
                                {
                                    //build base html files. Skip if this already exists.
                                    string xmlFilename  = allB[i].FullName + "\\" + workingHeader.XmlFileName;
                                    string htmlFilename = xmlFilename + ".html";
                                    if (!File.Exists(htmlFilename))
                                    {
                                        this.HTML(currentBase, xmlFilename, htmlFilename);
                                    }
                                }

                                if (currentNew != null && workingHeader != null)
                                {
                                    //html.RFile = workingHeader.XmlFileName;

                                    string newPath = Path.Combine(newDirectory.FullName, workingHeader.XmlFileName);
                                    this.rFileLoc1 = Path.Combine(newDirectory.FullName, Path.GetFileNameWithoutExtension(newPath) + ".html");

                                    string basePath = Path.Combine(baseDirectory.FullName, workingHeader.XmlFileName);
                                    this.rFileLoc2 = Path.Combine(baseDirectory.FullName, Path.GetFileNameWithoutExtension(basePath) + ".html");

                                    if (!this.ReportCompare(currentBase, currentNew, basePath, newPath, compareStart, out error))
                                    {
                                        failedRFiles++;
                                        reportFailed = true;
                                    }
                                }
                                else
                                {
                                    RLogger.Error("New report does not contain a matching report name.");
                                    htmlStarter("New report does not contain a matching report name<br>New Report does not contain a matching report name.",
                                                compareStart, out error);
                                    failedRFiles++;
                                    reportFailed = true;
                                }

                                totalRFiles++;
                                TimeSpan seconds = TimeSpan.FromMilliseconds(swCompare.ElapsedMilliseconds);
                                swCompare.Stop();
                            }
                            else //if (currentNew == null)
                            {
                                RLogger.Info("The 'Current' report was null. Setting appropriate variables and closing the current R report.");
                                //Set the variables, write the log entry and save the HTML
                                workingHeader = baseHeaders.Find(bh => bh.LongName == baseList[j].ReportLongName);

                                rFileLoc1 = allN[i].FullName + "\\" +
                                            workingHeader.XmlFileName.Remove(workingHeader.XmlFileName.Length - 4) + ".html";

                                rFileLoc2 = baseDirectory.FullName + "\\" +
                                            workingHeader.XmlFileName.Remove(workingHeader.XmlFileName.Length - 4) + ".html";

                                htmlStarter("Could not match report name for this report<br>The 'new' report name could not be matched", compareStart, out error);
                                failedRFiles++;
                                reportFailed = true;
                            }
                        }

                        //finish up the last report:
                        if (reportFailed)
                        {
                            failedFilings++;
                        }
                        totalFilings++;

                        if (html.reportStarted)
                        {
                            html.EndReport();
                        }
                    }
                    else
                    {
                        RLogger.Error("Could not find matching directory.");
                        Trace.TraceWarning("Warning: Could not find matching directory.");
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("Error: An error occured trying to compare the following report {0}: \n{1}", reportName, ex.Message);
                RLogger.Error(string.Format("An error occured trying to compare the following report {0}: \n{1}", reportName, ex.Message));
            }

            DateTime compareEnd    = DateTime.Now;
            TimeSpan timeToCompare = compareEnd.Subtract(compareStart);

            //get render time:

            if (html.reportStarted)
            {
                html.EndReport();
            }

            html.BuildSummary(compareStart, compareEnd, minCount, failedFilings, totalRFiles, failedRFiles, timeToCompare, renderStart,
                              renderEnd, totalRender, renderCount);
            //string path = string.Format("{0}\\Logs\\AutoTesterLog-{1}.html", newDirs.Root.FullName, DateTime.Now.ToString("yyyy-MM-dd_hhmmss"));
            DirectoryInfo logPath = new DirectoryInfo(System.Configuration.ConfigurationManager.AppSettings["logPath"]);

            if (logPath.Exists)
            {
                string path = string.Format("{0}\\AutoTesterLog-{1}.html", logPath.FullName, DateTime.Now.ToString("yyyy-MM-dd_hhmmss"));
                HTML(html.html.ToString(), path);
            }
            else
            {
                Trace.TraceError("Error: Unable to write the HTML log file. Check to make sure the specified log directory exists.");
                RLogger.Error("Unable to write the HTML log file. Check to make sure the specified log directory exists.");
            }
        }
Exemple #8
0
        private bool CompareRowCells(
            InstanceReportRow baseRow, InstanceReportRow newRow,
            InstanceReport baseReport, InstanceReport newReport,
            string basePath, string newPath,
            int rowCount, DateTime reportDate, out string error)
        {
            error = string.Empty;
            //Row# {0}:'{1}' has unmatched data.<br>Expected Results: '{2}' Actual Results: '{3}'
            output op        = new output(Output);
            bool   retval    = true;
            string labelText = baseRow.Label.Replace("\r\n", " ");


            //if (!string.Equals( baseRow.ToString(), newRow.ToString(), StringComparison.InvariantCultureIgnoreCase ) )
            //{
            for (int i = 0; i < baseRow.Cells.Count; i++)
            {
                Cell baseCell = baseRow.Cells[i];
                Cell newCell  = newRow.Cells[i];

                if (baseCell.HasEmbeddedReport == newCell.HasEmbeddedReport)
                {
                    if (newCell.HasEmbeddedReport)
                    {
                        this.ReportCompare(baseCell.EmbeddedReport.InstanceReport, newCell.EmbeddedReport.InstanceReport,
                                           basePath, newPath, reportDate, out error);
                        continue;
                    }
                }
                else
                {
                    if (baseCell.HasEmbeddedReport)
                    {
                        this.htmlStarter("Unmatched embedded reports<br>BaseRep cell has an embedded report, but NewRep cell does not.", reportDate, out error);
                    }
                    else
                    {
                        this.htmlStarter("Unmatched embedded reports<br>NewRep cell has an embedded report, but BaseRep cell does not.", reportDate, out error);
                    }
                }

                string baseText = WHITE_SPACE.Replace(baseCell.ToString().Trim(), " ");
                string newText  = WHITE_SPACE.Replace(newCell.ToString().Trim(), " ");
                if (!string.Equals(baseText, newText, StringComparison.InvariantCultureIgnoreCase))
                {
                    retval = false;


                    htmlStarter(string.Format(mismatchCell,
                                              i.ToString(), labelText, baseRow.Cells[i].ToString(), newRow.Cells[i].ToString()), reportDate, out error);

                    if (errorID > 0)
                    {
                        //RLogger.Info(string.Format(debugParameters, baseReport.ReportName, newReport.ReportName, errorID, 464));
                        using (BaselineRules baseL = new BaselineRules(baseReport, newReport, errorID))
                        {
                            baseL.EvaluateUnmatchedDataError(rowCount);
                        }
                    }
                    else if (errorID == 0)
                    {
                        RLogger.Error("No error ID on " + baseReport.ReportName + " " + workingHeader.XmlFileName + " SQL DB returned 0");
                    }
                }

                if (!string.Equals(baseCell.FootnoteIndexer, newCell.FootnoteIndexer))
                {
                    retval = false;
                    htmlStarter(string.Format(mismatchCell,
                                              i.ToString(), labelText, "Footnotes: " + baseCell.FootnoteIndexer, "Footnotes: " + newCell.FootnoteIndexer), reportDate, out error);
                }
            }
            //}
            return(retval);
        }