//TODO: show errors public static void EnsureConnection(DatabaseConnectionContext context, DatabaseConnectionContextCallback callback, object state) { if (context == null) { throw new ArgumentNullException("context"); } if (callback == null) { throw new ArgumentNullException("callback"); } IConnectionPool pool = context.ConnectionPool; if (pool.IsInitialized) { callback(context, true, state); return; } IDbFactory fac = DbFactoryService.GetDbFactory(context.ConnectionSettings); //FIXME: connection settings dialog //bool requiresPassword = fac.GetCapabilities ("ConnectionSettings", SchemaActions.Schema) == (int)ConnectionSettingsCapabilities.Password; bool requiresPassword = true; if (!context.ConnectionSettings.SavePassword && String.IsNullOrEmpty(context.ConnectionSettings.Password) && requiresPassword) { string password = MessageService.GetPassword( AddinCatalog.GetString("Please enter the password for connection '{0}'", context.ConnectionSettings.Name), AddinCatalog.GetString("Enter Password") ); if (password == null) { callback(context, false, state); return; } else { context.ConnectionSettings.Password = password; } } EnsureConnectionState internalState = new EnsureConnectionState(context, callback, state); ThreadPool.QueueUserWorkItem(new WaitCallback(EnsureConnectionThreaded), internalState); }
private static void EnsureConnectionThreaded(object obj) { EnsureConnectionState internalState = obj as EnsureConnectionState; IConnectionPool pool = internalState.ConnectionContext.ConnectionPool; try { bool connected = pool.Initialize(); DispatchService.GuiDispatch(delegate() { internalState.Callback(internalState.ConnectionContext, connected, internalState.State); }); } catch (Exception e) { LoggingService.LogDebug(e.ToString()); DispatchService.GuiDispatch(delegate() { internalState.Callback(internalState.ConnectionContext, false, internalState.State); }); } }
//TODO: show errors public static void EnsureConnection (DatabaseConnectionContext context, DatabaseConnectionContextCallback callback, object state) { if (context == null) throw new ArgumentNullException ("context"); if (callback == null) throw new ArgumentNullException ("callback"); IConnectionPool pool = context.ConnectionPool; if (pool.IsInitialized) { callback (context, true, state); return; } IDbFactory fac = DbFactoryService.GetDbFactory (context.ConnectionSettings); bool requiresPassword = fac.GetCapabilities ("ConnectionSettings", SchemaActions.Schema) == (int)ConnectionSettingsCapabilities.Password; if (!context.ConnectionSettings.SavePassword && String.IsNullOrEmpty (context.ConnectionSettings.Password) && requiresPassword) { string password = Services.MessageService.GetPassword ( GettextCatalog.GetString ("Please enter the password for connection '{0}'", context.ConnectionSettings.Name), GettextCatalog.GetString ("Enter Password") ); if (String.IsNullOrEmpty (password)) { callback (context, false, state); return; } else { context.ConnectionSettings.Password = password; } } EnsureConnectionState internalState = new EnsureConnectionState (context, callback, state); ThreadPool.QueueUserWorkItem (new WaitCallback (EnsureConnectionThreaded), internalState); }