/// <summary> /// Search for nuclides associated with a specific energy. /// </summary> /// <param name="energy"></param> private async void SearchForNucs() { if (specdata == null) { await GetSpecDataAsync("User"); } if (SelectedNuclide != null) { matches.ClearTenativeMatches((string)SelectedNuclide["NAME"]); } //string sort = Nuclides.Sort; //clear all the matches matches.ClearMatches(); try { //check the inputs if (SelectedPeak["ENERGY"] == DBNull.Value) { return; } matches.SetNuclides((double)SelectedPeak["ENERGY"], specdata.ElapsedWait, (double)SelectedPeak["FWHM"]); //Nuclides.Sort = sort; } catch (Exception ex) { DialogViewModel dialogViewModel = new DialogViewModel(ex.Message, "General Exception", true); dialogService.ShowDialog(dialogViewModel); } }
protected async Task GetLibrayDataAsync(string fileName, bool overwrite = false) { if (String.IsNullOrWhiteSpace(fileName)) { return; } try { Type libType = SpectralLibraryGenerator.GetSpectralDataType(fileName); //create an instance so we can actually use it libGen = Activator.CreateInstance(libType, new string[] { fileName }) as SpectralLibraryGenerator; //initilize the library data object if (!overwrite) { await libGen.LoadLibraryAsync(fileName); } LibraryFile = fileName; //FillWithLibrary(); //OnPropertyChanged("LibraryNuclides"); } catch (Exception ex) { DialogViewModel dialogViewModel = new DialogViewModel(ex.Message, "Exception", true); dialogService.ShowDialog(dialogViewModel); } }
/// <summary> /// Write the Lines to Library /// </summary> /// <param name="type">Write Type</param> protected virtual void WriteLines(WriteType type) { ////check if a nuclide is selected //if (matchedNuclidesGrid.SelectedRows.Count <= 0) // return; try { //get the nuclides to write to the library DataRow nuc = SelectedNuclide.Row; bool isPhotoPeak = (string)nuc["NAME"] != "S.E." && (string)nuc["NAME"] != "D.E." && !((string)nuc["NAME"]).Contains("Sum"); //check if the nuclide has a half-life that is too long if (nuc["HALF_LIFE_UNIT"].ToString().Equals("y") && (double)nuc["HALF_LIFE"] / (31557600 * 1E6) > Int32.MaxValue) { throw new ArgumentException($"The Half-life for " + (string)nuc["NAME"] + " is too large to be supported. It will not be added to the library"); } //get the lines to write to the library if (isPhotoPeak) { DataTable writeLines; switch (type) { case WriteType.All: writeLines = Lines.ToTable(); break; case WriteType.Matched: writeLines = Lines.ToTable().Select("MATCHED = True").CopyToDataTable(); break; case WriteType.Selected: writeLines = matches.Lines.Clone(); foreach (DataRowView line in SelectedLines) { writeLines.ImportRow(line.Row); } break; default: writeLines = matches.Lines.Select().CopyToDataTable(); break; } //write the nuclides to the library libGen.WriteNuclide(nuc, writeLines, CombineLinesCallback); } //set the persistent matches matches.SetPersistentMatches(); } catch (Exception ex) { DialogViewModel dialogViewModel = new DialogViewModel($"There was an exeption while writing to the library:\n {ex.Message}", "Library Exception", true); dialogService.ShowDialog(dialogViewModel); } }
private void SaveLibrary() { try { libGen.SaveFile(); this.LibraryFile = libGen.FileName; } catch (Exception ex) { DialogViewModel dialogViewModel = new DialogViewModel($"There was an exeption while writing to the library:\n{ex.Message}", "Library Exception", true); dialogService.ShowDialog(dialogViewModel); } }
/// <summary> /// Get a list of pasted nuclides and put them in the nuclides grid /// </summary> /// <param name="text"></param> private async void ImportPastedTextAsync(string text) { //try to split the string[] delims = { Environment.NewLine, ",", "|", " ", "\t", ";" }; string[] splitText = { "" }; foreach (string delim in delims) { splitText = text.Split(delim.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (splitText.Length > 1) { break; } } //check if we can use this array if (splitText.Length <= 1) { DialogViewModel dialogViewModel = new DialogViewModel($"The pasted values are not in a recongized format", "Could not read pasted values", true); dialogService.ShowDialog(dialogViewModel); return; } //apply the clean array if (specdata == null) { await GetSpecDataAsync("User"); } //loop through the pasted array and add them to the matchedNuclides Grid for (int i = 0; i < splitText.Length; i++) { //check for empites if (string.IsNullOrEmpty(splitText[i]) || string.IsNullOrWhiteSpace(splitText[i])) { continue; } //only add doubles if (double.TryParse(splitText[i], out double energy)) { DataRow row = matches.Peaks.NewRow(); row["ENERGY"] = energy; matches.Peaks.Rows.Add(row); } else { continue; } } SetPersistentLibraryMatches(); }
/// <summary> /// Asynchroniously get the spectal data from the file /// </summary> /// <param name="file"></param> /// <returns></returns> public async Task GetSpecDataAsync(string file) { //check the input if (String.IsNullOrWhiteSpace(file)) { return; } try { //get the type of spectral data Type specType = SpectralData.GetSpectralDataType(file); //create an instance so we can actually use it specdata = Activator.CreateInstance(specType, new string[] { file }) as SpectralData; //initilize the spectral data object await specdata.LoadDataAsync(matches.Peaks); SetPersistentLibraryMatches(); //apply the peaks to the lines matches.SpecData = specdata; OnPropertyChanged("InputFile"); } catch (System.Runtime.InteropServices.COMException) { DialogViewModel dialogViewModel = new DialogViewModel("Could not open: " + file, "Exeption: Bad File", true, false); dialogService.ShowDialog(dialogViewModel); } catch (IndexOutOfRangeException) { DialogViewModel dialogViewModel = new DialogViewModel("File: " + file + " did not contain any peak inforamtion", "Exeption: Bad File", true, false); dialogService.ShowDialog(dialogViewModel); } catch (System.IO.IOException) { DialogViewModel dialogViewModel = new DialogViewModel("File: " + file + " is in use by another program", "Exeption: File in Use", true, false); dialogService.ShowDialog(dialogViewModel); } catch (System.IO.FileFormatException ex) { DialogViewModel dialogViewModel = new DialogViewModel($"File: {file} \n\n{ex.Message}", "Exeption: File Format", true, false); dialogService.ShowDialog(dialogViewModel); } catch (Exception ex) { DialogViewModel dialogViewModel = new DialogViewModel(ex.Message + ":\n" + ex.StackTrace, "General Exception", true, false); dialogService.ShowDialog(dialogViewModel); } }
private async void UserInputCommand_Executed(object context) { if (InputFile != null || specdata != null) { DialogViewModel dialogView = new DialogViewModel($"Do you wish to close the current input and switch to a user input", "Close Input", false); if (dialogService.ShowDialog(dialogView) != true) { return; } } OnPropertyChanged("InputFile"); IsInputUser = false; await GetSpecDataAsync("User"); }
private void ExitCommand_Executed(object context) { if (libGen != null) { DialogViewModel dialogViewModel = new DialogViewModel($"Do you wisth to save {libGen.FileName} before exiting?", "Exit", false, true); bool? dialogResult = dialogService.ShowDialog(dialogViewModel); if (dialogResult == true) { libGen.SaveFile(); } else if (dialogResult == false) { return; } } Window win = context as Window; win.Close(); }
private async void OtherMenuCommand_Executed(object context) { string menuName = context.ToString().ToLowerInvariant(); if (menuName.Contains("rebuild")) { DialogViewModel dialogViewModel = new DialogViewModel("Are you sure you want to rebuild the library database? This operation may take several hours", "Confirmation", false, false); if (dialogService.ShowDialog(dialogViewModel) == true) { await library.InitializeAsync(); library.WriteToDatabase(); } } else if (menuName.Contains("about")) { StringBuilder message = new StringBuilder(); var assembly = System.Reflection.Assembly.GetExecutingAssembly(); object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false); foreach (AssemblyProductAttribute attrbute in attributes) { message.AppendLine(attrbute.Product); message.AppendLine(); } object[] version = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); foreach (AssemblyFileVersionAttribute attrbute in version) { message.AppendLine("Version: " + attrbute.Version); message.AppendLine(); } object[] copyright = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); foreach (AssemblyCopyrightAttribute attrbute in copyright) { message.AppendLine(attrbute.Copyright); message.AppendLine(); } object[] company = assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); foreach (AssemblyCompanyAttribute attrbute in company) { message.AppendLine(attrbute.Company); message.AppendLine(); } object[] description = assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); foreach (AssemblyDescriptionAttribute attrbute in description) { int chunkSize = 60; IEnumerable chunkString = Enumerable.Range(0, attrbute.Description.Length / chunkSize) .Select(i => attrbute.Description.Substring(i * chunkSize, chunkSize)); foreach (string chunk in chunkString) { message.AppendLine(chunk); } } DialogViewModel dialogViewModel = new DialogViewModel(message.ToString(), "About", false); dialogService.ShowDialog(dialogViewModel); } }
private bool?CombineLinesCallback(string energies) { DialogViewModel dialogViewModel = new DialogViewModel($"Lines of energies: { energies } keV are possibly unresovable, do you wish to combine them?", "Possible Unresolvable Lines", false, true); return(dialogService.ShowDialog(dialogViewModel)); }