Esempio n. 1
0
        public void TestGetInstanceDocPath()
        {
            string[][] testFilings = new string[10][];
            testFilings[0] = new string[] { "0000008670-08-000046", "adp-20080331.xml" };
            testFilings[1] = new string[] { "0000040545-08-000037", "ge-20080630.xml" };
            testFilings[2] = new string[] { "0000796343-08-000005", "adbe-20080616.xml" };
            testFilings[3] = new string[] { "0000893220-08-002188", "dd-20080630.xml" };
            testFilings[4] = new string[] { "0000950133-08-003012", "nihd-20080331.xml" };
            testFilings[5] = new string[] { "0000950135-08-002601", "gis-20080224.xml" };
            testFilings[6] = new string[] { "0000950135-08-003083", "dd-20080331.xml" };
            testFilings[7] = new string[] { "0000950135-08-004978", "trow-20071231.xml" };
            testFilings[8] = new string[] { "0000950137-08-010830", "gis-20080525.xml" };
            testFilings[9] = new string[] { "0000950137-08-012088", "gis-20080824.xml" };

            List <string> errors = new List <string>();

            foreach (string[] filing in testFilings)
            {
                FilingInfo fi = new FilingInfo();
                fi.AccessionNumber = filing[0];
                fi.ParentFolder    = testRoot;
                string instanceDocPath = fi.GetInstanceDocPath();

                string expectedPath = string.Format("{0}{1}{2}{1}{3}", testRoot, System.IO.Path.DirectorySeparatorChar, filing[0], filing[1]);

                if (!expectedPath.Equals(instanceDocPath, StringComparison.CurrentCultureIgnoreCase))
                {
                    errors.Add("Paths do not match.  Expected: '" + expectedPath + "'. Actual: '" + instanceDocPath + "'");
                }
            }

            if (errors.Count > 0)
            {
                string strErrors = string.Join(Environment.NewLine + "\t", errors.ToArray());
                Assert.Fail("The following errors were found: " + Environment.NewLine + "\t" + strErrors);
            }
        }
Esempio n. 2
0
        public void TestGetInstanceDocPath()
        {
            string[][] testFilings = new string[10][];
            testFilings[0] = new string[] { "0000008670-08-000046", "adp-20080331.xml" };
            testFilings[1] = new string[] { "0000040545-08-000037", "ge-20080630.xml" };
            testFilings[2] = new string[] { "0000796343-08-000005", "adbe-20080616.xml" };
            testFilings[3] = new string[] { "0000893220-08-002188", "dd-20080630.xml" };
            testFilings[4] = new string[] { "0000950133-08-003012", "nihd-20080331.xml" };
            testFilings[5] = new string[] { "0000950135-08-002601", "gis-20080224.xml" };
            testFilings[6] = new string[] { "0000950135-08-003083", "dd-20080331.xml" };
            testFilings[7] = new string[] { "0000950135-08-004978", "trow-20071231.xml" };
            testFilings[8] = new string[] { "0000950137-08-010830", "gis-20080525.xml" };
            testFilings[9] = new string[] { "0000950137-08-012088", "gis-20080824.xml" };

            List<string> errors = new List<string>();
            foreach (string[] filing in testFilings)
            {
                FilingInfo fi = new FilingInfo();
                fi.AccessionNumber = filing[0];
                fi.ParentFolder = testRoot;
                string instanceDocPath = fi.GetInstanceDocPath();

                string expectedPath = string.Format("{0}{1}{2}{1}{3}", testRoot, System.IO.Path.DirectorySeparatorChar, filing[0], filing[1]);

                if (!expectedPath.Equals(instanceDocPath, StringComparison.CurrentCultureIgnoreCase))
                {
                    errors.Add("Paths do not match.  Expected: '" + expectedPath + "'. Actual: '" + instanceDocPath + "'");
                }
            }

            if (errors.Count > 0)
            {
                string strErrors = string.Join(Environment.NewLine + "\t", errors.ToArray());
                Assert.Fail("The following errors were found: " + Environment.NewLine + "\t" + strErrors);
            }
        }
Esempio n. 3
0
        protected bool BuildReports(FilingInfo filing, string reportsFolder, out string error)
        {
            error = null;

            bool   foundFiles = true;
            string errorMsg   = string.Empty;

            string filingPath        = Path.Combine(filing.ParentFolder, filing.AccessionNumber);
            string filingReportsPath = Path.Combine(filingPath, "Reports");
            string filingErrorFile   = Path.Combine(filingReportsPath, ERROR_FILE_NAME);

            string instancePath = filing.GetInstanceDocPath();
            string taxonomyPath = filing.GetTaxonomyPath();

            if (string.IsNullOrEmpty(instancePath) ||
                !File.Exists(instancePath))
            {
                errorMsg = string.Format("Can not find instance document for filing: {0}", filing.AccessionNumber);
                FilingProcessorManager.TheMgr.WriteLogEntry(errorMsg, EventLogEntryType.Error);
                foundFiles = false;
            }
            else if (string.IsNullOrEmpty(taxonomyPath) ||
                     !File.Exists(taxonomyPath))
            {
                errorMsg = string.Format("Can not find taxonomy file for filing: {0}", filing.AccessionNumber);
                FilingProcessorManager.TheMgr.WriteLogEntry(errorMsg, EventLogEntryType.Error);
                foundFiles = false;
            }

            bool buildSucceeded = false;

            if (foundFiles)
            {
                string baseResourcePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                FilingProcessorManager.TheMgr.WriteLogEntry(string.Format("Setting base path for Rules Engine. Path: {0}", baseResourcePath), EventLogEntryType.Information);

                RulesEngineUtils.SetBaseResourcePath(baseResourcePath);
                ReportBuilder.SetSynchronizedResources(true);

                FilingProcessorManager.TheMgr.WriteLogEntry("Selected rule file: '" + FinancialRuleFile + "' for instance document: '" + Path.GetFileName(instancePath) + "'", EventLogEntryType.Information);

                ReportBuilder rb = new ReportBuilder(FinancialRuleFile, ReportFormat, HtmlReportFormat);
                rb.CurrencyMappingFile   = CurrencyMappingFile;
                rb.RemoteFileCachePolicy = RemoteFileCachePolicy;

                //if( XmlCatalog != null )
                //	rb.XmlCatalog = XmlCatalog;

                //Reports will be saves under the Filing's Processing folder then copied out to the actual reports folder,
                //this will allow us to only copy complete sets of R files to the Reports Folder.
                string filingSummaryFile = string.Format("{0}{1}{2}", filingReportsPath, Path.DirectorySeparatorChar, FilingSummary.FilingSummaryXmlName);

                //Make sure there is a clean folder where the reports will be written to.
                if (Directory.Exists(filingReportsPath))
                {
                    Directory.Delete(filingReportsPath, true);
                }

                Directory.CreateDirectory(filingReportsPath);
                FilingSummary summary = null;
                buildSucceeded = rb.BuildReports(instancePath, taxonomyPath, filingSummaryFile, filingReportsPath, out summary, out error);

                if (!buildSucceeded)
                {
                    errorMsg = string.Format("Call to BuildReports failed for Filing {0}: {1}", filing.AccessionNumber, error);
                    FilingProcessorManager.TheMgr.WriteLogEntry(errorMsg, EventLogEntryType.Error);

                    if (!Directory.Exists(filingReportsPath))
                    {
                        Directory.CreateDirectory(filingReportsPath);
                    }

                    File.WriteAllText(filingErrorFile, errorMsg);
                }
            }
            else
            {
                if (!Directory.Exists(filingReportsPath))
                {
                    Directory.CreateDirectory(filingReportsPath);
                }

                File.WriteAllText(filingErrorFile, errorMsg);
            }

            try
            {
                string errorFileName   = filing.AccessionNumber + "_" + Path.GetFileName(filingErrorFile);
                string reportErrorFile = Path.Combine(reportsFolder, errorFileName);
                string reportZipFile   = Path.Combine(reportsFolder, filing.AccessionNumber + ".zip");
                if (File.Exists(reportErrorFile))
                {
                    FileUtilities.DeleteFile(new FileInfo(reportErrorFile), true);
                }

                if (File.Exists(reportZipFile))
                {
                    FileUtilities.DeleteFile(new FileInfo(reportZipFile), true);
                }

                if (buildSucceeded)
                {
                    string[] filePathsToZip = Directory.GetFiles(filingReportsPath);
                    string[] filesToZip     = new string[filePathsToZip.Length];
                    for (int i = 0; i < filesToZip.Length; i++)
                    {
                        filesToZip[i] = Path.GetFileName(filePathsToZip[i]);
                    }

                    string zipFile = Path.Combine(filingReportsPath, filing.AccessionNumber + ".zip");
                    if (ZipUtilities.TryZipAndCompressFiles(zipFile, filingReportsPath, filesToZip))
                    {
                        File.Copy(zipFile, reportZipFile);
                    }
                }
                else
                {
                    File.Copy(filingErrorFile, reportErrorFile);
                }

                if (DeleteProcessedFilings)
                {
                    DirectoryInfo di = new DirectoryInfo(filingPath);
                    FileUtilities.DeleteDirectory(di, true, true);

                    di = new DirectoryInfo(filing.ParentFolder);
                    if (di.GetDirectories().Length == 0 && di.GetFiles().Length == 0)
                    {
                        FileUtilities.DeleteDirectory(di, true, true);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            if (buildSucceeded)
            {
                FilingProcessorManager.TheMgr.IncrementCompletedCount();
            }

            return(buildSucceeded);
        }