private static void PopulateAttributes(ISchemaEditorNode node) { Type type = node.Value.GetType(); NodeAttributeBridge nodeAttributeBridge = new NodeAttributeBridge(node); foreach (FieldInfo field in AttributeFields(type)) { AttributeFieldReference attributeFieldReference = new AttributeFieldReference(node.Value, field, SpecifiedField(field)); node.AddAttribute(attributeFieldReference); attributeFieldReference.HasValueChanged += new AttributeFieldReference.AttributeFieldReferenceEventHandler(nodeAttributeBridge.AttributeHandler); if (attributeFieldReference.HasValue == false) continue; node.ActivateAttribute(attributeFieldReference); } }
/// <overloads> /// Copies the <see cref="SchemaEditorNodeCollection"/> /// or a portion of it to a one-dimensional array. /// </overloads> /// <summary> /// Copies the entire <see cref="SchemaEditorNodeCollection"/> /// to a one-dimensional <see cref="Array"/> /// of <see cref="ISchemaEditorNode"/> elements, /// starting at the beginning of the target array. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array"/> that is the destination /// of the <see cref="ISchemaEditorNode"/> elements copied from the /// <see cref="SchemaEditorNodeCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentException"> /// The number of elements in the source /// <see cref="SchemaEditorNodeCollection"/> is greater than /// the available space in the destination <paramref name="array"/>. /// </exception> /// <remarks> /// Please refer to <see cref="ArrayList.CopyTo"/> for details. /// </remarks> public void CopyTo(ISchemaEditorNode[] array) { ((ICollection) this).CopyTo(array, 0); }
public void AddActiveNode(ISchemaEditorNode child) { Nodes.Add((TreeNode)child); activeNodes.Add(child); }
/// <summary> /// Adds the elements of a <see cref="ISchemaEditorNode"/> array /// to the end of the <see cref="SchemaEditorNodeCollection"/>. /// </summary> /// <param name="array"> /// An <see cref="Array"/> of <see cref="ISchemaEditorNode"/> /// elements that should be added to the end of the /// <see cref="SchemaEditorNodeCollection"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="NotSupportedException"><para> /// The <see cref="SchemaEditorNodeCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>SchemaEditorNodeCollection</b> already contains /// one or more elements in <paramref name="array"/>, /// and the <b>SchemaEditorNodeCollection</b> /// ensures that all elements are unique. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.AddRange"/> for details. /// </remarks> public virtual void AddRange(ISchemaEditorNode[] array) { if (array == null) throw new ArgumentNullException("array"); AddRange(array, array.Length); }
/// <summary> /// Searches a section of the sorted /// <see cref="SchemaEditorNodeCollection"/> for an /// <see cref="ISchemaEditorNode"/> element using the /// specified comparer and returns the zero-based index of the element. /// </summary> /// <param name="index"> /// The zero-based starting index of the range of elements to search. /// </param> /// <param name="count">The number of elements to search.</param> /// <param name="value"> /// The <see cref="ISchemaEditorNode"/> object to locate /// in the <see cref="SchemaEditorNodeCollection"/>. /// This argument may be a null reference. /// </param> /// <param name="comparer"> /// <para>The <see cref="IComparer"/> implementation /// to use when comparing elements.</para> /// <para>-or-</para> /// <para>A null reference to use the <see cref="IComparable"/> /// implementation of each element.</para></param> /// <returns> /// The zero-based index of <paramref name="value"/> in the sorted /// <see cref="SchemaEditorNodeCollection"/>, if <paramref name="value"/> /// is found; otherwise, a negative number, which is the bitwise /// complement of the index of the next element that is larger than /// <paramref name="value"/> or, if there is no larger element, the /// bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="ArgumentException"><para> /// <paramref name="index"/> and <paramref name="count"/> /// do not denote a valid range of elements in the /// <see cref="SchemaEditorNodeCollection"/>. /// </para><para>-or-</para><para> /// <paramref name="comparer"/> is a null reference, /// and ISchemaEditorNode does not implement /// the <see cref="IComparable"/> interface. /// </para></exception> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero.</para> /// <para>-or-</para> /// <para><paramref name="count"/> is less than zero.</para> /// </exception> /// <remarks> /// Please refer to /// <see cref="ArrayList.BinarySearch(Int32, Int32, Object, IComparer)"/> /// for details. /// </remarks> public int BinarySearch(int index, int count, ISchemaEditorNode value, IComparer comparer) { if (index < 0) throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative."); if (count < 0) throw new ArgumentOutOfRangeException("count", count, "Argument cannot be negative."); if (index + count > _data.Count) throw new ArgumentException("Arguments denote invalid range of elements."); return Array.BinarySearch(_data.Items, index, _data.Count, value, comparer); }
public override void AddRange(ISchemaEditorNode[] array) { throw new NotSupportedException("Read-only collections cannot be modified."); }
/// <summary> /// Initializes a new instance of the /// <see cref="SchemaEditorNodeCollection"/> class /// that contains elements copied from the specified /// <see cref="ISchemaEditorNode"/> array and that has the /// same initial capacity as the number of elements copied. /// </summary> /// <param name="array"> /// An <see cref="Array"/> of <see cref="ISchemaEditorNode"/> /// elements that are copied to the new collection.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <remarks> /// Please refer to <see cref="ArrayList(ICollection)"/> for details. /// </remarks> public SchemaEditorNodeCollection(ISchemaEditorNode[] array) { if (array == null) throw new ArgumentNullException("array"); _data = new Data(); _data.Items = new ISchemaEditorNode[array.Length]; AddRange(array, array.Length); }
/// <summary> /// This removes a node from the active nodes list /// </summary> /// <param name="node"></param> public void RemoveActiveNode(ISchemaEditorNode node) { Validation.NotNull(node); activeNodes.Remove(node); }
public ElementSchemaError(NodeFieldReference field, ISchemaEditorNode parentNode) { this.field = field; this.parentNode = parentNode; }
public static SchemaErrorCollection CheckSchemaCompliance(ISchemaEditorNode node) { SchemaErrorCollection errors = new SchemaErrorCollection(); NodeContainsErrors(node, errors); return errors; }
public void AddActiveNode(ISchemaEditorNode child) { activeNodes.Add(child); }
public NodeAttributeBridge(ISchemaEditorNode node) { this.node = node; }
private static void PopulateTextField(ISchemaEditorNode node) { Type type = node.Value.GetType(); FieldInfoCollection fields = TextFields(type); if(fields.Count==0)//there can be only one text field return; TextNodeFieldReference fieldReference = new TextNodeFieldReference(node.Value, fields[0]); node.AddAttribute(fieldReference); }
private static void PopulateElements(ISchemaEditorNode node, ISchemaEditorNodeFactory factory) { Type nodeObjectType = node.Value.GetType(); foreach (FieldInfo field in ElementFields(nodeObjectType)) { if(field.FieldType.IsArray) AddArrayField(node,field, factory); else AddField(node,field, factory); } }
public void SetCapacity(int capacity) { if (capacity == Items.Length) return; if (capacity == 0) { Items = new ISchemaEditorNode[DefaultCapacity]; return; } ISchemaEditorNode[] items = new ISchemaEditorNode[capacity]; Array.Copy(Items, items, Count); Items = items; }
/// <summary> /// Returns the zero-based index of the first occurrence /// of the specified <see cref="ISchemaEditorNode"/> in the /// <see cref="SchemaEditorNodeCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="ISchemaEditorNode"/> object /// to locate in the <see cref="SchemaEditorNodeCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// The zero-based index of the first occurrence of /// <paramref name="value"/> in the <see cref="SchemaEditorNodeCollection"/>, /// if found; otherwise, -1.</returns> /// <remarks> /// Please refer to <see cref="ArrayList.IndexOf"/> for details. /// </remarks> public int IndexOf(ISchemaEditorNode value) { int count = _data.Count; ISchemaEditorNode[] items = _data.Items; if ((object) value == null) { for (int i = 0; i < count; i++) { if ((object) items[i] == null) return i; } return -1; } for (int i = 0; i < count; i++) { if (value.Equals(items[i])) return i; } return -1; }
public override int Add(ISchemaEditorNode value) { throw new NotSupportedException("Read-only collections cannot be modified."); }
/// <summary> /// Inserts a <see cref="ISchemaEditorNode"/> element into the /// <see cref="SchemaEditorNodeCollection"/> at the specified index. /// </summary> /// <param name="index"> /// The zero-based index at which <paramref name="value"/> /// should be inserted.</param> /// <param name="value"> /// The <see cref="ISchemaEditorNode"/> object to insert /// into the <see cref="SchemaEditorNodeCollection"/>. /// This argument may be a null reference. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero.</para> /// <para>-or-</para><para> /// <paramref name="index"/> is greater than <see cref="Count"/>. /// </para></exception> /// <exception cref="NotSupportedException"><para> /// The <see cref="SchemaEditorNodeCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>SchemaEditorNodeCollection</b> /// already contains <paramref name="value"/>, /// and the <b>SchemaEditorNodeCollection</b> /// ensures that all elements are unique. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.Insert"/> for details. /// </remarks> public virtual void Insert(int index, ISchemaEditorNode value) { int count = _data.Count; if (index < 0) throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative."); if (index > count) throw new ArgumentOutOfRangeException("index", index, "Argument cannot exceed Count."); if (_data.IsUnique) CheckUnique(value); if (count == _data.Items.Length) _data.EnsureCapacity(count + 1); if (index < count) Array.Copy(_data.Items, index, _data.Items, index + 1, count - index); _data.Items[index] = value; _data.Count++; }
public override void Insert(int index, ISchemaEditorNode value) { throw new NotSupportedException("Read-only collections cannot be modified."); }
/// <summary> /// Removes the first occurrence of the specified /// <see cref="ISchemaEditorNode"/> from the /// <see cref="SchemaEditorNodeCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="ISchemaEditorNode"/> object to remove /// from the <see cref="SchemaEditorNodeCollection"/>. /// This argument may be a null reference. /// </param> /// <exception cref="NotSupportedException"> /// The <see cref="SchemaEditorNodeCollection"/> /// is read-only or has a fixed size.</exception> /// <remarks> /// Please refer to <see cref="ArrayList.Remove"/> for details. /// </remarks> public void Remove(ISchemaEditorNode value) { int index = IndexOf(value); if (index >= 0) RemoveAt(index); }
/// <summary> /// Adds a <see cref="ISchemaEditorNode"/> to the end /// of the <see cref="SchemaEditorNodeCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="ISchemaEditorNode"/> object to be added /// to the end of the <see cref="SchemaEditorNodeCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// The <see cref="SchemaEditorNodeCollection"/> /// index at which the <paramref name="value"/> has been added. /// </returns> /// <exception cref="NotSupportedException"><para> /// The <see cref="SchemaEditorNodeCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>SchemaEditorNodeCollection</b> /// already contains <paramref name="value"/>, /// and the <b>SchemaEditorNodeCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.Add"/> for details. /// </remarks> public virtual int Add(ISchemaEditorNode value) { if (_data.IsUnique) CheckUnique(value); int count = _data.Count; if (count == _data.Items.Length) _data.EnsureCapacity(count + 1); _data.Items[count] = value; return _data.Count++; }
/// <summary> /// Copies the elements of the <see cref="SchemaEditorNodeCollection"/> /// to a new <see cref="Array"/> of /// <see cref="ISchemaEditorNode"/> elements. /// </summary> /// <returns> /// A one-dimensional <see cref="Array"/> of /// <see cref="ISchemaEditorNode"/> elements containing copies of the /// elements of the <see cref="SchemaEditorNodeCollection"/>. /// </returns> /// <remarks> /// Please refer to <see cref="ArrayList.ToArray"/> for details. /// </remarks> public ISchemaEditorNode[] ToArray() { ISchemaEditorNode[] array = new ISchemaEditorNode[_data.Count]; Array.Copy(_data.Items, array, _data.Count); return array; }
/// <overloads> /// Uses a binary search algorithm to locate a specific element /// in the sorted <see cref="SchemaEditorNodeCollection"/> /// or a portion of it. /// </overloads> /// <summary> /// Searches the entire sorted <see cref="SchemaEditorNodeCollection"/> /// for an <see cref="ISchemaEditorNode"/> element using the /// specified comparer and returns the zero-based index of the element. /// </summary> /// <param name="value"> /// The <see cref="ISchemaEditorNode"/> object to locate /// in the <see cref="SchemaEditorNodeCollection"/>. /// This argument may be a null reference. /// </param> /// <param name="comparer"> /// <para>The <see cref="IComparer"/> implementation /// to use when comparing elements.</para> /// <para>-or-</para> /// <para>A null reference to use the <see cref="IComparable"/> /// implementation of each element.</para></param> /// <returns> /// The zero-based index of <paramref name="value"/> in the sorted /// <see cref="SchemaEditorNodeCollection"/>, if <paramref name="value"/> /// is found; otherwise, a negative number, which is the bitwise /// complement of the index of the next element that is larger than /// <paramref name="value"/> or, if there is no larger element, the /// bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="ArgumentException"> /// <paramref name="comparer"/> is a null reference, /// and ISchemaEditorNode does not implement /// the <see cref="IComparable"/> interface.</exception> /// <remarks> /// Please refer to /// <see cref="ArrayList.BinarySearch(Object, IComparer)"/> /// for details. /// </remarks> public int BinarySearch(ISchemaEditorNode value, IComparer comparer) { return Array.BinarySearch(_data.Items, 0, _data.Count, value, comparer); }
private void AddRange(ISchemaEditorNode[] array, int range) { if (range == 0) return; if (_data.IsUnique) { foreach (ISchemaEditorNode value in array) CheckUnique(value); } if (_data.Count + range > _data.Items.Length) _data.EnsureCapacity(_data.Count + range); Array.Copy(array, 0, _data.Items, _data.Count, range); _data.Count += range; }
/// <summary> /// Determines whether the <see cref="SchemaEditorNodeCollection"/> /// contains the specified <see cref="ISchemaEditorNode"/> element. /// </summary> /// <param name="value"> /// The <see cref="ISchemaEditorNode"/> object to locate /// in the <see cref="SchemaEditorNodeCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// <c>true</c> if <paramref name="value"/> is found in the /// <see cref="SchemaEditorNodeCollection"/>; otherwise, <c>false</c>. /// </returns> /// <remarks> /// Please refer to <see cref="ArrayList.Contains"/> for details. /// </remarks> public bool Contains(ISchemaEditorNode value) { return (IndexOf(value) >= 0); }
private void CheckUnique(ISchemaEditorNode value) { if (IndexOf(value) >= 0) throw new NotSupportedException("Unique collections cannot contain duplicate elements."); }
/// <summary> /// Copies the entire <see cref="SchemaEditorNodeCollection"/> /// to a one-dimensional <see cref="Array"/> /// of <see cref="ISchemaEditorNode"/> elements, /// starting at the specified index of the target array. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array"/> that is the destination /// of the <see cref="ISchemaEditorNode"/> elements copied from the /// <see cref="SchemaEditorNodeCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <param name="arrayIndex"> /// The zero-based index in <paramref name="array"/> /// at which copying begins.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="arrayIndex"/> is less than zero.</exception> /// <exception cref="ArgumentException"><para> /// <paramref name="arrayIndex"/> is equal to or /// greater than the length of <paramref name="array"/>. /// </para><para>-or-</para><para> /// The number of elements in the source /// <see cref="SchemaEditorNodeCollection"/> is greater /// than the available space from <paramref name="arrayIndex"/> /// to the end of the destination <paramref name="array"/>. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.CopyTo"/> for details. /// </remarks> public void CopyTo(ISchemaEditorNode[] array, int arrayIndex) { ((ICollection) this).CopyTo(array, arrayIndex); }
private void CheckUnique(ISchemaEditorNode value, int index) { int existing = IndexOf(value); if (existing >= 0 && existing != index) throw new NotSupportedException("Unique collections cannot contain duplicate elements."); }
/// <summary> /// This removes a node from the active nodes list /// </summary> /// <param name="node"></param> public void RemoveActiveNode(ISchemaEditorNode node) { Nodes.Remove((TreeNode)node); activeNodes.Remove(node); }
private static bool NodeContainsErrors(ISchemaEditorNode node, SchemaErrorCollection errors) { bool errorFound = false; foreach (IFieldReference attribute in node.Attributes) { if(attribute.IsRequired && attribute.HasValue==false) { node.HasSchemaError = true; errorFound = true; errors.Add(new AttributeSchemaError(attribute, node)); } } foreach (NodeFieldReference fieldReference in node.NodeFields) { if(fieldReference.AmountRequired>fieldReference.AmountExisting) { node.HasSchemaError = true; errorFound =true; errors.Add(new ElementSchemaError(fieldReference, node)); } } node.HasSchemaError = errorFound; errorFound = false; foreach (ISchemaEditorNode activeNode in node.ActiveNodes) { if(NodeContainsErrors(activeNode,errors)) { errorFound = true; } } node.ChildHasSchemaError = errorFound; return node.ChildHasSchemaError || node.HasSchemaError; }