예제 #1
0
        public int test()
        {
            PointXml p1 = new PointXml {
                point = new PointExXml {
                    name = "pp1", datafmt = "str"
                }
            };
            PointXml p2 = new PointXml {
                point = new PointExXml {
                    name = "pp1", datafmt = "str"
                }
            };
            PointXml p3 = new PointXml {
                point = new PointExXml {
                    name = "pp1"
                }
            };
            PointXml p4 = new PointXml {
                point = new PointExXml {
                    name = "pp1"
                }
            };

            ModuleCfgXml t1 = new ModuleCfgXml
            {
                name    = "t1",
                id      = 100,
                init    = 8,
                version = "0.1",
                depends = new DependsXml {
                    depend = new List <string> {
                        "dd1", "dd2"
                    }
                },
                subs = new SubsXml {
                    sub = new List <PointXml> {
                        p1, p2
                    }
                },
                pub = new PointXml {
                    point = new PointExXml {
                        name = "publish1"
                    }
                },
                subpubs = new SubPubsXml {
                    subpub = new List <SubPubXml> {
                        new SubPubXml {
                            pub = p1, sub = new List <PointXml> {
                                p1, p2
                            }
                        }
                    }
                },
                requests = new RequestsXml {
                    request = new List <PointXml> {
                        p3, p4
                    }
                },
                responses = new PointXml {
                    point = new PointExXml {
                        name = "response1"
                    }
                },
                fanins = new FaninsXml {
                    fanin = new List <PointXml> {
                        p2, p3
                    }
                },
                faninpubs = new FaninPubsXml {
                    faninpub = new List <FaninPubXml> {
                        new FaninPubXml {
                            fanin = p1, pub = p2
                        }
                    }
                },
                fanout = new FanoutXml {
                    fanout = new List <PointXml> {
                        p4, p1
                    }
                }
                //works = new WorksXml { work = new List<WorkXml> { new WorkXml { number = 1, pull = p1, push = p2 }, new WorkXml { number = 1, push = p3, pull = p4 } } }
            };


            string xml1 = XmlHelper.XmlSerialize(t1, Encoding.UTF8);
            string xml2 = XmlHelper.XmlSerialize(t1, Encoding.UTF8);

            Console.Out.WriteLine(xml1);
            Console.Out.WriteLine(xml2);
            return(0);
        }
예제 #2
0
        private int InitMod2(ModuleCfgXml mx, ref ModInfo mod)
        {
            if (mod == null || mx == null)
            {
                Logging.logger.Error("the in put mod is null");
                return(-1);
            }
            //2
            mod.subs = new List <Point>();
            if (mx.subs != null)
            {
                foreach (PointXml p in mx.subs.sub)
                {
                    Point point = GetPubsPoint(p.point.name);
                    if (point != null)
                    {
                        mod.subs.Add(point);
                    }
                }
            }
            else
            {
            }


            //4
            if (mx.subpubs != null)
            {
                foreach (SubPubXml s in mx.subpubs.subpub)
                {
                    foreach (PointXml nx in s.sub)
                    {
                        Point p = GetPubsPoint(nx.point.name);
                        if (p != null)
                        {
                            foreach (SubPub sp in mod.subpubs)
                            {
                                if (sp.pub.name == s.pub.point.name)
                                {
                                    sp.subs.Add(p);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
            }

            //5
            mod.reqs = new List <Point>();
            if (mx.requests != null)
            {
                foreach (PointXml r in mx.requests.request)
                {
                    Point point = GetResponsePoint(r.point.name);
                    mod.reqs.Add(point);
                }
            }



            //8
            mod.faninc = new List <Point>();
            if (mx.faninc != null)
            {
                foreach (PointXml f in mx.faninc.fanin)
                {
                    Point p = GetFaninSPoint(f.point.name);

                    if (p != null)
                    {
                        mod.faninc.Add(p);
                    }
                }
            }

            //11
            mod.fanoutc = new List <Point>();
            if (mx.fanoutc != null)
            {
                foreach (PointXml fp in mx.fanoutc.fanout)
                {
                    Point p = GetFanoutSPoint(fp.point.name);
                    if (p != null)
                    {
                        mod.fanoutc.Add(p);
                    }
                }
            }

            //12
            mod.usertasks = new List <string>();
            if (mx.usertasks != null)
            {
                foreach (string s in mx.usertasks.name)
                {
                    mod.usertasks.Add(s);
                }
            }
            else
            {
            }

            //14
            mod.fanworks = new List <FanWork>();
            if (mx.fanworks != null)
            {
                foreach (FanWorkXml fw in mx.fanworks.fanwork)
                {
                    FanWork f = new FanWork();
                    f.worknum = fw.workernum;
                    f.fanin   = GetFaninSPoint(fw.fanin.point.name);
                    f.fanout  = GetFanoutSPoint(fw.fanout.point.name);

                    mod.fanworks.Add(f);
                }
            }

            mod.status = ModStatus.Init;
            return(0);
        }
예제 #3
0
        private int InitCfg()
        {
            string[] fs = Files.GetAllFileNames(this.CfgPath, ModConst.ModFileFlag);

            if (fs == null)
            {
                Logging.logger.Error("Read mod config failed");
                return(-1);
            }

            List <ModuleCfgXml> rl = new List <ModuleCfgXml>();

            foreach (string f in fs)
            {
                ModuleCfgXml aa = XmlHelper.XmlDeserializeFromFile <ModuleCfgXml>(f, Encoding.UTF8);
                if (aa != null)
                {
                    rl.Add(aa);
                }
            }
            int     modid = 0;
            int     rlt;
            ModInfo mod;

            foreach (ModuleCfgXml mx in rl)
            {
                rlt = NewModIdWithName(mx.name, out modid);
                if (rlt < 0)
                {
                    Logging.logger.Error("get mod id failed");
                    continue;
                }

                mod = GetModinfoWithID(modid);
                InitMod(mx, ref mod);
            }

            foreach (ModuleCfgXml mx in rl)
            {
                mod = GetModinfoWithName(mx.name);
                InitMod2(mx, ref mod);

                if (Initlevel.ContainsKey(mod.init))
                {
                    if (Initlevel[mod.init].Contains(mod.modid))
                    {
                        Logging.logger.Warn("the mod id alread exist");
                    }
                    else
                    {
                        Initlevel[mod.init].Add(mod.modid);
                    }
                }
                else
                {
                    Initlevel.Add(mod.init, new List <int>());
                    Initlevel[mod.init].Add(mod.modid);
                }
            }
            return(0);
        }
예제 #4
0
        private int InitMod(ModuleCfgXml mx, ref ModInfo mod)
        {
            mod.modname = mx.name;
            mod.init    = mx.init;
            mod.status  = ModStatus.Generate;
            mod.depends = new List <string>();
            mod.cls     = mx.cls;
            mod.ipaddr  = mx.ipaddr;
            int modport = mod.modid + 10;


            //1
            mod.depends = new List <string>();
            if (mx.depends != null)
            {
                foreach (string d in mx.depends.depend)
                {
                    mod.depends.Add(d);
                }
            }



            //3
            if (mx.pub != null)
            {
                mod.pub = new Point();
                {
                    mod.pub.ip = mx.ipaddr;
                    if (mx.pub.point.datafmt != null)
                    {
                        mod.pub.dataFmt = mx.pub.point.datafmt;
                    }
                    mod.pub.port = modport++;
                    mod.pub.name = mx.pub.point.name;
                }
            }
            else
            {
                mod.pub = null;
            }

            //4
            mod.subpubs = new List <SubPub>();
            if (mx.subpubs != null)
            {
                foreach (SubPubXml s in mx.subpubs.subpub)
                {
                    SubPub sp = new SubPub();
                    sp.subs = new List <Point>();

                    sp.pub      = new Point();
                    sp.pub.name = s.pub.point.name;
                    sp.pub.ip   = mx.ipaddr;
                    sp.pub.port = modport++;
                    if (s.pub.point.datafmt != null)
                    {
                        sp.pub.dataFmt = s.pub.point.datafmt;
                    }
                    mod.subpubs.Add(sp);
                }
            }
            else
            {
            }



            //6
            if (mx.responses != null)
            {
                mod.Res      = new Point();
                mod.Res.name = mx.responses.point.name;
                if (mx.responses.point.datafmt != null)
                {
                    mod.Res.dataFmt = mx.responses.point.datafmt;
                }
                mod.Res.ip   = mx.ipaddr;
                mod.Res.port = modport++;
            }
            else
            {
                mod.Res = null;
            }

            //7
            mod.fanins = new List <Point>();
            if (mx.fanins != null)
            {
                foreach (PointXml f in mx.fanins.fanin)
                {
                    Point point = new Point();
                    point.name = f.point.name;
                    if (f.point.datafmt != null)
                    {
                        point.dataFmt = f.point.datafmt;
                    }
                    point.ip   = mx.ipaddr;
                    point.port = modport++;

                    mod.fanins.Add(point);
                }
            }



            //9
            mod.faninpubs = new List <FaninPub>();
            if (mx.faninpubs != null)
            {
                foreach (FaninPubXml fp in mx.faninpubs.faninpub)
                {
                    FaninPub f = new FaninPub();
                    f.fanin      = new Point();
                    f.fanin.ip   = mx.ipaddr;
                    f.fanin.name = fp.fanin.point.name;
                    if (fp.fanin.point.datafmt != null)
                    {
                        f.fanin.dataFmt = fp.fanin.point.datafmt;
                    }
                    f.fanin.port = modport++;

                    f.pub      = new Point();
                    f.pub.ip   = mx.ipaddr;
                    f.pub.name = fp.pub.point.name;
                    if (fp.pub.point.datafmt != null)
                    {
                        f.pub.dataFmt = fp.pub.point.datafmt;
                    }
                    f.pub.port = modport++;

                    mod.faninpubs.Add(f);
                }
            }

            //10
            mod.fanouts = new List <Point>();
            if (mx.fanout != null)
            {
                foreach (PointXml p in mx.fanout.fanout)
                {
                    Point point = new Point();
                    point.ip   = mx.ipaddr;
                    point.name = p.point.name;
                    if (p.point.datafmt != null)
                    {
                        point.dataFmt = p.point.datafmt;
                    }
                    point.port = modport++;

                    mod.fanouts.Add(point);
                }
            }

            //13
            mod.faninfanouts = new List <FaninFanout>();
            if (mx.faninfanouts != null)
            {
                foreach (FaninFanoutXml ff in mx.faninfanouts.faninfanout)
                {
                    FaninFanout f  = new FaninFanout();
                    Point       fi = new Point();
                    fi.ip   = mx.ipaddr;
                    fi.name = ff.fanin.point.name;
                    if (ff.fanin.point.datafmt != null)
                    {
                        fi.dataFmt = ff.fanin.point.datafmt;
                    }
                    fi.port = modport++;
                    f.fanin = fi;
                    Point fo = new Point();
                    fo.ip   = mx.ipaddr;
                    fo.name = ff.fanout.point.name;
                    if (ff.fanout.point.datafmt != null)
                    {
                        fo.dataFmt = ff.fanout.point.datafmt;
                    }
                    fo.port  = modport++;
                    f.fanout = fo;
                    mod.faninfanouts.Add(f);
                }
            }


            mod.modport = modport;
            return(0);
        }