Example #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);
            }
        }
Example #2
0
        public static MyEndPoint FormatEndPoint(string endPoint)
        {
            MyEndPoint mep = new MyEndPoint();

            mep.port = int.Parse(endPoint.Substring(endPoint.IndexOf(':') + 1));
            mep.ip   = endPoint.Substring(0, endPoint.IndexOf(':'));
            return(mep);
        }