@ -17,226 +17,234 @@ using System.Windows.Threading;
@@ -17,226 +17,234 @@ using System.Windows.Threading;
namespace ICSharpCode.Data.Core.UI.Windows
{
/// <summary>
/// Interaction logic for ConnectionWizardWindow.xaml
/// </summary>
public partial class ConnectionWizardWindow : Window , INotifyPropertyChanged
{
#region Fields
private Action _ addAction = null ;
private IDatabaseDriver _ selectedDatabaseDriver = null ;
private IDatasource _ selectedDatasource = null ;
private IDatabase _ selectedDatabase = null ;
private bool _ isLoading = false ;
private Exception _d atasourceException = null ;
#endregion
#region Properties
public Action AddAction
{
get { return _ addAction ; }
set { _ addAction = value ; }
}
public IDatabaseDriver SelectedDatabaseDriver
{
get { return _ selectedDatabaseDriver ; }
set
{
_ selectedDatabaseDriver = value ;
OnPropertyChanged ( "SelectedDatabaseDriver" ) ;
}
}
public IDatasource SelectedDatasource
{
get { return _ selectedDatasource ; }
set
{
if ( value ! = null )
btnConnect . IsEnabled = true ;
else
btnConnect . IsEnabled = false ;
_ selectedDatasource = value ;
OnPropertyChanged ( "SelectedDatasource" ) ;
}
}
public IDatabase SelectedDatabase
{
get { return _ selectedDatabase ; }
set
{
_ selectedDatabase = value ;
OnPropertyChanged ( "SelectedDatabase" ) ;
}
}
public bool IsLoading
{
get { return _ isLoading ; }
set
{
_ isLoading = value ;
OnPropertyChanged ( "IsLoading" ) ;
}
}
public Exception DatasourceException
{
get { return _d atasourceException ; }
set
{
_d atasourceException = value ;
OnPropertyChanged ( "DatasourceException" ) ;
}
}
#endregion
#region Constructor
public ConnectionWizardWindow ( )
{
InitializeComponent ( ) ;
}
#endregion
#region Private methods
private void SetIsLoading ( bool value )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = > { IsLoading = value ; } ) ) ;
}
private void SetException ( Exception exception )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = > { DatasourceException = exception ; } ) ) ;
}
private void SetSelectedDatasource ( IDatasource datasource )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = > { SelectedDatasource = datasource ; } ) ) ;
}
private void PopulateDatasources ( )
{
Thread thread = new Thread ( new ThreadStart ( delegate ( )
{
if ( SelectedDatabaseDriver ! = null )
{
SetIsLoading ( true ) ;
SelectedDatabaseDriver . PopulateDatasources ( ) ;
SetIsLoading ( false ) ;
}
}
) ) ;
thread . SetApartmentState ( ApartmentState . STA ) ;
thread . IsBackground = true ;
thread . Start ( ) ;
}
private void PopulateDatabases ( )
{
SetException ( null ) ;
Thread thread = new Thread ( new ThreadStart ( delegate ( )
{
if ( SelectedDatabaseDriver ! = null )
{
SetIsLoading ( true ) ;
try
{
SelectedDatabaseDriver . PopulateDatabases ( ) ;
}
catch ( Exception ex )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = >
{
MessageBox . Show ( this , ex . Message , this . Title , MessageBoxButton . OK , MessageBoxImage . Error ) ;
} ) ) ;
}
SetIsLoading ( false ) ;
}
} ) ) ;
thread . SetApartmentState ( ApartmentState . STA ) ;
thread . IsBackground = true ;
thread . Start ( ) ;
}
#endregion
#region Event handlers
private void btnAutoDiscover_Click ( object sender , RoutedEventArgs e )
{
PopulateDatasources ( ) ;
}
private void btnConnect_Click ( object sender , RoutedEventArgs e )
{
PopulateDatabases ( ) ;
}
private void cboDatasources_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . Key = = Key . Enter )
{
if ( SelectedDatabaseDriver ! = null )
{
SelectedDatasource = SelectedDatabaseDriver . AddNewDatasource ( cboDatasources . Text ) ;
}
}
}
private void cboDatabases_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
btnAdd . IsEnabled = true ;
}
private void btnAdd_Click ( object sender , RoutedEventArgs e )
{
if ( _ addAction = = null )
{
DialogResult = true ;
Close ( ) ;
}
else
{
_ addAction . Invoke ( ) ;
}
}
private void btnCancel_Click ( object sender , RoutedEventArgs e )
{
DialogResult = false ;
Close ( ) ;
}
#endregion
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged ;
protected void OnPropertyChanged ( string property )
{
if ( PropertyChanged ! = null )
{
PropertyChanged ( this , new PropertyChangedEventArgs ( property ) ) ;
}
}
#endregion
}
/// <summary>
/// Interaction logic for ConnectionWizardWindow.xaml
/// </summary>
public partial class ConnectionWizardWindow : Window , INotifyPropertyChanged
{
#region Fields
private Action _ addAction = null ;
private IDatabaseDriver _ selectedDatabaseDriver = null ;
private IDatasource _ selectedDatasource = null ;
private IDatabase _ selectedDatabase = null ;
private bool _ isLoading = false ;
private Exception _d atasourceException = null ;
#endregion
#region Properties
public Action AddAction
{
get { return _ addAction ; }
set { _ addAction = value ; }
}
public IDatabaseDriver SelectedDatabaseDriver
{
get { return _ selectedDatabaseDriver ; }
set
{
_ selectedDatabaseDriver = value ;
OnPropertyChanged ( "SelectedDatabaseDriver" ) ;
}
}
public IDatasource SelectedDatasource
{
get { return _ selectedDatasource ; }
set
{
if ( value ! = null )
btnConnect . IsEnabled = true ;
else
btnConnect . IsEnabled = false ;
_ selectedDatasource = value ;
OnPropertyChanged ( "SelectedDatasource" ) ;
}
}
public IDatabase SelectedDatabase
{
get { return _ selectedDatabase ; }
set
{
_ selectedDatabase = value ;
OnPropertyChanged ( "SelectedDatabase" ) ;
}
}
public bool IsLoading
{
get { return _ isLoading ; }
set
{
_ isLoading = value ;
OnPropertyChanged ( "IsLoading" ) ;
}
}
public Exception DatasourceException
{
get { return _d atasourceException ; }
set
{
_d atasourceException = value ;
OnPropertyChanged ( "DatasourceException" ) ;
}
}
#endregion
#region Constructor
public ConnectionWizardWindow ( )
{
InitializeComponent ( ) ;
}
#endregion
#region Private methods
private void SetIsLoading ( bool value )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = > { IsLoading = value ; } ) ) ;
}
private void SetException ( Exception exception )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = > { DatasourceException = exception ; } ) ) ;
}
private void SetSelectedDatasource ( IDatasource datasource )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = > { SelectedDatasource = datasource ; } ) ) ;
}
private void PopulateDatasources ( )
{
SetException ( null ) ;
Thread thread = new Thread (
new ThreadStart (
delegate ( ) {
try {
if ( SelectedDatabaseDriver ! = null ) {
SetIsLoading ( true ) ;
SelectedDatabaseDriver . PopulateDatasources ( ) ;
}
} catch ( Exception ex ) {
SetException ( ex ) ;
} finally {
SetIsLoading ( false ) ;
}
}
)
) ;
thread . SetApartmentState ( ApartmentState . STA ) ;
thread . IsBackground = true ;
thread . Start ( ) ;
}
private void PopulateDatabases ( )
{
SetException ( null ) ;
Thread thread = new Thread ( new ThreadStart ( delegate ( )
{
if ( SelectedDatabaseDriver ! = null )
{
SetIsLoading ( true ) ;
try
{
SelectedDatabaseDriver . PopulateDatabases ( ) ;
}
catch ( Exception ex )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) = >
{
MessageBox . Show ( this , ex . Message , this . Title , MessageBoxButton . OK , MessageBoxImage . Error ) ;
} ) ) ;
}
SetIsLoading ( false ) ;
}
} ) ) ;
thread . SetApartmentState ( ApartmentState . STA ) ;
thread . IsBackground = true ;
thread . Start ( ) ;
}
#endregion
#region Event handlers
private void btnAutoDiscover_Click ( object sender , RoutedEventArgs e )
{
PopulateDatasources ( ) ;
}
private void btnConnect_Click ( object sender , RoutedEventArgs e )
{
PopulateDatabases ( ) ;
}
private void cboDatasources_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . Key = = Key . Enter )
{
if ( SelectedDatabaseDriver ! = null )
{
SelectedDatasource = SelectedDatabaseDriver . AddNewDatasource ( cboDatasources . Text ) ;
}
}
}
private void cboDatabases_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
btnAdd . IsEnabled = true ;
}
private void btnAdd_Click ( object sender , RoutedEventArgs e )
{
if ( _ addAction = = null )
{
DialogResult = true ;
Close ( ) ;
}
else
{
_ addAction . Invoke ( ) ;
}
}
private void btnCancel_Click ( object sender , RoutedEventArgs e )
{
DialogResult = false ;
Close ( ) ;
}
#endregion
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged ;
protected void OnPropertyChanged ( string property )
{
if ( PropertyChanged ! = null )
{
PropertyChanged ( this , new PropertyChangedEventArgs ( property ) ) ;
}
}
#endregion
}
}