Task.Factory.StartNew((args) =>
{
string serverName = (string)((object[])args)[0];
string userName = (string)((object[])args)[1];
string pwd = (string)((object[])args)[2];
string dbName = (string)((object[])args)[3];
Exception exc;
bool rc = SQLServerDbConnectionInfo.CheckConnection(serverName, userName, pwd, dbName, out exc);
return new object[] { rc, exc?.Message, dbName, serverName, userName };
}, new object[] { this.ServerName, this.UserName, this.Password, this.DatabaseName }).ContinueWith((t) =>
{
this.IsBusy = false;
if (!t.IsCompleted || t.IsFaulted || !(bool)t.Result[0])
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat((string)WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("myAssembly:Properties.Resources:DBConnectionFailedExtendedMessage", null, WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.Culture), (string)t.Result[2], (string)t.Result[3], (string)t.Result[4]);
if (!String.IsNullOrEmpty((string)t.Result[1]))
{
sb.Append(System.Environment.NewLine);
sb.AppendLine((string)t.Result[1]);
}
var parentWindow = Window.GetWindow(this);
if (parentWindow == null)
{
parentWindow = Application.Current?.MainWindow;
}
MessageBox.Show(parentWindow, sb.ToString(), (string)WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("myAssembly:Properties.Resources:ConnectionFailed", null, WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.Culture));
if (onCompletedAction != null)
{
onCompletedAction(false);
}
}
else
{
if (showSuccessMsgBox)
{
var parentWindow = Window.GetWindow(this);
if (parentWindow == null)
{
parentWindow = Application.Current?.MainWindow;
}
MessageBox.Show(parentWindow, (string)WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("myAssembly:Properties.Resources:ConnectionTestSucceeded", null, WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.Culture), null);
}
if (onCompletedAction != null)
{
onCompletedAction(true);
}
}
}, TaskScheduler.FromCurrentSynchronizationContext());
|