Exemple #1
0
 public void LoadValidationHierarchy()
 {
     Arcs.Clear();
     Arcs.AddRange(this.VariableArcs);
     Arcs.AddRange(this.VariableFilterArcs);
     Arcs.AddRange(this.VariableSetFilterArcs); //.Where(i=>i.Complement=false));
     if (this.AssertionSet != null)
     {
         Identifiables.Add(this.AssertionSet);
     }
     Identifiables.AddRange(this.ValueAssertions);
     Identifiables.AddRange(this.DimensionFilters);
     Identifiables.AddRange(this.TupleFilters);
     Identifiables.AddRange(this.GeneralFilters);
     Identifiables.AddRange(this.ConceptFilters);
     Identifiables.AddRange(this.AspectFilters);
     Identifiables.AddRange(this.FactVariables);
     Identifiables.AddRange(this.Filters);
     foreach (var identifiable in Identifiables)
     {
         var df = identifiable as DimensionFilter;
         if (df != null)
         {
             var nsuri = NsManager.LookupNamespace(df.Dimension.QName.Domain);
             df.Dimension.QName.Domain = Taxonomy.FindNamespacePrefix(nsuri, df.Dimension.QName.Domain);
             var exdf = df as ExplicitDimensionFilter;
             if (exdf != null)
             {
                 foreach (var m in exdf.Members)
                 {
                     nsuri             = NsManager.LookupNamespace(m.QName.Domain);
                     m.QName.Domain    = Taxonomy.FindNamespacePrefix(nsuri, m.QName.Domain);
                     m.IsDefaultMember = Taxonomy.IsDefaultMember(m.QName);
                 }
             }
             var tydf = df as TypedDimensionFilter;
             if (tydf != null)
             {
                 //tydf.
             }
         }
         var cf = identifiable as ConceptFilter;
         if (cf != null)
         {
             var cfn = cf as ConceptNameFilter;
             if (cfn != null)
             {
                 foreach (var concept in cfn.Concepts)
                 {
                     var nsprefix = concept.QName.Domain;
                     var nsuri    = NsManager.LookupNamespace(nsprefix);
                     concept.QName.Domain = Taxonomy.FindNamespacePrefix(nsuri, nsprefix);
                 }
             }
         }
     }
     ValidationRoot = Hierarchy <XbrlIdentifiable> .GetHierarchy(Arcs, Identifiables,
                                                                 (i, a) => i.Item.LabelID == a.From, (i, a) => i.Item.LabelID == a.To,
                                                                 (i, a) => {
         if (i.Item is Filter && a is ComplementArc)
         {
             var filter        = i.Item as Filter;
             var arc           = a as ComplementArc;
             filter.Complement = arc.Complement;
         }
         if (a is VariableArc)
         {
             var varc      = a as VariableArc;
             var variable  = i.Item as Variable;
             variable.Name = varc.Name;
         }
         if (a is VariableFilterArc && i.Item is Filter)
         {
             var vfarc = a as VariableFilterArc;
             var ac    = i.Item as Filter;
             ac.Cover  = vfarc.Cover;
         }
     });
 }
Exemple #2
0
        public void LoadLayoutHierarchy(LogicalModel.Table logicaltable)
        {
            Identifiables.Clear();
            Arcs.Clear();
            Identifiables.AddRange(Tables);
            Identifiables.AddRange(BreakDowns);
            Identifiables.AddRange(RuleNodes);
            Identifiables.AddRange(AspectNodes);
            Identifiables.AddRange(DimensionFilters);
            Identifiables.AddRange(DimensionRelationShips);
            Arcs.AddRange(BreakdownTrees);
            Arcs.AddRange(TableBreakDowns);
            Arcs.AddRange(DefinitionNodeSubTrees);
            Arcs.AddRange(AspectNodeFilters);

            foreach (var identifiable in Identifiables)
            {
                var li = new LogicalModel.LayoutItem();
                li.Table = logicaltable;
                var hi = new Hierarchy <LogicalModel.LayoutItem>(li);
                li.ID      = identifiable.ID;
                li.LabelID = identifiable.LabelID;
                li.LoadLabel(Taxonomy);

                var df = identifiable as DimensionFilter;
                if (df != null)
                {
                    li.Category = LogicalModel.LayoutItemCategory.Filter;

                    var dfexp = df as ExplicitDimensionFilter;
                    if (dfexp != null)
                    {
                        var member = dfexp.Members.FirstOrDefault();
                        if (member != null)
                        {
                            li.Role     = member.LinkRole;
                            li.RoleAxis = member.Axis;
                        }
                    }
                    var drel = df as DimensionRelationShip;
                    if (drel != null)
                    {
                        var member = drel.Member;
                        if (member != null)
                        {
                            li.Role     = drel.LinkRole;
                            li.RoleAxis = drel.Axis;
                            var dim = new LogicalModel.Dimension();
                            dim.DimensionItem = drel.Dimension.QName.Content;
                            dim.Domain        = drel.Member.Domain;
                            //dim.DomainMember = member.Value;
                            dim.SetTyped();
                            li.Dimensions.Add(dim);
                            li.Category = LogicalModel.LayoutItemCategory.Aspect;
                        }
                    }
                }

                var rule = identifiable as RuleNode;
                if (rule != null)
                {
                    li.Category = LogicalModel.LayoutItemCategory.Rule;

                    if (rule.Concept != null)
                    {
                        li.Concept = Mappings.ToLogical(rule.Concept); //rule.Concept.QName.Content;
                    }
                    if (rule.Abstract)
                    {
                        li.IsAbstract = rule.Abstract;
                    }
                    var dimensions = rule.Dimensions;//.Where(i=>i.)
                    foreach (var dimension in dimensions)
                    {
                        var logicaldimension  = new LogicalModel.Dimension();
                        var explicitDimension = dimension as ExplicitDimension;
                        var typedDimension    = dimension as TypedDimension;
                        if (explicitDimension != null)
                        {
                            logicaldimension.DimensionItem = explicitDimension.Dimension;
                            if (explicitDimension.Members.Count == 1)
                            {
                                var member = explicitDimension.Members.FirstOrDefault();
                                logicaldimension.Domain       = member.QName.Domain;
                                logicaldimension.DomainMember = member.QName.Value;
                            }
                            else
                            {
                                Logger.WriteLine("Multiple Members Detected");
                            }
                        }
                        if (typedDimension != null)
                        {
                            Logger.WriteLine("Typed Dimension Detected");
                        }
                        li.Dimensions.Add(logicaldimension);
                    }
                }

                var aspect = identifiable as AspectNode;
                if (aspect != null)
                {
                    li.Category = LogicalModel.LayoutItemCategory.Aspect;
                    var logicaldimension = new LogicalModel.Dimension();
                    logicaldimension.DimensionItem = aspect.DimensionAspect.Content;
                    var hc = logicaltable.HyperCubes.FirstOrDefault(i => i.DimensionItems.Any(j => j.FullName == logicaldimension.DimensionItem));
                    if (hc != null)
                    {
                        var dimitem = hc.DimensionItems.FirstOrDefault(i => i.FullName == logicaldimension.DimensionItem);
                        if (dimitem != null && dimitem.Domains.Count > 0)
                        {
                            //logicaldimension.Domain = dimitem.Domains.FirstOrDefault().FullName;
                            var domain = dimitem.Domains.FirstOrDefault();
                            logicaldimension.Domain = LogicalModel.Taxonomy.IsTyped(domain.FullName) ? domain.FullName : domain.ID;
                        }
                    }
                    logicaldimension.SetTyped();
                    li.Dimensions.Add(logicaldimension);
                }
                var breakdown = identifiable as BreakDown;

                if (breakdown != null)
                {
                    li.Category = LogicalModel.LayoutItemCategory.BreakDown;
                }

                logicaltable.LayoutItems.Add(hi);
            }

            var layoutfilename            = Utilities.Strings.GetFileName(this.LayoutPath);
            XmlNamespaceManager nsmanager = null;
            var layoutdoc = this.Taxonomy.TaxonomyDocuments.FirstOrDefault(i => i.FileName == layoutfilename);

            if (layoutdoc != null)
            {
                nsmanager = Utilities.Xml.GetTaxonomyNamespaceManager(layoutdoc.XmlDocument);
            }
            var d_con = new Dictionary <string, string>();

            foreach (var li in logicaltable.LayoutItems)
            {
                var concept = li.Item.Concept;
                if (concept != null)
                {
                    var nsuri = nsmanager.LookupNamespace(concept.Namespace);
                    concept.Namespace = Taxonomy.FindNamespacePrefix(nsuri, concept.Namespace);
                }
                foreach (var dimension in li.Item.Dimensions)
                {
                    var dimqname = new QName(dimension.DimensionItem);
                    var nsuri    = nsmanager.LookupNamespace(dimqname.Domain);
                    dimqname.Domain         = Taxonomy.FindNamespacePrefix(nsuri, dimqname.Domain);
                    dimension.DimensionItem = dimqname.Content;

                    string domnsuri;

                    if (dimension.IsTyped)
                    {
                        var domqname = new QName(dimension.Domain);
                        domnsuri         = nsmanager.LookupNamespace(domqname.Domain);
                        domqname.Domain  = Taxonomy.FindNamespacePrefix(domnsuri, domqname.Domain);
                        dimension.Domain = domqname.Content;
                    }
                    else
                    {
                        domnsuri         = nsmanager.LookupNamespace(dimension.Domain);
                        dimension.Domain = Taxonomy.FindNamespacePrefix(domnsuri, dimension.Domain);
                    }
                }
            }

            logicaltable.LayoutRoot = Hierarchy <LogicalModel.LayoutItem> .GetHierarchy(Arcs, logicaltable.LayoutItems,
                                                                                        (i, a) => i.Item.LabelID == a.From, (i, a) => i.Item.LabelID == a.To,
                                                                                        (i, a) => { i.Item.Order = a.Order; i.Item.Axis = a is TableBreakDownArc ? ((TableBreakDownArc)a).Axis.ToString() : ""; });

            logicaltable.ID   = logicaltable.LayoutRoot.Item.ID;
            logicaltable.Name = logicaltable.LayoutRoot.Item.LabelContent;
            logicaltable.SetHtmlPath();
            Utilities.FS.WriteAllText(logicaltable.LayoutPath, logicaltable.LayoutRoot.ToHierarchyString(GetLayoutString));
            //var x = GetXbrlRendering();
            //Utilities.FS.WriteAllText(logicaltable.FullHtmlPath.Replace(".html", "_layout.txt"), x.ToHierarchyString(GetLayoutString));
        }