コード例 #1
0
        public void TryToAutoSignIn()
        {
            try
            {
                var  userCredentials = SerializeManager.Deserialize <UserCredentials>(StaticResources.CurrentUserSerializedPath);
                User currentUser;

                try
                {
                    currentUser = ChatService.GetUserByLogin(userCredentials.Login);
                }
                catch (Exception ex)
                {
                    Logger.Log("Failed to get user by login", ex);
                    return;
                }

                if (currentUser == null)
                {
                    Logger.Log("User " + userCredentials.Login + "does not exist");
                    return;
                }
                try
                {
                    if (!currentUser.CheckPassword(userCredentials.Password))
                    {
                        Logger.Log("Wrong password " + userCredentials.Password);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(
                        String.Format(WpfApp1.Properties.Resources.SignIn_FailedToValidatePassword, Environment.NewLine, ex.Message), ex);
                    return;
                }
                CurrentUser = currentUser;
                Logger.Log("Auto signed in as " + userCredentials.Login);
            }
            catch (Exception e)
            {
                Logger.Log("Old user was not loaded", e);
            }
        }
コード例 #2
0
        public MainWindow()
        {
            // deserializing user when app starts
            // if such users exists do autologin else redirect to login
            var user            = SerializeManager.Deserialize <User>(StationManager.UserFilePath);
            var userNameIsEmpty = String.IsNullOrEmpty(user?.UserName);

            // In case the previous function returned new User()
            if (!userNameIsEmpty)
            {
                try
                {
                    StationManager.CurrentUser = WordsCountServiceWrapper.GetUserByName(user.UserName);
                }
                catch (Exception e)
                {
                    Logger.Log("Error getting user", e);
                }

                if (StationManager.CurrentUser != null)
                {
                    // writing logs (what current user have just done)
                    Logger.Log($"User {StationManager.CurrentUser?.UserName} was autologged-in");

                    try
                    {
                        StationManager.CurrentUser.LastVisit = DateTime.Now;
                        WordsCountServiceWrapper.EditEntity(StationManager.CurrentUser);
                    }
                    catch (Exception e)
                    {
                        Logger.Log("Error updating user", e);
                    }

                    GoToCabinet();
                    return;
                }

                Logger.Log("Error on autologin");
            }

            Login();
        }
コード例 #3
0
        public static void Start()
        {
            new System.Threading.Thread(() =>
            {
                if (File.Exists(SessionBagFile))
                {
                    _SessionPools = SerializeManager <ConcurrentDictionary <string, SessionIdentity> > .Deserialize(SessionBagFile);
                    if (_SessionPools == null)
                    {
                        _SessionPools = new ConcurrentDictionary <string, SessionIdentity>();
                    }
                }
                runningstate = true;
                int tick     = 0;
                int tick2    = 0;
                while (runningstate)
                {
                    System.Threading.Thread.Sleep(1000);
                    tick  += 1000;
                    tick2 += 1000;
                    if (tick / 1000 >= 5 * 60) //5分钟 写入磁盘一次
                    {
                        SaveSessionToDisk();
                        tick = 0;
                    }

                    //test
                    if (true)
                    {
                        RemoveExpiredSession();
                    }
                    //end test

                    if (tick2 / 1000 >= 3600 * 24) //24个小时清理一次过期session
                    {
                        RemoveExpiredSession();
                        tick2 = 0;
                    }
                }
            }).Start();
        }
コード例 #4
0
        public CabinetWindow()
        {
            InitializeComponent();
            try
            {
                var user = SerializeManager.Deserialize <User>(User.FileName);

                //якщо не існує файлу з серіалізованим користувачем, то ми відкриваємо вікно Логіну
                if (user == null)
                {
                    OpenLoginWindow();
                }
                //в іншому випадку користувача десеріалізують
                else
                {
                    var curUser = BoSiReminderService_Wrapper.GetUser(user.Id);
                    if (curUser == null)
                    {
                        OpenLoginWindow();
                    }
                    else
                    {
                        curUser.PreviousLog = DateTime.Now;
                        BoSiReminderService_Wrapper.EditUser(curUser);

                        //встановлюємо поточного користувача та відриваємо вікно Кабінету
                        StationManager.CurrentUser = curUser;
                        InitializeCabinet();
                    }
                }
            }
            catch (Exception ex)
            {
                LogWriter.LogWrite("Exception while Initializing cabinet window", ex);
            }
        }