Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ await HttpPostAsync<Fr8DataDTO, ActivityDTO>(
Assert.NotNull(responseActionDTO.CrateStorage);
var crateStorage = Crate.FromDto(responseActionDTO.CrateStorage);
//There will be no DesignTimeCrate only Configuration crate
Assert.AreEqual(1, crateStorage.Count);
Assert.AreEqual(2, crateStorage.Count);
Assert.AreEqual(1, crateStorage.CratesOfType<StandardConfigurationControlsCM>().Count());
var controls = crateStorage.CrateContentsOfType<StandardConfigurationControlsCM>().Single();
AssertConfigureControls(controls);
//Check that Error message is shown
var connStringTextBox = (TextBox)controls.Controls[0];
Assert.AreEqual("Incorrect Connection String", connStringTextBox.Value);
Assert.AreEqual("This is incorrect database connection string!", connStringTextBox.Value);
}

/// <summary>
Expand Down
58 changes: 41 additions & 17 deletions terminalAzure/Activities/Write_To_Sql_Server_v1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Write_To_Sql_Server_v1 : ExplicitTerminalActivity
protected override ActivityTemplateDTO MyTemplate => ActivityTemplateDTO;


public Write_To_Sql_Server_v1(ICrateManager crateManager, IDbProvider dbProvider)
public Write_To_Sql_Server_v1(ICrateManager crateManager, IDbProvider dbProvider)
: base(crateManager)
{
_dbProvider = dbProvider;
Expand All @@ -52,8 +52,6 @@ public override Task Initialize()
//if the user provides a connection string, this action attempts to connect to the sql server and get its columns and tables
public override Task FollowUp()
{
//Verify controls, make sure that TextBox with value exists
ValidateControls();
//In all followup calls, update data fields of the configuration store
try
{
Expand All @@ -71,16 +69,16 @@ public override Task FollowUp()
var textSourceControls = ConfigurationControls.Controls.OfType<TextSource>();
foreach (var control in textSourceControls.ToList())
{
RemoveControl<TextSource>(control.Name);
RemoveControl<TextSource>(control.Name);
}
var columns = GetTableColumns(dropDownControl.Value);

foreach (var column in columns)
{
if(identityColumn != column.ColumnName)
if (identityColumn != column.ColumnName)
{
var textSource = UiBuilder.CreateSpecificOrUpstreamValueChooser(column.ColumnName, column.ColumnName);

if (column.isNullable == false)
{
textSource.Required = true;
Expand All @@ -94,7 +92,7 @@ public override Task FollowUp()
//this needs to be updated to hold Crates instead of FieldDefinitionDTO
// Storage.Add("Sql Table Columns", new KeyValueListCM(contentsList.Select(col => new KeyValueDTO { Key = col, Value = col })));
}
catch(Exception e)
catch (Exception e)
{
AddErrorToControl();
}
Expand Down Expand Up @@ -224,7 +222,7 @@ private void ListTableColumns(string connectionString, string tableName, Action<
//public List<string> GetFieldMappings()
//{
// var connStringField = ConfigurationControls.Controls.First();

// return (List<string>)_dbProvider.ConnectToSql(connStringField.Value, (command) =>
// {
// command.CommandText = FieldMappingQuery;
Expand All @@ -246,24 +244,50 @@ private void ListTableColumns(string connectionString, string tableName, Action<
// });
//}

private void ValidateControls()
protected override Task Validate()
{
if (Storage.Count == 0)

var connStringField = ConfigurationControls.Controls.FirstOrDefault();
if(connStringField != null)
{
throw new TerminalCodedException(TerminalErrorCode.SQL_SERVER_CONNECTION_STRING_MISSING);
if (string.IsNullOrEmpty(connStringField.Value))
{
ValidationManager.SetError("Connection string can't be empty", connStringField);
}
else
{
try
{
var columns = GetTables();
}
catch (Exception e)
{
ValidationManager.SetError(e.Message, connStringField);
}
}
}


if (ConfigurationControls == null)
var dropDownControl = ConfigurationControls.Controls.OfType<DropDownList>().FirstOrDefault();
if(dropDownControl != null)
{
throw new TerminalCodedException(TerminalErrorCode.SQL_SERVER_CONNECTION_STRING_MISSING);
if (string.IsNullOrEmpty(dropDownControl?.Value) && dropDownControl.ListItems.Count > 0)
{
ValidationManager.SetError("Table must be selected", dropDownControl);
}
}

var connStringField = ConfigurationControls.Controls.First();
if (string.IsNullOrEmpty(connStringField?.Value))
var textSourceControls = ConfigurationControls.Controls.OfType<TextSource>();
foreach (var control in textSourceControls)
{
throw new TerminalCodedException(TerminalErrorCode.SQL_SERVER_CONNECTION_STRING_MISSING);
if (control.Required == true && string.IsNullOrEmpty(control.TextValue))
{
ValidationManager.SetError("Column is not nullable", control);
}
}
return Task.FromResult(0);
}

private void AddErrorToControl()
{
var connStringTextBox = GetControl<TextBox>("connection_string");
Expand Down Expand Up @@ -361,7 +385,7 @@ private IEnumerable<Table> CreateTable()
var values = new List<FieldValue>();
foreach (var control in textSourceControls)
{
if(!string.IsNullOrEmpty(control.TextValue))
if (!string.IsNullOrEmpty(control.TextValue))
{
values.Add(new FieldValue(control.Name, control.TextValue));
}
Expand Down