private static void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value) { ISetAttributes setAttributes = schemaElement as ISetAttributes; if (setAttributes == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixStrings.EXP_ISchemaElementDoesnotImplementISetAttribute, schemaElement.GetType().FullName)); } else { setAttributes.SetAttribute(name, value); } }
/// <summary> /// Parses an ISchemaElement from the XmlElement. /// </summary> /// <param name="schemaElement">ISchemaElement to fill in.</param> /// <param name="element">XmlElement to parse from.</param> private void ParseObjectFromElement(ISchemaElement schemaElement, XmlElement element) { foreach (XmlAttribute attribute in element.Attributes) { this.SetAttributeOnObject(schemaElement, attribute.LocalName, attribute.Value); } foreach (XmlNode node in element.ChildNodes) { XmlElement childElement = node as XmlElement; if (childElement != null) { ISchemaElement childSchemaElement = null; ICreateChildren createChildren = schemaElement as ICreateChildren; if (createChildren == null) { throw new InvalidOperationException("ISchemaElement with name " + element.LocalName + " does not implement ICreateChildren."); } else { childSchemaElement = createChildren.CreateChild(childElement.LocalName); } if (childSchemaElement == null) { childSchemaElement = this.CreateObjectFromElement(childElement); if (childSchemaElement == null) { throw new InvalidOperationException("XmlElement with name " + childElement.LocalName + " does not have a corresponding ISchemaElement."); } } this.ParseObjectFromElement(childSchemaElement, childElement); IParentElement parentElement = (IParentElement)schemaElement; parentElement.AddChild(childSchemaElement); } else { XmlText childText = node as XmlText; if (childText != null) { this.SetAttributeOnObject(schemaElement, "Content", childText.Value); } } } }
public virtual void AddChild(ISchemaElement child) { this.children.AddElement(child); }
public virtual void RemoveChild(ISchemaElement child) { this.children.RemoveElement(child); }
public XmlElement(ISchemaElement definition, IXmlElement parentElement, IParseLocationInfo parseLocation) { Definition = definition; ParentElement = parentElement; ParseLocation = parseLocation; }
/// <summary> /// Index an element by its corresponding row. /// </summary> /// <param name="row">The row corresponding to the element.</param> /// <param name="element">The element to index.</param> public void IndexElement(Row row, ISchemaElement element) { this.elements.Add(String.Concat(row.TableDefinition.Name, ':', row.GetPrimaryKey(PrimaryKeyDelimiter)), element); }
/// <summary> /// Removes a child element from this collection. /// </summary> /// <param name="element">The element to remove.</param> /// <exception cref="ArgumentException">Thrown if the element is not of an allowed type.</exception> public void RemoveElement(ISchemaElement element) { foreach (object obj in this.items) { CollectionItem collectionItem = obj as CollectionItem; if (collectionItem != null) { if (collectionItem.ElementType.IsAssignableFrom(element.GetType())) { if (collectionItem.Elements.Count == 0) { return; } collectionItem.RemoveElement(element); if (collectionItem.Elements.Count == 0) { this.containersUsed--; } this.totalContainedItems--; return; } continue; } ElementCollection collection = obj as ElementCollection; if (collection != null) { if (collection.Count == 0) { continue; } try { collection.RemoveElement(element); if (collection.Count == 0) { this.containersUsed--; } this.totalContainedItems--; return; } catch (ArgumentException) { // Eat the exception and keep looking. We'll throw our own if we can't find its home. } continue; } } throw new ArgumentException(String.Format( CultureInfo.InvariantCulture, WixStrings.EXP_ElementOfTypeIsNotValidForThisCollection, element.GetType().Name)); }
/// <summary> /// Adds a child element to this collection. /// </summary> /// <param name="element">The element to add.</param> /// <exception cref="ArgumentException">Thrown if the child is not of an allowed type.</exception> public void AddElement(ISchemaElement element) { foreach (object obj in this.items) { bool containerUsed; CollectionItem collectionItem = obj as CollectionItem; if (collectionItem != null) { containerUsed = collectionItem.Elements.Count != 0; if (collectionItem.ElementType.IsAssignableFrom(element.GetType())) { collectionItem.AddElement(element); if (!containerUsed) { this.containersUsed++; } this.totalContainedItems++; return; } continue; } ElementCollection collection = obj as ElementCollection; if (collection != null) { containerUsed = collection.Count != 0; try { collection.AddElement(element); if (!containerUsed) { this.containersUsed++; } this.totalContainedItems++; return; } catch (ArgumentException) { // Eat the exception and keep looking. We'll throw our own if we can't find its home. } continue; } } throw new ArgumentException(String.Format( CultureInfo.InvariantCulture, "Element of type {0} is not valid for this collection.", element.GetType().Name)); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Initialize a new constraint builder. You must call its Register method to create an dregister the constraint /// </summary> /// <param name="schemaElement"> /// The schema element associates to the constraint /// </param> /// <param name="propertyName"> /// Property name if any (Used to personalize the message and to send a data error info if the domain is observable) /// </param> /// <param name="expression"> /// Expression used to validate the constraint /// </param> /// <param name="message"> /// (Optional) Message to display when the constraint is not respected /// </param> /// <param name="isImplicit"> /// (Optional) true if this instance is implicit. /// </param> ///------------------------------------------------------------------------------------------------- public ConstraintBuilder(ISchemaElement schemaElement, string propertyName, Func <T, bool> expression = null, DiagnosticMessage message = null, bool isImplicit = false) : this(schemaElement, propertyName, expression, isImplicit) { Message(message); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Creates a new identifier. /// </summary> /// <param name="key"> /// the key. /// </param> /// <param name="schemaElement"> /// (Optional) the schema element. /// </param> /// <returns> /// An Identity. /// </returns> ///------------------------------------------------------------------------------------------------- public Identity CreateId(long key, ISchemaElement schemaElement = null) { return(CreateId(key.ToString(), schemaElement)); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Gets the elements in this collection. /// </summary> /// <param name="metaClass"> /// (Optional) the meta class. /// </param> /// <param name="skip"> /// (Optional) the skip. /// </param> /// <returns> /// An enumerator that allows foreach to be used to process the elements in this collection. /// </returns> ///------------------------------------------------------------------------------------------------- public virtual IEnumerable <IModelElement> GetElements(ISchemaElement metaClass = null, int skip = 0) { CheckInitialized(); return(L1Cache.GetElements(metaClass, skip)); }
IEnumerable <IModelElement> IDomainModel.GetElements(ISchemaElement metadata, int skip) { yield break; }
IModelElement IDomainModel.GetElement(Identity id, ISchemaElement schemaElement) { DebugContract.Requires(id); return(((ISchema)this).GetSchemaInfo(id)); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Creates a new identifier. /// </summary> /// <exception cref="NotSupportedException"> /// Thrown when the requested operation is not supported. /// </exception> /// <param name="key"> /// the key. /// </param> /// <param name="schemaElement"> /// (Optional) the schema element. /// </param> /// <returns> /// An Identity. /// </returns> ///------------------------------------------------------------------------------------------------- public Identity CreateId(long key, ISchemaElement schemaElement = null) { throw new NotSupportedException(); }
public SchemaElementBuilder(ISchemaElement schemaElement) { _schemaElement = schemaElement; }
private void ParseObjectFromElement(ISchemaElement schemaElement, XmlElement element) { foreach (XmlAttribute attribute in element.Attributes) { SetAttributeOnObject(schemaElement, attribute.LocalName, attribute.Value); } foreach (XmlNode node in element.ChildNodes) { XmlElement childElement = node as XmlElement; if (childElement != null) { ISchemaElement childSchemaElement = null; ICreateChildren createChildren = schemaElement as ICreateChildren; if (createChildren == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixStrings.EXP_ISchemaElementDoesnotImplementICreateChildren, element.LocalName)); } else { childSchemaElement = createChildren.CreateChild(childElement.LocalName); } if (childSchemaElement == null) { childSchemaElement = this.CreateObjectFromElement(childElement); if (childSchemaElement == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixStrings.EXP_XmlElementDoesnotHaveISchemaElement, childElement.LocalName)); } } this.ParseObjectFromElement(childSchemaElement, childElement); IParentElement parentElement = (IParentElement)schemaElement; parentElement.AddChild(childSchemaElement); } else { XmlText childText = node as XmlText; if (childText != null) { SetAttributeOnObject(schemaElement, "Content", childText.Value); } } } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Initialize a new constraint builder. You must call its Register method to create an dregister the constraint /// </summary> /// <param name="schemaElement"> /// The schema element associates to the constraint /// </param> /// <param name="propertyName"> /// Property name if any (Used to personalize the message and to send a data error info if the domain is observable) /// </param> /// <param name="expression"> /// Expression used to validate the constraint /// </param> /// <param name="message"> /// (Optional) Message to display when the constraint is not respected /// </param> /// <param name="isImplicit"> /// (Optional) true if this instance is implicit. /// </param> ///------------------------------------------------------------------------------------------------- public ConstraintBuilder(ISchemaElement schemaElement, string propertyName, Func <T, bool> expression, string message = null, bool isImplicit = false) : this(schemaElement, propertyName, expression, isImplicit) { this._message = message; }
/// <summary> /// Removes an element from this collection. /// </summary> /// <param name="element">The element to remove.</param> /// <exception cref="ArgumentException">Thrown if the element's type isn't assignable to the collection's type.</exception> public void RemoveElement(ISchemaElement element) { if (!this.elementType.IsAssignableFrom(element.GetType())) { throw new ArgumentException( String.Format( CultureInfo.InvariantCulture, "Element must be a subclass of {0}, but was of type {1}.", this.elementType.Name, element.GetType().Name), "element"); } this.elements.Remove(element); }
/// <summary> /// Removes a child element from this collection. /// </summary> /// <param name="element">The element to remove.</param> /// <exception cref="ArgumentException">Thrown if the element is not of an allowed type.</exception> public void RemoveElement(ISchemaElement element) { foreach (object obj in this.items) { CollectionItem collectionItem = obj as CollectionItem; if (collectionItem != null) { if (collectionItem.ElementType.IsAssignableFrom(element.GetType())) { if (collectionItem.Elements.Count == 0) { return; } collectionItem.RemoveElement(element); if (collectionItem.Elements.Count == 0) { this.containersUsed--; } this.totalContainedItems--; return; } continue; } ElementCollection collection = obj as ElementCollection; if (collection != null) { if (collection.Count == 0) { continue; } try { collection.RemoveElement(element); if (collection.Count == 0) { this.containersUsed--; } this.totalContainedItems--; return; } catch (ArgumentException) { // Eat the exception and keep looking. We'll throw our own if we can't find its home. } continue; } } throw new ArgumentException(String.Format( CultureInfo.InvariantCulture, "Element of type {0} is not valid for this collection.", element.GetType().Name)); }
/// <summary> /// Removes an element from this collection. /// </summary> /// <param name="element">The element to remove.</param> /// <exception cref="ArgumentException">Thrown if the element's type isn't assignable to the collection's type.</exception> public void RemoveElement(ISchemaElement element) { if (!this.elementType.IsAssignableFrom(element.GetType())) { throw new ArgumentException( String.Format( CultureInfo.InvariantCulture, WixStrings.EXP_ElementIsSubclassOfDifferentType, this.elementType.Name, element.GetType().Name), "element"); } this.elements.Remove(element); }
IEnumerable <IModelElement> IDomainModel.GetElements(ISchemaElement containerSchema, int skip) { throw new NotImplementedException(); }
/// <summary> /// Sets an attribute on an ISchemaElement. /// </summary> /// <param name="schemaElement">Schema element to set attribute on.</param> /// <param name="name">Name of the attribute to set.</param> /// <param name="value">Value to set on the attribute.</param> private void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value) { ISetAttributes setAttributes = schemaElement as ISetAttributes; if (setAttributes == null) { throw new InvalidOperationException("ISchemaElement with name " + schemaElement.GetType().FullName.ToString() + " does not implement ISetAttributes."); } else { setAttributes.SetAttribute(name, value); } }
///------------------------------------------------------------------------------------------------- /// <summary> /// A schema relationship. /// </summary> /// <param name="start"> /// The start element schema. /// </param> /// <param name="end"> /// The end element schema. /// </param> /// <param name="cardinality"> /// (Optional) /// Cardinality of the relationship. /// </param> /// <param name="isEmbedded"> /// (Optional) /// Defines if the relationship is embedded. /// </param> /// <param name="name"> /// (Optional) /// Relationship's name. /// </param> /// <param name="startPropertyName"> /// (Optional) /// The start property name. /// </param> /// <param name="endPropertyName"> /// (Optional) /// The end property name. /// </param> /// <param name="inheritedSchema"> /// (Optional) The schema element inherited by the relationship. /// </param> ///------------------------------------------------------------------------------------------------- public SchemaRelationship(ISchemaElement start, ISchemaElement end, Cardinality cardinality = Cardinality.OneToOne, bool isEmbedded = false, string name = null, string startPropertyName = null, string endPropertyName = null, ISchemaRelationship inheritedSchema = null) : base(start, end, typeof(T), cardinality, isEmbedded, name ?? typeof(T).FullName, inheritedSchema, startPropertyName, endPropertyName) { }