private void AddAFile(string draggedFilePath) { // this line is NOT used because .xml.gz (extensions with two dots) mess up with Path.GetExtension //var theExtension = Path.GetExtension(draggedFilePath).ToLowerInvariant(); // we need to get the filename before parsing out the extension because if we assume that everything after the dot // is the extension and there are dots in the file path (i.e. in a folder name), this will mess up var filename = System.IO.Path.GetFileName(draggedFilePath); var theExtension = System.IO.Path.GetExtension(filename).ToLowerInvariant(); bool compressed = theExtension.EndsWith("gz"); // allows for .bgz and .tgz, too which are used on occasion theExtension = compressed ? System.IO.Path.GetExtension(System.IO.Path.GetFileNameWithoutExtension(filename)).ToLowerInvariant() : theExtension; switch (theExtension) { case ".xml": case ".fasta": case ".fa": ProteinDbForDataGrid uu = new ProteinDbForDataGrid(draggedFilePath); if (!DatabaseExists(ProteinDbObservableCollection, uu)) { ProteinDbObservableCollection.Add(uu); if (theExtension.Equals(".xml")) { try { GlobalVariables.AddMods(UsefulProteomicsDatabases.ProteinDbLoader.GetPtmListFromProteinXml(draggedFilePath).OfType <Modification>(), true); PrintErrorsReadingMods(); } catch (Exception ee) { MessageBox.Show(ee.ToString()); GuiWarnHandler(null, new StringEventArgs("Cannot parse modification info from: " + draggedFilePath, null)); ProteinDbObservableCollection.Remove(uu); } } } break; default: GuiWarnHandler(null, new StringEventArgs("Unrecognized file type: " + theExtension, null)); break; } }
private bool DatabaseExists(ObservableCollection <ProteinDbForDataGrid> pDOC, ProteinDbForDataGrid uuu) { foreach (ProteinDbForDataGrid pdoc in pDOC) { if (pdoc.FilePath == uuu.FilePath) { return(true); } } return(false); }