/// <summary> /// Routine to open a file /// </summary> /// <param name="entry"></param> /// <param name="filename"></param> /// <returns></returns> private bool OpenFile(IBioDataProvider entry, string filename) { IBioDataLoader dataLoader = entry.Create(filename); if (dataLoader != null) { var dvm = new OpenBioDataViewModel(filename, entry.SupportedTypes, dataLoader, entry); dvm.Load(); dvm.CloseRequest += OnDataSourceClosing; OpenDataSources.Add(dvm); return(true); } return(false); }
/// <summary> /// This method creates a new workspace /// </summary> private void OnCreateNewWorkspace() { SaveFileDialog sfd = new SaveFileDialog { CheckPathExists = true, AddExtension = true, Filter = "Bio Workspaces|*" + Workspace.WS_EXTENSION, RestoreDirectory = true, DefaultExt = Workspace.WS_EXTENSION, OverwritePrompt = true, Title = "Select the name and location of the new Workspace to create." }; bool?result = sfd.ShowDialog(); if (result.Value) { var ws = new Workspace { Filename = sfd.FileName, Name = Path.GetFileNameWithoutExtension(sfd.FileName) }; OpenDataSources.Add(new WorkspaceViewModel(ws)); ws.Save(); } }
/// <summary> /// This is called to prompt the user for a file data source. /// </summary> private void OpenFileDataSource() { // Get a list of all the file types we can load. var loaders = Extensions.Current.DataProviders.Where(ldr => !string.IsNullOrEmpty(ldr.FileFilter)); StringBuilder sb = new StringBuilder(); foreach (var extension in loaders.Select(ldr => ldr.FileFilter.Split('|'))) { for (int i = 1; i < extension.Count(); i += 2) { sb.Append(extension[i]); } sb.Append(";"); } string allExtensions = sb + "*" + Workspace.WS_EXTENSION; sb.Clear(); sb.Append("All Supported Formats|" + allExtensions); sb.Append("|Bio Workspaces|*" + Workspace.WS_EXTENSION); foreach (var ldr in loaders.Where(ldr => !string.IsNullOrEmpty(ldr.FileFilter))) { sb.Append("|" + ldr.FileFilter); } OpenFileDialog ofd = new OpenFileDialog { Filter = sb.ToString() }; if (ofd.ShowDialog().Value) { bool rc = false; var filename = ofd.FileName; var formatLoader = GetProviderForFile(filename); if (formatLoader == null) { var ws = Workspace.Load(filename); if (ws != null) { OpenDataSources.Add(new WorkspaceViewModel(ws)); rc = true; } } else { rc = OpenFile(formatLoader, filename); } if (!rc) { var errorVisualizer = ServiceProvider.Resolve <IErrorVisualizer>(); if (errorVisualizer != null) { errorVisualizer.Show("Failed to open file", "Could not open " + filename + ".\r\nThe provider could not be found or the file is not in the correct format."); } } } }