예제 #1
0
 /// <summary>
 /// Reads the contents of a section block from an XML document.
 /// </summary>
 /// <param name="node">XML node which represents an instance of this data block.</param>
 /// <param name="index">Index within a sequence (starts at 0).</param>
 public void ReadXml(XmlNode thisNode, int index)
 {
     try
     {
         SRXmlNodeReader reader = new SRXmlNodeReader(thisNode);
         sectionID = reader.ReadUInt32("id");
         gpuSize = reader.ReadUInt32("gpu_size");
         XmlNode cpuDataNode = reader.GetNodeOptional("cpu_data");
         if (cpuDataNode == null)
             cpuData = null;
         else if (SRRawDataBlock.HasRawXmlData(cpuDataNode))
             cpuData = new SRRawDataBlock(cpuDataNode);
         else
             cpuData = new SRZoneObjectSectionCpuData(cpuDataNode);
     }
     catch (Exception e)
     {
         // Add context information for the error message
         if (index >= 0)
             e.Data[BlockName] = index + 1;
         throw;
     }
 }
예제 #2
0
        /// <summary>
        /// Reads a property from an XML document and creates a new property object containing the data.
        /// The returned property will be an instance of one of the concrete derived property classes.
        /// </summary>
        /// <param name="thisNode">XML node which represents an instance of this data block.</param>
        /// <param name="index">Index within a sequence (starts at 0).</param>
        /// <returns>The new zone property which was read from the input stream.</returns>
        public static SRZoneProperty Create(XmlNode parentNode, int index)
        {
            SRZoneProperty property;
            try
            {
                // Read the common header
                SRXmlNodeReader reader = new SRXmlNodeReader(parentNode);
                UInt16 type = reader.ReadUInt16("type");
                Int32 nameCrc = reader.ReadInt32("name_crc");

                // Create the appropriate derived class based on the header information
                if (SRRawDataBlock.HasRawXmlData(parentNode))
                    property = new SRZoneDataProperty(type, nameCrc);
                else
                    property = Create(type, nameCrc);

                // Read the class-specific data into the derived class
                property.ReadXmlData(SRXmlNodeReader.GetNode(parentNode, "value"));

                // Read the optional padding data
                XmlNode paddingNode = reader.GetNodeOptional("padding");
                if (paddingNode != null && SRRawDataBlock.HasRawXmlData(paddingNode))
                    property.paddingData = new SRRawDataBlock(paddingNode);
            }
            catch (Exception e)
            {
                // Add context information for the error message
                if (index >= 0)
                    e.Data[BlockName] = index + 1;
                throw;
            }
            return property;
        }