Beispiel #1
0
        public void Config()
        {
            if (File.Exists(BASE_DIR + CONF_NAME) == false)
            {
                System.Windows.MessageBox.Show(CONF_NAME + ": can't find it.");
                return;
            }

            try {
                XmlDocument doc = new XmlDocument();
                doc.Load(BASE_DIR + CONF_NAME);

                // cmdtable
                foreach (XmlNode item in doc.SelectNodes("/configuration/commands/cmditem"))
                {
                    CmdUnit cmd = new CmdUnit();
                    cmd.ID          = item.Attributes["id"].Value;
                    cmd.Name        = item.Attributes["name"].Value;
                    cmd.Cmd         = item.Attributes["content"].Value;
                    cmd.Encrypt     = bool.Parse(item.Attributes["encrypt"].Value);
                    cmd.ContentMode = (ServiceRequestContentMode)Enum.Parse(typeof(ServiceRequestContentMode), item.Attributes["content-mode"].Value);
                    uidata.CmdTable.Add(cmd);
                }

                /// sockunit
                foreach (XmlNode item in doc.SelectNodes("/configuration/sockets/sockitem"))
                {
                    string[]   str      = item.Attributes["ep"].Value.Split(':');
                    IPEndPoint ep       = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1]));
                    SockType   sockType = (SockType)Enum.Parse(typeof(SockType), item.Attributes["type"].Value);
                    SockUnit   sockUnit = new SockUnit()
                    {
                        ID      = item.Attributes["id"].Value,
                        Name    = item.Attributes["name"].Value,
                        Type    = sockType,
                        Lep     = sockType == SockType.listen ? ep : null,
                        Rep     = sockType == SockType.connect ? ep : null,
                        State   = SockState.Closed,
                        Autorun = bool.Parse(item.Attributes["autorun"].Value),
                    };
                    uidata.AddSockUnit(sockUnit);

                    if (sockUnit.Autorun)
                    {
                        string id = "service.sesslisten";
                        if (sockType == SockType.connect)
                        {
                            id = "service.sessconnect";
                        }
                        object req = new {
                            id   = id,
                            ip   = ep.Address.ToString(),
                            port = ep.Port,
                        };
                        core.AddServiceRequest(ServiceRequest.Parse(JsonConvert.SerializeObject(req)));
                    }
                }
            } catch (Exception) {
                System.Windows.MessageBox.Show(CONF_NAME + ": syntax error.");
            }
        }