private async void AddCountingRequest(object o) { using (var fbd = new FolderBrowserDialog()) { DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { OnRequestLoader(true); var countingResult = await Task.Run(() => { var filesCount = Directory.GetFiles(fbd.SelectedPath).Length; var directoriesCount = Directory.GetDirectories(fbd.SelectedPath).Length; var size = GetDirectorySize(fbd.SelectedPath); CountingRequest countingRequest = new CountingRequest(fbd.SelectedPath, StationManager.CurrentUser, directoriesCount, filesCount, size); CountingRequestServiceWrapper.AddCountingRequest(countingRequest); return(countingRequest); }); _countingRequests.Add(countingResult); _selectedCountingRequest = countingResult; OnPropertyChanged(); OnRequestLoader(false); } } }
private async void SignUp(object obj) { bool isUserCreated = false; OnRequestLoader(true); await Task.Run(() => { try { if (!new EmailAddressAttribute().IsValid(_email)) { MessageBox.Show(String.Format(Resources.SignUp_EmailIsNotValid, _email)); return; } if (CountingRequestServiceWrapper.UserExists(_login)) { MessageBox.Show(String.Format(Resources.SignUp_UserAlreadyExists, _login)); return; } } catch (Exception ex) { Logger.Log(String.Format(Resources.SignUp_FailedToValidateData, Environment.NewLine, ex.Message), ex); MessageBox.Show(String.Format(Resources.SignUp_FailedToValidateData, Environment.NewLine, ex.Message)); return; } try { var user = new User(_firstName, _lastName, _email, _login, _password); CountingRequestServiceWrapper.AddUser(user); isUserCreated = true; } catch (Exception ex) { Logger.Log(String.Format(Resources.SignUp_FailedToCreateUser, Environment.NewLine, ex.Message), ex); MessageBox.Show(String.Format(Resources.SignUp_FailedToCreateUser, Environment.NewLine, ex.Message)); return; } MessageBox.Show(String.Format(Resources.SignUp_UserSuccessfulyCreated, _login)); }); OnRequestLoader(false); if (isUserCreated) { OnRequestClose(); } }
private async void SignIn(object obj) { OnRequestLoader(true); var result = await Task.Run(() => { User currentUser = null; try { currentUser = CountingRequestServiceWrapper.GetUserByLogin(_login); } catch (Exception ex) { Logger.Log(String.Format(Resources.SignIn_FailedToGetUser, Environment.NewLine, ex.Message), ex); MessageBox.Show(String.Format(Resources.SignIn_FailedToGetUser, Environment.NewLine, ex.Message)); return(false); } if (currentUser == null) { MessageBox.Show(String.Format(Resources.SignIn_UserDoesntExist, _login)); return(false); } try { if (!currentUser.CheckPassword(_password)) { MessageBox.Show(Resources.SignIn_WrongPassword); return(false); } } catch (Exception ex) { Logger.Log( String.Format(Resources.SignIn_FailedToValidatePassword, Environment.NewLine, ex.Message), ex); MessageBox.Show(String.Format(Resources.SignIn_FailedToValidatePassword, Environment.NewLine, ex.Message)); return(false); } StationManager.CurrentUser = currentUser; return(true); }); OnRequestLoader(false); if (result) { OnRequestClose(false); } }