Example #1
0
 public void RunBeforeEachTest()
 {
     Scenario s = new Scenario();
     this.Name = s.Name;
     this.ValueName = s.ValueName;
     this.ValueType = s.ValueType;
     this.Schema = s.Schema;
     this.Namespace = s.Namespace;
 }
Example #2
0
        /// <summary>
        /// Determines if supplied <see cref="Scenario"/> value equals this <see cref="Scenario"/> by comparing on properties defined
        ///  by supplied parameter.
        /// </summary>
        /// <param name="s"><see cref="Scenario"/> to be compared with this <see cref="Scenario"/>.</param>
        /// <param name="includeNamespaceAndSchema">A <see cref="Boolean"/> that, if true, indicates that
        /// method is to include namespace and schema in comparison.</param>
        /// <returns>An <see cref="int"/>: Zero if supplied <see cref="Scenario"/> is equal in value
        /// to this <see cref="Scenario"/>.</returns>
        public int CompareValue(Scenario s, Boolean includeNamespaceAndSchema)
        {
            //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Comparing s=" + s.ValueName + " to this=" + this.ValueName);
            int ret = 0;
            if (this.DimensionInfo != null)
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": this.DimensionInfo not null.  Comparing dimensions.");
                if (s.DimensionInfo == null)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal because s has no dimension.");
                    return 1;
                }

                return this.DimensionInfo.CompareValue(s.DimensionInfo);

            }
            else
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": this.DimensionInfo is null. Looking for dimensions in s.");
                if (s.DimensionInfo != null)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal because s has dimension.");
                    return -1;
                }
            }

            ret = this.ValueName.CompareTo( s.ValueName);
            if (ret != 0)
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to value names");
                return ret;
            }

            ret = this.ValueType.CompareTo( s.ValueType);
            if (ret != 0)
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to value types. "
                //    + "this.ValueType=" + this.ValueType + ", s.ValueType=" + s.ValueType );
                return ret;
            }

            if (includeNamespaceAndSchema == true)
            {
                ret = this.Namespace.CompareTo(s.Namespace);
                if (ret != 0)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to namespaces. "
                    //    + "this.Namespace=" + this.Namespace + ", s.Namespace=" + s.Namespace);
                    return ret;
                }

                ret = this.Schema.CompareTo(s.Schema);
                if (ret != 0)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to schemas. "
                    //    + "this.Schema=" + this.Schema + ", s.Schema=" + s.Schema);
                    return ret;
                }
            }

            return ret;
        }
        protected bool ScenarioEquals( Scenario s1, Scenario s2 )
        {
            if ( s1.ValueName.CompareTo( s2.ValueName ) != 0 ) return false;
            if ( s1.ValueType.CompareTo( s2.ValueType ) != 0 ) return false;

            return true;
        }
Example #4
0
        public static int Compare( Scenario x, Scenario y )
        {
            int typeCompare = x.ValueType.CompareTo( y.ValueType );
            if ( typeCompare == 0 )
            {
                return x.ValueName.CompareTo( y.ValueName );
            }

            return typeCompare;
        }
Example #5
0
 /// <summary>
 /// Determines if supplied <see cref="Scenario"/> value equals this <see cref="Scenario"/> by comparing on all significant properties.
 /// </summary>
 public int CompareValue(Scenario s)
 {
     return CompareValue(s, true);
 }
Example #6
0
 public static string BuildSegmentScenarioName(Scenario s)
 {
     s.ValueName = s.ValueName.Replace(Environment.NewLine, " ");
     return s.ValueName == string.Empty ? s.ValueType : "{" + s.ValueType + "} : " + s.ValueName;
     //return s.ValueName == string.Empty ? s.ValueType : s.ValueName;
 }
Example #7
0
        /// <summary>
        /// Determines if supplied <see cref="Scenario"/> value equals this <see cref="Scenario"/> by comparing on properties defined
        ///  by supplied parameter.
        /// </summary>
        /// <param name="s"><see cref="Scenario"/> to be compared with this <see cref="Scenario"/>.</param>
        /// <param name="includeNamespaceAndSchema">A <see cref="Boolean"/> that, if true, indicates that
        /// method is to include namespace and schema in comparison.</param>
        /// <returns>An <see cref="int"/>: Zero if supplied <see cref="Scenario"/> is equal in value
        /// to this <see cref="Scenario"/>.</returns>
        public int CompareValue(Scenario s, Boolean includeNamespaceAndSchema)
        {
            //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Comparing s=" + s.ValueName + " to this=" + this.ValueName);
            int ret = 0;

            if (this.DimensionInfo != null)
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": this.DimensionInfo not null.  Comparing dimensions.");
                if (s.DimensionInfo == null)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal because s has no dimension.");
                    return(1);
                }

                return(this.DimensionInfo.CompareValue(s.DimensionInfo));
            }
            else
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": this.DimensionInfo is null. Looking for dimensions in s.");
                if (s.DimensionInfo != null)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal because s has dimension.");
                    return(-1);
                }
            }

            ret = this.ValueName.CompareTo(s.ValueName);
            if (ret != 0)
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to value names");
                return(ret);
            }

            ret = this.ValueType.CompareTo(s.ValueType);
            if (ret != 0)
            {
                //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to value types. "
                //    + "this.ValueType=" + this.ValueType + ", s.ValueType=" + s.ValueType );
                return(ret);
            }

            if (includeNamespaceAndSchema == true)
            {
                ret = this.Namespace.CompareTo(s.Namespace);
                if (ret != 0)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to namespaces. "
                    //    + "this.Namespace=" + this.Namespace + ", s.Namespace=" + s.Namespace);
                    return(ret);
                }

                ret = this.Schema.CompareTo(s.Schema);
                if (ret != 0)
                {
                    //Debug.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + ": Scenarios NOT equal due to schemas. "
                    //    + "this.Schema=" + this.Schema + ", s.Schema=" + s.Schema);
                    return(ret);
                }
            }

            return(ret);
        }
Example #8
0
 /// <summary>
 /// Determines if supplied <see cref="Scenario"/> value equals this <see cref="Scenario"/> by comparing on all significant properties.
 /// </summary>
 public int CompareValue(Scenario s)
 {
     return(CompareValue(s, true));
 }
Example #9
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();
        }
Example #10
0
 /// <summary>
 /// Add a parameter-supplied <see cref="Scenario"/> to this <see cref="ContextProperty"/>'s segments collection.
 /// </summary>
 /// <param name="s">The <see cref="Scenario"/> to be added.</param>
 public void AddScenario(Scenario s)
 {
     Scenarios.Add( s );
 }