Esempio n. 1
0
        /// <summary>
        /// 添加映射器  已经启动无法再添加
        /// </summary>
        /// <param name="wi"></param>
        public static bool Add(WorkItem wi)
        {
            //如果已经被启动则不能添加
            if (startState)
            {
                return(false);
            }
            else
            {
                //用户不能设置ID
                if (wi._id != null)
                {
                    return(false);
                }
                //设置顺序ID
                wi._id = OtherUtils.getGUID();
                if (wi.ip_local == null)
                {
                    //设置本地IP
                    wi.ip_local = new IPEndPoint(OtherUtils.getLoaclIP(), OtherUtils.GetFirstAvailablePort() + mWorkItemList.Count);
                }
                MyEndPoint mep = OtherUtils.FormatEndPoint(wi.ip_local.ToString());
                //如果添加Upnp失败直接返回 false
                if (!OtherUtils.AddUpnp(wi.lExternalPort, "TCP", mep.port, mep.ip, true, "Mapping Y1ca"))
                {
                    return(false);
                }

                mWorkItemList.Add(wi);
                return(true);
            }
        }
Esempio n. 2
0
 private void FormAdd_Load(object sender, EventArgs e)
 {
     textBox_IpOut.Text = OtherUtils.getLoaclIP().ToString();
 }