/// <summary> /// Save inputs so that the program remembers them if program is closed /// </summary> public void SaveInputs() { ReportingAssesmentInputParams input = new ReportingAssesmentInputParams { AssesmentTitle = Model.AssesmentTitle, //CombinedTracts = Model.CombinedTracts, SelectedTractCombination = Model.SelectedTractCombination, Authors = Model.Authors, Country = Model.Country, DepositType = Model.DepositType, DescModel = Model.DescModelPath, DescModelName = Model.DescModelName, GTModel = Model.GTModelPath, GTModelName = Model.GTModelName, RaefFile = Model.RaefFilePath, RaefFileName = Model.RaefFileName, AddDescriptive = Model.AddDescriptive.ToString(), AddGradeTon = Model.AddGradeTon.ToString(), AddRaef = Model.AddRaef.ToString(), EnableDescCheck = Model.EnableDescCheck.ToString(), EnableGTCheck = Model.EnableGTCheck.ToString(), EnableRaefCheck = Model.EnableRaefCheck.ToString(), TractImageFile = Model.TractImageFile, AsDate = Model.AsDate, AsDepth = Model.AsDepth, AsLeader = Model.AsLeader, AsTeamMembers = Model.AsTeamMembers, IsRaefDone = Model.IsRaefDone, IsScreenerDone = Model.IsScreenerDone, IsUndiscDepDone = Model.IsUndiscDepDone }; string outputFolder = Path.Combine(input.Env.RootPath, "Reporting"); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } input.Save(Path.Combine(outputFolder, "assesment_report_input_params.json")); }
/// <summary> /// Initialize new instance of ReportingViewModel class. /// </summary> /// <param name="logger">Logging for the MapWizard</param> /// <param name="dialogService">Service for using project's dialogs and notifications</param> /// <param name="settingsService">Service for using and editing project's settings</param> public ReportingAssesmentViewModel(ILogger logger, IDialogService dialogService, ISettingsService settingsService) { this.logger = logger; this.dialogService = dialogService; this.settingsService = settingsService; viewModelLocator = new ViewModelLocator(); RunToolCommand = new RelayCommand(RunTool, CanRunTool); GoToAssesmentReportCommand = new RelayCommand(GoToAssesmentReport, CanChangeView); CheckTractFilesCommand = new RelayCommand(CheckFiles, CanRunTool); FindTractsCommand = new RelayCommand(FindTractIDs, CanRunTool); FindCombinedTractsCommand = new RelayCommand(FindCombinedTracts, CanRunTool); SelectTractImageFileCommand = new RelayCommand(SelectTractImageFile, CanRunTool); ReportingAssesmentInputParams inputParams = new ReportingAssesmentInputParams(); string outputFolder = Path.Combine(settingsService.RootPath, "Reporting"); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } string param_json = Path.Combine(outputFolder, "assesment_report_input_params.json"); if (File.Exists(param_json)) { try { inputParams.Load(param_json); Model = new ReportingAssesmentModel { AssesmentTitle = inputParams.AssesmentTitle, SelectedTractCombination = inputParams.SelectedTractCombination, Authors = inputParams.Authors, Country = inputParams.Country, DescModelPath = inputParams.DescModel, DescModelName = inputParams.DescModelName, GTModelPath = inputParams.GTModel, GTModelName = inputParams.GTModelName, RaefFilePath = inputParams.RaefFile, RaefFileName = inputParams.RaefFileName, AddDescriptive = Convert.ToBoolean(inputParams.AddDescriptive), AddGradeTon = Convert.ToBoolean(inputParams.AddGradeTon), AddRaef = Convert.ToBoolean(inputParams.AddRaef), EnableDescCheck = Convert.ToBoolean(inputParams.EnableDescCheck), EnableGTCheck = Convert.ToBoolean(inputParams.EnableGTCheck), EnableRaefCheck = Convert.ToBoolean(inputParams.EnableRaefCheck), TractImageFile = inputParams.TractImageFile, AsDate = inputParams.AsDate, AsDepth = inputParams.AsDepth, AsLeader = inputParams.AsLeader, AsTeamMembers = inputParams.AsTeamMembers, IsUndiscDepDone = inputParams.IsUndiscDepDone, IsRaefDone = inputParams.IsRaefDone, IsScreenerDone = inputParams.IsScreenerDone }; FindTractIDs(); // Gets the tractID names from PermissiveTractTool's Tracts folder. CheckFiles(); // Check which of the needed files for creating a report exist. FindCombinedTracts(); // Check if the tool have ever been correctly ran before. if (Model.SelectedTractCombination != null) // Check if the tool have ever been correctly ran before. { //viewModelLocator.ReportingViewModel.Model.RunStatus = 0; Remove this? string docOutputFile = Path.Combine(outputFolder, Model.SelectedTractCombination, "AssesmentReport" + Model.SelectedTractCombination + ".docx"); if (File.Exists(docOutputFile))// If reporting file exist then the tool have been ran. { viewModelLocator.ReportingViewModel.Model.RunStatus = 1; } } SaveInputs(); // Save inputs to tract_report_input_params.json file. This might be not needed(?). } catch (Exception ex) { // If something goes wrong then the tool will be initialized to have default parameters. Model = new ReportingAssesmentModel(); logger.Error(ex, "Failed to read json file"); dialogService.ShowNotification("Couldn't load Reporting tool's Assesment report's inputs correctly. Inputs were initialized to default values.", "Error"); viewModelLocator.SettingsViewModel.WriteLogText("Couldn't load Reporting tool's Assesment report's inputs correctly. Inputs were initialized to default values.", "Error"); } } else { Model = new ReportingAssesmentModel(); FindTractIDs(); // Gets the tractID names from PermissiveTractTool's Trats folder. } // Check if the DepositType have been given correctly for the project. if (settingsService.Data.DepositType != null) { Model.DepositType = settingsService.Data.DepositType; } var lastRunFile = Path.Combine(settingsService.RootPath, "Reporting", "tract_report_last_run.lastrun"); if (File.Exists(lastRunFile)) { viewModelLocator.ReportingViewModel.Model.LastRunDate = "Last Run: " + (new FileInfo(lastRunFile)).LastWriteTime.ToString(); } }
/// <summary> /// Run tool with user input. /// </summary> private async void RunTool() { try { logger.Info("-->{0}", this.GetType().Name); Model.TractIDNames.Clear(); Model.TractIDChoices.Clear(); foreach (var item in Model.TractIDCollection) { Model.TractIDNames.Add(item.TractName); Model.TractIDChoices.Add(item.IsTractChosen.ToString()); } // 1. Collect input parameters ReportingAssesmentInputParams input = new ReportingAssesmentInputParams { AssesmentTitle = Model.AssesmentTitle, //CombinedTracts = Model.CombinedTracts, TractIDNames = Model.TractIDNames, TractIDChoices = Model.TractIDChoices, SelectedTractCombination = Model.SelectedTractCombination, Authors = Model.Authors, Country = Model.Country, DepositType = Model.DepositType, DescModel = Model.DescModelPath, DescModelName = Model.DescModelName, GTModel = Model.GTModelPath, GTModelName = Model.GTModelName, RaefFile = Model.RaefFilePath, RaefFileName = Model.RaefFileName, AddDescriptive = Model.AddDescriptive.ToString(), AddGradeTon = Model.AddGradeTon.ToString(), AddRaef = Model.AddRaef.ToString(), EnableDescCheck = Model.EnableDescCheck.ToString(), EnableGTCheck = Model.EnableGTCheck.ToString(), EnableRaefCheck = Model.EnableRaefCheck.ToString(), TractImageFile = Model.TractImageFile, AsDate = Model.AsDate, AsDepth = Model.AsDepth, AsLeader = Model.AsLeader, AsTeamMembers = Model.AsTeamMembers, IsUndiscDepDone = Model.IsUndiscDepDone, IsRaefDone = Model.IsRaefDone, IsScreenerDone = Model.IsScreenerDone }; // User can choose not to insert Descriptive model document into report. if (Model.AddDescriptive == false) { input.DescModelName = "-"; } // User can chose not to insert Grade Tonnage file into report. if (Model.AddGradeTon == false) { input.GTModelName = "-"; } // User can chose not to insert Raef file into report. if (Model.AddRaef == false) { input.RaefFileName = "-"; } //// User can chose not to insert Report document into report. //if (Model.AddReport == false) //{ // input.ReportDocumentName = "-"; //} // 2. Execute tool ReportingAssesmentResult ddResult = default(ReportingAssesmentResult); Model.IsBusy = true; await Task.Run(() => { ReportingAssesmentTool tool = new ReportingAssesmentTool(); ddResult = tool.Execute(input) as ReportingAssesmentResult; }); var lastRunFile = Path.Combine(settingsService.RootPath, "Reporting", "tract_report_last_run.lastrun"); File.Create(lastRunFile).Close(); dialogService.ShowNotification("Reporting tool completed successfully", "Success"); viewModelLocator.SettingsViewModel.WriteLogText("Assesment report in Reporting tool completed successfully.", "Success"); viewModelLocator.ReportingViewModel.Model.LastRunDate = "Last Run: " + DateTime.Now.ToString("g"); viewModelLocator.ReportingViewModel.Model.RunStatus = 1; } catch (Exception ex) { logger.Error(ex, "Failed to build documentation file"); dialogService.ShowNotification("Run failed. Check output for details\r\n- Are all input parameters correct?\r\n- Are all input files valid? \r\n- Are all input and output files closed?", "Error"); viewModelLocator.SettingsViewModel.WriteLogText("Assesment report in Reporting tool run failed. Check output for details\r\n- Are all input parameters correct?\r\n- Are all input files valid? \r\n- Are all input and output files closed?", "Error"); viewModelLocator.ReportingViewModel.Model.RunStatus = 0; } finally { Model.IsBusy = false; } logger.Info("<--{0} completed", this.GetType().Name); }