/// <summary> /// Loads a saved connection, the name of the connection will be the name of the /// file (without the file extension) /// </summary> /// <param name="path"></param> public static void LoadConnection(string path) { FdoConnection conn = FdoConnection.LoadFromFile(path); string name = Path.GetFileNameWithoutExtension(path); ConnectionManager.AddConnection(name, conn); }
public override void Run() { string path = FileService.OpenFile(Res.GetString("TITLE_LOAD_CONNECTION"), Res.GetString("FILTER_CONNECTION_FILE")); if (FileService.FileExists(path)) { FdoConnection conn = FdoConnection.LoadFromFile(path); FdoConnectionManager mgr = ServiceManager.Instance.GetService <FdoConnectionManager>(); string name = string.Empty; name = Msg.ShowInputBox(Res.GetString("TITLE_NEW_CONNECTION"), Res.GetString("PROMPT_ENTER_NEW_CONNECTION_NAME"), name); if (name == null) { return; } while (name == string.Empty || mgr.NameExists(name)) { name = Msg.ShowInputBox(Res.GetString("TITLE_NEW_CONNECTION"), Res.GetString("PROMPT_ENTER_NEW_CONNECTION_NAME"), name); if (name == null) { return; } } using (TempCursor cur = new TempCursor(Cursors.WaitCursor)) { mgr.AddConnection(name, conn); } } }
/// <summary> /// Handles the file drop /// </summary> /// <param name="file">The file being dropped</param> public void HandleDrop(string file) { IFdoConnectionManager connMgr = ServiceManager.Instance.GetService <IFdoConnectionManager>(); NamingService namer = ServiceManager.Instance.GetService <NamingService>(); FdoConnection conn = null; try { conn = FdoConnection.LoadFromFile(file, true); } catch (Exception ex) { LoggingService.Error("Failed to load connection", ex); return; } string name = namer.GetDefaultConnectionName(conn.Provider); connMgr.AddConnection(name, conn); }
/// <summary> /// Load all persisted connections from the session directory /// </summary> public void Load() { string path = Preferences.SessionDirectory; if (System.IO.Directory.Exists(path)) { try { string[] files = System.IO.Directory.GetFiles(path, "*.conn", System.IO.SearchOption.AllDirectories); SortedDictionary <string, FdoConnection> connections = new SortedDictionary <string, FdoConnection>(); foreach (string f in files) { try { string dir = System.IO.Path.GetDirectoryName(f); string name = string.Empty; if (dir != path) { System.Diagnostics.Debug.Assert(dir.Length > path.Length && dir.Contains(path)); //Directory is child of session dir string relDir = dir.Substring(path.Length + 1); //To remove the trailing slash if (!relDir.EndsWith("\\")) { relDir += "\\"; } name = relDir + System.IO.Path.GetFileNameWithoutExtension(f); } else { name = System.IO.Path.GetFileNameWithoutExtension(f); } FdoConnection conn = FdoConnection.LoadFromFile(f, true); connections.Add(name, conn); } catch (Exception ex) { LoggingService.Warn("Could not create connection from " + f + ": " + ex.Message); } } foreach (string name in connections.Keys) { try { this.AddConnection(name, connections[name]); } catch (Exception ex) { LoggingService.Warn("Could not load connection " + name + ": " + ex.Message); } } } finally { //After loading all connections, remove any directories in the session directory string[] directories = System.IO.Directory.GetDirectories(path); foreach (string dir in directories) { System.IO.Directory.Delete(dir, true); } } } }