/// <summary> /// Get TractIDs. /// </summary> public void FindTractIDs() { var tractIDCollection = Model.TractIDCollection; var tractIDNames = Model.TractIDNames; Model.TractIDCollection = new ObservableCollection <ReportingAssesmentModel>(); Model.TractIDCollection.Clear(); Model.TractIDNames = new ObservableCollection <string>(); Model.TractIDNames.Clear(); string tractRootPath = Path.Combine(settingsService.RootPath, "TractDelineation", "Tracts"); if (Directory.Exists(tractRootPath)) { DirectoryInfo di = new DirectoryInfo(tractRootPath); foreach (DirectoryInfo dir in di.GetDirectories()) { string tractReport = Path.Combine(settingsService.RootPath, "Reporting", dir.Name, "TractReport" + dir.Name + ".docx"); if (!dir.Name.StartsWith("AGG") && File.Exists(tractReport)) { ReportingAssesmentModel item = new ReportingAssesmentModel { TractName = dir.Name, IsTractChosen = false }; Model.TractIDCollection.Add(item); // Get TractID by getting the name of the directory. Model.TractIDNames.Add(dir.Name); } } } if (Model.TractIDNames.SequenceEqual(tractIDNames)) { Model.TractIDCollection = tractIDCollection; Model.TractIDNames = tractIDNames; } else { Directory.CreateDirectory(Path.Combine(settingsService.RootPath, "TractDelineation", "Tracts")); } }
/// <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(); } }