Esempio n. 1
0
        private void HandleQueue()
        {
            T item;

            try
            {
                do
                {
                    lock (_syncObj)
                    {
                        if (_queue.Count == 0)
                        {
                            _handleDone = true;
                            return;
                        }

                        item = _queue.Dequeue();
                    }

                    if (_cancellationToken.IsCancellationRequested)
                    {
                        _handleDone = true;
                        return;
                    }

                    Hander.Invoke(item, _cancellationToken);
                } while (!_cancellationToken.IsCancellationRequested && item != null);
            }
            finally
            {
                _handleDone = true;
            }
        }
Esempio n. 2
0
        public async Task <Response <Hotel> > Update([FromBody] Hotel hotel)
        {
            //if (string.IsNullOrEmpty(hotel.Name))
            //{
            //    return new Response<Hotel>() { Status = StatusEnum.ValidateModelError, Massage = "没有宾馆名称" };
            //}
            //if (!Hander.CheckPassword(hotel))
            //{
            //    return new Response<Hotel>() { Status = StatusEnum.ValidateModelError, Massage = "密码错误" };
            //}
            //hotel.UpdateTime = DateTime.Now;
            //await Hander.Update(hotel, "Name", "Region", "Address", "UpdateTime","Remark");
            KeyValuePair <bool, string> result = await Task.Run(() => { return(Hander.Update(hotel)); });

            if (result.Key)
            {
                hotel.HotelPassword = null;
                return(new Response <Hotel>()
                {
                    Status = StatusEnum.Success,
                    Massage = "修改成功",
                    Data = hotel
                });
            }
            else
            {
                return(new Response <Hotel>()
                {
                    Status = StatusEnum.ValidateModelError, Massage = result.Value
                });
            }
        }
Esempio n. 3
0
        public async Task <Response <RoomResponseExt> > Add([FromBody] Room room)
        {
            string manager = HttpContext.User.Identity.Name;

            room.IsDel = false;

            Room r = await Task.Run(() => { return(Hander.Add(room, manager)); });

            return(new Response <RoomResponseExt>()
            {
                Status = StatusEnum.Success,
                Massage = "添加成功",
                Data = new RoomResponseExt()
                {
                    Id = r.Id,
                    HotelId = r.HotelId,
                    RoomNo = r.RoomNo,
                    RoomType = r.RoomType,
                    Remark = r.Remark,
                    IsDel = r.IsDel,
                    roomTypeName = EnumHander.GetName(r.RoomType),
                    CreateTime = r.CreateTime,
                    UpdateTime = r.UpdateTime
                }
            });
        }
Esempio n. 4
0
        /// <summary>
        /// 异步发送数据
        /// </summary>
        /// <param name="data">异步发送的数据内容</param>
        public void SendAsync(byte[] data)
        {
            if (!IsConnected)  //判断是否已经连接
            {
                throw new SocketException(10057);
            }
            if (data == null)  //发送数据为null
            {
                throw new ArgumentNullException("data null");
            }
            if (data.Length == 0)  //发送数据长度为0
            {
                throw new ArgumentException("data length = 0");
            }

            SocketAsyncState state = new SocketAsyncState();  //设置异步状态

            state.Data    = data;
            state.IsAsync = true;

            try
            {
                Hander.BeginSend(data, 0, data.Length, Stream, EndSend, state);  //开始发送数据
            }
            catch
            {
                Disconnected(true);  //发送异常,则断开Socket连接
            }
        }
Esempio n. 5
0
        public async Task <BaseResponse> Delete([FromBody] Guest guest)
        {
            string manager = HttpContext.User.Identity.Name;
            await Task.Run(() => { Hander.Delete(guest, manager); });

            return(new BaseResponse()
            {
                Status = StatusEnum.Success,
                Massage = "删除入住人成功"
            });
        }
Esempio n. 6
0
        public async Task <Response <Guest> > Add([FromBody] Guest guest)
        {
            string manager = HttpContext.User.Identity.Name;
            await Task.Run(() => { Hander.Add(guest, manager); });

            return(new Response <Guest>()
            {
                Status = StatusEnum.Success,
                Massage = "添加入住人成功",
                Data = guest
            });
        }
Esempio n. 7
0
        public async Task <BaseResponse> Updete([FromBody] Room room)
        {
            string manager = HttpContext.User.Identity.Name;

            await Task.Run(() => { Hander.Update(room, manager); });

            return(new BaseResponse()
            {
                Status = StatusEnum.Success,
                Massage = "更新成功"
            });
        }
Esempio n. 8
0
        public async Task <Response <Hotel> > Create([FromBody] HotelAndManager hotelAndManager)
        {
            if (string.IsNullOrEmpty(hotelAndManager.WxOpenId))
            {
                return(new Response <Hotel>()
                {
                    Status = StatusEnum.ValidateModelError, Massage = "没有微信ID"
                });
            }
            if (string.IsNullOrEmpty(hotelAndManager.Name))
            {
                return(new Response <Hotel>()
                {
                    Status = StatusEnum.ValidateModelError, Massage = "没有宾馆名称"
                });
            }
            var existHotel = await Task.Run(() => { return(ManagerHander.GetHotelByOpenId(hotelAndManager.WxOpenId)); });

            if (existHotel != null)
            {
                return(new Response <Hotel>()
                {
                    Status = StatusEnum.Error, Massage = "此用户已有宾馆"
                });
            }
            Hotel hotel = new Hotel()
            {
                Name          = hotelAndManager.Name,
                HotelPassword = hotelAndManager.Password,
                Address       = hotelAndManager.Address,
                Region        = hotelAndManager.Region,
                Remark        = hotelAndManager.Remark
            };
            Hotelmanager manager = new Hotelmanager()
            {
                WxOpenId  = hotelAndManager.WxOpenId,
                WxUnionId = hotelAndManager.WxUnionId
            };

            hotel = await Task.Run(() => { return(Hander.Create(hotel, manager)); });

            hotel.HotelPassword = null;
            hotel.Salt          = null;

            return(new Response <Hotel>()
            {
                Status = StatusEnum.Success,
                Massage = "添加成功",
                Data = hotel
            });
        }
Esempio n. 9
0
        public async Task <BaseResponse> Delete([FromBody] Hotel hotel)
        {
            hotel.IsDel      = true;
            hotel.UpdateTime = DateTime.Now;
            await Task.Run(() => {
                Hander.Update(hotel, "IsDel", "UpdateTime");
            });

            return(new BaseResponse()
            {
                Status = StatusEnum.Success,
                Massage = "删除成功"
            });
        }
Esempio n. 10
0
        public async Task <ListResponse <Hotel> > GetHotels([FromBody] dynamic obj)
        {
            string name   = obj.name;
            string region = obj.region;
            var    hotels = await Task.Run(() => {
                return(Hander.GetList(h => h.Region == region && name.Contains(h.Name) && !h.IsDel.Value));
            });

            return(new ListResponse <Hotel>()
            {
                Status = StatusEnum.Success,
                Massage = "查询成功",
                Data = hotels
            });
        }
Esempio n. 11
0
        public async Task <BaseResponse> BatchDel([FromBody] List <Room> rooms)
        {
            string manager = HttpContext.User.Identity.Name;
            await Task.Run(() => {
                foreach (Room room in rooms)
                {
                    Hander.Delete(room, manager);
                }
            });

            return(new BaseResponse()
            {
                Status = StatusEnum.Success,
                Massage = "删除成功"
            });
        }
Esempio n. 12
0
        private void EndSend(IAsyncResult iar)
        {
            SocketAsyncState state = (SocketAsyncState)iar.AsyncState;

            state.Completed = Hander.EndSend(iar); //是否完成
            if (!state.Completed)                  //如果没有完成,则断开Socket连接
            {
                Disconnected(true);
            }

            if (state.IsAsync && SendCompleted != null)  //发送完成事件
            {
                SendCompleted(this, new SocketEventArgs(this, SocketAsyncOperation.Send)
                {
                    Data = state.Data
                });
            }
        }
Esempio n. 13
0
        public async Task <Response <Hotel> > GetHotelById(int hotelId)
        {
            //int hotelId;

            //if(!int.TryParse(obj.hotelId.toString(),out hotelId))
            if (hotelId <= 0)
            {
                return(new Response <Hotel>()
                {
                    Status = StatusEnum.ValidateModelError, Massage = "参数错误"
                });
            }

            Hotel hotel = await Task.Run(() => { return(Hander.Get(h => h.Id == hotelId && !h.IsDel.Value)); });

            return(new Response <Hotel>()
            {
                Status = StatusEnum.Success, Data = hotel, Massage = "获取成功"
            });
        }
Esempio n. 14
0
        protected void EndReceive(IAsyncResult iar)
        {
            SocketAsyncState state = (SocketAsyncState)iar.AsyncState;

            byte[] data = Hander.EndReceive(iar); //接收的数据
            if (data.Length == 0)                 //如果接收数据长度为0,则断开连接
            {
                Disconnected(true);
                return;
            }

            Hander.BeginReceive(Stream, EndReceive, state); //再次开始接收数据
            if (ReceiveCompleted != null)                   //接收完成事件
            {
                ReceiveCompleted(this, new SocketEventArgs(this, SocketAsyncOperation.Receive)
                {
                    Data = data
                });
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 异步连接完成
        /// </summary>
        /// <param name="iar">异步结果</param>
        private void EndConnect(IAsyncResult iar)
        {
            SocketAsyncState state = (SocketAsyncState)iar.AsyncState;

            try
            {
                Socket.EndConnect(iar);
            }
            catch                                              //出现异常
            {
                state.Completed = true;                        //连接失败
                if (state.IsAsync && ConnectCompleted != null) //判断是否异步,如果异步则触发异步完成事件
                {
                    ConnectCompleted(this, new SocketEventArgs(this, SocketAsyncOperation.Connect));
                }
                return;
            }

            Stream = new NetworkStream(Socket); //连接成功,创建Socket网络流
            if (IsUseAuthenticate)              //
            {
                NegotiateStream negotiate = new NegotiateStream(Stream);
                negotiate.AuthenticateAsClient();
                while (!negotiate.IsMutuallyAuthenticated)
                {
                    System.Threading.Thread.Sleep(10);
                }
            }

            state.Completed = true;  //连接完成
            if (state.IsAsync && ConnectCompleted != null)
            {
                ConnectCompleted(this, new SocketEventArgs(this, SocketAsyncOperation.Connect));
            }

            Hander.BeginReceive(Stream, EndReceive, state);  //开始接收数据
        }
Esempio n. 16
0
        public async Task <ListResponse <RoomResponseExt> > GetRooms(int hotelId)
        {
            var rooms = await Task.Run(() => { return(Hander.GetRooms(hotelId)); });

            var result = rooms.Select(r => new RoomResponseExt()
            {
                Id           = r.Id,
                HotelId      = r.HotelId,
                RoomNo       = r.RoomNo,
                RoomType     = r.RoomType,
                Remark       = r.Remark,
                IsDel        = r.IsDel,
                roomTypeName = EnumHander.GetName(r.RoomType),
                CreateTime   = r.CreateTime,
                UpdateTime   = r.UpdateTime
            }).ToList();

            return(new ListResponse <RoomResponseExt>()
            {
                Status = StatusEnum.Success,
                Massage = "获取房间成功",
                Data = result
            });
        }
Esempio n. 17
0
 public Hander(Hander theNextHandler)
 {
     m_NextHandler = theNextHandler;
 }
Esempio n. 18
0
 public ConcreteHandler3(Hander theNextHandler) : base(theNextHandler)
 {
 }
Esempio n. 19
0
        public async Task <Response <Login> > WxLogin([FromBody] dynamic request)
        {
            string wxcode = request.wxcode;

            Login  resultData = new Login();
            string appid      = Configuration.GetValue <string>("AppSetting:WxAppid");
            string secret     = Configuration.GetValue <string>("AppSetting:WxSecret");
            string uri        = $"https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={secret}&js_code={wxcode}&grant_type=authorization_code";
            string response   = await Task.Run(() => { return(HttpHelper.HttpJsonGetRequest(uri)); });

            if (!string.IsNullOrEmpty(response))
            {
                WxLoginInfo wxInfo = JsonConvert.DeserializeObject <WxLoginInfo>(response);

                if (wxInfo != null && !string.IsNullOrEmpty(wxInfo.openid))
                {
                    resultData.OpenId  = wxInfo.openid;
                    resultData.UnionId = wxInfo.unionid;

                    var claims = new Claim[] {
                        new Claim(ClaimTypes.Name, wxInfo.openid),
                        //new Claim(JwtRegisteredClaimNames.NameId, wxInfo.openid),
                        //new Claim(JwtRegisteredClaimNames.UniqueName,string.IsNullOrEmpty(wxInfo.unionid)?"":wxInfo.unionid)
                    };

                    var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetValue <string>("AppSetting:JwtSigningKey")));
                    var token     = new JwtSecurityToken(
                        issuer: Configuration.GetValue <string>("AppSetting:JwtIssuer"),
                        audience: Configuration.GetValue <string>("AppSetting:JwtAudience"),
                        claims: claims,
                        notBefore: DateTime.Now,
                        expires: DateTime.Now.AddDays(1),
                        signingCredentials: new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256)
                        );

                    resultData.JwtToken = new JwtSecurityTokenHandler().WriteToken(token);

                    //获取对应的宾馆
                    //var hotel = Hander.GetHotelByOpenId(wxInfo.openid);


                    var manager = await Task.Run(() =>
                    {
                        return(Hander.Get(m => m.WxOpenId == wxInfo.openid && m.IsDel.HasValue && !m.IsDel.Value));
                    });

                    if (manager != null)
                    {
                        resultData.Role = manager.Role;
                        var hotel = await Task.Run(() => { return(HotelHander.Get(h => h.Id == manager.HotelId)); });

                        resultData.Hotel = hotel;
                    }
                    else
                    {
                        resultData.Role = -1;
                    }
                }
                else
                {
                    throw new Exception("微信登录接口返回异常!" + response);
                }
            }
            else
            {
                throw new Exception("微信登录接口返回为空");
            }
            return(new Response <Login>()
            {
                Status = StatusEnum.Success, Massage = "登录成功", Data = resultData
            });
        }