public Initializer Map(PlayerIdProviderResult playerIdProviderResult) { _logger.Debug("Mapping the player champion."); if (playerIdProviderResult == null) { throw new ArgumentNullException(nameof(playerIdProviderResult)); } if (!_mappings.TryGetValue(playerIdProviderResult.Team, out var teamMappings)) { throw new ArgumentException($"Unsupported team: {playerIdProviderResult.Team}"); } if (!teamMappings.TryGetValue(playerIdProviderResult.Id, out var initializer)) { throw new ArgumentException($"Unsuporrted id: {playerIdProviderResult.Id}"); } return(initializer); }
//Record button private async void _buttonRecord_Click(object sender, EventArgs e) { _logger.Info(Info.NewProcessStartInfo); _logger.Info($"League of Legends folder: {_textBoxLeagueClientDirectoryPath.Text}."); _logger.Info($"League of Legends executable name: {_textBoxClientExecutableName.Text} "); CloseLauncher = true; _buttonRecord.Enabled = false; _buttonCancel.Enabled = true; _comboBoxScreenMode.Enabled = false; LockOrUnlockTextBoxInputs(isReadOnly: true); CancellationToken cancelToken = _recordingCancellationManager.Generate(); await Task.Factory.StartNew(async() => { try { Invoke(new Action(() => { _labelAdditionalInfo.Text = string.Empty; _circularProgressBar1.Visible = false; _labelRecordingStatusInfo.Text = LauncherPreparingText; _labelAdditionalInfo.Text = string.Empty; })); _logger.Info($"Getting information about replay playbacks from selected JSON file : {_textBoxRecordingMetadataPath.Text}"); CheckForExecutionCancelRequest(cancelToken); List <ReplayPlayback> replayPlaybacks = await _replayPlaybackProvider.ProvideAsync(_textBoxRecordingMetadataPath.Text); if (replayPlaybacks.Count == 0) { _logger.Warn($"No replay playbacks in provided attached JSON file: {_textBoxRecordingMetadataPath.Text}. Stopping the process."); MessageBox.Show(NoReplaysText); return; } if (string.IsNullOrEmpty(_textBoxRecordingSavePath.Text)) { _logger.Warn(Info.ProvideSavePathInfo); MessageBox.Show(ProvideSavePathText); return; } _logger.Info($"Selected recording save path: {_textBoxRecordingSavePath.Text}"); _logger.Info($"Launching the selected ROFL file: {_textBoxRoflFilePath.Text} "); CheckForExecutionCancelRequest(cancelToken); if (IsLeagueProcessAlreadyRunning()) { _logger.Info(Info.AntoherClientExecutingInfo); DialogResult dialogResult = MessageBox.Show(ClientAlreadyRunningText, WarningText, MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { _logger.Info(Info.ProcessAbortInfo); CloseLauncher = false; return; } _logger.Info(Info.ClientProcessAbortInfo); TerminateLeagueProcessIfRunning(); } await _leagueClientLauncher.RunAsync(_textBoxLeagueClientDirectoryPath.Text, _textBoxClientExecutableName.Text, _textBoxRoflFilePath.Text); Invoke(new Action(() => _labelRecordingStatusInfo.Text = LaunchingText)); _logger.Info(Info.WaitingForClientToStartInfo); ReplayRecording replayRecording = await _replayRepository.GetReplayRecordingAsync(); _logger.Info(Info.LeagueClientStaredInfo); Invoke(new Action(() => { _labelRecordingStatusInfo.Text = $"Recording... (0 / {replayPlaybacks.Count})"; _circularProgressBar1.Text = InitialProgressBarText; })); _logger.Info(Info.DeletingTemporaryFilesInfo); CheckForExecutionCancelRequest(cancelToken); await _unprocessedFilesMonitor.DeleteUnprocessedFilesAsync(_textBoxRecordingSavePath.Text); int totalRecordingLength = replayPlaybacks.Sum(replay => replay.Length); _logger.Info($"Starting Recording processing | Number of recordings: {replayPlaybacks.Count}"); foreach (var replayPlaybackInfo in replayPlaybacks.Select((replayPlayback, i) => (replayPlayback, i))) { var recoringInfoText = $"Recording ({replayPlaybackInfo.i + 1} / {replayPlaybacks.Count})"; _logger.Info(recoringInfoText); Invoke(new Action(() => _labelRecordingStatusInfo.Text = recoringInfoText)); await _replayRepository.RecordAsync(new Recording { IsRecording = false }); CheckForExecutionCancelRequest(cancelToken); string selectedItem = string.Empty; Invoke(new Action(() => selectedItem = _comboBoxScreenMode.SelectedItem.ToString())); await _screenModeOperator.UpdateScreenMode(_stringToScreenModeMapper.Map(selectedItem)); _logger.Info(Info.GettingSummonerFocusInfo); CheckForExecutionCancelRequest(cancelToken); Initializer initializer = Initializer.Unknown; try { PlayerIdProviderResult playerIdResult = _playerIdProvider.Provide(_textBoxLeagueClientDirectoryPath.Text, replayPlaybackInfo.replayPlayback.ChampionName); initializer = _participantIdToInitializerMapper.Map(playerIdResult); _logger.Info($"Summoner to focus on chosen: ({replayPlaybackInfo.replayPlayback.ChampionName}) - key: {(int)initializer}"); } catch (PlayerIdProviderException) { var championInitializerErrorText = $"Champion: {replayPlaybackInfo.replayPlayback.ChampionName} cannot be mapped to id for current data provided. Using default camera instead."; _logger.Warn(championInitializerErrorText); Invoke(new Action(() => _labelAdditionalInfo.Text = championInitializerErrorText)); } CheckForExecutionCancelRequest(cancelToken); Recording recording = _recordingProvider.Provide(replayPlaybackInfo.replayPlayback, DefaultReplaySpeed, DefaultFramesPerSecond, _textBoxRecordingSavePath.Text); var record = await _replayRepository.RecordAsync(recording); if (record == null) { throw new RestRepositoryException(Error.IncorrecServerDataError); } if (initializer != Initializer.Unknown) { _logger.Info(Info.FocusingOnChampionInfo); await _pressKeySimulator.SendKeystrokeAsync(initializer); } await _progressBarOperator.Update(replayPlaybackInfo.replayPlayback.Length, totalRecordingLength, this, _circularProgressBar1, _labelRecordingStatusInfo, cancelToken); _logger.Info(Info.WaitingForUnsavedRecordingsInfo); CheckForExecutionCancelRequest(cancelToken); Invoke(new Action(() => _labelRecordingStatusInfo.Text = $"Checking for temporary files... ({replayPlaybackInfo.i + 1} / {replayPlaybacks.Count})")); bool canProceed = await _unprocessedFilesMonitor.CheckForUnprocessedFilesAsync(_textBoxRecordingSavePath.Text); if (!canProceed) { var savingRecordingErrorText = $"There was a problem on saving recording: {replayPlaybackInfo.i + 1}. Continue?"; _logger.Error(savingRecordingErrorText); if (MessageBox.Show(savingRecordingErrorText, ErrorText, MessageBoxButtons.YesNo) == DialogResult.No) { return; } } } _logger.Info(Info.RecordingCompleteInfo); Invoke(new Action(() => { _circularProgressBar1.Text = CompleteProgressBarText; _labelRecordingStatusInfo.Text = CompletedText; })); } catch (ReplayPlaybackProviderException) { _logger.Error(Error.InvalidMetadataFileError); MessageBox.Show(Error.InvalidMetadataFileError); } catch (LeagueClientLauncherException) { _logger.Error(Error.LaunchingReplayError); MessageBox.Show(Error.LaunchingReplayError); } catch (UnprocessedFilesMonitorException) { _logger.Error(Error.CriticalError); MessageBox.Show(Error.CriticalError); } catch (RecordingProviderException) { _logger.Error(Error.CreateRecordingError); MessageBox.Show(Error.CreateRecordingError); } catch (RestRepositoryException) { _logger.Error(Error.ReplayApiNotRespondingError); MessageBox.Show(Error.ReplayApiNotRespondingError); } catch (OperationCanceledException) { _logger.Warn(Warn.OperationCancelledWarn); Invoke(new Action(() => _labelAdditionalInfo.Text = Info.CancelInfo)); BringControlsToDefaultState(); } catch (LeagueOfLegendsProcessException) { CloseLauncher = true; TerminateLeagueProcessIfRunning(); _logger.Error(Error.LeagueClientNotRespondingError); MessageBox.Show(Error.LeagueClientNotRespondingError); } catch (Exception) { _logger.Error(Error.UnhandledExceptionError); Invoke(new Action(() => _labelAdditionalInfo.Text = Error.UnhandledExceptionError)); } finally { _logger.Info(Info.CleaningDataInfo); BringControlsToDefaultState(); await _unprocessedFilesMonitor.CheckForUnprocessedFilesAsync(_textBoxRecordingSavePath.Text); } }, cancelToken); }