/// <summary> /// This method sets directory where output files will be generated /// </summary> public void SelectOutputDirectory() { OutputPath = GeneratorViewModelHelpers.GetOutputPath(); _Settings.SetSetting(ActualOperation, "PathToTsv", OutputPath); GenerateFilesCommand.InvokeCanExecuteChanged(); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "OutputPath"); }
/// <summary> /// This method allows picking of overview reports (.xml) by the dialog /// </summary> private void SelectOverviewReports() { ReportsPaths = GeneratorViewModelHelpers.GetOverviewReportPaths(); if (ReportsPaths != null) { if (ReportsPaths.Count > 0 && _generatorService != null) { IsChoosingSheetAvailable = true; ConfirmMtsSheet?.InvokeCanExecuteChanged(); } } OpenMtsFileCommand?.InvokeCanExecuteChanged(); }
/// <summary> /// This method sets confirmed mts sheet and calls loading of mts data for specified modules /// </summary> /// <returns>async Task</returns> private async Task SaveChoosenMtsSheet() { if (_generatorService != null) { IsOperationTypeComboboxEnabled = false; GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "IsOperationTypeComboboxEnabled"); _generatorService.SetSheetName(ActualMtsSheet); IsSheetChoosen = true; IsChoosingSheetAvailable = false; ConfirmMtsSheet.InvokeCanExecuteChanged(); await LoadDataFromMts(); //GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "IsChoosingSheetAvailable"); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "IsSheetsDropdownEnabled"); } }
/// <summary> /// This method removes selected row of the datagrid /// </summary> private void RemoveSelectedRow() { /* remove module from service */ _generatorService.RemoveModuleData(SelectedObject.Name); /* remove module row from datagrid */ ModulesForUi.Remove(SelectedObject); /* clear selected object */ SelectedObject = null; /* refresh buttons if necessary */ RemoveObjectFromDataGridCommand.InvokeCanExecuteChanged(); OpenOutputDirectoryCommand.InvokeCanExecuteChanged(); /* refresh ui controlls if necessary*/ GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "IsSheetsDropdownEnabled"); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "ModulesForUi"); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "SelectedObject"); }
/// <summary> /// This method loads mts (excel) file and loads needed excel sheets /// </summary> /// <returns>Async task</returns> private async Task SelectMtsFile() { /* get path*/ string newMtsPath = GeneratorViewModelHelpers.GetMtsFilePath(); try { /*if path was chosen*/ if (newMtsPath != string.Empty) { /* set new mts path */ MtsFilePath = newMtsPath; /* create new instance of generator service by its factory */ _generatorService = GeneratorServiceFactory.CreateService(ActualOperation, ExcelProvider_ShowWorkProgressEvent); /* load excel sheets asynchronously */ MtsSheets = new BindableCollection <string>(await Task.Run(() => _generatorService.GetSheetNames(MtsFilePath))); /* set first sheet as default one */ ActualMtsSheet = MtsSheets[0]; /* refresh view model */ GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "MtsFilePath"); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "MtsSheets"); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "ActualMtsSheet"); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "IsSheetsDropdownEnabled"); if (ActualOperation == OperationType.Test_Specification_From_Module_Test_State) { OpenOutputDirectoryCommand.InvokeCanExecuteChanged(); } else { OpenOverviewReportsCommand.InvokeCanExecuteChanged(); } } } catch (Exception ex) { MessageBox.Show($"Error: {ex}"); } }
/// <summary> /// Loads data from mts for modules stored as reports paths /// TODO: ---- TO BE SIMPLIFIED ------ /// </summary> /// <returns>async Task</returns> private async Task LoadDataFromMts() { if (ReportsPaths != null) { List <string> moduleNames = await Task.Run(() => GeneratorViewModelHelpers.GetModuleNamesFromPaths(ReportsPaths, ActualOperation)); if (_generatorService != null) { await Task.Run(() => _generatorService.LoadDataFromMts(moduleNames)); List <ModuleToUiDto> itemsToAdd = _generatorService.GetDtosForUi(); GeneratorViewModelHelpers.SetOverviewReportsPathsToModules(ref itemsToAdd, ReportsPaths); /* helper list to check if new loaded elements are already displayed on ui */ List <string> allModuleNamesOnUi = ModulesForUi.Select(x => x.Name).ToList(); /* remove dupplicated elements */ foreach (string moduleName in allModuleNamesOnUi) { itemsToAdd.RemoveAll(x => x.Name.Contains(moduleName)); } /* show new loaded elements on ui */ ModulesForUi.AddRange(itemsToAdd); } _generatorService.CloseExcelDocument(); RemoveObjectFromDataGridCommand.InvokeCanExecuteChanged(); OpenOutputDirectoryCommand.InvokeCanExecuteChanged(); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "ModulesForUi"); GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "IsSheetsDropdownEnabled"); } }
/// <summary> /// This method is an event listener which updates current progress of the application /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">progress information</param> public void ExcelProvider_ShowWorkProgressEvent(object sender, string progress) { ExcelProviderProgress = $"{progress}"; GeneratorViewModelHelpers.RefreshViewModel(this, PropertyChanged, "ExcelProviderProgress"); }