Skip to content

Commit

Permalink
Enabled Connection Testing for Define Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Jul 30, 2019
1 parent ab7dc3d commit 6679cc8
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions taskt/Core/Automation/Commands/DatabaseDefineConnectionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,13 @@ public DatabaseDefineConnectionCommand()

public override void RunCommand(object sender)
{
//get engine and preference
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
var connection = v_ConnectionString.ConvertToUserVariable(sender);
var instance = v_InstanceName.ConvertToUserVariable(sender);
var testPreference = v_TestConnection.ConvertToUserVariable(sender);
var connectionPass = v_ConnectionStringPassword.ConvertToUserVariable(sender);

if (connectionPass.StartsWith("!"))
{
connectionPass = connectionPass.Substring(1);
connectionPass = EncryptionServices.DecryptString(connectionPass, "taskt-database-automation");
}

connection = connection.Replace("#pwd", connectionPass);

var oleDBConnection = new OleDbConnection(connection);
//create connection
var oleDBConnection = CreateConnection(sender);

//attempt to open and close connection
if (testPreference == "Yes")
Expand All @@ -99,6 +91,21 @@ public override void RunCommand(object sender)
engine.AddAppInstance(instance, oleDBConnection);

}
private OleDbConnection CreateConnection(object sender)
{
var connection = v_ConnectionString.ConvertToUserVariable(sender);
var connectionPass = v_ConnectionStringPassword.ConvertToUserVariable(sender);

if (connectionPass.StartsWith("!"))
{
connectionPass = connectionPass.Substring(1);
connectionPass = EncryptionServices.DecryptString(connectionPass, "taskt-database-automation");
}

connection = connection.Replace("#pwd", connectionPass);

return new OleDbConnection(connection);
}
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);
Expand All @@ -119,10 +126,20 @@ public override List<Control> Render(frmCommandEditor editor)

var connectionLabel = CommandControls.CreateDefaultLabelFor("v_ConnectionString", this);
var connectionHelpers = CommandControls.CreateUIHelpersFor("v_ConnectionString", this, new[] { ConnectionString }, editor);
CommandItemControl testConnectionControl = new CommandItemControl();
testConnectionControl.Padding = new Padding(10, 0, 0, 0);
testConnectionControl.ForeColor = Color.AliceBlue;
testConnectionControl.Font = new Font("Segoe UI Semilight", 10);
testConnectionControl.Name = "connection_helper";
testConnectionControl.CommandImage = UI.Images.GetUIImage("VariableCommand");
testConnectionControl.CommandDisplay = "Test Connection";
testConnectionControl.Click += (sender, e) => TestConnection(sender, e);
RenderedControls.Add(testConnectionControl);

RenderedControls.Add(connectionLabel);
RenderedControls.Add(helperControl);
RenderedControls.AddRange(connectionHelpers);
RenderedControls.Add(testConnectionControl);
RenderedControls.Add(ConnectionString);

ConnectionStringPassword = (TextBox)CommandControls.CreateDefaultInputFor("v_ConnectionStringPassword", this);
Expand Down Expand Up @@ -155,6 +172,7 @@ public override List<Control> Render(frmCommandEditor editor)
encryptHelperControl.Click += (sender, e) => EncryptPassword(passwordHelperControl, e);
RenderedControls.Add(encryptHelperControl);


var label = new Label();
label.AutoSize = true;
label.Font = new Font("Segoe UI", 10, FontStyle.Regular);
Expand All @@ -166,11 +184,30 @@ public override List<Control> Render(frmCommandEditor editor)
RenderedControls.Add(ConnectionStringPassword);
ConnectionStringPassword.PasswordChar = '*';



RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_TestConnection", this, editor));

return RenderedControls;

}
private void TestConnection(object sender, EventArgs e)
{
try
{
var engine = new Engine.AutomationEngineInstance();
var oleDBConnection = CreateConnection(engine);
oleDBConnection.Open();
oleDBConnection.Close();
MessageBox.Show("Connection Successful", "Test Connection", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Connection Failed: {ex.ToString()}", "Test Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
}



}

private void Button_Click(object sender, EventArgs e)
Expand Down

0 comments on commit 6679cc8

Please sign in to comment.