Exemplo n.º 1
0
        /// <summary>
        /// Builds a dictionary of all elements for 1 report, specified by <paramref name="rh"/>.
        /// </summary>
        /// <param name="rh">The <see cref="ReportHeader"/> whose elements should be loaded.</param>
        /// <returns></returns>
        private Dictionary <string, int> BuildInUseElementsForCurrentReport(ReportHeader rh)
        {
            if (rh.ReportType == ReportHeaderType.Sheet || rh.ReportType == ReportHeaderType.Notes)
            {
                if (!this.uniqueReportElements.ContainsKey(rh.XmlFileName) ||
                    this.uniqueReportElements == null ||
                    this.uniqueReportElements.Count == 0)
                {
                    InstanceReport report         = InstanceReport.LoadXml(Path.Combine(this.currentReportDirectory, rh.XmlFileName));
                    string[]       uniqueElements = report.GetUniqueInUseElements();
                    this.uniqueReportElements[rh.XmlFileName] = new List <string>(uniqueElements);
                }
            }

            Dictionary <string, int> reportUniqueElements = new Dictionary <string, int>();

            if (this.uniqueReportElements.ContainsKey(rh.XmlFileName) && this.uniqueReportElements.Count > 0)
            {
                foreach (string key in this.uniqueReportElements[rh.XmlFileName])
                {
                    reportUniqueElements[key] = 1;
                }
            }

            return(reportUniqueElements);
        }
Exemplo n.º 2
0
        public void CleanupFlowThroughColumns()
        {
            for (int rhIndex = 0; rhIndex < currentFilingSummary.MyReports.Count; rhIndex++)
            {
                ReportHeader rh = currentFilingSummary.MyReports[rhIndex] as ReportHeader;

                //Equity reports that do not have segments still need to have flow through columns
                //cleaned up because they were not processed with the regular equity processing logic
                bool isEquityStatement = false;

                if (ReportUtils.IsStatementOfEquityCombined(rh.LongName))
                {
                    isEquityStatement = true;
                }

                if (isEquityStatement)
                {
                    string         instanceFile = Path.Combine(this.currentReportDirectory, rh.XmlFileName);
                    InstanceReport ir           = InstanceReport.LoadXml(instanceFile);
                    if (ir.IsEquityReport)
                    {
                        continue;
                    }
                }

                if (rh.ReportType == ReportHeaderType.Sheet || rh.ReportType == ReportHeaderType.Notes)
                {
                    if (cleanupStatementsOnly)
                    {
                        if (ReportUtils.IsStatement(rh.LongName) == true)
                        {
                            this.currentFilingSummary.TraceInformation("Process Flow-Through: " + rh.LongName);

                            InstanceReport.ElementSegmentCombinations allInUseElementsSegments = this.BuildInUseElementSegmentCombinationsForAllReports(rh);
                            this.CleanupColumns(rh, allInUseElementsSegments);
                            this.uniqueReportElementSegmentCombos.Remove(rh.XmlFileName);
                        }
                    }
                    else
                    {
                        this.currentFilingSummary.TraceInformation("Process Flow-Through: " + rh.LongName);

                        InstanceReport.ElementSegmentCombinations allInUseElementsSegments = this.BuildInUseElementSegmentCombinationsForAllReports(rh);
                        this.CleanupColumns(rh, allInUseElementsSegments);
                        this.uniqueReportElementSegmentCombos.Remove(rh.XmlFileName);
                    }
                }
            }

            this.uniqueReportElements             = new Dictionary <string, List <string> >();
            this.uniqueReportSegments             = new Dictionary <string, List <string> >();
            this.uniqueReportElementSegmentCombos = new Dictionary <string, InstanceReport.ElementSegmentCombinations>();
        }
Exemplo n.º 3
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));
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Builds a nested dictionary of all elements and which Segments they are combined with for 1 report, specified by <paramref name="rh"/>.
        /// </summary>
        /// <param name="rh">The <see cref="ReportHeader"/> whose element/segment combinations should be loaded.</param>
        /// <returns></returns>
        private InstanceReport.ElementSegmentCombinations BuildInUseElementSegmentCombinationsForCurrentReport(ReportHeader rh)
        {
            if (rh.ReportType == ReportHeaderType.Sheet || rh.ReportType == ReportHeaderType.Notes)
            {
                if (!this.uniqueReportElementSegmentCombos.ContainsKey(rh.XmlFileName) ||
                    this.uniqueReportElementSegmentCombos == null ||
                    this.uniqueReportElementSegmentCombos.Count == 0)
                {
                    InstanceReport report = InstanceReport.LoadXml(Path.Combine(this.currentReportDirectory, rh.XmlFileName));
                    InstanceReport.ElementSegmentCombinations elementSegmentCombinations = report.GetUniqueInUseElementSegmentCombinations();
                    this.uniqueReportElementSegmentCombos[rh.XmlFileName] = elementSegmentCombinations;
                }
            }

            if (this.uniqueReportElementSegmentCombos.ContainsKey(rh.XmlFileName))
            {
                return(uniqueReportElementSegmentCombos[rh.XmlFileName]);
            }

            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Go thorugh each column to determine if the columns should be removed --
        /// if all elements (that have data) in the columns can be found in other reports then consider this a flow thru column and delete it.
        /// For "disclosures", if one element or one dimension member s unique, do remove ANY columns from the disclosure
        /// </summary>
        /// <param name="rh"></param>
        /// <param name="inUseElements"></param>
        /// <param name="inUseSegments"></param>
        private void CleanupColumns(ReportHeader rh, Dictionary <string, int> inUseElements, Dictionary <string, int> inUseSegments)
        {
            string         filePath = Path.Combine(this.currentReportDirectory, rh.XmlFileName);
            InstanceReport report   = InstanceReport.LoadXml(filePath);

            if (report == null)
            {
                return;
            }

            List <InstanceReportColumn> columnsToRemove = new List <InstanceReportColumn>();
            List <InstanceReportRow>    uniqueRows      = report.Rows.FindAll(
                row =>
            {
                if (string.IsNullOrEmpty(row.ElementName))
                {
                    return(false);
                }

                if (row.IsEmpty())
                {
                    return(false);
                }

                if (inUseElements.ContainsKey(row.ElementName))
                {
                    return(false);
                }

                return(true);
            });

            bool hasAnyUniqeRows = uniqueRows.Count > 0;

            for (int c = 0; c < report.Columns.Count; c++)
            {
                InstanceReportColumn col     = report.Columns[c];
                bool columnHasUniqueSegments = false;
                bool columnHasUniqueCells    = ReportUtils.Exists(uniqueRows, row => row.Cells[c].HasData);
                if (!columnHasUniqueCells)                  //this column might need to be removed
                {
                    Dictionary <string, int> colSegments = report.GetUniqueInUseSegments(col);
                    foreach (string key in colSegments.Keys)
                    {
                        if (!inUseSegments.ContainsKey(key))
                        {
                            columnHasUniqueSegments = true;
                            break;
                        }
                    }
                }

                if (!(columnHasUniqueCells || columnHasUniqueSegments))
                {
                    columnsToRemove.Add(col);
                }
            }

            if (columnsToRemove.Count > 0 && columnsToRemove.Count < report.Columns.Count)
            {
                foreach (InstanceReportColumn col in columnsToRemove)
                {
                    col.RemoveSelf(report);
                }

                if (report.Columns.Count > 1)
                {
                    report.PromoteSharedColumnLabelsAfterRemoveFlowThroughColumns();
                }

                report.BuildXMLDocument(filePath, false, false, this.currentFilingSummary);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Go thorugh each column to determine if the columns should be removed --
        /// if all elements (that have data) in the columns can be found in other reports then consider this a flow thru column and delete it.
        /// For "disclosures", if one element or one dimension member s unique, do remove ANY columns from the disclosure
        /// </summary>
        /// <param name="rh"></param>
        /// <param name="allInUseElementsSegments"></param>
        private void CleanupColumns(ReportHeader rh, InstanceReport.ElementSegmentCombinations allInUseElementsSegments)
        {
            string         filePath = Path.Combine(this.currentReportDirectory, rh.XmlFileName);
            InstanceReport report   = InstanceReport.LoadXml(filePath);

            if (report == null)
            {
                return;
            }

            InstanceReportColumn lastSegmentColumn = null;
            bool hasSegmentsOnRows = report.HasSegmentsOnRows();
            List <InstanceReportColumn> columnsToRetain = new List <InstanceReportColumn>();

            foreach (InstanceReportRow row in report.Rows)
            {
                if (hasSegmentsOnRows)
                {
                    if (row.OriginalInstanceReportColumn != null)
                    {
                        lastSegmentColumn = row.OriginalInstanceReportColumn;
                    }
                }

                //we can't test this row
                if (string.IsNullOrEmpty(row.ElementName))
                {
                    continue;
                }

                //we can't test this row
                if (row.IsEmpty())
                {
                    continue;
                }

                for (int c = 0; c < row.Cells.Count; c++)
                {
                    //skip this cell if we already have this column
                    InstanceReportColumn currentColumn = report.Columns[c];
                    if (columnsToRetain.Contains(currentColumn))
                    {
                        continue;
                    }

                    //we only want columns for cells which have data
                    Cell cell = row.Cells[c];
                    if (!cell.HasData)
                    {
                        continue;
                    }

                    //if the element doesn't even exist, we're set - add the column
                    InstanceReportColumn segmentColumn = hasSegmentsOnRows ? lastSegmentColumn : currentColumn;
                    if (!allInUseElementsSegments.ContainsElement(row.ElementName))
                    {
                        columnsToRetain.Add(currentColumn);
                    }
                    else if (segmentColumn != null)
                    {
                        if (segmentColumn.Segments != null && segmentColumn.Segments.Count > 0)
                        {
                            //if the element exists, but maybe its combination with the segments does not
                            StringBuilder sb = new StringBuilder();
                            foreach (string segmentKey in segmentColumn.GetUniqueInUseSegments().Keys)
                            {
                                sb.AppendLine(segmentKey);
                            }

                            if (!allInUseElementsSegments.ContainsElementAndSegments(row.ElementName, sb.ToString()))
                            {
                                columnsToRetain.Add(currentColumn);
                            }
                        }
                    }
                }

                if (columnsToRetain.Count == report.Columns.Count)
                {
                    return;
                }
            }

            if (columnsToRetain.Count == 0 || columnsToRetain.Count == report.Columns.Count)
            {
                return;
            }

            List <InstanceReportColumn> columnsToRemove = report.Columns.FindAll(col => !columnsToRetain.Contains(col));

            foreach (InstanceReportColumn col in columnsToRemove)
            {
                this.currentFilingSummary.TraceInformation("\tProcess Flow-Through: Removing column '" + col.Label + "'");
                col.RemoveSelf(report);
            }

            if (report.Columns.Count > 1)
            {
                report.PromoteSharedColumnLabelsAfterRemoveFlowThroughColumns();
            }

            report.BuildXMLDocument(filePath, false, false, this.currentFilingSummary);
        }