Beispiel #1
0
        /// <summary>
        /// Constructs a <see cref="ContextDimensionInfo"/> object from the
        /// parent <see cref="DimensionNode"/> of this <see cref="DimensionNode"/>.
        /// </summary>
        /// <returns>The newly constructed <see cref="ContextDimensionInfo"/>.</returns>
        public ContextDimensionInfo BuildContextInfo()
        {
            DimensionNode parentNode = GetParentDimensionTypeDimensionNode();

            if (parentNode == null || parentNode.Id == this.Id)
            {
                return(null);
            }

            ContextDimensionInfo cdi = new ContextDimensionInfo();

            cdi.Id = this.Id;

            cdi.dimensionId = parentNode.Id;
            cdi.type        = ContextDimensionInfo.DimensionType.explicitMember;
            return(cdi);
        }
Beispiel #2
0
        private void WriteDimensionInfo(XmlElement parent, ContextDimensionInfo cdi,
                                        XmlElement root, XmlDocument doc, Taxonomy[] taxonomies)
        {
            if (taxonomies != null)
            {
                root.SetAttribute(string.Format(DocumentBase.NAME_FORMAT, DocumentBase.XMLNS, DocumentBase.XBRLDI_PREFIX), DocumentBase.XBRLDI_URI);

                //Add the dimension TI to the root attributes...
                Element      dimensionEle;
                TaxonomyItem dimensionTI = GetMemberTaxonomyItem(cdi.dimensionId,
                                                                 taxonomies, out dimensionEle);
                if (dimensionTI != null)
                {
                    root.SetAttribute(string.Format(DocumentBase.NAME_FORMAT, DocumentBase.XMLNS, dimensionTI.Namespace), dimensionTI.WebLocation);
                }
                else
                {
                    //error
                    return;
                }
                Element      memberEle;
                TaxonomyItem memberTI = GetMemberTaxonomyItem(cdi.Id,
                                                              taxonomies, out memberEle);
                if (memberTI != null)
                {
                    root.SetAttribute(string.Format(DocumentBase.NAME_FORMAT, DocumentBase.XMLNS, memberTI.Namespace), memberTI.WebLocation);
                }
                else
                {
                    //error
                    return;
                }
                //need to find the member taxonomy item
                XmlElement innerEle = doc.CreateElement(DocumentBase.XBRLDI_PREFIX, EXPLICITMEMBER, DocumentBase.XBRLDI_URI);
                innerEle.SetAttribute(DIMENSION, string.Format(DocumentBase.NAME_FORMAT, dimensionTI.Namespace, dimensionEle.Name));
                parent.AppendChild(innerEle);
                innerEle.InnerText = string.Format(DocumentBase.NAME_FORMAT, memberTI.Namespace, memberEle.Name);
            }
            else
            {
                //error
            }
        }
Beispiel #3
0
 private void GetInformationToValidate(ArrayList segments, ArrayList scenarios,
                                       out List <ContextDimensionInfo> cdiList, ref bool hasUnSupportedData)
 {
     cdiList = new List <ContextDimensionInfo>();
     if (this.IsSegment)
     {
         foreach (Segment seg in segments)
         {
             ContextDimensionInfo cdi = seg.GetContextDimensionInfo();
             if (cdi != null)
             {
                 cdiList.Add(cdi);
                 if (!this.DimensionsById.ContainsKey(cdi.dimensionId))
                 {
                     hasUnSupportedData = true;
                 }
             }
             else
             {
                 hasUnSupportedData = true;
             }
         }
     }
     else
     {
         foreach (Scenario sce in scenarios)
         {
             ContextDimensionInfo cdi = sce.GetContextDimensionInfo();
             if (cdi != null)
             {
                 cdiList.Add(cdi);
                 if (!this.DimensionsById.ContainsKey(cdi.dimensionId))
                 {
                     hasUnSupportedData = true;
                 }
             }
             else
             {
                 hasUnSupportedData = true;
             }
         }
     }
 }
Beispiel #4
0
        private bool IsValidMarkup(ContextProperty cp,
                                   Dimension.MeasureHyperCubeInfo mhci,
                                   ref ArrayList errors)
        {
            BuildValidMembersByDimension();
            ListDictionary instanceDimensionInfos = new ListDictionary();

            if (mhci.IsScenario)
            {
                foreach (Scenario sc in cp.Scenarios)
                {
                    if (sc.DimensionInfo != null)
                    {
                        instanceDimensionInfos[sc.DimensionInfo.dimensionId] = sc.DimensionInfo;
                    }
                }
            }
            else
            {
                //TODO: same thing for segments..
            }

            ListDictionary validationByDimension = new ListDictionary();

            int baseValidationData = 0;

            if (mhci.IsAllRelationShip)
            {
                baseValidationData += ValidationDataEnum.ALLRelationShip.GetHashCode();
            }
            else
            {
                baseValidationData += ValidationDataEnum.NotAllRelationShip.GetHashCode();
            }

            if (mhci.IsClosed)
            {
                baseValidationData += ValidationDataEnum.IsClosed.GetHashCode();
            }
            else
            {
                baseValidationData += ValidationDataEnum.IsNotClosed.GetHashCode();
            }

            foreach (DictionaryEntry de in validMembersByDimension)
            {
                int  validationData = baseValidationData;
                bool found          = false;
                bool hasDefault     = false;

                ContextDimensionInfo cdi = instanceDimensionInfos[de.Key] as ContextDimensionInfo;
                instanceDimensionInfos.Remove(de.Key);
                if (cdi == null)
                {
                    validationData += ValidationDataEnum.DimensionNotInInstance.GetHashCode();
                }
                else
                {
                    HybridDictionary validMembers = de.Value as HybridDictionary;
                    if (validMembers != null)
                    {
                        found = validMembers[cdi.Id] != null;
                    }
                }

                if (found)
                {
                    validationData += ValidationDataEnum.Found.GetHashCode();
                }
                else
                {
                    validationData += ValidationDataEnum.NotFound.GetHashCode();
                }

                if (hasDefault)
                {
                    validationData += ValidationDataEnum.DimensionHasDefault.GetHashCode();

                    //TODO: determine if the default value is being used
                    //which is not a good thing and is an error condition.
                }

                ValidateResult(validationData, errors);
            }

            if (instanceDimensionInfos.Keys.Count != 0)
            {
                if (mhci.IsClosed)
                {
                    //this is an error condition as we have dimensions that are not part of
                    //the cube in the instance but the cube is a closed cube and does not
                    //allow other dimension infos
                    //TODO: enhance the error message...
                    string error = "Found invalid dimension for an element that is using a closed hypercube";

                    errors.Add(error);
                }
            }

            return(errors.Count == 0);
        }
Beispiel #5
0
        internal static bool TryCreateFromXml(XmlNode node, XmlNamespaceManager theManager, out ContextProperty cp, ref ArrayList errors)
        {
            if (errors == null)
            {
                errors = new ArrayList();
            }

            cp           = new ContextProperty();
            cp.ErrorList = errors;

            cp.ContextID = node.Attributes[ID_ATTR].Value;

            XmlNode entity = node.SelectSingleNode("./link2:" + ENTITY, theManager);

            if (entity == null)
            {
                if ((entity = node.SelectSingleNode(ENTITY)) == null)
                {
                    Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, "Entity");
                    return(false);
                }
            }

            XmlNode identifier = entity.SelectSingleNode("./link2:" + IDENTIFIER, theManager);

            if (identifier == null)
            {
                if ((identifier = entity.SelectSingleNode("./" + IDENTIFIER)) == null)
                {
                    Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, "identifier");
                    return(false);
                }
            }

            cp.EntitySchema = identifier.Attributes[SCHEME_ATTR].Value;
            cp.EntityValue  = identifier.InnerXml;

            XmlNode segments = entity.SelectSingleNode("./link2:" + SEGMENT, theManager);

            if (segments == null)
            {
                segments = entity.SelectSingleNode("./" + SEGMENT);
            }

            if (segments != null)
            {
                foreach (XmlNode segment in segments.ChildNodes)
                {
                    if (segment is XmlComment)
                    {
                        continue;
                    }

                    bool createSegment = true;
                    if (segment.LocalName.ToLower().Equals(EXPLICITMEMBER.ToLower()) &&
                        segment.NamespaceURI.Equals(DocumentBase.XBRLDI_URI))
                    {
                        //we have a dimension info
                        string dimensionId = null;
                        string valueId     = segment.InnerXml.Replace(":", "_");
                        foreach (XmlAttribute attr in segment.Attributes)
                        {
                            if (attr.Name.Equals(DIMENSION))
                            {
                                dimensionId = attr.Value.Replace(":", "_");
                                break;
                            }
                        }
                        if (dimensionId != null)
                        {
                            Segment seg             = new Segment(string.Empty, valueId, dimensionId, DocumentBase.XBRLDI_PREFIX, segment.NamespaceURI);
                            ContextDimensionInfo di = new ContextDimensionInfo();
                            di.dimensionId    = dimensionId;
                            di.Id             = valueId;
                            seg.DimensionInfo = di;

                            cp.AddSegment(seg);
                            createSegment = false;
                        }
                    }

                    if (createSegment)
                    {
                        cp.AddSegment(segment.Prefix, segment.InnerXml, segment.LocalName, segment.NamespaceURI);
                    }
                }
            }

            XmlNode scenarios = node.SelectSingleNode("./link2:" + SCENARIO, theManager);

            if (scenarios == null)
            {
                scenarios = node.SelectSingleNode("./" + SCENARIO);
            }

            if (scenarios != null)
            {
                foreach (XmlNode scenario in scenarios)
                {
                    bool createScenario = true;
                    if (scenario.LocalName.ToLower().Equals(EXPLICITMEMBER.ToLower()) &&
                        scenario.NamespaceURI.Equals(DocumentBase.XBRLDI_URI))
                    {
                        //we have a dimension info
                        string dimensionId = null;
                        string valueId     = scenario.InnerXml.Replace(":", "_");
                        foreach (XmlAttribute attr in scenario.Attributes)
                        {
                            if (attr.Name.Equals(DIMENSION))
                            {
                                dimensionId = attr.Value.Replace(":", "_");
                                break;
                            }
                        }
                        if (dimensionId != null)
                        {
                            Scenario             seg = new Scenario(string.Empty, valueId, dimensionId, DocumentBase.XBRLDI_PREFIX, scenario.NamespaceURI);
                            ContextDimensionInfo di  = new ContextDimensionInfo();
                            di.dimensionId    = dimensionId;
                            di.Id             = valueId;
                            seg.DimensionInfo = di;

                            cp.AddScenario(seg);
                            createScenario = false;
                        }
                    }

                    if (createScenario)
                    {
                        cp.AddScenario(scenario.Prefix, scenario.InnerXml, scenario.LocalName, scenario.NamespaceURI);
                    }
                }
            }

            // lastly, repopulate the time period
            XmlNode timePeriod = node.SelectSingleNode("./link2:" + PERIOD, theManager);

            if (timePeriod == null)
            {
                timePeriod = node.SelectSingleNode("./" + PERIOD);
                if (timePeriod == null)
                {
                    Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, "TimePeriod");
                    return(false);
                }
                else
                {
                    if (!cp.ParsePeriods(timePeriod, theManager))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (!cp.ParsePeriods(timePeriod, theManager))
                {
                    return(false);
                }
            }

            return(cp.IsValid());
        }