Ejemplo n.º 1
0
 protected void LoadDBCFile(string fileName, DBCDataColumn[] columns)
 {
     this.fileName = fileName;
     this.columns = columns;
 }
Ejemplo n.º 2
0
 public DBCFile(string fileName, DBCDataColumn[] columns)
 {
     LoadDBCFile(fileName, columns);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the formatted XML document, supplying information about the DBC file to read.
        /// </summary>
        /// <param name="xmlStream">A stream containing the XML document.</param>
        void readXml(Stream xmlStream)
        {
            //-- Create a new XmlTextReader 
            XmlTextReader xml = new XmlTextReader(xmlStream);

            //-- Move to the content
            xml.MoveToContent();

            xml.ReadToDescendant("field_count");
            int fieldCount = int.Parse(xml.ReadElementContentAsString());
            columns = new DBCDataColumn[fieldCount];

            //-- Move to the 'fields' node
            bool found = false;
            while (xml.Read() && !found)
            {
                if (xml.LocalName == "fields")
                    break;
            }

            int index = 0;
            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.Element)
                {
                    // Check if this node is a 'field' element
                    if (xml.LocalName != "field")
                        break;

                    // Try retrieving the column's name
                    string fieldName = null;
                    try { fieldName = xml.GetAttribute("name"); }
                    catch
                    {
                        throw new DBCException("Couldn't parse field attribute 'name' (" + xml.LineNumber + ", " + xml.LinePosition + ").");
                    }

                    // Try parsing the column's type
                    Type fieldType = null;
                    try {  fieldType = parseXMLType(xml.GetAttribute("type")); }
                    catch
                    {
                        throw new DBCException("Couldn't parse field attribute 'type' (" + xml.LineNumber + ", " + xml.LinePosition + ").");
                    }

                    // Check if this column name has already been taken
                    if (doesColumnNameExist(fieldName))
                        throw new DBCException("Ambigious field name '" + fieldName + "' (" + xml.LineNumber + ", " + xml.LinePosition + ").");

                    // Set this column with the associating information
                    columns[index] = new DBCDataColumn(fieldName, fieldType, fieldType == typeof(string));

                    // Increase the column pointer
                    index++;
                }       
            }
        }