Esempio n. 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);
        }
Esempio n. 2
0
        public override void WriteData(APGen gen, XmlWriter writer)
        {
            string xml;

            APGenSection section = gen.GetSectionInstance(this, false);

            if (section != null)
            {
                xml = section.SerializeSection(Name);

                string externalDataXml = section.ExternalDataXml;
                string filePath        = gen.FileName;

                if (!String.IsNullOrEmpty(filePath) && !String.IsNullOrEmpty(externalDataXml))
                {
                    using (StreamWriter sw = new StreamWriter(filePath))
                    {
                        sw.Write(externalDataXml);
                    }
                }
            }
            else
            {
                xml = gen.GetSectionXml(this);
            }

            if (xml != null)
            {
                writer.WriteRaw(xml);
            }
        }
Esempio n. 3
0
        public override object CreateInstance()
        {
            object       obj     = base.CreateInstance();
            APGenSection section = obj as APGenSection;

            if (section != null)
            {
                section.SectionInformation.SetName(Name);
            }
            return(obj);
        }
Esempio n. 4
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;
        }
Esempio n. 5
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);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Adds a APGenSection object to the APGenSectionCollection.
 /// </summary>
 /// <param name="name">The name of the section to be added.</param>
 /// <param name="section">The section to be added.</param>
 public void Add(string name, APGenSection section)
 {
     _gen.CreateSection(_group, name, section);
 }
		/// <summary>
		/// Adds a APGenSection object to the APGenSectionCollection.
		/// </summary>
		/// <param name="name">The name of the section to be added.</param>
		/// <param name="section">The section to be added.</param>
		public void Add(string name, APGenSection section)
		{
			_gen.CreateSection(_group, name, section);
		}
		/// <summary>
		/// Copies this APGenSectionCollection object to an array.
		/// </summary>
		/// <param name="array">The array to which to copy.</param>
		/// <param name="index">The index location at which to begin copying.</param>
		public void CopyTo(APGenSection[] array, int index)
		{
			for (int n = 0; n < _group.Sections.Count; n++)
				array[n + index] = this[n];
		}
Esempio n. 9
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;
		}