Exemple #1
0
 /// <summary>
 /// Merge attributes with source attribute collection.
 /// </summary>
 /// <param name="coll">Source attribute collection.</param>
 /// <param name="res">The parameters determine the resolution of attributes name conflicts</param>
 public void Merge(DDAttributesCollection coll, ResolveConflict res)
 {
     foreach (var item in coll)
     {
         Add(item.Key, item.Value, res);
     }
 }
Exemple #2
0
 /// <summary>
 /// Compares the two DDAttributesCollection of the same values and returns an integer that indicates whether the current instance precedes. Very slow
 /// </summary>
 /// <param name="value1">First DDAttributesCollection to compare</param>
 /// <param name="value2">Second DDAttributesCollection to compare</param>
 /// <returns>A value that indicates the relative order of the objects being compared. The return value has two meanings:
 /// Zero - the both DDAttributesCollection have some items and their values.
 /// The difference between the number of elements of the first and second DDAttributes Collection
 /// One - values of collection is not equal.</returns>
 /// <remarks>The both null object is equal and return value will be Zero. Very slow</remarks>
 public static int Compare(DDAttributesCollection value1, DDAttributesCollection value2)
 {
     if (((object)value1 == null) && ((object)value2 == null))
     {
         return(0);                                                      // if both are null -> return true
     }
     if (((object)value1 == null) || ((object)value2 == null))
     {
         return(1);                                                      // if only one of them are null ->  return false
     }
     if ((value1.Count != value2.Count))
     {
         return(value1.Count - value2.Count);                                // The difference between the number of elements of the first and second DDAttributes Collection
     }
     foreach (var keyValue1 in value1)
     {
         if (!value2.Contains(keyValue1.Key))
         {
             return(-1);                                 //
         }
         var valueCompareResult = DDValue.Compare(keyValue1.Value, value2[keyValue1.Key]);
         if (valueCompareResult != 0)
         {
             return(valueCompareResult);
         }
     }
     return(0);
 }
Exemple #3
0
        /// <summary>
        /// Returns attributes collection contains merged all attributes from all parent nodes (including root node) for specific node
        /// </summary>
        /// <param name="n">node</param>
        /// <param name="rc">conflict resolution</param>
        public static DDAttributesCollection GetMergedParentAttributes(DDNode n, ResolveConflict rc)
        {
            var current = new DDAttributesCollection();

            while (n != null)
            {
                current.Merge(n.Attributes, rc);
                n = n.Parent;
            }
            return(current);
        }
Exemple #4
0
        /// <summary>
        /// Compares the two DDNode of the same values and returns an integer that indicates whether the current instance precedes. Very slow.
        /// Return value that indicates the relative order of the objects being compared. The return value can be one of the <typeparamref name="NODE_COMPARISION_RESULT"/>
        /// </summary>
        /// <param name="value1">First DDNode to compare</param>
        /// <param name="value2">Second DDNode to compare</param>
        /// <returns>A value that indicates the relative order of the objects being compared. The return value can be one of the <typeparamref name="NODE_COMPARISION_RESULT"/></returns>>
        /// Zero - the both DDNode have some items and their values otherwise nodes are not equals
        /// <remarks>Very slow. The following properties are not involved in the comparison:
        /// - IsRoot; - Path; - Level
        /// </remarks>
        public static int Compare(DDNode value1, DDNode value2)
        {
            if (((object)value1 == null) && ((object)value2 == null))
            {
                return((int)NODE_COMPARISION_RESULT.NODE_EQUAL);                                                      // if both are null -> return true
            }
            if (((object)value1 == null) || ((object)value2 == null))
            {
                return((int)NODE_COMPARISION_RESULT.NODE_NULL);                                                      // if only one of them are null ->  return false
            }
            if ((value1.Name != value2.Name))
            {
                return(1);                              // if Name is not Equals->  return false
            }
            if (value1.Type.CompareTo(value2.Type) != 0)
            {
                return((int)NODE_COMPARISION_RESULT.NODE_TYPE_MISMATCH);                                         // node type is not matched
            }
            if ((value1.HasAttributes != value2.HasAttributes))
            {
                return((int)NODE_COMPARISION_RESULT.NODE_ATTRIBUTES_NOT_EQUAL);                                                // if HasAttributes is not Equals->  return false
            }
            if ((value1.HasChildNodes != value2.HasChildNodes))
            {
                return(1);                                                // if HasChildNodes is not Equals->  return false
            }
            // [-] fix revert comparison
            if ((value1.Count != value2.Count))
            {
                return((int)NODE_COMPARISION_RESULT.NODE_CHILD_NODES_NOT_EQUAL);                                // if Count of ChildNodes is not Equals->  return false
            }
            int compareResult = DDAttributesCollection.Compare(value1.Attributes, value2.Attributes);

            if (compareResult != 0)
            {
                return(compareResult);
            }

            foreach (var keyValue1 in value1)
            {
                if (!value2.Contains(keyValue1.Key))
                {
                    return((int)NODE_COMPARISION_RESULT.NODE_CHILD_NODES_NOT_EQUAL);                                 //
                }
                var valueCompareResult = DDNode.Compare(keyValue1.Value, value2[keyValue1.Key]);
                if (valueCompareResult != 0)
                {
                    return(valueCompareResult);
                }
            }
            return(0);
        }
Exemple #5
0
        /// <summary>
        /// Determines whether the Attribute Collection contains an elements with the specified names and will be throw new <exception cref="ContainsAttributesException"/> if one of these attributes was not found
        /// </summary>
        /// <param name="attr">collection of DDValue that can be accessed by name.</param>
        /// <param name="names">list of names of mandatory attributes</param>
        /// <exception cref="DDMissingSomeOfAttributesException"/>
        private static void containsAttributesOtherwiseThrow(this DDAttributesCollection attr, IEnumerable <string> names)
        {
            var nel = new List <string>();

            foreach (var name in names)
            {
                if (!attr.Contains(name))
                {
                    nel.Add(name);
                }
            }
            if (nel.Count > 0)
            {
                throw new DDMissingSomeOfAttributesException(nel.ToArray());
            }
        }
Exemple #6
0
        /// <summary>
        /// Creates a copy of the current Attribute Collection
        /// </summary>
        /// <returns>A copy of the current Attribute Collection</returns>
        public virtual DDAttributesCollection Clone()
        {
            var aDic = new DDAttributesCollection();

            foreach (var a in this)
            {
                if (a.Value == null)
                {
                    aDic.Add(a.Key, null);
                }
                else
                {
                    aDic.Add(a.Key, a.Value.Clone());
                }
            }
            return(aDic);
        }
Exemple #7
0
 public DDNode(string name, DDType type)
 {
     if (!IsNameCorect(name))
     {
         throw new DDNodeIncorrectNameException(name);
     }
     attributes = new DDAttributesCollection();
     Name       = name;
     childNodes = new Dictionary <string, DDNode>();
     if ((type == null) || (type.Name == null))
     {
         Type.Name = new DDType(string.Empty);
     }
     else
     {
         Type = type;
     }
 }
Exemple #8
0
 /// <summary>
 /// Determines whether the Attribute Collection contains an elements with the specified names and will be throw new <exception cref="ContainsAttributesException"/> if one of these attributes was not found
 /// </summary>
 /// <param name="attr">collection of DDValue that can be accessed by name.</param>
 /// <param name="names">list of names of mandatory attributes</param>
 /// <exception cref="DDMissingSomeOfAttributesException"/>
 public static void ContainsAttributesOtherwiseThrow(this DDAttributesCollection attr, params string[] names)
 {
     containsAttributesOtherwiseThrow(attr, names);
 }
Exemple #9
0
 /// <summary>
 /// Merge attributes with source attribute collection. In case of conflict, an appropriate exception is thrown
 /// </summary>
 /// <param name="coll">Source attribute collection.</param>
 public void Merge(DDAttributesCollection coll)
 {
     Merge(coll, ResolveConflict.THROW_EXCEPTION);
 }
Exemple #10
0
 protected bool Equals(DDAttributesCollection other)
 {
     return(Equals(attributes, other.attributes));
 }