internal APXmlElementInformation(APXmlElement owner, APXmlPropertyInformation propertyInfo)
		{
			_propertyInfo = propertyInfo;
			_owner = owner;

			_properties = new APXmlPropertyInformationCollection();
			foreach (APXmlProperty prop in owner.Properties)
				_properties.Add(new APXmlPropertyInformation(owner, prop));
		}
Exemple #2
0
        internal APXmlElementInformation(APXmlElement owner, APXmlPropertyInformation propertyInfo)
        {
            _propertyInfo = propertyInfo;
            _owner        = owner;

            _properties = new APXmlPropertyInformationCollection();
            foreach (APXmlProperty prop in owner.Properties)
            {
                _properties.Add(new APXmlPropertyInformation(owner, prop));
            }
        }
Exemple #3
0
 /// <summary>
 /// Adds a APXmlElement to the APXmlElementCollection.
 /// </summary>
 /// <param name="index">The index location at which to add the specified APXmlElement.</param>
 /// <param name="element">The APXmlElement to add.</param>
 protected virtual void BaseAdd(int index, APXmlElement element)
 {
     if (_keyMode)
     {
         if (ThrowOnDuplicate && BaseIndexOf(element) != -1)
         {
             throw new APXmlException(APResource.APXml_DuplicateElementInCollection);
         }
     }
     _list.Insert(index, element);
 }
Exemple #4
0
        /// <summary>
        /// Overridden. Causes the system to throw an exception.
        /// </summary>
        /// <param name="elementName">The name of the unrecognized element.</param>
        /// <param name="reader">An input stream that reads XML from the xml file.</param>
        /// <returns>true if the unrecognized element was deserialized successfully; otherwise, false. The default is false.</returns>
        protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader)
        {
            if (elementName == _addElementName)
            {
                APXmlElement elem = CreateNewElementInternal(null);
                elem.DeserializeElement(reader, false);
                BaseAdd(elem);
                return(true);
            }

            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Writes the contents of this element to the file when implemented in a derived class.
        /// </summary>
        /// <param name="writer">The XmlWriter that writes to the file.</param>
        /// <param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param>
        /// <returns>true if any data was actually serialized; otherwise, false.</returns>
        protected internal virtual bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
        {
            PreSerialize(writer);

            if (serializeCollectionKey)
            {
                APXmlPropertyCollection props = GetKeyProperties();
                foreach (APXmlProperty prop in props)
                {
                    writer.WriteAttributeString(prop.Name, prop.ConvertToString(this[prop.Name]));
                }
                return(props.Count > 0);
            }

            bool wroteData = false;

            foreach (APXmlPropertyInformation prop in ElementInformation.Properties)
            {
                if (prop.IsElement || prop.ValueOrigin == APXmlPropertyValueOrigin.Default)
                {
                    continue;
                }

                if (!object.Equals(prop.Value, prop.DefaultValue))
                {
                    writer.WriteAttributeString(prop.Name, prop.GetStringValue());
                    wroteData = true;
                }
            }

            foreach (APXmlPropertyInformation prop in ElementInformation.Properties)
            {
                if (!prop.IsElement)
                {
                    continue;
                }

                APXmlElement val = prop.Value as APXmlElement;
                if (val != null)
                {
                    wroteData = val.SerializeToXmlElement(writer, prop.Name) || wroteData;
                }
            }

            return(wroteData);
        }
Exemple #6
0
        /// <summary>
        /// Overridden. Writes the data to an XML element in the xml file when overridden in a derived class.
        /// </summary>
        /// <param name="writer">Output stream that writes XML to the xml file.</param>
        /// <param name="serializeCollectionKey">true to serialize the collection key; otherwise, false.</param>
        /// <returns>true if the APXmlElementCollection was written to the xml file successfully.</returns>
        protected internal override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
        {
            if (serializeCollectionKey)
            {
                return(base.SerializeElement(writer, serializeCollectionKey));
            }

            bool wroteData = false;

            for (int i = 0; i < _list.Count; i++)
            {
                APXmlElement elem = (APXmlElement)_list[i];
                elem.SerializeToXmlElement(writer, _addElementName);
            }

            wroteData = wroteData || _list.Count > 0;

            return(wroteData);
        }
Exemple #7
0
 /// <summary>
 /// Adds a APXmlElement to the APXmlElementCollection.
 /// </summary>
 /// <param name="element">The APXmlElement to add.</param>
 /// <param name="throwIfExists">true to throw an exception if the APXmlElement specified
 /// is already contained in the APXmlElementCollection; otherwise, false.</param>
 protected void BaseAdd(APXmlElement element, bool throwIfExists)
 {
     if (_keyMode)
     {
         int oldIndex = IndexOfKey(GetElementKey(element));
         if (oldIndex >= 0)
         {
             if (element.Equals(_list[oldIndex]))
             {
                 return;
             }
             if (throwIfExists)
             {
                 throw new APXmlException(APResource.APXml_DuplicateElementInCollection);
             }
             _list.RemoveAt(oldIndex);
         }
     }
     _list.Add(element);
 }
Exemple #8
0
        /// <summary>
        /// Determines whether two Object instances are equal.
        /// </summary>
        /// <param name="compareTo">The Object to compare with the current Object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
        public override bool Equals(object compareTo)
        {
            APXmlElement other = compareTo as APXmlElement;

            if (other == null)
            {
                return(false);
            }

            if (GetType() != other.GetType())
            {
                return(false);
            }

            foreach (APXmlProperty prop in Properties)
            {
                if (!object.Equals(this[prop], other[prop]))
                {
                    return(false);
                }
            }
            return(true);
        }
		/// <summary>
		/// Gets the element key for a specified configuration element when overridden in a derived class.
		/// </summary>
		/// <param name="element">The APXmlElement to return the key for.</param>
		/// <returns>An Object that acts as the key for the specified APXmlElement.</returns>
		protected abstract object GetElementKey(APXmlElement element);
		/// <summary>
		/// Gets a element by key;
		/// </summary>
		/// <param name="element">The element.</param>
		/// <returns>The key of element.</returns>
		protected override object GetElementKey(APXmlElement element)
		{
			return ((APRptFilterDef)element).Serial;
		}
		/// <summary>
		/// Adds a APXmlElement to the APXmlElementCollection.
		/// </summary>
		/// <param name="index">The index location at which to add the specified APXmlElement.</param>
		/// <param name="element">The APXmlElement to add.</param>
		protected virtual void BaseAdd(int index, APXmlElement element)
		{
			if (_keyMode)
			{
				if (ThrowOnDuplicate && BaseIndexOf(element) != -1)
					throw new APXmlException(APResource.APXml_DuplicateElementInCollection);
			}
			_list.Insert(index, element);
		}
		/// <summary>
		/// The index of the specified APXmlElementCollection.
		/// </summary>
		/// <param name="element">The APXmlElement for the specified index location.</param>
		/// <returns>The index of the specified APXmlElement; otherwise, -1.</returns>
		protected int BaseIndexOf(APXmlElement element)
		{
			return _list.IndexOf(element);
		}
		/// <summary>
		/// Adds a APXmlElement to the APXmlElementCollection.
		/// </summary>
		/// <param name="element">The APXmlElement to add.</param>
		protected virtual void BaseAdd(APXmlElement element)
		{
			BaseAdd(element, ThrowOnDuplicate);
		}
		/// <summary>
		/// Adds a APXmlElement to the APXmlElementCollection.
		/// </summary>
		/// <param name="element">The APXmlElement to add.</param>
		/// <param name="throwIfExists">true to throw an exception if the APXmlElement specified
		/// is already contained in the APXmlElementCollection; otherwise, false.</param>
		protected void BaseAdd(APXmlElement element, bool throwIfExists)
		{
			if (_keyMode)
			{
				int oldIndex = IndexOfKey(GetElementKey(element));
				if (oldIndex >= 0)
				{
					if (element.Equals(_list[oldIndex]))
						return;
					if (throwIfExists)
						throw new APXmlException(APResource.APXml_DuplicateElementInCollection);
					_list.RemoveAt(oldIndex);
				}
			}
			_list.Add(element);
		}
		/// <summary>
		/// Copies the contents of the APXmlElementCollection to an array.
		/// </summary>
		/// <param name="array">Array to which to copy the contents of the APXmlElementCollection.</param>
		/// <param name="index">Index location at which to begin copying.</param>
		public void CopyTo(APXmlElement[] array, int index)
		{
			_list.CopyTo(array, index);
		}
Exemple #16
0
 /// <summary>
 /// The index of the specified APXmlElementCollection.
 /// </summary>
 /// <param name="element">The APXmlElement for the specified index location.</param>
 /// <returns>The index of the specified APXmlElement; otherwise, -1.</returns>
 protected int BaseIndexOf(APXmlElement element)
 {
     return(_list.IndexOf(element));
 }
Exemple #17
0
        /// <summary>
        /// Removes the APXmlElement at the specified index location.
        /// </summary>
        /// <param name="index">The index location of the APXmlElement to remove.</param>
        protected internal void BaseRemoveAt(int index)
        {
            APXmlElement elem = (APXmlElement)_list[index];

            _list.RemoveAt(index);
        }
Exemple #18
0
 /// <summary>
 /// Gets the element key for a specified configuration element when overridden in a derived class.
 /// </summary>
 /// <param name="element">The APXmlElement to return the key for.</param>
 /// <returns>An Object that acts as the key for the specified APXmlElement.</returns>
 protected abstract object GetElementKey(APXmlElement element);
Exemple #19
0
        /// <summary>
        /// Reads XML from the xml file.
        /// </summary>
        /// <param name="reader">The XmlReader that reads from the xml file.</param>
        /// <param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param>
        protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            Hashtable readProps = new Hashtable();

            reader.MoveToContent();

            while (reader.MoveToNextAttribute())
            {
                APXmlPropertyInformation prop = ElementInformation.Properties[reader.LocalName];
                if (prop == null || (serializeCollectionKey && !prop.IsKey))
                {
                    if (reader.LocalName == "xmlns")
                    {
                        // Ignore
                    }
                    else if (!OnDeserializeUnrecognizedAttribute(reader.LocalName, reader.Value))
                    {
                        throw new APXmlException(APResource.GetString(APResource.APXml_UnrecognizedAttribute, reader.LocalName));
                    }

                    continue;
                }

                if (readProps.ContainsKey(prop))
                {
                    throw new APXmlException(APResource.GetString(APResource.APXml_DuplicateAttribute, prop.Name));
                }

                string value = null;
                try
                {
                    value = reader.Value;
                    ValidateValue(prop.Property, value);
                    prop.SetStringValue(value);
                }
                catch (APXmlException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new APXmlException(APResource.GetString(APResource.APXml_PropertyCannotBeParsed, prop.Name), ex, reader);
                }
                readProps[prop] = prop.Name;
            }

            reader.MoveToElement();

            if (reader.IsEmptyElement)
            {
                reader.Skip();
            }
            else
            {
                int depth = reader.Depth;

                reader.ReadStartElement();
                reader.MoveToContent();

                do
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        reader.Skip();
                        continue;
                    }

                    APXmlPropertyInformation prop = ElementInformation.Properties[reader.LocalName];
                    if (prop == null || (serializeCollectionKey && !prop.IsKey))
                    {
                        if (!OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                        {
                            if (prop == null)
                            {
                                APXmlElementCollection collection = GetDefaultCollection();
                                if (collection != null && collection.OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                                {
                                    continue;
                                }
                            }
                            throw new APXmlException(APResource.GetString(APResource.APXml_UnrecognizedElement, reader.LocalName));
                        }
                        continue;
                    }

                    if (!prop.IsElement)
                    {
                        throw new APXmlException(APResource.GetString(APResource.APXml_NotAElement, prop.Name));
                    }

                    if (readProps.Contains(prop))
                    {
                        throw new APXmlException(APResource.GetString(APResource.APXml_DuplicateElement, prop.Name));
                    }

                    APXmlElement val = prop.Value as APXmlElement;
                    val.DeserializeElement(reader, serializeCollectionKey);
                    readProps[prop] = prop.Name;
                } while (depth < reader.Depth);

                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    reader.Read();
                }
            }

            foreach (APXmlPropertyInformation prop in ElementInformation.Properties)
            {
                if (!String.IsNullOrEmpty(prop.Name) && prop.IsRequired && !readProps.ContainsKey(prop))
                {
                    APXmlPropertyInformation property = ElementInformation.Properties[prop.Name];
                    if (property == null)
                    {
                        object val = OnRequiredPropertyNotFound(prop.Name);
                        if (!object.Equals(val, prop.DefaultValue))
                        {
                            prop.Value = val;
                        }
                    }
                }
            }

            PostDeserialize();
        }
		internal APXmlPropertyInformation(APXmlElement owner, APXmlProperty property)
		{
			_owner = owner;
			_property = property;
		}
Exemple #21
0
 internal APXmlPropertyInformation(APXmlElement owner, APXmlProperty property)
 {
     _owner    = owner;
     _property = property;
 }
		/// <summary>
		/// Gets a element by key;
		/// </summary>
		/// <param name="element">The element.</param>
		/// <returns>The key of element.</returns>
		protected override object GetElementKey(APXmlElement element)
		{
			return ((APRptReferDef)element).ColumnId;
		}
Exemple #23
0
 /// <summary>
 /// Adds a APXmlElement to the APXmlElementCollection.
 /// </summary>
 /// <param name="element">The APXmlElement to add.</param>
 protected virtual void BaseAdd(APXmlElement element)
 {
     BaseAdd(element, ThrowOnDuplicate);
 }