Exemple #1
0
        internal APGenSection GetSectionInstance(SectionInfo sectionInfo, bool createDefaultInstance)
        {
            object       data    = _elementData[sectionInfo];
            APGenSection section = data as APGenSection;

            if (section != null || !createDefaultInstance)
            {
                return(section);
            }

            object sectionObj = sectionInfo.CreateInstance();

            section = sectionObj as APGenSection;
            if (section == null)
            {
                APGenDefaultSection defaultSection = new APGenDefaultSection();
                defaultSection.SectionHandler = sectionObj as IAPGenSectionHandler;
                section = defaultSection;
            }

            if (data != null)
            {
                string xml = data as string;

                section.RawXml = xml;

                using (XmlTextReader reader = new XmlTextReader(new StringReader(xml)))
                {
                    section.DeserializeSection(reader);
                }
            }

            _elementData[sectionInfo] = section;
            return(section);
        }
Exemple #2
0
        /// <summary>
        /// Removes the specified APGenSection object from this APGenSectionCollection.
        /// </summary>
        /// <param name="name">The name of the section to be removed.</param>
        public void Remove(string name)
        {
            SectionInfo secData = _group.Sections[name] as SectionInfo;

            if (secData != null)
            {
                _gen.RemoveGenInfo(secData);
            }
        }
Exemple #3
0
        internal void CreateSection(SectionGroupInfo groupInfo, string name, APGenSection section)
        {
            if (groupInfo.HasChild(name))
            {
                throw new APGenException(APResource.GetString(APResource.APGen_SectionAlreadyExists, name));
            }

            if (section.SectionInformation.Type == null)
            {
                section.SectionInformation.Type = GenHost.GetGenTypeName(section.GetType());
            }

            SectionInfo sectionInfo = new SectionInfo(name, section.SectionInformation);

            sectionInfo.StreamName = _streamName;
            sectionInfo.GenHost    = GenHost;
            groupInfo.AddChild(sectionInfo);
            _elementData[sectionInfo] = section;
        }
Exemple #4
0
 /// <summary>
 /// Get a section by name.
 /// </summary>
 /// <param name="name">The specified section name.</param>
 /// <returns>The section object.</returns>
 public APGenSection this[string name]
 {
     get
     {
         APGenSection section = BaseGet(name) as APGenSection;
         if (section == null)
         {
             SectionInfo sectionInfo = _group.Sections[name] as SectionInfo;
             if (sectionInfo == null)
             {
                 return(null);
             }
             section = _gen.GetSectionInstance(sectionInfo, true);
             if (section == null)
             {
                 return(null);
             }
             BaseSet(name, section);
         }
         return(section);
     }
 }
Exemple #5
0
        public override void ReadGen(APGen gen, string streamName, XmlTextReader reader)
        {
            StreamName = streamName;
            GenHost    = gen.GenHost;

            if (reader.LocalName != "genSections")
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.Name == "name")
                    {
                        Name = reader.Value;
                    }
                    else if (reader.Name == "type")
                    {
                        TypeName = reader.Value;
                        Type     = null;
                    }
                    else
                    {
                        ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, ""), reader);
                    }
                }

                if (Name == null)
                {
                    ThrowException(APResource.GetString(APResource.APGen_MissingRequiredAttribute, "sectionGroup", "name"), reader);
                }
            }

            if (TypeName == null)
            {
                TypeName = typeof(APGenSectionGroup).FullName;
            }

            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return;
            }

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

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

                string  name = reader.LocalName;
                GenInfo info = null;

                if (name == "section")
                {
                    info = new SectionInfo();
                }
                else if (name == "sectionGroup")
                {
                    info = new SectionGroupInfo();
                }
                else
                {
                    ThrowException(APResource.GetString(APResource.APGen_UnrecognizedElement, reader.Name), reader);
                }


                info.ReadGen(gen, streamName, reader);
                GenInfo actInfo = Groups[info.Name];
                if (actInfo == null)
                {
                    actInfo = Sections[info.Name];
                }

                if (actInfo != null)
                {
                    if (actInfo.GetType() != info.GetType())
                    {
                        ThrowException(APResource.GetString(APResource.APGen_SectionNameAlreadyExists, info.Name), reader);
                    }

                    actInfo.StreamName = streamName;
                }
                else
                {
                    AddChild(info);
                }
            }

            reader.ReadEndElement();
        }
Exemple #6
0
        /// <summary>
        /// Removes the specified APGenSection object from this APGenSectionCollection.
        /// </summary>
        /// <param name="index">The index of the section to be removed.</param>
        public void RemoveAt(int index)
        {
            SectionInfo secData = _group.Sections[index] as SectionInfo;

            _gen.RemoveGenInfo(secData);
        }
		public override void ReadGen(APGen gen, string streamName, XmlTextReader reader)
		{
			StreamName = streamName;
			GenHost = gen.GenHost;

			if (reader.LocalName != "genSections")
			{
				while (reader.MoveToNextAttribute())
				{
					if (reader.Name == "name")
					{
						Name = reader.Value;
					}
					else if (reader.Name == "type")
					{
						TypeName = reader.Value;
						Type = null;
					}
					else
					{
						ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, ""), reader);
					}
				}

				if (Name == null)
					ThrowException(APResource.GetString(APResource.APGen_MissingRequiredAttribute, "sectionGroup", "name"), reader);
			}

			if (TypeName == null)
				TypeName = typeof(APGenSectionGroup).FullName;

			if (reader.IsEmptyElement)
			{
				reader.Skip();
				return;
			}

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

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

				string name = reader.LocalName;
				GenInfo info = null;

				if (name == "section")
					info = new SectionInfo();
				else if (name == "sectionGroup")
					info = new SectionGroupInfo();
				else
					ThrowException(APResource.GetString(APResource.APGen_UnrecognizedElement, reader.Name), reader);


				info.ReadGen(gen, streamName, reader);
				GenInfo actInfo = Groups[info.Name];
				if (actInfo == null)
					actInfo = Sections[info.Name];

				if (actInfo != null)
				{
					if (actInfo.GetType() != info.GetType())
						ThrowException(APResource.GetString(APResource.APGen_SectionNameAlreadyExists, info.Name), reader);

					actInfo.StreamName = streamName;
				}
				else
					AddChild(info);
			}

			reader.ReadEndElement();
		}
Exemple #8
0
		internal void CreateSection(SectionGroupInfo groupInfo, string name, APGenSection section)
		{
			if (groupInfo.HasChild(name))
				throw new APGenException(APResource.GetString(APResource.APGen_SectionAlreadyExists, name));

			if (section.SectionInformation.Type == null)
				section.SectionInformation.Type = GenHost.GetGenTypeName(section.GetType());

			SectionInfo sectionInfo = new SectionInfo(name, section.SectionInformation);
			sectionInfo.StreamName = _streamName;
			sectionInfo.GenHost = GenHost;
			groupInfo.AddChild(sectionInfo);
			_elementData[sectionInfo] = section;
		}
Exemple #9
0
		internal APGenSection GetSectionInstance(SectionInfo sectionInfo, bool createDefaultInstance)
		{
			object data = _elementData[sectionInfo];
			APGenSection section = data as APGenSection;
			if (section != null || !createDefaultInstance)
				return section;

			object sectionObj = sectionInfo.CreateInstance();
			section = sectionObj as APGenSection;
			if (section == null)
			{
				APGenDefaultSection defaultSection = new APGenDefaultSection();
				defaultSection.SectionHandler = sectionObj as IAPGenSectionHandler;
				section = defaultSection;
			}

			if (data != null)
			{
				string xml = data as string;

				section.RawXml = xml;

				using (XmlTextReader reader = new XmlTextReader(new StringReader(xml)))
				{
					section.DeserializeSection(reader);
				}
			}

			_elementData[sectionInfo] = section;
			return section;
		}
Exemple #10
0
		internal void SetSectionXml(SectionInfo sectionInfo, string data)
		{
			_elementData[sectionInfo] = data;
		}
Exemple #11
0
		internal string GetSectionXml(SectionInfo sectionInfo)
		{
			return _elementData[sectionInfo] as string;
		}
Exemple #12
0
 internal void SetSectionXml(SectionInfo sectionInfo, string data)
 {
     _elementData[sectionInfo] = data;
 }
Exemple #13
0
 internal string GetSectionXml(SectionInfo sectionInfo)
 {
     return(_elementData[sectionInfo] as string);
 }