Example #1
0
    private bool _NextToken(XmlReader reader)
    {
        while (!reader.EOF && reader.Read() && !reader.IsStartElement())
            ;

        return !reader.EOF;
    }
    private object ReadObject(string classname, List<object> list, XmlReader reader)
    {
        object res = null;
        int count = 0;
        string attribute = null;
        int fieldcount;

            if (classname == null)
            {
                reader.Read();
                if (reader.IsStartElement())
                    classname = XmlConvert.DecodeName(reader.Name);
                count = Convert.ToInt32(reader["count"]);
            }

            if (classname == null)
                return null;
        fieldcount = Convert.ToInt32(reader["fieldcount"]);
        attribute = reader["reference"];
        reader.Read();
        if (reader.IsStartElement() || reader.Value != null)
        {
            Type objtype = Type.GetType(classname);

            if (attribute != null)
            {
                //  string attribute = reader["reference"];
                if (attribute != null)
                {
                    res = list[Convert.ToInt32(attribute)];
                }
            }
            else if (objtype.IsPrimitive)
            {
                res = (object)objtype.InvokeMember("Parse",
                      BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public,
                      null, null, new object[] { XmlConvert.DecodeName(reader.Value.Trim()) });
                list.Add(res);
            }
            else if (objtype.Equals(typeof(string)))
            {
                res = XmlConvert.DecodeName(reader.Value.Trim());
            }
            else
            {
                if (objtype.IsArray)
                {
                    //count = Convert.ToInt32(reader["count"]);
                    int index = 0;
                    res = Activator.CreateInstance(objtype, count);
                    list.Add(res);
                    while (index < count)
                    {
                        //reader.Read();
                        while(!reader.IsStartElement())
                            reader.Read();
                        string s = reader.Name;
                        ((System.Array)res).SetValue(ReadObject(s, list, reader), index++);
                    }
                }
                else
                {
                    res = Activator.CreateInstance(objtype);
                    list.Add(res);
                    int index = 0;
                    //count = Convert.ToInt32(reader["count"]);
                    while (index < fieldcount)
                    {
                        while (!reader.IsStartElement())
                            reader.Read();
                        index++;
                        string fieldname = reader.Name;
                        object fieldobject = ReadObject(null, list, reader);
                        FieldInfo fiendinf = objtype.GetField(fieldname, BindingFlags.GetField | BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                        if (fiendinf != null)
                            fiendinf.SetValue(res, fieldobject);
                    }

                }
            }
        } 
     return res;
    }
Example #3
0
 private bool _GetToken(XmlReader reader, out string strToken)
 {
     bool fResult = reader.IsStartElement();
     strToken = fResult ? reader.LocalName : null;
     return fResult;
 }
 /* Method to extract the client specific parts of the config file */
 private bool ExtractClientConfig(XmlReader reader)
 {
     try {
         while (reader.Read()) {
             if (reader.IsStartElement()) {
                 if (reader.Name == "client") {
                     client_config.Add(new ClientConfig());
                     while (reader.MoveToNextAttribute()) {
                         if (reader.Name == "name")
                             client_config.Last().name.Add("short_name", reader.Value);
                         else if (reader.Name == "lname")
                             client_config.Last().name.Add("full_name", reader.Value);
                         else
                             Console.WriteLine("Unknown report configuration attribute: " + reader.Name);
                     }
                 }
                 else if (reader.Name == "project")
                     client_config.Last().projects.Add(reader.ReadString());
                 else if (reader.Name == "priority")
                     client_config.Last().priority.Add(reader.ReadString());
                 else if (reader.Name == "email")
                     client_config.Last().email.Add(reader.ReadString());
             }
         }
         return true;
     }
     catch (Exception ex) {
         Console.WriteLine("Exception when extracting client data from config XML: " + ex.Message);
         return false;
     }
 }