/// <summary> /// Initialize new instance of DepositDensityViewModel class. /// </summary> /// <param name="logger">Logging for the MapWizard.</param> /// <param name="dialogService">Service for using dialogs and notifications.</param> /// <param name="settingsService">Service for using and editing settings.</param> public DepositDensityViewModel(ILogger logger, IDialogService dialogService, ISettingsService settingsService) { this.logger = logger; this.dialogService = dialogService; this.settingsService = settingsService; result = new DepositDensityResultModel(); viewModelLocator = new ViewModelLocator(); RunToolCommand = new RelayCommand(RunTool, CanRunTool); OpenDepositDenPlotCommand = new RelayCommand(OpenDepositDenPlotFile, CanRunTool); TractChangedDeposit = new RelayCommand(TractChanged, CanRunTool); DepositDensityInputParams inputParams = new DepositDensityInputParams(); string outputFolder = Path.Combine(settingsService.RootPath, "UndiscDep"); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } string param_json = Path.Combine(outputFolder, "deposit_density_input_params.json"); if (File.Exists(param_json)) { try { inputParams.Load(param_json); Model = new DepositDensityModel { N10 = inputParams.N10, N50 = inputParams.N50, N90 = inputParams.N90, Note = inputParams.Note, CSVPath = inputParams.CSVPath, MedianTonnage = Convert.ToDouble(inputParams.MedianTonnage), AreaOfPermissiveTract = Convert.ToDouble(inputParams.AreaOfTrack), NumbOfKnownDeposits = Convert.ToInt32(inputParams.NumbOfKnownDeposits), ExistingDepositDensityModelID = inputParams.ExistingDepositDensityModelID, SelectedTract = inputParams.TractId }; FindTractIDs(); if (Directory.GetFiles(outputFolder).Length != 0) { LoadResults(); } } catch (Exception ex) { Model = new DepositDensityModel(); logger.Error(ex, "Failed to read json file"); dialogService.ShowNotification("Couldn't load Deposit Density tool's inputs correctly. Inputs were initialized to default values.", "Error"); viewModelLocator.SettingsViewModel.WriteLogText("Couldn't load Deposit Density tool's inputs correctly. Inputs were initialized to default values.", "Error"); } } else { Model = new DepositDensityModel(); FindTractIDs(); } }
public void PorCuCalculation() { DepositDensityInputParams input = new DepositDensityInputParams { DepositTypeId = "xxx", MedianTonnage = "0.5", AreaOfTrack = "10000", NumbOfKnownDeposits = "0", ExistingDepositDensityModelID = "PorCu", CSVPath = "c:\\temp\\mapWizard\\PorCuCSV_wHeaders.csv" }; DepositDensityTool DepositDensityTool = new DepositDensityTool(); var result = DepositDensityTool.Execute(input); Assert.IsNotNull(result); }
public void ExecuteTest02() { DepositDensityInputParams input = new DepositDensityInputParams { DepositTypeId = "xxx", MedianTonnage = "0.5", AreaOfTrack = "3228", NumbOfKnownDeposits = "2", ExistingDepositDensityModelID = "General", CSVPath = "c:\\temp\\mapWizard\\generalCSV_wHeaders.csv" }; DepositDensityTool DepositDensityTool = new DepositDensityTool(); var result = DepositDensityTool.Execute(input); Assert.IsNotNull(result); }
/// <summary> /// Run tool with user input. /// </summary> private async void RunTool() { logger.Info("-->{0}", this.GetType().Name); // 1. Collect input parameters. DepositDensityInputParams input = new DepositDensityInputParams { DepositTypeId = "xxx", MedianTonnage = Model.MedianTonnage.ToString(), AreaOfTrack = Model.AreaOfPermissiveTract.ToString(), NumbOfKnownDeposits = Model.NumbOfKnownDeposits.ToString(), ExistingDepositDensityModelID = Model.ExistingDepositDensityModelID, CSVPath = Model.CSVPath, TractId = Model.SelectedTract }; // 2. Execute tool. DepositDensityResult ddResult = default(DepositDensityResult); Model.IsBusy = true; try { await Task.Run(() => { DepositDensityTool tool = new DepositDensityTool(); ddResult = tool.Execute(input) as DepositDensityResult; Result.N10 = ddResult.N10; Result.N50 = ddResult.N50; Result.N90 = ddResult.N90; Result.PlotImagePath = ddResult.PlotImagePath; Result.PlotImageBitMap = BitmapFromUri(ddResult.PlotImagePath); Result.Model = Model.ExistingDepositDensityModelID; if (Model.ExistingDepositDensityModelID == "General") { Result.MTonnage = Model.MedianTonnage.ToString(); } else { Result.MTonnage = "-"; } Result.TArea = Model.AreaOfPermissiveTract.ToString(); Result.NKnown = Model.NumbOfKnownDeposits.ToString(); Result.Note = ddResult.Note; }); input.N10 = Result.N10; input.N50 = Result.N50; input.N90 = Result.N90; input.Note = Result.Note; string outputFolder = Path.Combine(settingsService.RootPath, "UndiscDep"); input.Save(Path.Combine(outputFolder, "deposit_density_input_params.json")); dialogService.ShowNotification("DepositDensityTool completed successfully.", "Success"); viewModelLocator.SettingsViewModel.WriteLogText("DepositDensityTool completed successfully.", "Success"); Model.LastRunDate = "Last Run: " + DateTime.Now.ToString("g"); Model.RunStatus = 1; } catch (Exception ex) { logger.Error(ex, "Failed to execute REngine() script"); 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("Run failed in Deposit Density Tool. 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); }