Beispiel #1
0
        public bool BuildReports(string instanceFolder, string instanceName, string taxonomyName, out FilingSummary filingSummary, out string error)
        {
            Console.WriteLine("=================================================");
            Console.WriteLine("  BUILD " + instanceFolder + "...");
            Console.WriteLine("=================================================");

            this.processingTime = TimeSpan.Zero;
            DateTime startTime = DateTime.Now;

            string instance          = PathCombine(instanceFolder, instanceName + ".xml");
            string taxonomy          = PathCombine(instanceFolder, taxonomyName + ".xsd");
            string reportDir         = PathCombine(instanceFolder, "Reports");
            string filingSummaryPath = PathCombine(reportDir, "FilingSummary.xml");

            CleanAndPrepareFolder(reportDir);

            XRB.ReportBuilder myReportBuilder = new XRB.ReportBuilder();
            myReportBuilder.ReportFormat              = OutputFormat;
            myReportBuilder.HtmlReportFormat          = HtmlFormat;
            myReportBuilder.RemoteFileCachePolicy     = CachePolicy;
            myReportBuilder.OnBuildReportsProcessing += this.FireBuildReportsProcessing;
            myReportBuilder.OnBuildReportsProcessed  += this.FireBuildReportsProcessed;

            if (string.IsNullOrEmpty(ResourcePath))
            {
                RulesEngineUtils.SetBaseResourcePath(null);
            }
            else
            {
                RulesEngineUtils.SetBaseResourcePath(ResourcePath);
            }

            bool status = myReportBuilder.BuildReports(instance, taxonomy, filingSummaryPath, reportDir, out filingSummary, out error);

            this.myFilingSummary = status ? filingSummary : null;

            myReportBuilder.OnBuildReportsProcessing -= this.FireBuildReportsProcessing;
            myReportBuilder.OnBuildReportsProcessed  -= this.FireBuildReportsProcessed;

            DateTime endTime = DateTime.Now;

            this.processingTime = (endTime - startTime);

            return(status);
        }
Beispiel #2
0
        public void ProcessFiling(Filing f, bool isMultipleFilings)
        {
            executor.Invoke("Information: Preparing " + f.InstancePath);

            if (!File.Exists(f.InstancePath))
            {
                executor.Invoke("Error: Instance document not found at " + f.InstancePath + ".");
                executor.Invoke("\tSkipping filing: " + f.InstancePath);
                return;
            }

            Filing.SaveAs saveAs = Filing.SaveAs.Auto;
            bool          isZip  = string.Equals(Path.GetExtension(f.InstancePath), ".zip", StringComparison.CurrentCultureIgnoreCase);

            if (isZip)
            {
                saveAs = Filing.SaveAs.Zip;
                if (this.SaveAs == Filing.SaveAs.Xml)
                {
                    saveAs = Filing.SaveAs.Xml;
                }
            }
            else
            {
                saveAs = Filing.SaveAs.Xml;
                if (this.SaveAs == Filing.SaveAs.Zip)
                {
                    saveAs = Filing.SaveAs.Zip;
                }
            }

            string outputPath;
            string basePath = Path.GetDirectoryName(f.InstancePath);

            if (!this.GetOutputPath(basePath, saveAs, isMultipleFilings, f, out outputPath))
            {
                return;
            }

            string tmpPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(f.InstancePath));

            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }
            else
            {
                CleanPath(tmpPath);
            }

            try
            {
                if (isZip)
                {
                    string[] packageFiles;
                    if (!UnzipPackage(executor, f, tmpPath, out packageFiles))
                    {
                        return;
                    }

                    string taxonomy;
                    bool   instanceFound = false;
                    foreach (string file in packageFiles)
                    {
                        if (IsInstance(file, out taxonomy))
                        {
                            instanceFound  = true;
                            f.InstancePath = file;
                            f.TaxonomyPath = taxonomy;
                            break;
                        }
                    }

                    if (!instanceFound)
                    {
                        executor.Invoke("Error: The ZIP file does not contain an instance document.");
                        executor.Invoke("\tSkipping filing: " + f.InstancePath);
                        return;
                    }
                }
                else
                {
                    string taxonomyPath;
                    if (!this.IsInstance(f.InstancePath, out taxonomyPath))
                    {
                        executor.Invoke("Error: Instance document not found at " + f.InstancePath + ".");
                        executor.Invoke("\tSkipping filing: " + f.InstancePath);
                        return;
                    }

                    f.TaxonomyPath = taxonomyPath;
                }
                string        error;
                FilingSummary fs;
                string        reportsPath = isZip ? Path.Combine(tmpPath, "Reports") : tmpPath;
                string        fsPath      = Path.Combine(reportsPath, FilingSummary.FilingSummaryXmlName);

                XRB.ReportBuilder rb = new XRB.ReportBuilder(executor, RulesEngineUtils.DefaultRulesFile, this.ReportFormat, this.HtmlReportFormat);
                rb.CurrencyMappingFile   = this.CurrencyMappingFile;
                rb.RemoteFileCachePolicy = this.RemoteFileCachePolicy;
                rb.XsltStylesheetPath    = this.XsltStylesheetPath;

                if (!rb.BuildReports(f.InstancePath, f.TaxonomyPath, fsPath, reportsPath, out fs, out error))
                {
                    executor.Invoke("Unexpected error: " + error);
                    executor.Invoke("\tFailed filing: " + f.InstancePath);
                }

                if (saveAs == Filing.SaveAs.Xml)
                {
                    foreach (string copyFrom in Directory.GetFiles(reportsPath))
                    {
                        string copyTo = Path.Combine(outputPath, Path.GetFileName(copyFrom));
                        File.Copy(copyFrom, copyTo);
                    }
                }
                else
                {
                    string[] reports = Directory.GetFiles(reportsPath);
                    this.ZipReports(outputPath, reports);
                }

                executor.Invoke("Information: Reports successfully created.");
                executor.Invoke("\t" + (fs.MyReports.Count - 1) + " reports created at " + outputPath + ".");
                if (string.IsNullOrEmpty(error))
                {
                    executor.Invoke("reload");
                }
            }
            catch (Exception ex)
            {
                executor.Invoke("Unexpected error: " + ex.Message);
            }
            finally
            {
                CleanPath(tmpPath);
            }
        }
        public bool BuildReports(FilingInfo filing)
        {
            string instancePath = GetInstanceDocPath(filing);
            if (string.IsNullOrEmpty(instancePath) ||
                !File.Exists(instancePath))
            {
                myEventLog.WriteEntry("Can not find instance document for filing: " + filing.AccessionNumber);
                return false;
            }

            string taxonomyPath = GetTaxonomyPath(filing);
            if (string.IsNullOrEmpty(taxonomyPath) ||
                !File.Exists(taxonomyPath))
            {
                myEventLog.WriteEntry("Can not find taxonomy file for filing: " + filing.AccessionNumber);
                return false;
            }

            ReportBuilder rb = new ReportBuilder();

            string reportPath = string.Format("{0}{1}{2}", reportsFolder, Path.DirectorySeparatorChar, filing.AccessionNumber);
            string filingFile = string.Format("{0}{1}{2}", reportPath, Path.DirectorySeparatorChar, FilingSummary._FilingSummaryXmlName);

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

            //TODO:  get this info from the manifest once we have it
            //rb.PeriodEnding = filing.period_ending;
            //rb.FilingDate = filing.filing_date;
            //rb.TickerSymbol = filing.ticker_symbol;
            //rb.CompanyName = filing.company_name;
            //rb.AccessionNumber = filing.accession_number;
            //rb.FiscalYearEnd = filing.fiscal_year_end;

            string error = null;
            FilingSummary summary = null;
            if (!rb.BuildReports(instancePath, taxonomyPath, filingFile, reportPath, filing.FormType, out summary, out error))
            {
                myEventLog.WriteEntry("build reports failed! " + error, EventLogEntryType.Error);
                return false;
            }
            //Increment the number of filings that were successfully process.  This needs to be done
            //using Interlocked because other worker threads could be accessing the property as well
            Interlocked.Increment(ref completedFilings);
            return true;
        }
Beispiel #4
0
        public bool BuildReports( string instanceFolder, string instanceName, string taxonomyName, string formType, out FilingSummary filingSummary, out string error )
        {
            Console.WriteLine( "=================================================" );
            Console.WriteLine( "  BUILD " + instanceFolder + "..." );
            Console.WriteLine( "=================================================" );

            this.processingTime = TimeSpan.Zero;
            DateTime startTime = DateTime.Now;

            string instance = PathCombine( instanceFolder, instanceName + ".xml" );
            string taxonomy = PathCombine( instanceFolder, taxonomyName + ".xsd" );
            string reportDir = PathCombine( instanceFolder, "Reports" );
            string filingSummaryPath = PathCombine( reportDir, "FilingSummary.xml" );

            CleanFolder( reportDir );

            XRB.ReportBuilder myReportBuilder = new XRB.ReportBuilder();
            myReportBuilder.ReportFormat = RB_Tests.OutputFormat;
            myReportBuilder.HtmlReportFormat = RB_Tests.HtmlFormat;
            myReportBuilder.RemoteFileCachePolicy = RB_Tests.CachePolicy;

            if( string.IsNullOrEmpty( RB_Tests.ResourcePath ) )
                RulesEngineUtils.SetBaseResourcePath( null );
            else
                RulesEngineUtils.SetBaseResourcePath( RB_Tests.ResourcePath );

            bool status = myReportBuilder.BuildReports( instance, taxonomy, filingSummaryPath, reportDir, formType, out filingSummary, out error );
            this.myFilingSummary = status ? filingSummary : null;

            DateTime endTime = DateTime.Now;
            this.processingTime = ( endTime - startTime );

            return status;
        }
Beispiel #5
0
        public void ProcessFiling( Filing f, bool isMultipleFilings )
        {
            executor.Invoke( "Information: Preparing " + f.InstancePath );

            if( !File.Exists( f.InstancePath ) )
            {
                executor.Invoke( "Error: Instance document not found at " + f.InstancePath + "." );
                executor.Invoke( "\tSkipping filing: " + f.InstancePath );
                return;
            }

            Filing.SaveAs saveAs = Filing.SaveAs.Auto;
            bool isZip = string.Equals( Path.GetExtension( f.InstancePath ), ".zip", StringComparison.CurrentCultureIgnoreCase );
            if( isZip )
            {
                saveAs = Filing.SaveAs.Zip;
                if( this.SaveAs == Filing.SaveAs.Xml )
                    saveAs = Filing.SaveAs.Xml;
            }
            else
            {
                saveAs = Filing.SaveAs.Xml;
                if( this.SaveAs == Filing.SaveAs.Zip )
                    saveAs = Filing.SaveAs.Zip;
            }

            string outputPath;
            string basePath = Path.GetDirectoryName( f.InstancePath );
            if( !this.GetOutputPath( basePath, saveAs, isMultipleFilings, f, out outputPath ) )
                return;

            string tmpPath = Path.Combine( Path.GetTempPath(), Path.GetFileNameWithoutExtension( f.InstancePath ) );
            if( !Directory.Exists( tmpPath ) )
                Directory.CreateDirectory( tmpPath );
            else
                CleanPath( tmpPath );

            try
            {
                if( isZip )
                {
                    string[] packageFiles;
                    if( !UnzipPackage(executor, f, tmpPath, out packageFiles ) )
                        return;

                    string taxonomy;
                    bool instanceFound = false;
                    foreach( string file in packageFiles )
                    {
                        if( IsInstance( file, out taxonomy ) )
                        {
                            instanceFound = true;
                            f.InstancePath = file;
                            f.TaxonomyPath = taxonomy;
                            break;
                        }
                    }

                    if( !instanceFound )
                    {
                        executor.Invoke( "Error: The ZIP file does not contain an instance document." );
                        executor.Invoke( "\tSkipping filing: " + f.InstancePath );
                        return;
                    }
                }
                else
                {
                    string taxonomyPath;
                    if( !this.IsInstance( f.InstancePath, out taxonomyPath ) )
                    {
                        executor.Invoke( "Error: Instance document not found at " + f.InstancePath + "." );
                        executor.Invoke( "\tSkipping filing: " + f.InstancePath );
                        return;
                    }

                    f.TaxonomyPath = taxonomyPath;
                }
                string error;
                FilingSummary fs;
                string reportsPath = isZip ? Path.Combine( tmpPath, "Reports" ) : tmpPath;
                string fsPath = Path.Combine( reportsPath, FilingSummary.FilingSummaryXmlName );

                XRB.ReportBuilder rb = new XRB.ReportBuilder(executor, RulesEngineUtils.DefaultRulesFile, this.ReportFormat, this.HtmlReportFormat );
                rb.CurrencyMappingFile = this.CurrencyMappingFile;
                rb.RemoteFileCachePolicy = this.RemoteFileCachePolicy;
                rb.XsltStylesheetPath = this.XsltStylesheetPath;

                if( !rb.BuildReports( f.InstancePath, f.TaxonomyPath, fsPath, reportsPath, out fs, out error ) )
                {
                    executor.Invoke( "Unexpected error: " + error );
                    executor.Invoke( "\tFailed filing: " + f.InstancePath );
                }

                if( saveAs == Filing.SaveAs.Xml )
                {
                    foreach( string copyFrom in Directory.GetFiles( reportsPath ) )
                    {
                        string copyTo = Path.Combine( outputPath, Path.GetFileName( copyFrom ) );
                        File.Copy( copyFrom, copyTo );
                    }
                }
                else
                {
                    string[] reports = Directory.GetFiles( reportsPath );
                    this.ZipReports( outputPath, reports );
                }

                executor.Invoke( "Information: Reports successfully created." );
                executor.Invoke( "\t" + ( fs.MyReports.Count - 1 ) + " reports created at " + outputPath + "." );
                if (string.IsNullOrEmpty(error))
                {
                    executor.Invoke("reload");
                }
            }
            catch( Exception ex )
            {
                executor.Invoke( "Unexpected error: " + ex.Message );
            }
            finally
            {
                CleanPath( tmpPath );
            }
        }
        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;
        }