示例#1
0
        public static InstanceInfo fromXml(Stream stream)
        {
            string body;

            stream.Seek(0, SeekOrigin.Begin);
            using (var reader = new StreamReader(stream))
            {
                body = AsyncHelpers.RunSync <string>(() => reader.ReadToEndAsync());
            };
            var xmldoc = FrmLib.Extend.Static_xmltools.LoadXmlFromString(body);
            // stream.Seek(0, SeekOrigin.Begin);
            XmlSerializer xmlserilize = new XmlSerializer(typeof(InstanceInfo));
            XmlReader     xreader     = XmlReader.Create((new StringReader(body)));
            var           oneIns      = (InstanceInfo)xmlserilize.Deserialize(xreader);



            oneIns.dataCenterInfo.name = Static_xmltools.SelectXmlNode(xmldoc, "//dataCenterInfo/name").InnerText;
            var nodelist = Static_xmltools.SelectXmlNodes(xmldoc, "//metadata/*");

            foreach (XmlNode node in nodelist)
            {
                oneIns.metadata.Add(node.Name, node.InnerText);
            }
            return(oneIns);
        }
示例#2
0
        public virtual IList <TimeDoTask> initTasklist(string taskConfigFile)
        {
            if (string.IsNullOrEmpty(taskConfigFile))
            {
                return(null);
            }
            var    rootdir     = System.AppDomain.CurrentDomain.BaseDirectory;
            string xmlfilename = System.IO.Path.Combine(rootdir, taskConfigFile);

            if (!File.Exists(xmlfilename))
            {
                return(null);
            }

            List <TimeDoTask> alltask = new List <TimeDoTask>();

            FrmLib.Log.commLoger.runLoger.Debug(string.Format("now createTaskList"));

            Type[] nodeTaskHandles = FrmLib.Extend.tools_static.GetTypesFromAssemblysByType(typeof(ICronTask));


            XmlDocument tmpxmldoc = Static_xmltools.GetXmlDocument(xmlfilename);
            XmlNodeList alllist   = null;
            string      xpathstr  = "/configuration/CronTask";

            alllist = Static_xmltools.SelectXmlNodes(tmpxmldoc, xpathstr);
            FrmLib.Log.commLoger.runLoger.Debug(string.Format("createTaskList count:{0}", alllist.Count));
            TimeDoTask            tdt    = null;
            TimeNowDoEventHandler myfunc = null;

            foreach (XmlNode onenode in alllist)
            {
                int    tasktype     = int.Parse(Static_xmltools.GetXmlAttr(onenode, "taskType"));
                string paramvalue   = Static_xmltools.GetXmlAttr(onenode, "paramValue");
                string procesorName = Static_xmltools.GetXmlAttr(onenode, "procesorName");
                try
                {
                    var nodeTaskHandle = FrmLib.Extend.tools_static.getTypeHaveMethodByName(nodeTaskHandles, procesorName);
                    if (nodeTaskHandle == null)
                    {
                        continue;
                    }
                    myfunc = (TimeNowDoEventHandler)Delegate.CreateDelegate(typeof(TimeNowDoEventHandler), nodeTaskHandle, procesorName);
                    if (tasktype == (int)enum_taskType.interval)
                    {
                        tdt = new TimeDoTask(int.Parse(paramvalue), myfunc);
                    }
                    else
                    {
                        tdt = new TimeDoTask(paramvalue, myfunc, (enum_taskType)tasktype);
                    }
                    alltask.Add(tdt);
                }
                catch (Exception exp)
                {
                    FrmLib.Log.commLoger.runLoger.Error("create task error, info:" + onenode.InnerText);
                    return(null);
                }
            }
            return(alltask);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        public void loadPortProxyCfg()
        {
            string filename = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, localRunServer.portProxyFileName);

            if (!File.Exists(filename))
            {
                return;
            }
            XmlDocument tmpxmldoc = Static_xmltools.GetXmlDocument(filename);

            if (tmpxmldoc == null)
            {
                return;
            }
            XmlNodeList groupList = null;

            string xpathstr = "//application/group";

            groupList = Static_xmltools.SelectXmlNodes(tmpxmldoc, xpathstr);
            foreach (XmlNode obj in groupList)
            {
                //todo
                string appkey     = Static_xmltools.GetXmlAttr(obj, "Appkey");
                string listenport = Static_xmltools.GetXmlAttr(obj, "listenPort");
                string str        = Static_xmltools.GetXmlAttr(obj, "Policy");
                int    policy     = 0;
                int.TryParse(str, out policy);

                int mapType = 0;
                str = Static_xmltools.GetXmlAttr(obj, "mapType");
                int.TryParse(str, out mapType);
                if (mapType == 1)
                {
                    listenport = this.port;
                }
                string _httpsPort = Static_xmltools.GetXmlAttr(obj, "listenHttpsPort");

                outPortSelectPolicy selectpolicy = (outPortSelectPolicy)policy;
                str = Static_xmltools.GetXmlAttr(obj, "MaxWaitQueue");
                int maxQueueCount = -1;
                int.TryParse(str, out maxQueueCount);
                string host     = Static_xmltools.GetXmlAttr(obj, "Host");
                int    usehttps = 0;
                str = Static_xmltools.GetXmlAttr(obj, "useHttps");
                int.TryParse(str, out usehttps);
                mapPortGroup mpg = new mapPortGroup(host, listenport, appkey, maxQueueCount, selectpolicy
                                                    , _httpsPort, this, (listenHttpsEnum)(usehttps), mapType);
                xpathstr = ".//portMap";
                XmlNodeList maplist = Static_xmltools.SelectXmlNodes(obj, xpathstr);
                foreach (XmlNode onenode in maplist)
                {
                    string outHost       = Static_xmltools.GetXmlAttr(onenode, "host");
                    string outPort       = Static_xmltools.GetXmlAttr(onenode, "port");
                    string _outhttpsPort = Static_xmltools.GetXmlAttr(onenode, "httpsPort");
                    str = Static_xmltools.GetXmlAttr(onenode, "maxConnect");
                    int maxcount = int.Parse(str);
                    str = Static_xmltools.GetXmlAttr(onenode, "minConnect");
                    int    mincount  = int.Parse(str);
                    bool   needcheck = true;
                    string needcl    = Static_xmltools.GetXmlAttr(onenode, "needCheckLive");
                    bool.TryParse(needcl, out needcheck);

                    mpg.addOutPort(outHost, outPort, _outhttpsPort, maxcount, needcheck);
                }
                if (mapType == 0)
                {
                    if (mapPortGroup_dic.ContainsKey(listenport))
                    {
                        continue;
                    }


                    mapPortGroup_dic.Add(listenport, mpg);
                }
                else
                {
                    if (maphttpGroup_dic.ContainsKey(appkey))
                    {
                        continue;
                    }
                    maphttpGroup_dic.Add(appkey, mpg);
                }
            }
        }