private async void TestConnectivityAsync(IConnection connection) { bool completedSuccessfully = false; try { ValidationResult validationResult = connection.Validate(); if (validationResult.IsValid) { CancellationTokenSource cancel = new CancellationTokenSource(); Progress <ExecutionProgress> progress = new Progress <ExecutionProgress>(); ApplicationState.Default.NotifyAsyncProcessStarted(cancel, progress, 1); ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Information, string.Format(Properties.Resources.DataSourceFormConnectionTest, connection.Name))); ConnectivityResult result = await Task.Run(() => ((IAvailableProvider)connection).IsAvailable(cancel.Token, progress)); if (cancel.IsCancellationRequested) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Warning, string.Format(Properties.Resources.DataSourceFormConnectionTestStopped, connection.Name))); } else if (result.IsAvailable) { completedSuccessfully = true; ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Information, string.Format(Properties.Resources.DataSourceFormConnectionTestAvailable, connection.Name))); } else { completedSuccessfully = true; ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, string.Format(Properties.Resources.DataSourceFormConnectionTestNotAvailable, connection.Name, result.ErrorMessage))); } } else { validationResult.Errors.ForEach(error => ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, error.Message))); } } catch (OperationCanceledException) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Warning, string.Format(Properties.Resources.DataSourceFormConnectionTestStopped, connection.Name))); } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, string.Format(Properties.Resources.DataSourceFormConnectionTestNotAvailable, connection.Name, ex.Message), ex)); } finally { ApplicationState.Default.NotifyAsyncProgressStopped(completedSuccessfully); } }
public override ConnectivityResult IsAvailable(CancellationToken cancel, IProgress <ExecutionProgress> progress) { ConnectivityResult result = new ConnectivityResult(false); try { using (SftpClient client = new SftpClient(hostName, port, userName, new AESEncrypter().Decrypt(password))) { client.Connect(); } result.IsAvailable = true; } catch (Exception ex) { result.ErrorMessage = ex.Message; } return(result); }
/// <summary> /// Checks whether SQL Server is available. /// </summary> /// <param name="cancel">The cancellation token.</param> /// <param name="progress">The progress.</param> /// <returns>The connectivity result.</returns> public ConnectivityResult IsAvailable(CancellationToken cancel, IProgress <ExecutionProgress> progress) { ConnectivityResult result = new ConnectivityResult(false); try { using (SqlConnection connection = new SqlConnection(new AESEncrypter().Decrypt(ConnectionString))) { connection.Open(); } result.IsAvailable = true; } catch (Exception ex) { result.ErrorMessage = ex.Message; } return(result); }
/// <summary> /// Checks if the connection is available. /// </summary> /// <param name="cancel">The cancellation token.</param> /// <param name="progress">The connectivity progress.</param> /// <returns>True if the connection is available, false otherwise.</returns> public ConnectivityResult IsAvailable(CancellationToken cancel, IProgress <ExecutionProgress> progress) { ConnectivityResult result = new ConnectivityResult(false); try { CrmServiceClient serviceClient = new CrmServiceClient(GetConnectionString()); if (serviceClient.IsReady) { result.IsAvailable = true; } else { result.ErrorMessage = serviceClient.LastCrmError; } } catch (Exception ex) { result.ErrorMessage = ex.Message; } return(result); }