Пример #1
0
 /// <summary>
 /// This method executes the given delegate on all servers.
 /// </summary>
 internal void ExecuteAll(UseSocket use)
 {
     foreach (SocketPool socketPool in hostList)
     {
         Execute(socketPool, use);
     }
 }
Пример #2
0
        internal T Execute <T>(SocketPool pool, T defaultValue, UseSocket <T> use)
        {
            MSocket sock = null;

            try
            {
                //Acquire a socket
                sock = pool.Acquire();

                //Use the socket as a parameter to the delegate and return its result.
                if (sock != null)
                {
                    return(use(sock));
                }
            }
            catch (Exception e)
            {
                logger.Error("Error in Execute<T>: " + pool.Host, e);

                //Socket is probably broken
                if (sock != null)
                {
                    sock.Close();
                }
            }
            finally
            {
                if (sock != null)
                {
                    sock.Dispose();
                }
            }
            return(defaultValue);
        }
Пример #3
0
        internal void Execute(SocketPool pool, UseSocket use)
        {
            MSocket sock = null;

            try
            {
                //Acquire a socket
                sock = pool.Acquire();

                //Use the socket as a parameter to the delegate and return its result.
                if (sock != null)
                {
                    use(sock);
                }
            }
            catch (Exception e)
            {
                logger.Error("Error in Execute: " + pool.Host, e);

                //Socket is probably broken
                if (sock != null)
                {
                    sock.Close();
                }
            }
            finally
            {
                if (sock != null)
                {
                    sock.Dispose();
                }
            }
        }
Пример #4
0
 /// <summary>
 /// This method executes the given delegate on all servers.
 /// </summary>
 internal void ExecuteAll(UseSocket use)
 {
     foreach (KeyValuePair <string, HostNode> item in hostList)
     {
         Execute(item.Value, use);
     }
 }
Пример #5
0
 /// <summary>
 /// This method executes the given delegate on all servers.
 /// </summary>
 private void ExecuteAll(UseSocket use)
 {
     foreach (SocketPool socketPool in HostList)
     {
         Execute(socketPool, use);
     }
 }
Пример #6
0
        private void Execute(SocketPool pool, UseSocket use)
        {
            PooledSocket sock = null;

            try
            {
                //Acquire a socket
                sock = pool.Acquire();

                //Use the socket as a parameter to the delegate and return its result.
                if (sock != null)
                {
                    use(sock);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in Execute: " + pool.Host);

                //Socket is probably broken
                if (sock != null)
                {
                    sock.Close();
                }
            }
            finally
            {
                if (sock != null)
                {
                    sock.Dispose();
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 注册
        /// </summary>
        public void register()
        {
            new driverService().Register();
            new MessgeService().Register();
            new orderService().Register();

            var ws = UseSocket.CreateSocket();

            ws.Message = (username, message) =>
            {
                var request = Newtonsoft.Json.JsonConvert.DeserializeObject <Request>(message);
                request.Head.Add("wxcount", username);
                if (request.ClientType.Other.Equals("uploadLocation"))
                {
                    request.AddService = () =>
                    {
                        IDbConnection con         = new MySqlConnection(this.Configuration["mysql"]);
                        var           driverState = con.ExecuteScalar <long>("select count(1) from orders where driverid=" + request.Head["KeyID"] + " and state=2");
                        return(driverState.ToString());
                    }
                }
                ;
                var result = Hup.CreateMsg.Run(request);
            };
        }

        void outTimeOrders()
        {
            var           t  = Startup.GlobConfiguration["mysql"];
            IDbConnection db = new MySql.Data.MySqlClient.MySqlConnection(this.Configuration["mysql"]);

            db.Open();
            JObject obj = new JObject();

            obj.Add("state", 3);
            var lists = db.Query <orders>("select * from orders where state='0' ");
            TaskManagerService tak   = TaskManagerService.Factory();
            TokenService       token = new TokenService(this.Configuration["appsecret"], this.Configuration["AppID"]);

            foreach (var key in lists)
            {
                Task.Run(async() =>
                {
                    await tak.AutoRun(key.StartTime, keys =>
                    {
                        IDbConnection _db = new MySql.Data.MySqlClient.MySqlConnection(this.Configuration["mysql"]);
                        JObject js        = JObject.Parse(key.ordersInfo);
                        string sql        = uilt.uiltT.Update(obj, "orders", " where id='" + key.id + "' ");
                        _db.Execute(sql);
                        uilt.uiltT.SendWxMessage(token, "您的订单从" + js["startingPoint"] + "到" + js["endingPoint"] + "的   行程,由于长时间没有司机接单已经超时,请重新创建行程。", js["openid"].ToString());
                        _db.Close();
                        return(Task.CompletedTask);
                    });
                });
            }
            db.Close();
        }
    }
Пример #8
0
        /// <summary>
        /// This method executes the given delegate on a socket from the server that corresponds to the given hash.
        /// If anything causes an error, the given defaultValue will be returned instead.
        /// This method takes care of disposing the socket properly once the delegate has executed.
        /// </summary>
        internal T Execute <T>(uint hash, T defaultValue, UseSocket <T> use)
        {
            SocketPool pool = GetSocketPool(hash);

            if (pool.socketPoolBak == null && serverPoolBak != null)
            {
                //为主Socket池挂接备份的Socket池
                pool.socketPoolBak = serverPoolBak.GetSocketPool(hash);
            }
            return(Execute(pool, defaultValue, use));
        }
Пример #9
0
        //internal HostInstance GetSocketPool(string host)
        //{
        //    return Array.Find(HostList, delegate(HostInstance socketPool) { return socketPool.Host == host; });
        //}

        /// <summary>
        /// This method executes the given delegate on a socket from the server that corresponds to the given hash.
        /// If anything causes an error, the given defaultValue will be returned instead.
        /// This method takes care of disposing the socket properly once the delegate has executed.
        /// </summary>
        internal T Execute <T>(uint hash, T defaultValue, UseSocket <T> use)
        {
            HostNode node = GetHost(hash);

            if (node.HostNodeBak == null && hostServerBak != null)
            {
                //为主Socket池挂接备份的Socket池
                node.HostNodeBak = hostServerBak.GetHost(hash, node.Host);
            }
            return(Execute(node, defaultValue, use));
        }
Пример #10
0
        /// <summary>
        /// This method executes the given delegate on a socket from the server that corresponds to the given hash.
        /// If anything causes an error, the given defaultValue will be returned instead.
        /// This method takes care of disposing the socket properly once the delegate has executed.
        /// </summary>
        internal T Execute <T>(uint hash, T defaultValue, UseSocket <T> use)
        {
            var socketPool = GetSocketPool(hash);
            var result     = Execute(socketPool, defaultValue, use);

            if (this.Scope == ServerScope.Write && this.slavePoolMap.ContainsKey(socketPool.Host))
            {
                var slaves = this.slavePoolMap[socketPool.Host];
                foreach (var slaveSocket in slaves)
                {
                    //AppInstance.GetThreadPool().QueueWorkItem(
                    Action action = () => {
                        LogManager.GetLogger(MemcachedProxy.MemcachedLogger).Debug("Sync Slave {0} By Master:{1}", slaveSocket.Host, socketPool.Host);
                        Execute(slaveSocket, defaultValue, use);
                    };

                    AppInstance.GetThreadPool().QueueWorkItem(action);
                }
            }
            return(result);
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Register"></param>
        public override void RegisterServieceRequest(Hup.MessageBus.Service.ServiceRegister Register)
        {
            Register.Register("uploadLocation", (Request parm, ref Request results) => {
                driverlocation result = new driverlocation();
                var parameter         = (Hup.MessageBus.Request)parm;
                result.title          = "快车";
                result.content        = parameter.Head["KeyID"];
                result.pointy         = double.Parse(parameter.Head["latitude"]);
                result.pointx         = double.Parse(parameter.Head["longitude"]);

                Action t1 = () =>
                {
                    if (driverinfo.ContainsKey(parameter.Head["wxcount"]))
                    {
                        driverinfo[parameter.Head["wxcount"]] = result;
                    }
                    else
                    {
                        driverinfo.Add(parameter.Head["wxcount"], result);
                    }
                    var state     = parameter.AddService();
                    result.status = int.Parse(state) > 0 ? 0 : 1;
                };
                if (isLock)
                {
                    action += t1;
                }
                else
                {
                    t1();
                }
                results = parameter;
            });

            Register.Register("orderMessage", (Request parameter, ref Request results) => {
                var parm = (Hup.MessageBus.Request)parameter;
                UseSocket.CreateSocket().Send(((Request)parameter), "");
            });
        }
Пример #12
0
        /// <summary>
        /// websocket注册
        /// </summary>
        public void WebsocketRegedit()
        {
            UseSocket use = UseSocket.CreateSocket();

            use.Message = (username, Message) =>
            {
                var result = JsonConvert.DeserializeObject <Request>(Message);
                if (result.ClientType.type == "File")
                {
                    var item = CreateMsg.Run(result);
                    use.CreatStream(username, (UpFileInfo)item.Content);
                }
                else
                {
                    CreateMsg.Run(result);
                }
            };
            use.BinaryMessage = (username, key) =>
            {
                use.listfs[username].Write(key);
            };
        }
Пример #13
0
 /// <summary>
 /// This method executes the given delegate on a socket from the server that corresponds to the given hash.
 /// If anything causes an error, the given defaultValue will be returned instead.
 /// This method takes care of disposing the socket properly once the delegate has executed.
 /// </summary>
 internal T Execute <T>(uint hash, T defaultValue, UseSocket <T> use)
 {
     return(Execute(GetSocketPool(hash), defaultValue, use));
 }
Пример #14
0
        public IEnumerable <driverlocation> nearbydriver(double lat, double lng, string id)
        {
            var result   = new List <driverlocation>();
            var userlist = new List <string>();

            var order = this.idb.QueryFirstOrDefault <orders>("select * from orders where id=" + id);

            if (order == null)
            {
                return(null);
            }
            var req = Hup.CreateMsg.CreateRequest(order, "orderMessage");

            driverService.isLock = true;
            double statusR = -1;
            double statusTR = -1;
            int    ids = -1, idst = -1;

            foreach (var key in driverService.driverinfo)
            {
                var n = uilt.uiltT.getDistance(lat, lng, key.Value.pointy, key.Value.pointx);
                if (key.Value.status == 1)
                {
                    if (statusR > n || statusR == -1)
                    {
                        statusR = n;
                        ids     = int.Parse(key.Value.content);
                    }
                    if (n <= radius)
                    {
                        result.Add(key.Value);
                        userlist.Add(key.Key);
                    }
                }
                else
                if (statusTR > n || statusR == -1)
                {
                    idst     = int.Parse(key.Value.content);
                    statusTR = n;
                }
            }
            driverService.isLock = false;
            if (userlist.Count == 0)
            {
                var systemList = UseSocket.CreateSocket().getSystemUser();
                req.RecUserlist.AddRange(systemList);
                req.SendUser  = "******";
                req.Head["r"] = statusR.ToString();
                userinfo ui = null;
                if (ids != -1)
                {
                    ui = this.idb.QueryFirst <userinfo>("select * from userinfo where id='" + ids + "'");
                    req.Head.Add("ch", ui.username);
                    req.Head.Add("mobile", ui.mobile);
                }
                Hup.CreateMsg.Run(req);
            }
            else
            {
                req.RecUserlist = userlist;
                req.SendUser    = "******";
                Hup.CreateMsg.Run(req);
            }
            return(result);
        }