public RulesHolder() { ReportBuilder neverUsed = new ReportBuilder(); //CleanupFlowthroughColumns.xml neverUsed.CleanupFlowThroughColumns(); bool isNewGAAP = neverUsed.IsNewGAAP; bool isGAAP2005 = neverUsed.IsGAAP2005; //CleanupFlowthroughReports.xml neverUsed.CleanupFlowThroughReports(); isGAAP2005 = neverUsed.IsGAAP2005; //DisplayAsRatio.xml neverUsed.CurrentElementName += neverUsed.CurrentElementName; neverUsed.IsRatioElement |= neverUsed.IsRatioElement; //DisplayZeroAsNone.xml neverUsed.CurrentElementName += neverUsed.CurrentElementName; neverUsed.IsZeroAsNoneElement |= neverUsed.IsZeroAsNoneElement; //TotalLabel.xml string currentRowPreferredLabelRole = neverUsed.CurrentRowPreferredLabelRole; InstanceReport neverUsedReport = new InstanceReport(); //ColumnHeaders.xml neverUsedReport.SetCalendarLabels(null, null); //CurrencySymbol.xml neverUsedReport.AssignCurrencySymbol(); //EquityStatement.xml neverUsedReport.ProcessEquity(null, null, null); //InstantAndDuration.xml neverUsedReport.ProcessMergeInstanceDuration_Rule(null); //ProcessBeginningEndingBalances.xml neverUsedReport.ProcessBeginningAndEndingBalances(); //PromoteSharedLabels.xml neverUsedReport.GetSegmentScenarioLabels(); neverUsedReport.GetCurrencyLabels(); neverUsedReport.GetSharedSegmentsAndScenariosLabel(null); neverUsedReport.GetSharedCurrencyLabel(null); neverUsedReport.ConcatenateSharedLabels(null, null); //Rounding.xml neverUsedReport.EvaluateRoundingLevels(null); neverUsedReport.SetRoundingOption(null, null, null, null, null, null, null, null); //Segments.xml neverUsedReport.ProcessSegments_Rule(null); }
public RulesHolder() { ReportBuilder neverUsed = new ReportBuilder(); //CleanupFlowthroughColumns.xml neverUsed.CleanupFlowThroughColumns(); bool isNewGAAP = neverUsed.IsNewGAAP; bool isGAAP2005 = neverUsed.IsGAAP2005; //CleanupFlowthroughReports.xml neverUsed.CleanupFlowThroughReports(); isGAAP2005 = neverUsed.IsGAAP2005; //DisplayAsRatio.xml neverUsed.CurrentElementName += neverUsed.CurrentElementName; neverUsed.IsRatioElement |= neverUsed.IsRatioElement; //DisplayZeroAsNone.xml neverUsed.CurrentElementName += neverUsed.CurrentElementName; neverUsed.IsZeroAsNoneElement |= neverUsed.IsZeroAsNoneElement; //TotalLabel.xml string currentRowPreferredLabelRole = neverUsed.CurrentRowPreferredLabelRole; InstanceReport neverUsedReport = new InstanceReport(); //ColumnHeaders.xml neverUsedReport.SetCalendarLabels( null, null ); //CurrencySymbol.xml neverUsedReport.AssignCurrencySymbol(); //EquityStatement.xml neverUsedReport.ProcessEquity(null, null, null); //InstantAndDuration.xml neverUsedReport.ProcessMergeInstanceDuration_Rule(null); //ProcessBeginningEndingBalances.xml neverUsedReport.ProcessBeginningAndEndingBalances(); //PromoteSharedLabels.xml neverUsedReport.GetSegmentScenarioLabels(); neverUsedReport.GetCurrencyLabels(); neverUsedReport.GetSharedSegmentsAndScenariosLabel(null); neverUsedReport.GetSharedCurrencyLabel(null); neverUsedReport.ConcatenateSharedLabels(null, null); //Rounding.xml neverUsedReport.EvaluateRoundingLevels(null); neverUsedReport.SetRoundingOption(null, null, null, null, null, null, null, null); //Segments.xml neverUsedReport.ProcessSegments_Rule(null); }
private void WriteMonetary(ref int roundingLevels, StringBuilder sbRoundingOption, RoundingLevel roundingMonetary, string uniformRoundingString) { //nothing to see here if (roundingMonetary <= RoundingLevel.NoRounding) { return; } roundingLevels++; string stLevel = ReportBuilder.GetRoundingLevelString(roundingMonetary); sbRoundingOption.Append(string.Format(uniformRoundingString, stLevel)); }
private void WritePerShare(ref int roundingLevels, StringBuilder sbRoundingOption, RoundingLevel roundingMonetary, RoundingLevel roundingShares, RoundingLevel roundingPerShare, string perShareNoRoundingString, string perShareRoundingString, string otherRoundingString) { //nothing to see here if (roundingPerShare == RoundingLevel.UnKnown) { return; } //still nothing to see here if (roundingLevels == 0) { return; } //if we are equal, this value has already been set if (roundingPerShare == roundingShares) { return; } if (roundingLevels == 1) { sbRoundingOption.Append(", except "); if (roundingPerShare == RoundingLevel.NoRounding) { sbRoundingOption.Append(perShareNoRoundingString); } else { string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares); sbRoundingOption.Append(string.Format(perShareRoundingString, stLevel)); } } else //2 { //if we are equal, this value has already been set if (roundingPerShare == roundingMonetary) { return; } sbRoundingOption.Append(", " + otherRoundingString); } roundingLevels++; }
//[Description( "SEC 140" )] public void Test_29039() { Test_Abstract.OutputFormat = (Test_Abstract.OutputFormat & ReportFormat.Xml) | ReportFormat.Html; Test_Abstract.HtmlFormat = HtmlReportFormat.Complete; const string accessionNumber = "29039"; string reportsFolder = PathCombine(this.baseDir, accessionNumber, "Reports"); CleanAndPrepareFolder(reportsFolder); string resultsFolder = PathCombine(this.baseDir, accessionNumber, "Results"); FilingSummary fs = new FilingSummary(); foreach (string from in Directory.GetFiles(resultsFolder, "R1_*.xml")) { string file = Path.GetFileName(from); string to = PathCombine(reportsFolder, file); FileUtilities.Copy(from, to); ReportHeader header = new ReportHeader(file, file); fs.MyReports.Add(header); } XRB.ReportBuilder rb = new XRB.ReportBuilder(); rb.ReportFormat = ReportFormat.Html; rb.HtmlReportFormat = HtmlReportFormat.Complete; rb.GetType().GetField("currentFilingSummary", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(rb, fs); rb.GetType().GetField("currentReportDirectory", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(rb, reportsFolder); rb.GetType().GetMethod("GenerateHtmlFiles", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(rb, null); foreach (string file in Directory.GetFiles(reportsFolder, "R1_*.htm")) { string html = File.ReadAllText(file); int start = html.IndexOf("<body"); int end = html.IndexOf("</body"); end = html.IndexOf('>', end) + 1; html = html.Substring(start, end - start); html = html.Replace("<br>", "<br />"); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(html); XmlNodeList headerRows = xDoc.SelectNodes("/body/table/tr[ th ]"); Assert.AreEqual(2, headerRows.Count, "The transform must generate 2 headers rows for the right display."); } }
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); }
private RoundingLevel GetNormalizedRoundingLevel(RoundingLevel roundingLevel) { switch (roundingLevel) { case RoundingLevel.UnKnown: case RoundingLevel.NoRounding: return(roundingLevel); } try { string levelStr = ReportBuilder.GetRoundingLevelString(roundingLevel); return((RoundingLevel)Enum.Parse(typeof(RoundingLevel), levelStr)); } catch { } return(RoundingLevel.UnKnown); }
public void Test_29039() { Test_Abstract.OutputFormat = ( Test_Abstract.OutputFormat & ReportFormat.Xml ) | ReportFormat.Html; Test_Abstract.HtmlFormat = HtmlReportFormat.Complete; const string accessionNumber = "29039"; string reportsFolder = PathCombine( this.baseDir, accessionNumber, "Reports" ); CleanAndPrepareFolder( reportsFolder ); string resultsFolder = PathCombine( this.baseDir, accessionNumber, "Results" ); FilingSummary fs = new FilingSummary(); foreach( string from in Directory.GetFiles( resultsFolder, "R1_*.xml" ) ) { string file = Path.GetFileName( from ); string to = PathCombine( reportsFolder, file ); FileUtilities.Copy( from, to ); ReportHeader header = new ReportHeader( file, file ); fs.MyReports.Add( header ); } XRB.ReportBuilder rb = new XRB.ReportBuilder(); rb.ReportFormat = ReportFormat.Html; rb.HtmlReportFormat = HtmlReportFormat.Complete; rb.GetType().GetField( "currentFilingSummary", BindingFlags.NonPublic | BindingFlags.Instance ).SetValue( rb, fs ); rb.GetType().GetField( "currentReportDirectory", BindingFlags.NonPublic | BindingFlags.Instance ).SetValue( rb, reportsFolder ); rb.GetType().GetMethod( "GenerateHtmlFiles", BindingFlags.NonPublic | BindingFlags.Instance ).Invoke( rb, null ); foreach( string file in Directory.GetFiles( reportsFolder, "R1_*.htm" ) ) { string html = File.ReadAllText( file ); int start = html.IndexOf( "<body" ); int end = html.IndexOf( "</body" ); end = html.IndexOf( '>', end ) + 1; html = html.Substring( start, end - start ); html = html.Replace( "<br>", "<br />" ); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml( html ); XmlNodeList headerRows = xDoc.SelectNodes( "/body/table/tr[ th ]" ); Assert.AreEqual( 2, headerRows.Count, "The transform must generate 2 headers rows for the right display." ); } }
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; }
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; }
public void SetRoundingOption( string uniformRoundingString, string sharesNoRoundingString, string sharesRoundingString, string bothSharesNoRoundingString, string bothSharesRoundingString, string perShareNoRoundingString, string perShareRoundingString, string otherRoundingString) { if (uniformRoundingString.Split(new string[] { ROUNDING_LEVEL_PLACEHOLDER }, StringSplitOptions.None).Length > 2) { throw new Exception("Invalid format for uniformRoundingString"); } else { uniformRoundingString = uniformRoundingString.Replace(ROUNDING_LEVEL_PLACEHOLDER, "{0}"); } if (sharesRoundingString.Split(new string[] { ROUNDING_LEVEL_PLACEHOLDER }, StringSplitOptions.None).Length > 2) { throw new Exception("Invalid format for shareRoundingString"); } else { sharesRoundingString = sharesRoundingString.Replace(ROUNDING_LEVEL_PLACEHOLDER, "{0}"); } if (bothSharesRoundingString.Split(new string[] { ROUNDING_LEVEL_PLACEHOLDER }, StringSplitOptions.None).Length > 2) { throw new Exception("Invalid format for shareRoundingString"); } else { bothSharesRoundingString = bothSharesRoundingString.Replace(ROUNDING_LEVEL_PLACEHOLDER, "{0}"); } //Let's get the simple scenarios out of the way... //#1 - If all of the "known" items are of the same scale, then return that scale Dictionary <RoundingLevel, int> levels = new Dictionary <RoundingLevel, int>(); //Store the normalized value RoundingLevel roundingMonetary = GetNormalizedRoundingLevel(this.MonetaryRoundingLevel); levels[roundingMonetary] = 1; //monetary RoundingLevel roundingShares = GetNormalizedRoundingLevel(this.SharesRoundingLevel); levels[roundingShares] = 1; //shares RoundingLevel roundingPerShare = GetNormalizedRoundingLevel(this.PerShareRoundingLevel); levels[roundingPerShare] = 1; //per share levels.Remove(RoundingLevel.UnKnown); if (levels.Count == 0) { //All values were unknown this.RoundingOption = string.Empty; return; } //if we only have 1 distinct level, return that value in order of precedence if (levels.Count == 1) { RoundingLevel[] tmpLevel = new RoundingLevel[1]; levels.Keys.CopyTo(tmpLevel, 0); RoundingLevel level = tmpLevel[0]; if (level == RoundingLevel.NoRounding) { //All values were whole numbers this.RoundingOption = string.Empty; return; } if (level == roundingMonetary) { string stLevel = ReportBuilder.GetRoundingLevelString(roundingMonetary); this.RoundingOption = string.Format(uniformRoundingString, stLevel); if (this.HasCustomUnits) { this.RoundingOption += ", " + otherRoundingString; } return; } if (level == roundingShares) { string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares); this.RoundingOption = string.Format(uniformRoundingString, stLevel); if (this.HasCustomUnits) { this.RoundingOption += ", " + otherRoundingString; } return; } } int roundingLevels = 0; StringBuilder sbRoundingOption = new StringBuilder(); WriteMonetary(ref roundingLevels, sbRoundingOption, roundingMonetary, uniformRoundingString); WriteShares(ref roundingLevels, sbRoundingOption, roundingMonetary, roundingShares, roundingPerShare, uniformRoundingString, sharesNoRoundingString, sharesRoundingString, bothSharesNoRoundingString, bothSharesRoundingString); if (this.HasCustomUnits) { //The`otherRoundingString` should be the final string //Increasing the `roundingLevel` negates the possibility of entering the "per share" block // it also negates the possibility of duplicates below if (roundingLevels == 2) { roundingLevels = 3; sbRoundingOption.Append(", " + otherRoundingString); } else if (roundingLevels == 1) { if (roundingPerShare == RoundingLevel.UnKnown || roundingPerShare == roundingShares) { roundingLevels = 3; sbRoundingOption.Append(", " + otherRoundingString); } } } if (roundingLevels < 3) { WritePerShare(ref roundingLevels, sbRoundingOption, roundingMonetary, roundingShares, roundingPerShare, perShareNoRoundingString, perShareRoundingString, otherRoundingString); } if (this.HasCustomUnits) { if (roundingLevels == 2) { sbRoundingOption.Append(", " + otherRoundingString); } } this.RoundingOption = sbRoundingOption.ToString(); }
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; }
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 ); } }
void Test_29029_1_Rule_Change(object sender, EventArgs e) { XRB.ReportBuilder rb = sender as XRB.ReportBuilder; // Only turn this on if not running multiple tests // rb.BuilderRules.MyRules[ RulesEngineUtils.DISPLAY_US_DATE_FORMAT ].Enabled = false; }
private void WriteShares(ref int roundingLevels, StringBuilder sbRoundingOption, RoundingLevel roundingMonetary, RoundingLevel roundingShares, RoundingLevel roundingPerShare, string uniformRoundingString, string sharesNoRoundingString, string sharesRoundingString, string bothSharesNoRoundingString, string bothSharesRoundingString) { //nothing to see here if (roundingShares == RoundingLevel.UnKnown) { return; } //if we are equal, this value has already been set if (roundingShares == roundingMonetary) { return; } //if not monetary, and not shares, do not set the rounding if (roundingMonetary <= RoundingLevel.NoRounding && roundingShares <= RoundingLevel.NoRounding) { return; } //write out the "uniform" rounding string if (roundingMonetary == RoundingLevel.UnKnown && roundingShares > RoundingLevel.NoRounding) { roundingLevels++; string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares); sbRoundingOption.Append(string.Format(uniformRoundingString, stLevel)); return; } if (roundingMonetary == RoundingLevel.NoRounding && roundingShares > RoundingLevel.NoRounding) { if (roundingShares != roundingPerShare) { string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares); sbRoundingOption.Append(string.Format(sharesRoundingString, stLevel)); } else { string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares); sbRoundingOption.Append(string.Format(bothSharesRoundingString, stLevel)); } roundingLevels++; return; } if (roundingMonetary > RoundingLevel.NoRounding) { //the scenario where these match is covered above if (roundingShares > RoundingLevel.UnKnown) { sbRoundingOption.Append(", except "); } if (roundingShares == RoundingLevel.NoRounding) { if (roundingPerShare == RoundingLevel.NoRounding) { sbRoundingOption.Append(bothSharesNoRoundingString); } else { sbRoundingOption.Append(sharesNoRoundingString); } } else { if (roundingShares == roundingPerShare) { string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares); sbRoundingOption.Append(string.Format(bothSharesRoundingString, stLevel)); } else { string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares); sbRoundingOption.Append(string.Format(sharesRoundingString, stLevel)); } } roundingLevels++; return; } }
private bool ProcessMultiCurrencyMaps(List <ColumnInstantDurationMap> columnMaps) { this.SynchronizeGrid(); //let's put this way to the right int maxColumnId = this.Columns.Count + 5; //first, convert the duration index to the duration ID //also, lookup and store the instant columns Dictionary <int, List <InstanceReportColumn> > durIdToInstantCols = new Dictionary <int, List <InstanceReportColumn> >(); foreach (ColumnInstantDurationMap colMap in columnMaps) { int durID = this.Columns[colMap.DurationColumnIndex].Id; if (!durIdToInstantCols.ContainsKey(durID)) { durIdToInstantCols[durID] = new List <InstanceReportColumn>(); } durIdToInstantCols[durID].Add(this.Columns[colMap.InstantColumnIndex]); } //now we get a set of duration IDs in reverse so that we can work "from right to left" List <int> durationIDs = new List <int>(durIdToInstantCols.Keys); durationIDs.Sort(); durationIDs.Reverse(); bool reprocessMerge = false; foreach (int durID in durationIDs) { InstanceReportColumn durationColumn = this.Columns.Find(col => col.Id == durID); if (!string.IsNullOrEmpty(durationColumn.CurrencyCode)) { continue; } List <InstanceReportColumn> instantColumns = durIdToInstantCols[durID]; if (instantColumns.Count < 2) { continue; } List <string> currencies = new List <string>(); foreach (InstanceReportColumn iCol in instantColumns) { if (string.IsNullOrEmpty(iCol.CurrencyCode)) { continue; } if (!currencies.Contains(iCol.CurrencyCode)) { currencies.Add(iCol.CurrencyCode); } } if (currencies.Count < 2) { continue; } //set this flag so that we know that the mapping needs to be run again. reprocessMerge = true; //alphabetical order... currencies.Sort(); //...USD first if (currencies.Contains(InstanceUtils.USDCurrencyCode)) { currencies.Remove(InstanceUtils.USDCurrencyCode); currencies.Insert(0, InstanceUtils.USDCurrencyCode); } int newLabelId = 0; durationColumn.Labels.ForEach(ll => newLabelId = Math.Max(newLabelId, ll.Id)); int durationIndex = this.Columns.IndexOf(durationColumn); int insertIndex = durationIndex; //create the clones first... InstanceReportColumn original = null; foreach (string currency in currencies) { insertIndex++; //keep moving this up - we do not want duplicated IDs maxColumnId++; InstanceReportColumn clone = (InstanceReportColumn)durationColumn.Clone(); clone.Id = maxColumnId; clone.CurrencyCode = currency; clone.CurrencySymbol = ReportBuilder.GetISOCurrencySymbol(currency); //we will have to clean up at the end - make sure this column sticks somehow if (string.Equals(clone.CurrencyCode, durationColumn.CurrencyCode)) { //if the currency code matches, this is preferred - always store it original = clone; } else { //we will have to clean up at the end - if no column has been selected yet, pick the first //later, if the currency code matches, we'll replace `original` with that if (original == null) { original = clone; } clone.IsPseudoColumn = true; } if (string.IsNullOrEmpty(clone.CurrencySymbol)) { clone.Labels.Add(new LabelLine(newLabelId, clone.CurrencyCode)); } else { clone.Labels.Add(new LabelLine(newLabelId, clone.CurrencyCode + " (" + clone.CurrencySymbol + ")")); } this.Columns.Insert(insertIndex, clone); foreach (InstanceReportRow row in this.Rows) { Cell c = (Cell)row.Cells[durationIndex].Clone(); c.Id = maxColumnId; row.Cells.Insert(insertIndex, c); } } original.IsPseudoColumn = false; //...then remove the original this.RemoveColumn(durationIndex); } if (reprocessMerge) { this.SynchronizeGrid(); } return(reprocessMerge); }