Esempio n. 1
0
File: Core.cs Progetto: yiend/mnncs
        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);

                /// ** config DataUI
                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),
                    };
                    DataUI.AddSockUnit(sockUnit);

                    if (sockUnit.Autorun)
                        SockOpen(sockUnit.ID, sockType, ep);
                }
            } catch (Exception) {
                System.Windows.MessageBox.Show(CONF_NAME + ": syntax error.");
            }
        }
Esempio n. 2
0
        public void AddSockUnit(SockUnit unit)
        {
            System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                switch (unit.Type) {
                    case SockType.listen:
                    case SockType.connect:
                        SockUnitGroup.Add(unit);
                        break;

                    case SockType.accept:
                        var subset = from s in SockUnitGroup
                                     where s.Type == SockType.listen && s.Lep.Port == unit.Lep.Port
                                     select s;
                        if (subset.Count() != 0) {
                            subset.First().Childs.Add(unit);
                            CurrentAcceptCount++;
                            HistoryAcceptOpenCount++;
                        }
                        break;
                }
            }));
        }
Esempio n. 3
0
File: Core.cs Progetto: yiend/mnncs
        // SockSess Event
        protected override void AcceptEvent(object sender, SockSessAccept sess)
        {
            sess.close_event += new SockSessDelegate(CloseEvent);
            sess.recv_event += new SockSessDelegate(RecvEvent);
            sess_group.Add(sess);

            SockUnit sockUnit = new SockUnit() {
                ID = "at" + sess.rep.ToString(),
                Name = "accept",
                Type = SockType.accept,
                Lep = sess.lep,
                Rep = sess.rep,
                State = SockState.Opened,
            };
            DataUI.AddSockUnit(sockUnit);
        }