示例#1
0
        /// <summary>借出</summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public static ServerItem Pop(String ip)
        {
            lock (typeof(ServerItem))
            {
                ServerItem rdp = null;
                // 优先安排上一次使用的服务器
                var list2 = Queue.Where(e => e.LastClient == ip).ToList();
                if (list2 != null && list2.Count > 0)
                {
                    // 最近使用的,倒序
                    rdp = list2.OrderByDescending(e => e.LastTime).FirstOrDefault();
                }
                else
                {
                    // 优先安排最久不使用的服务器,防止抢了别人不用而断线的
                    rdp = Queue.Where(e => e.Status == ServerStatus.Free).OrderBy(e => e.LastTime).FirstOrDefault();
                }
                if (rdp == null)
                {
                    return(null);
                }

                // 借出
                rdp.LastClient = ip;
                rdp.LastTime   = DateTime.Now;
                rdp.Status     = ServerStatus.Busy;
                rdp.Times++;

                return(rdp);
            }
        }
示例#2
0
        public override void StartWork()
        {
            // 要求马上重新加载配置
            Setting.Current = null;
            var set = Setting.Current;

            // 初始化队列
            ServerItem.Init();
            if (ServerItem.Queue.Count < 1)
            {
                WriteLine("没有正确配置远程地址,停止服务");
                Stop();
                return;
            }

            Svr      = new RDPServer();
            Svr.Port = set.Port;
            if (set.Debug)
            {
                Svr.Log = XTrace.Log;
            }
            Svr.Start();

            _timer = new TimerX(Check, null, 10000, 10000);
        }
示例#3
0
        public static void Init()
        {
            Queue.Clear();

            var set = Setting.Current;

            // 准备服务器集合
            foreach (var item in set.Servers)
            {
                var rdp = new ServerItem();
                rdp.EndPoint = NetHelper.ParseEndPoint(item, 3389);
                Queue.Add(rdp);
            }
        }
示例#4
0
        protected override void OnDispose(Boolean disposing)
        {
            var rdp = Rdp;

            if (rdp == null)
            {
                return;
            }
            Rdp = null;

            // 输出日志
            WriteLog(" 归还服务器 " + rdp);

            rdp.Push();

            base.OnDispose(disposing);
        }
示例#5
0
        public override void Start()
        {
            var rdp = ServerItem.Pop(Remote.Address + "");

            if (rdp == null)
            {
                WriteLog("没有取得可用服务器。");

                Dispose();

                return;
            }

            // 输出日志
            WriteLog("取得服务器 " + rdp);

            RemoteServerUri = new NetUri(NetType.Tcp, rdp.EndPoint);

            Rdp = rdp;

            base.Start();
        }