/// <summary> /// Method that receives the player's email /// </summary> /// <param name="obj">The telegram data</param> /// <param name="exception">The exception to log</param> public static void Log(object obj, Exception exception) { string date = DateTime.Now.ToString("yyyy-MM-dd"); string time = DateTime.Now.ToString("HH:mm:ss"); string path = "Log/log-" + date + ".txt"; string pathDirectory = "Log"; try { if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } StreamWriter streamWriter = new StreamWriter(path, true); StackTrace stacktrace = new StackTrace(); streamWriter.WriteLine(obj.GetType().FullName + " " + time); streamWriter.WriteLine(stacktrace.GetFrame(1).GetMethod().Name + " - " + exception.ToString()); streamWriter.WriteLine(""); streamWriter.Flush(); streamWriter.Close(); } catch (IOException exceptionLog) { TelegramBot.SendToTelegram(exceptionLog); } }
private void MissGame() { dispatcher.Stop(); try { InstanceContext instanceContext = new InstanceContext(this); PlayConnectClient playConnect = new PlayConnectClient(instanceContext); playConnect.PlayerDisconnect(nickname); InstanceContext instanceContextChat = new InstanceContext(this); ChatManagerClient chatManagerClient = new ChatManagerClient(instanceContextChat); chatManagerClient.RemoveUser(nickname); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } LostGame lostGame = new LostGame(); lostGame.Owner = this; lostGame.ShowDialog(); Lobby lobby = new Lobby(); lobby.EmailReceived(emailAccount); lobby.ColocateBestScores(); lobby.ColocatePersonalInformation(); lobby.Show(); this.Close(); }
private void SendRecoveryCode(object sender, RoutedEventArgs eventSendCode) { if (ValidateEmail() && SearchEmail()) { try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient sendCode = new PlayerManagerClient(instanceContext); int code = ValidationData.GenerateConfirmationCode(); sendCode.SendEmail(tbEmail.Text, code); RecoverAccount recover = new RecoverAccount(); recover.EmailReceived(tbEmail.Text); recover.CodeReceived(code); recover.Show(); this.Close(); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); CloseWindow(); } } }
private void Send(object sender, RoutedEventArgs eventSend) { if (ValidatePassword() && ValidateCode()) { try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient changePassword = new PlayerManagerClient(instanceContext); changePassword.ChangePassword(emailAccount, Security.Encrypt(pbNewPassword.Password)); if (response) { System.Windows.Forms.MessageBox.Show(Properties.Resources.PasswordChangedDetails, Properties.Resources.PasswordChanged , MessageBoxButtons.OK, MessageBoxIcon.Information); } else { System.Windows.Forms.MessageBox.Show(Properties.Resources.ErrorDataBaseDetails, Properties.Resources.ErrorDataBase , MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } MainWindow main = new MainWindow(); main.Show(); this.Close(); } }
private void LogIn(object sender, RoutedEventArgs eventLog) { if (ValidateCredential()) { string email = tbEmail.Text; string password = Security.Encrypt(pbPassword.Password); try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient logIn = new PlayerManagerClient(instanceContext); logIn.LogIn(email, password); if (responseGeneral) { tbEmail.BorderBrush = Brushes.LightGreen; pbPassword.BorderBrush = Brushes.LightGreen; Lobby lobby = new Lobby(); lobby.EmailReceived(email); lobby.ColocateBestScores(); lobby.ColocatePersonalInformation(); lobby.Show(); this.Close(); } else { WrongCredentials(); } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } } }
private bool SearchEmail() { bool emailExist = false; try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient searchEmail = new PlayerManagerClient(instanceContext); searchEmail.SearchEmailPlayer(tbEmail.Text); if (responseCallback) { emailExist = true; } else { tbEmail.BorderBrush = Brushes.Red; tbValidateEmail.BorderBrush = Brushes.Red; System.Windows.Forms.MessageBox.Show(Properties.Resources.EmailNotFoundDetails, Properties.Resources.EmailNotFound , MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); CloseWindow(); } return(emailExist); }
private void DeleteAccountPlayer(object sender, RoutedEventArgs routedEventArgs) { try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient playerManager = new PlayerManagerClient(instanceContext); playerManager.DeleteAccountPlayer(player.NickName); bool isDeletePlayer = responseBoolean; if (isDeletePlayer) { OpenMessageBox(Properties.Resources.DeleteAccountMessage, Properties.Resources.DeleteAccountMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Information); MainWindow main = new MainWindow(); main.Show(); this.Close(); } else { OpenMessageBox(Properties.Resources.NoDeleteAccountMessage, Properties.Resources.DeleteAccountMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error); } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
/// <summary> /// Constructor of the App class /// </summary> public App() { string language = "es-MX"; System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language); Setting.LanguageReceive(language); Play.LanguageReceive(language); mediaElement = new MediaElement(); try { string routeSound = ObtainRoute(); mediaElement.Source = new Uri(routeSound); } catch (System.UriFormatException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); } double volume = 10.0; mediaElement.Volume = volume; Setting.ValueSoundReceive(volume); mediaElement.LoadedBehavior = MediaState.Play; mediaElement.UnloadedBehavior = MediaState.Play; mediaElement.MediaEnded += MediaElement_MediaEnded; }
private void Play(object sender, RoutedEventArgs e) { try { InstanceContext instanceContext = new InstanceContext(this); PlayConnectClient playConnectClient = new PlayConnectClient(instanceContext); playConnectClient.VerifyGameStart(); if (isStartGameCurrent) { MessageBox.Show(Properties.Resources.NoOpenMatchMessage, Properties.Resources.TitleMatch, (MessageBoxButton)System.Windows.Forms.MessageBoxButtons.OK, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Exclamation); } else { WaitingRoom waitingRoom = new WaitingRoom(); waitingRoom.NicknameReceived(nickname); waitingRoom.EmailReceived(emailAccount); waitingRoom.ObtainListPlayer(); waitingRoom.Show(); this.Close(); } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
private void StartGame(object sender, RoutedEventArgs routedEventArgs) { try { InstanceContext instanceContext = new InstanceContext(this); PlayConnectClient playConnect = new PlayConnectClient(instanceContext); playConnect.StartGame(nickname); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
private void AcceptCodeConfirmation(object sender, RoutedEventArgs routedEventArgs) { imgErrorCodeConfirmation.Visibility = Visibility.Hidden; tbConfirmationCode.BorderBrush = Brushes.Transparent; bool isValidConfirmationCode; isValidConfirmationCode = ValidationData.ValidateConfirmationCode(tbConfirmationCode.Text); if (isValidConfirmationCode) { bool isEqualConfirmationCode = ValidateEqualsConfirmationCode(); if (isEqualConfirmationCode) { tbConfirmationCode.BorderBrush = Brushes.Green; try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient registry = new PlayerManagerClient(instanceContext); registry.Register(account, accountPlayer); if (responseConfirmation) { OpenMessageBox(Properties.Resources.AccountRegistrationMessage, Properties.Resources.AccountRegistrationMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Information); } else { OpenMessageBox(Properties.Resources.NoAccountRegisteredMessage, Properties.Resources.AccountRegistrationMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error); } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } MainWindow mainWindow = new MainWindow(); mainWindow.Show(); this.Close(); } else { tbConfirmationCode.BorderBrush = Brushes.Red; OpenMessageBox(Properties.Resources.ErrorEqualConfirmationCodeMessage, Properties.Resources.IncorrectCodeMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } } else { tbConfirmationCode.BorderBrush = Brushes.Red; imgErrorCodeConfirmation.Visibility = Visibility.Visible; OpenMessageBox(Properties.Resources.IncorrectCodeMessage, Properties.Resources.IncorrectCodeMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } }
/// <summary> /// Method that gets the list of connected players /// </summary> public void ObtainListPlayer() { try { InstanceContext instanceContext = new InstanceContext(this); PlayConnectClient playerConnect = new PlayConnectClient(instanceContext); playerConnect.PlayerConnect(nickname); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
/// <summary> /// Method to place the reports in the table lvReportList /// </summary> public void ColocateReports() { try { InstanceContext instanceContext = new InstanceContext(this); ReportListClient reportListClient = new ReportListClient(instanceContext); reportListClient.ReportList(nickname); lvReportList.ItemsSource = reportList; } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
private void MediaElement_MediaEnded(object sender, RoutedEventArgs e) { try { string routeSound = ObtainRoute(); mediaElement.Source = new Uri(routeSound); } catch (System.UriFormatException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); } mediaElement.LoadedBehavior = MediaState.Play; mediaElement.UnloadedBehavior = MediaState.Play; }
private void UpdateAccount(object sender, RoutedEventArgs e) { try { ModifyAccount modifyAccount = new ModifyAccount(); modifyAccount.EmailReceived(emailAccount); modifyAccount.ObtainAccount(); modifyAccount.Show(); this.Close(); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
/// <summary> /// This method displays the list of the best scores /// </summary> public void ColocateBestScores() { try { InstanceContext instanceContext = new InstanceContext(this); PlayerScoresManagerClient searchBestScores = new PlayerScoresManagerClient(instanceContext); searchBestScores.SearchBestScoresPlayer(); dgBestScores.ItemsSource = servicePlayers; } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
/// <summary> /// This method displays the personal information of the player who logged in. /// </summary> public void ColocatePersonalInformation() { try { InstanceContext instanceContext = new InstanceContext(this); InformationPlayerManagerClient personalInformation = new InformationPlayerManagerClient(instanceContext); personalInformation.SearchInformationPlayer(emailAccount); lbNickname.Content = nickname; lbScore.Content = score; } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs cancelEventArgs) { try { InstanceContext instanceContext = new InstanceContext(this); PlayConnectClient playConnect = new PlayConnectClient(instanceContext); playConnect.PlayerDisconnect(nickname); InstanceContext instanceContextChat = new InstanceContext(this); ChatManagerClient chatManagerClient = new ChatManagerClient(instanceContextChat); chatManagerClient.RemoveUser(nickname); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } dispatcher.Stop(); }
/// <summary> /// This method sends the exception to telegram /// </summary> /// <param name="exception">The exception to send</param> public static void SendToTelegram(Exception exception) { try { string menssage = "Error message: " + exception.Message; if (exception.InnerException != null) { menssage = menssage + "\nInner exception: " + exception.InnerException.Message; } menssage = menssage + "\nStack trace: " + exception.StackTrace; telegramBotClient.SendTextMessageAsync(idGroup, menssage); } catch (IOException ioException) { TelegramBot telegramBot = new TelegramBot(); LogException.Log(telegramBot, ioException); } }
private void ChangeAccountPassword(object sender, RoutedEventArgs routedEventArgs) { imgErrorConfirmationPassword.Visibility = Visibility.Hidden; imgErrorCurrentPassword.Visibility = Visibility.Hidden; imgErrorNewPassword.Visibility = Visibility.Hidden; pbConfirmationPassword.BorderBrush = Brushes.Transparent; pbPassword.BorderBrush = Brushes.Transparent; pbNewPassword.BorderBrush = Brushes.Transparent; isValidNewPassword = false; ValidatePassword(); ValidateNewPassword(); if (isValidPassword && isValidNewPassword) { string passwordEncrypt = Security.Encrypt(pbNewPassword.Password); try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient playerManager = new PlayerManagerClient(instanceContext); playerManager.ChangePassword(account.Email, passwordEncrypt); if (responseBoolean) { OpenMessageBox(Properties.Resources.ChangePasswordMessage, Properties.Resources.ChangePasswordMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Information); } else { OpenMessageBox(Properties.Resources.NoChangePasswordMessage, Properties.Resources.ChangePasswordMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error); } ModifyAccount modifyAccount = new ModifyAccount(); modifyAccount.ObtainAccount(); modifyAccount.Show(); this.Close(); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } } else { OpenMessageBox(Properties.Resources.IncorrectDataMessage, Properties.Resources.IncorrectDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } }
private void EndGame() { try { InstanceContext instanceContext = new InstanceContext(this); PlayConnectClient endGame = new PlayConnectClient(instanceContext); ServiceWinner serviceWinner = new ServiceWinner(); serviceWinner.NickName = nickname; serviceWinner.Points = Int32.Parse(tbCurrentScore.Text); serviceWinner.Time = time; serviceWinner.Mistakes = countError; endGame.GameOver(serviceWinner); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } }
private void GoOut(object sender, RoutedEventArgs routedEventArgs) { try { InstanceContext instanceContext = new InstanceContext(this); PlayConnectClient playConnect = new PlayConnectClient(instanceContext); playConnect.PlayerDisconnect(nickname); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } Lobby lobby = new Lobby(); lobby.EmailReceived(emailAccount); lobby.ColocateBestScores(); lobby.ColocatePersonalInformation(); lobby.Show(); isClosing = false; this.Close(); }
private void ReportPlayer(object sender, RoutedEventArgs routedEventArgs) { ServiceReportMisConduct serviceReportMisConduct = new ServiceReportMisConduct(); serviceReportMisConduct.IdReportedPlayer = nicknameReported; serviceReportMisConduct.IdReportingPlayer = nickname; string dataContext = ValidationData.DeleteSpaceWord(tbContext.Text); if (dataContext.Length > Number.NumberValue(NumberValues.ZERO)) { serviceReportMisConduct.AdditionalContext = dataContext; } string typeReport = null; if (rbTypeOne.IsChecked == true) { typeReport = Properties.Resources.VerbalMotive; } else { if (rbTypeTwo.IsChecked == true) { typeReport = Properties.Resources.OffensiveMotive; } else { if (rbTypeThree.IsChecked == true) { typeReport = Properties.Resources.HateMotive; } } } if (!string.IsNullOrEmpty(typeReport)) { serviceReportMisConduct.TypeReport = typeReport; try { InstanceContext instanceContext = new InstanceContext(this); ReportPlayerClient reportPlayerClient = new ReportPlayerClient(instanceContext); reportPlayerClient.ReportPlayer(serviceReportMisConduct); if (isReportPlayer) { OpenMessageBox(Properties.Resources.ReportPlayerMessage, Properties.Resources.TitleRegisterReportMessage, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Information); } else { OpenMessageBox(Properties.Resources.ReportPlayerErrorMessage, Properties.Resources.TitleRegisterReportMessage, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error); } Play.ReportPlayerReceived(isReportPlayer); this.Close(); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } } else { OpenMessageBox(Properties.Resources.TypeReportErrorMessage, Properties.Resources.IncorrectDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error); } }
private void RegisterPlayer(object sender, RoutedEventArgs routedEventArgs) { bool isValidData = ValidateDataPlaye(); if (isValidData) { string name = tbName.Text; string lastName = tbLastName.Text; string nickname = tbNickname.Text; string email = tbEmail.Text; string password = Security.Encrypt(pbPassword.Password); int codeConfirmation = ValidationData.GenerateConfirmationCode(); ServiceAccount account = new ServiceAccount(); account.PasswordAccount = password; account.Email = email; account.ConfirmationCode = codeConfirmation; ServicePlayer accountPlayer = new ServicePlayer(); accountPlayer.NickName = nickname; accountPlayer.NamePlayer = ValidationData.DeleteSpaceWord(name); accountPlayer.LastName = ValidationData.DeleteSpaceWord(lastName); accountPlayer.StatusPlayer = "Active"; accountPlayer.ScoreObtained = 0; try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient validatePlayer = new PlayerManagerClient(instanceContext); validatePlayer.SearchNicknamePlayer(nickname); bool isValidRepeatNickname = responseBoolean; validatePlayer.SearchEmailPlayer(email); bool isValidRepeatEmail = responseBoolean; if (isValidRepeatEmail && isValidRepeatNickname) { OpenMessageBox(Properties.Resources.RegisteredEmailNicknameMessage, Properties.Resources.RepeatedDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } else { if (isValidRepeatEmail) { OpenMessageBox(Properties.Resources.RegisteredEmailMessage, Properties.Resources.RepeatedDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } else { if (isValidRepeatNickname) { OpenMessageBox(Properties.Resources.RegisteredNicknameMessage, Properties.Resources.RepeatedDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } else { EmailConfirmation emailConfirmation = new EmailConfirmation(); emailConfirmation.AccountReceived(account); emailConfirmation.PlayerReceived(accountPlayer); emailConfirmation.SendConfirmationCodePlayer(); emailConfirmation.Show(); this.Close(); } } } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } } else { OpenMessageBox(Properties.Resources.IncorrectDataMessage, Properties.Resources.IncorrectDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } }
private void Modify(object sender, RoutedEventArgs routedEventArgs) { playerEdit = new ServicePlayer(); emailEdit = account.Email; ValidateDataAccount(); if (isUpdateData || !emailEdit.Equals(emailAccount)) { if (isValidData) { try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient playerManager = new PlayerManagerClient(instanceContext); bool isValidRepeatEmail = false; if (isUpdateEmail) { playerManager.SearchRepeatEmailAccount(emailEdit, account.IdAccount); isValidRepeatEmail = responseBoolean; } bool updateEmail = false; if (isUpdateEmail && !isValidRepeatEmail) { playerManager.UpdateEmail(emailEdit, account.IdAccount); updateEmail = responseBoolean; } bool updatePlayer = false; if (isUpdateData) { playerManager.UpdatePlayer(player.NickName, playerEdit); updatePlayer = responseBoolean; } if (updatePlayer || updateEmail) { OpenMessageBox(Properties.Resources.ModifyAccountMessage, Properties.Resources.ModifyAccountMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Information); } else { OpenMessageBox(Properties.Resources.NoModifyAccountMessage, Properties.Resources.ModifyAccountMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error); } Lobby lobby = new Lobby(); if (isUpdateEmail) { lobby.EmailReceived(emailEdit); } lobby.ColocateBestScores(); lobby.ColocatePersonalInformation(); lobby.Show(); this.Close(); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } } else { OpenMessageBox(Properties.Resources.IncorrectDataMessage, Properties.Resources.IncorrectCodeMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); isUpdateData = false; } } else { OpenMessageBox(Properties.Resources.ModifyLeastDataMessage, Properties.Resources.ModifyLeastDataMessageTile, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } }