/// <summary> /// Creates a new InstanceStatistics. /// </summary> public InstanceStatistics(Instance currentInstance) { this.currentInstance = currentInstance; if (this.currentInstance != null) { BuildStatistics(); } }
private string CreateMergedTaxonomyFileNameFromInstanceDocumentMultiple(Instance instanceDoc, bool promptUser, string baseHref) { StringBuilder taxonomyNameSpace = new StringBuilder(); StringBuilder prefix = new StringBuilder(); StringBuilder importStatement = new StringBuilder(); string linkbaseStatement = instanceDoc.GetEmbeddedLinkbaseInfo(); foreach (string loc in instanceDoc.schemaRefs) { string location = ApplyBaseHRef(baseHref, loc); Taxonomy t = new Taxonomy(); if (t.Load(location, promptUser) > 0) return string.Empty; t.GetNSPrefix(); prefix.Append(t.nsPrefix); taxonomyNameSpace.Append(t.TargetNamespace); string href = ApplyBaseHRef(baseHref, t.schemaFile); //CEE 2009-05-28: Clean up the & within "W R Grace & Company" //Remove 1 level of encoding, and then reapply it. href = href.Replace( "&", "&" ).Replace( "&", "&" ); importStatement.Append(string.Format(@"<import namespace=""{0}"" schemaLocation=""{1}"" />", t.TargetNamespace, href ) ); importStatement.Append(Environment.NewLine); } string fileName = "Temp_" + DateTime.Now.Ticks.ToString() + "_Merged.xsd"; fileName = Path.Combine(System.Environment.CurrentDirectory, fileName); string taxonomyFileInfo = string.Format(Taxonomy.WrapperTaxonomyTemplate, taxonomyNameSpace.ToString(), prefix.ToString(), importStatement.ToString(), linkbaseStatement); StreamWriter sw = new StreamWriter(fileName, false); sw.Write(taxonomyFileInfo); sw.Close(); return fileName; }
public void ValidateInstanceInformationForRequiresElementCheck( Instance ins, out string[] validationsFailures ) { validationsFailures = null; if ( this.NetDefinisionInfo == null ) return; Hashtable uniqueElementIds = new Hashtable(); foreach ( MarkupProperty mp in ins.markups ) { uniqueElementIds[mp.elementId] = 1; } ValidateInstanceInformationForRequiresElementCheck( uniqueElementIds, out validationsFailures ); }
/// <summary> /// Load and Parser a taxonomy based on the instance document /// </summary> /// <param name="currentFolder"></param> /// <param name="instanceDoc"></param> /// <param name="promptUser"></param> /// <returns></returns> public bool LoadTaxonomyFromInstanceDocument(string currentFolder, Instance instanceDoc, bool promptUser, string baseHref) { if (!string.IsNullOrEmpty(baseHref)) { baseHref = baseHref.TrimEnd('/', '\\'); } lock (synObjectForLoadTaxonomyFromInstanceDocument) { string oldworkingfolder = System.Environment.CurrentDirectory; System.Environment.CurrentDirectory = currentFolder; this.PromptUser = promptUser; bool deleteFile = false; string fileName = string.Empty; try { if (instanceDoc.schemaRefs.Count == 1) { fileName = ApplyBaseHRef(baseHref, instanceDoc.schemaRefs[0] as string); } else { deleteFile = true; fileName = this.CreateMergedTaxonomyFileNameFromInstanceDocumentMultiple(instanceDoc, promptUser, baseHref); if (string.IsNullOrEmpty(fileName)) { string msg = string.Format("Failed to build Taxonomy from Instance document {0}", instanceDoc.mergeFilename); errorList = new ArrayList(); errorList.Add(msg); Common.WriteError(msg, new ArrayList() ); return false; } } if (this.Load(fileName, promptUser) > 0) return false; int error = 0; return this.Parse(out error); } catch (Exception exp) { string msg = string.Format("Failed to build Taxonomy from Instance document {0}", instanceDoc.mergeFilename); errorList = new ArrayList(); errorList.Add(msg); Common.WriteError("XBRLParser.Error.Exception", errorList, exp.Message); return false; } finally { if (deleteFile) { if (File.Exists(fileName)) File.Delete(fileName); } System.Environment.CurrentDirectory = oldworkingfolder; } } }
public bool LoadTaxonomyFromInstanceDocument(string currentFolder, Instance instanceDoc, bool promptUser) { return LoadTaxonomyFromInstanceDocument(currentFolder, instanceDoc, promptUser, string.Empty); }
/// <summary> /// <para>Performs the "building of reports" based on the <paramref name="instancePath"/> and <paramref name="taxonomy"/> provided.</para> /// <para>As a result, <paramref name="filingSummary"/>.<see>MyReports</see> (<see cref="FilingSummary"/>) will be populated with instances of <see cref="ReportHeader"/>,</para> /// <para>and <paramref name="filingSummary"/>.<see>MyReports</see> will be XML serialized to <paramref name="filingSummaryPath"/></para> /// <para>If an error occurs, <paramref name="error" /> will be populated.</para> /// </summary> /// <param name="instancePath">The path to the instance document.</param> /// <param name="taxonomy">The loaded and parsed taxonomy object.</param> /// <param name="filingSummaryPath">The path where the generated <see cref="FilingSummary"/> object should be saved.</param> /// <param name="reportDirectory">The path where the generated content is saved.</param> /// <param name="filingSummary">The <see cref="FilingSummary"/> object to populate.</param> /// <param name="error">The error message for any critical errors which might occur.</param> /// <returns>True on success or false for fail.</returns> public bool BuildReports( string instancePath, Taxonomy taxonomy, string filingSummaryPath, string reportDirectory, out FilingSummary filingSummary, out string error ) { error = string.Empty; filingSummary = null; DateTime dtStart = DateTime.Now; try { this.currentFilingSummary = new FilingSummary(); this.currentInstancePath = instancePath; this.currentTaxonomy = taxonomy; this.currentReportDirectory = reportDirectory; if( !this.ValidateSettings( out error ) ) return false; //create the reports directory so that defnref can be generated if( !Directory.Exists( this.currentReportDirectory ) ) Directory.CreateDirectory( this.currentReportDirectory ); if( !string.IsNullOrEmpty( this.CurrencyMappingFile ) ) this.LoadCurrencies(); //set up this symbol for reuse throughout InstanceUtils.USDCurrencySymbol = InstanceUtils.GetCurrencySymbolFromCode( InstanceUtils.USDCurrencyCode ); if( string.IsNullOrEmpty( this.preferredLanguage ) ) this.preferredLanguage = this.GetPreferredLanguage(); bool isIMBased = this.CheckIsIMBased(); //DateTime startInstance = DateTime.Now; ArrayList errors = null; if( !InstanceUtils.TryLoadInstanceDocument( this.currentInstancePath, out this.currentInstance, out errors ) ) { string[] arrErrors = new string[ errors.Count ]; for( int i = 0; i < errors.Count; i++ ) { arrErrors[ i ] = ( (ParserMessage)errors[ i ] ).Message; } string instanceDocErrors = string.Join( "\r\n ", arrErrors ); Regex splitPoint = new Regex( @"\S\s+at" ); arrErrors = splitPoint.Split( instanceDocErrors ); instanceDocErrors = arrErrors[ 0 ]; error = "Unable to load the instance document:\r\n " + instanceDocErrors; return false; } ArrayList taxonomies = new ArrayList(); taxonomies.Add( this.currentTaxonomy ); this.currentInstance.FixPrefixInInstanceDocument( taxonomies ); //this.currentFilingSummary.InstanceLoadTime = DateTime.Now - startInstance; //this.currentFilingSummary.FactCount = this.currentInstance.markups.Count; this.PopulateMarkupDictionaries(); this.BuildFilingSummary(); this.FireBuildReportsProcessing(); this.currentFilingSummary.MyReports.Clear(); ArrayList topNodes = currentTaxonomy.GetNodesByPresentation( false, this.ExcludedReports ); foreach( Node topNode in topNodes ) { InstanceReport report = null; try { if( this.BuildReport( topNode, out report ) ) { if( report.IsEmbedReport || report.HasEmbeddedReports ) { this.roleAxes[ report.RoleURI ] = report.AxisByPresentation; this.roleAxisDefaults[ report.RoleURI ] = report.AxisMemberDefaults; this.roleAxisMembers[ report.RoleURI ] = report.AxisMembersByPresentation; } ReportHeader header = this.currentFilingSummary.AddReport( report ); this.ApplyRulesToReport( report ); report.OnRuleProcessing -= this.OnRuleProcessing; report.OnRuleProcessing += this.OnRuleProcessing; report.OnRuleProcessed -= this.OnRuleProcessed; report.OnRuleProcessed += this.OnRuleProcessed; report.UnitDictionary = this.unitDictionary; string fullPath = Path.Combine( this.currentReportDirectory, header.XmlFileName ); report.BuildXMLDocument( fullPath, true, isIMBased, this.currentFilingSummary ); report.UnitDictionary = null; report.OnRuleProcessing -= this.OnRuleProcessing; report.OnRuleProcessed -= this.OnRuleProcessed; if( header.HasEmbeddedReports ) this.reportsWithEmbeds.Add( header ); } } finally { if( report != null ) report.Dispose(); } } //Build Missing Elements (Uncategorized) Report before we flush the markups InstanceReport missingReport; if( this.BuildMissingDataReport( out missingReport ) ) { ReportHeader uncatHeader = this.currentFilingSummary.AddReport( missingReport ); uncatHeader.XmlFileName = InstanceUtils.TOP_LEVEL_REPORT_INDICATOR+ _missingReportIndex +".xml"; } //Free up some resources this.currentInstance = null; if( this.internalReports.Count == 0 ) { this.currentTaxonomy.Close(); this.currentTaxonomy = null; } //clear the dictionaries after checking internalReports this.ClearMarkupDictionaries(); #region Clean up Columns //if the company has filed earning release, do not touch the reports. //Based on request from SEC, do not remove any reports if the base taxonomy is the new GAAP taxonomy (2208) if( !this.HasEarningRelease() ) { //DO NOT REMOVE - These are used in rule processing isGAAP2005 = this.TaxonomyIsGAAP2005(); isNewGAAP = ( !isGAAP2005 ); ProcessFlowThroughColumnsReports(); } #endregion #region Build All Reports //Build book ReportHeader r1 = new ReportHeader(); r1.LongName = _allReports; r1.ShortName = _allReports; r1.ReportType = ReportHeaderType.Book; r1.IsDefault = this.currentFilingSummary.MyReports.Count == 0; this.currentFilingSummary.AddReports( r1 ); #endregion #region Process Embeeded Reports bool isRuleEnabled = this.FireRuleProcessing( RulesEngineUtils.EMBED_REPORTS_RULE ); if( isRuleEnabled && this.reportsWithEmbeds.Count > 0 ) { List<ReportHeader> embedReports = this.ProcessEmbeddedReports(); if( embedReports.Count > 0 ) { foreach( ReportHeader embedReport in embedReports ) { if( this.currentFilingSummary.MyReports.Contains( embedReport ) ) { this.currentFilingSummary.MyReports.Remove( embedReport ); string reportNameToDelete = Path.Combine( this.currentReportDirectory, embedReport.XmlFileName ); if( File.Exists( reportNameToDelete ) ) File.Delete( reportNameToDelete ); } } } this.FireRuleProcessed( RulesEngineUtils.EMBED_REPORTS_RULE ); } #endregion #region Generate Excel Workbook isRuleEnabled = this.FireRuleProcessing( RulesEngineUtils.GENERATE_EXCEL_RULE ); if( isRuleEnabled ) { string excelReportName = "Financial_Report"; bool processed = ExcelUtility.GenerateExcelWorkbook( this.currentFilingSummary, this.currentReportDirectory, excelReportName ); this.FireRuleProcessed( RulesEngineUtils.GENERATE_EXCEL_RULE ); if( !processed ) { error = "Failed to generate Excel Workbook for report: " + this.currentReportDirectory + " " + excelReportName; return false; } } #endregion #region Generate Output Formats if( ( this.ReportFormat & ReportFormat.Html ) == ReportFormat.Html ) { if( !this.GenerateHtmlFiles() ) { //The error was logged to the tracer } } if( ( this.ReportFormat & ReportFormat.Xml ) == ReportFormat.Xml ) { //this format already exists } else { // this.currentFilingSummary.TraceInformation( "Information: Report Formart does not include 'Xml'. Removing references and files." ); foreach( ReportHeader rh in this.currentFilingSummary.MyReports ) { if( !string.IsNullOrEmpty( rh.HtmlFileName ) ) { string deleteFile = Path.Combine( this.currentReportDirectory, rh.XmlFileName ); if( File.Exists( deleteFile ) ) File.Delete( deleteFile ); rh.XmlFileName = null; } } } #endregion #region Check and fix default report //Recheck the default report just in case it was deleted bool foundDefault = false; foreach( ReportHeader header in this.currentFilingSummary.MyReports ) { if( header.IsDefault ) { foundDefault = true; break; } } if( !foundDefault ) { foreach( ReportHeader header in this.currentFilingSummary.MyReports ) { if( header.IsBalanceSheet() || header.ReportType == ReportHeaderType.Book ) { header.IsDefault = true; break; } } } #endregion return true; } catch( Exception ex ) { error = string.Format( "Exception thrown in BuildReports: {0}", ex.Message ); return false; } finally { this.FireBuildReportsProcessed(); this.currentFilingSummary.ProcessingTime = DateTime.Now - dtStart; this.currentFilingSummary.SaveAsXml( filingSummaryPath ); filingSummary = this.currentFilingSummary; this.currentFilingSummary = null; if( this.currentTaxonomy != null ) this.currentTaxonomy.Close(); this.currentTaxonomy = null; } }
private void ValidateInstanceDoc( Taxonomy tax, string fileName, int countErrors, Hashtable prefixXRef ) { Instance ins = new Instance(); ArrayList errs; if( !ins.TryLoadInstanceDoc( fileName, out errs )) { Assert.Fail( "Failed to load instance document" + fileName); } foreach( MarkupProperty mp in ins.markups ) { if ( prefixXRef[mp.elementPrefix] != null ) { string realPrefix = prefixXRef[mp.elementPrefix] as string; mp.elementPrefix = realPrefix; mp.elementId = string.Format(DocumentBase.ID_FORMAT, mp.elementPrefix, mp.elementName); } } string[] validationErrors; tax.ValidateInstanceInformationForRequiresElementCheck( ins, out validationErrors ); Assert.IsNotNull( validationErrors , "Validation errors object should not be null"); foreach( string str in validationErrors ) { Console.WriteLine( str ); } Assert.AreEqual( countErrors, validationErrors.Length,"Failed to ValidateInstanceInformationForRequiresElementCheck"); }
public static bool TryLoadInstanceDocument(string instanceDocPath, out Instance currentInstance, out ArrayList errors) { errors = new ArrayList(); currentInstance = new Instance(); if (currentInstance.TryLoadInstanceDoc( instanceDocPath, out errors )) { if ( currentInstance.NumAttributeErrors > 0 || currentInstance.NumSchemaErrors > 0 ) { Console.WriteLine( "Instance doc parsing attribute errors: " + currentInstance.NumAttributeErrors ); Console.WriteLine( "Instance doc parsing schema errors: " + currentInstance.NumSchemaErrors ); } return true; } else { Console.WriteLine( "TryLoadInstanceDoc failed" ); errors.Sort(); foreach ( ParserMessage pm in errors ) { if ( pm.Level != TraceLevel.Error ) { break; // thru the errors } Console.WriteLine( "InstanceDoc error: " + pm.Message ); } } return false; }
public static InstanceStatistics GetStatisticsFromInstance(Instance currentInstance) { InstanceStatistics instanceStat = new InstanceStatistics(currentInstance); return instanceStat; }
public void TestPerformSECValidations2() { Taxonomy tax = new Taxonomy(); tax.Load(@"S:\TESTSCHEMAS\BEN Taxonomy\ben-20091231.xsd"); int errors; Assert.IsTrue(tax.Parse(out errors), "Failed to parse taxonomy"); Instance ins = new Instance(); ArrayList errorsstr; Assert.IsTrue(ins.TryLoadInstanceDoc(@"S:\TESTSCHEMAS\BEN Taxonomy\ben-20091231.xml", out errorsstr)); Dictionary<string, bool> eleDt = new Dictionary<string,bool>(); List<MarkupProperty> validMarkups = new List<MarkupProperty>(); foreach (MarkupProperty mp in ins.markups) { mp.element = new Node( tax.allElements[mp.elementId] as Element); eleDt[mp.elementId] = true; validMarkups.Add(mp); } List<ValidationErrorInfo> outParam = new List<ValidationErrorInfo>(); tax.PerformSECValidations(validMarkups, eleDt, null, false, ref outParam); outParam.Sort(); foreach( ValidationErrorInfo vei in outParam ) { Console.WriteLine( vei.MyErrorString); } }
public void TestLoadTaxonomyFromInstanceDocument_SEC_4Tax_Local_Partial2() { string copyTo = Path.GetTempFileName(); string curDir = Path.GetDirectoryName( copyTo ); string fileName = @"http://www.sec.gov/Archives/edgar/data/908823/000119312506095211/aabxx-20060228.xml"; string baseHRef = @"http://www.sec.gov/Archives/edgar/data/908823/000119312506095211/"; WebClient cli = new WebClient(); cli.DownloadFile( fileName, copyTo ); Instance ins = new Instance(); ArrayList errors; ins.TryLoadInstanceDoc( copyTo, out errors ); Taxonomy tax = new Taxonomy(); Assert.IsTrue( tax.LoadTaxonomyFromInstanceDocument( curDir, ins, false, baseHRef ), "Failed to load taxonomy." ); }
public void TestLoadTaxonomyFromInstanceDocument_SEC_4Tax_Local_HREF() { string fileName = @"S:\TestSchemas\BaseHRef\Instance\aabxx-20060228.xml"; string baseHRef = @"S:\TestSchemas\BaseHRef\Instance\"; Instance ins = new Instance(); ArrayList errors; ins.TryLoadInstanceDoc( fileName, out errors ); Taxonomy tax = new Taxonomy(); Assert.IsTrue( tax.LoadTaxonomyFromInstanceDocument( Path.GetTempPath(), ins, false, baseHRef ), "Failed to load taxonomy" ); ArrayList nodes = tax.GetNodesByPresentation(); Assert.IsTrue( nodes.Count >= 16, "should have presentation nodes" ); }
public void TestLoadTaxonomyFromInstanceDocument_SEC_4Tax() { string fileName = @"http://www.sec.gov/Archives/edgar/data/908823/000119312506095211/aabxx-20060228.xml"; string baseHRef = @"http://www.sec.gov/Archives/edgar/data/908823/000119312506095211/"; Instance ins = new Instance(); ArrayList errors; ins.TryLoadInstanceDoc( fileName, out errors ); Taxonomy tax = new Taxonomy(); Assert.IsTrue( tax.LoadTaxonomyFromInstanceDocument( Path.GetTempPath(), ins, false, baseHRef ), "Failed to load taxonomy" ); ArrayList nodes = tax.GetNodesByPresentation(); Assert.IsTrue( nodes.Count >= 16, "should have presentation nodes" ); }
public void TestLoadTaxonomyFromInstanceDocument_SEC_2Tax() { string fileName = @"http://www.sec.gov/Archives/edgar/data/89800/000095015208008578/shw-20080930.xml"; string baseHRef = @"http://www.sec.gov/Archives/edgar/data/89800/000095015208008578"; Instance ins = new Instance(); ArrayList errors; ins.TryLoadInstanceDoc( fileName, out errors ); Taxonomy tax = new Taxonomy(); Assert.IsTrue( tax.LoadTaxonomyFromInstanceDocument( Path.GetTempPath(), ins, false, baseHRef ), "Failed to load taxonomy" ); ArrayList nodes = tax.GetNodesByPresentation(); Assert.IsTrue( nodes.Count >= 5, "should have presentation nodes" ); }
public void TestLoadTaxonomyFromInstanceDocument() { string fileName = @"S:\TestSchemas\Instance With TaxonomyInfo.xml"; Instance ins = new Instance(); ArrayList errors; ins.TryLoadInstanceDoc( fileName, out errors ); Taxonomy tax = new Taxonomy(); Assert.IsTrue( tax.LoadTaxonomyFromInstanceDocument( @"S:\TestSchemas", ins, false ), "Failed to load taxonomy" ); ArrayList nodes = tax.GetNodesByPresentation(); Assert.IsTrue( nodes.Count > 10, "should have presentation nodes" ); }