Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
        /// <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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public virtual void AddChild(ISchemaElement child)
 {
     this.children.AddElement(child);
 }
Ejemplo n.º 4
0
 public virtual void RemoveChild(ISchemaElement child)
 {
     this.children.RemoveElement(child);
 }
Ejemplo n.º 5
0
 public XmlElement(ISchemaElement definition, IXmlElement parentElement, IParseLocationInfo parseLocation)
 {
     Definition    = definition;
     ParentElement = parentElement;
     ParseLocation = parseLocation;
 }
Ejemplo n.º 6
0
 /// <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);
 }
Ejemplo n.º 7
0
        /// <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));
        }
Ejemplo n.º 8
0
        /// <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);
 }
Ejemplo n.º 10
0
 ///-------------------------------------------------------------------------------------------------
 /// <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));
 }
Ejemplo n.º 11
0
 ///-------------------------------------------------------------------------------------------------
 /// <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));
 }
Ejemplo n.º 12
0
 IEnumerable <IModelElement> IDomainModel.GetElements(ISchemaElement metadata, int skip)
 {
     yield break;
 }
Ejemplo n.º 13
0
 IModelElement IDomainModel.GetElement(Identity id, ISchemaElement schemaElement)
 {
     DebugContract.Requires(id);
     return(((ISchema)this).GetSchemaInfo(id));
 }
Ejemplo n.º 14
0
 ///-------------------------------------------------------------------------------------------------
 /// <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();
 }
Ejemplo n.º 15
0
 public SchemaElementBuilder(ISchemaElement schemaElement)
 {
     _schemaElement = schemaElement;
 }
Ejemplo n.º 16
0
        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;
 }
Ejemplo n.º 18
0
 /// <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);
 }
Ejemplo n.º 19
0
            /// <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);
            }
Ejemplo n.º 20
0
        /// <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));
        }
Ejemplo n.º 21
0
            /// <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);
            }
Ejemplo n.º 22
0
 IEnumerable <IModelElement> IDomainModel.GetElements(ISchemaElement containerSchema, int skip)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 23
0
 /// <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)
 {
 }