/// <summary> /// Save inputs so that the program remembers them if program is closed /// </summary> public void SaveInputs() { ReportingInputParams input = new ReportingInputParams { TractIDNames = Model.TractIDNames, SelectedTract = Model.SelectedTract, Authors = Model.Authors, Country = Model.Country, DepositType = Model.DepositType, DescModel = Model.DescModelPath, DescModelName = Model.DescModelName, GTModel = Model.GTModelPath, GTModelName = Model.GTModelName, AddDescriptive = Model.AddDescriptive.ToString(), AddGradeTon = Model.AddGradeTon.ToString(), EnableDescCheck = Model.EnableDescCheck.ToString(), EnableGTCheck = Model.EnableGTCheck.ToString(), TractImageFile = Model.TractImageFile, KnownDepositsFile = Model.KnownDepositsFile, ProspectsOccurencesFile = Model.ProspectsOccurencesFile, ExplorationFile = Model.ExplorationFile, SourcesFile = Model.SourcesFile, ReferencesFile = Model.ReferencesFile, AsDate = Model.AsDate, AsDepth = Model.AsDepth, AsLeader = Model.AsLeader, AsTeamMembers = Model.AsTeamMembers, IsUndiscDepDone = Model.IsUndiscDepDone, IsRaefDone = Model.IsRaefDone, IsScreenerDone = Model.IsScreenerDone }; string outputFolder = Path.Combine(input.Env.RootPath, "Reporting"); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } input.Save(Path.Combine(outputFolder, "tract_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 ReportingViewModel(ILogger logger, IDialogService dialogService, ISettingsService settingsService) { this.logger = logger; this.dialogService = dialogService; this.settingsService = settingsService; viewModelLocator = new ViewModelLocator(); RunToolCommand = new RelayCommand(RunTool, CanRunTool); GoToTractReportCommand = new RelayCommand(GoToTractReport, CanChangeView); GoToReportSelectionCommand = new RelayCommand(GoToReportSelection, CanChangeView); CheckTractFilesCommand = new RelayCommand(CheckFiles, CanRunTool); FindTractsCommand = new RelayCommand(FindTractIDs, CanRunTool); SelectTractImageFileCommand = new RelayCommand(SelectTractImageFile, CanRunTool); SelectKnownDepositsFileCommand = new RelayCommand(SelectKnownDepositsFile, CanRunTool); SelectProspectsOccurencesFileCommand = new RelayCommand(SelectProspectsOccurencesFile, CanRunTool); SelectExplorationFileCommand = new RelayCommand(SelectExplorationFile, CanRunTool); SelectSourcesFileCommand = new RelayCommand(SelectSourcesFile, CanRunTool); SelectReferencesFileCommand = new RelayCommand(SelectReferencesFile, CanRunTool); ReportingInputParams inputParams = new ReportingInputParams(); string outputFolder = Path.Combine(settingsService.RootPath, "Reporting"); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } string param_json = Path.Combine(outputFolder, "tract_report_input_params.json"); if (File.Exists(param_json)) { try { inputParams.Load(param_json); Model = new ReportingModel { TractImageFile = inputParams.TractImageFile, KnownDepositsFile = inputParams.KnownDepositsFile, ProspectsOccurencesFile = inputParams.ProspectsOccurencesFile, ExplorationFile = inputParams.ExplorationFile, SourcesFile = inputParams.SourcesFile, ReferencesFile = inputParams.ReferencesFile, SelectedTract = inputParams.SelectedTract, Authors = inputParams.Authors, Country = inputParams.Country, DescModelPath = inputParams.DescModel, DescModelName = inputParams.DescModelName, GTModelPath = inputParams.GTModel, GTModelName = inputParams.GTModelName, AddDescriptive = Convert.ToBoolean(inputParams.AddDescriptive), AddGradeTon = Convert.ToBoolean(inputParams.AddGradeTon), EnableDescCheck = Convert.ToBoolean(inputParams.EnableDescCheck), EnableGTCheck = Convert.ToBoolean(inputParams.EnableGTCheck), AsDate = inputParams.AsDate, AsDepth = inputParams.AsDepth, AsLeader = inputParams.AsLeader, AsTeamMembers = inputParams.AsTeamMembers, IsRaefDone = inputParams.IsRaefDone, IsScreenerDone = inputParams.IsScreenerDone, IsUndiscDepDone = inputParams.IsUndiscDepDone }; FindTractIDs(); // Gets the tractID names from PermissiveTractTool's Tracts folder. CheckFiles(); // Check which of the needed files for creating a report exist. if (Model.SelectedTract != null) // Check if the tool have ever been correctly ran before. { //Model.RunStatus = 0; Remove this? string docOutputFile = Path.Combine(outputFolder, Model.SelectedTract, "TractReport" + Model.SelectedTract + ".docx"); if (File.Exists(docOutputFile))// If reporting file exist then the tool have been ran. { 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 ReportingModel(); logger.Error(ex, "Failed to read json file"); dialogService.ShowNotification("Couldn't load Reporting tool's inputs correctly. Inputs were initialized to default values.", "Error"); viewModelLocator.SettingsViewModel.WriteLogText("Couldn't load Reporting tool's inputs correctly. Inputs were initialized to default values.", "Error"); } } else { Model = new ReportingModel(); 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)) { 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); // 1. Collect input parameters ReportingInputParams input = new ReportingInputParams { TractIDNames = Model.TractIDNames, SelectedTract = Model.SelectedTract, Authors = Model.Authors, Country = Model.Country, DepositType = Model.DepositType, DescModel = Model.DescModelPath, DescModelName = Model.DescModelName, GTModel = Model.GTModelPath, GTModelName = Model.GTModelName, AddDescriptive = Model.AddDescriptive.ToString(), AddGradeTon = Model.AddGradeTon.ToString(), EnableDescCheck = Model.EnableDescCheck.ToString(), EnableGTCheck = Model.EnableGTCheck.ToString(), TractImageFile = Model.TractImageFile, KnownDepositsFile = Model.KnownDepositsFile, ProspectsOccurencesFile = Model.ProspectsOccurencesFile, ExplorationFile = Model.ExplorationFile, SourcesFile = Model.SourcesFile, ReferencesFile = Model.ReferencesFile, AsDate = Model.AsDate, AsDepth = Model.AsDepth, AsLeader = Model.AsLeader, AsTeamMembers = Model.AsTeamMembers, IsUndiscDepDone = Model.IsUndiscDepDone, IsRaefDone = Model.IsRaefDone, IsScreenerDone = Model.IsScreenerDone }; // User can chöose not to insert Descriptive model document into report. if (Model.AddDescriptive == false) { input.DescModelName = "-"; } // User can chöose not to insert Grade Tonnage file into report. if (Model.AddGradeTon == false) { input.GTModelName = "-"; } // 2. Execute tool ReportingResult ddResult = default(ReportingResult); Model.IsBusy = true; await Task.Run(() => { ReportingTool tool = new ReportingTool(); logger.Info("calling ReportingTool.Execute(inputParams)"); ddResult = tool.Execute(input) as ReportingResult; logger.Trace("ReportingResult:\n" + "\tOutputFile: '{0}'", ddResult.OutputDocument); }); 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("Reporting tool completed successfully.", "Success"); Model.LastRunDate = "Last Run: " + DateTime.Now.ToString("g"); 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("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"); Model.RunStatus = 0; } finally { Model.IsBusy = false; } logger.Info("<--{0} completed", this.GetType().Name); }