为了自由,幸福而不断奋斗,前行!!!

一笑看风云过....

博客园 首页 新随笔 联系 订阅 管理

namespace ConsoleApplication1
{
    public class Configuration
    {

        Collection<Group> groups = new Collection<Group>();
        public Collection<Group> Groups
        {
            get { return groups; }
            set { groups = value; }
        }
    }

    public class Group
    {
        Collection<string> name=new Collection<string>();
        public Collection<string> Name
        {
            get{return name;}
            set{name=value;}
        }
        Collection<string> ip=new Collection<string>();
        public Collection<string> IP
        {
            get{return ip;}
            set{ip=value;}
        }
        Collection<string> timeout=new Collection<string>();
        public Collection<string> Timeout
        {
            get{return timeout;}
            set{timeout=value;}
        }
        Collection<string> interval=new Collection<string>();
        public Collection<string> Interval
        {
            get{return interval;}
            set{interval=value;}
        }

    }
 
    public class test
    {
        static void Main()
        {
            //序列化
            Configuration cfg = new Configuration();

            CMySql sql = new CMySql();
            string str = "select servername,ipaddress from serverconfig";
            DataTable tb = sql.SelectDt(str);
            for(int i=0;i<tb.Rows.Count;i++)
            {
                Group g = new Group();
                string server=string.Format("{0}",tb.Rows[i][0]);
                string ip=string.Format("{0}",tb.Rows[i][1]);
                g.Name.Add(server);
                g.IP.Add(ip);
                g.Interval.Add("2000");
                g.Timeout.Add("2000");
                cfg.Groups.Add(g);

            }

            XmlSerializer xs = new XmlSerializer(typeof(Configuration));
            StringWriter sw = new StringWriter();
            xs.Serialize(sw, cfg);

            Console.WriteLine(sw.ToString());
            Console.ReadLine();
        }
    }
}

posted on 2008-07-25 15:05  YAO'STAR  阅读(210)  评论(0编辑  收藏  举报