コード例 #1
0
        public async void start()
        {
            await Task.Run(() => server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    var logs      = new YummyOnlineDAO.Models.Log();
                    logs.DateTime = DateTime.Now;
                    logs.Level    = YummyOnlineDAO.Models.Log.LogLevel.Success;
                    logs.Program  = YummyOnlineDAO.Models.Log.LogProgram.Manager;
                    logs.Message  = $"{socket.ConnectionInfo.ClientIpAddress}:{socket.ConnectionInfo.ClientPort} WebSocket Open";
                    sysdb.Logs.Add(logs);
                    sysdb.SaveChanges();
                    Console.WriteLine("Open!");
                    allSockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    var logs      = new YummyOnlineDAO.Models.Log();
                    logs.DateTime = DateTime.Now;
                    logs.Level    = YummyOnlineDAO.Models.Log.LogLevel.Warning;
                    logs.Program  = YummyOnlineDAO.Models.Log.LogProgram.Manager;
                    logs.Message  = $"{socket.ConnectionInfo.ClientIpAddress}:{socket.ConnectionInfo.ClientPort} WebSocket Close";
                    sysdb.Logs.Add(logs);
                    sysdb.SaveChanges();
                    Console.WriteLine("Close!");

                    allSockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                };
            }));
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: zyhbill/YummyOnline
        protected void Application_End()
        {
            var logs = new YummyOnlineDAO.Models.Log();

            logs.Program  = YummyOnlineDAO.Models.Log.LogProgram.Manager;
            logs.Level    = YummyOnlineDAO.Models.Log.LogLevel.Error;
            logs.DateTime = DateTime.Now;
            logs.Message  = $"Thread was killed";
            var db = new YummyOnlineContext();

            db.Logs.Add(logs);
            db.SaveChanges();
        }
コード例 #3
0
        /// <summary>
        /// 登陆验证
        /// </summary>
        /// <returns>验证信息</returns>
        public async Task <JsonResult> Verification(RemoteUser User)
        {
            RStatus rs;
            string  ConnectingStr;

            using (var db = new YummyOnlineContext())
            {
                string PasswordHash = Method.GetMd5(User.password);
                var    clerk        = db.Staffs.Where(ck => ck.SigninName == User.username && ck.PasswordHash == PasswordHash);
                var    ClerkInfo    = await clerk.FirstOrDefaultAsync();

                int?Hotel = clerk.FirstOrDefault()?.HotelId;
                ConnectingStr            = db.Hotels.Where(ht => ht.Id == Hotel).First().ConnectionString;
                Session["ConnectString"] = ConnectingStr;
                var hotel = new HotelContext(ConnectingStr);
                rs = clerk.Count() > 0 ? new RStatus {
                    Status = true, HotelId = ClerkInfo.HotelId, Name = hotel.Staffs.Where(s => s.Id == ClerkInfo.Id).Select(s => s.Name).FirstOrDefault(), ClerkId = ClerkInfo.Id
                } : new RStatus {
                    Status = false
                };
                var logs = new YummyOnlineDAO.Models.Log();
                logs.DateTime = DateTime.Now;
                logs.Level    = YummyOnlineDAO.Models.Log.LogLevel.Success;
                logs.Program  = YummyOnlineDAO.Models.Log.LogProgram.Identity;
                logs.Message  = $"Manager Signin: {ClerkInfo.Id} (HotelId {ClerkInfo.HotelId}), Host: {Request.UserHostAddress}";
                db.Logs.Add(logs);
                db.SaveChanges();
            }
            using (var db = new HotelContext(ConnectingStr))
            {
                if (rs.Status)
                {
                    FormsAuthentication.SetAuthCookie(User.username, false);
                    int[] roles = (from s in db.Staffs
                                   from r in s.StaffRoles
                                   where s.Id == rs.ClerkId
                                   select r.Id).ToArray();
                    var models = from r in db.StaffRoles
                                 from s in r.Schemas
                                 where roles.Contains(r.Id)
                                 select s.Schema;
                    int Rate = db.HotelConfigs.Select(h => h.PointsRatio).FirstOrDefault();
                    Session["Rate"]  = Rate;
                    rs.IsStaffPay    = 0;
                    rs.IsStaffReturn = 0;
                    rs.IsStaffEdit   = 0;
                    foreach (var m in models)
                    {
                        if (m == Schema.StaffPay)
                        {
                            rs.IsStaffPay = 1;
                        }
                        else if (m == Schema.StaffReturn)
                        {
                            rs.IsStaffReturn = 1;
                        }
                        else if (m == Schema.StaffEdit)
                        {
                            rs.IsStaffEdit = 1;
                        }
                        else
                        {
                        }
                    }
                }
                else
                {
                }
            }
            Session["User"]     = rs;
            Session["Username"] = User.username;
            return(await Task.Run(() => Json(rs)));
        }