Skip to content

Commit

Permalink
Syntax update, build against RDMP git
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Jun 23, 2023
1 parent aaafe35 commit a8d7913
Show file tree
Hide file tree
Showing 41 changed files with 331 additions and 272 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "RDMP"]
path = RDMP
url = https://github.com/HicServices/RDMP.git
branch = feature/rc4
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public BasicAutomationCommandExecution(IBasicActivateItems activator):base(activ
}
catch (System.Exception e)
{
SetImpossible("No Automation Repository Found:" + e.Message);
SetImpossible($"No Automation Repository Found:{e.Message}");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,19 @@ public DataTable GetIdentifiersTable()

public SuccessfullyExtractedResults GetSuccessIfAnyFor(IExtractableDataSet ds)
{
return _repository.GetAllObjects<SuccessfullyExtractedResults>(@"WHERE ExtractableDataSet_ID = " + ds.ID + " AND AutomateExtraction_ID = " + ID).SingleOrDefault();
return _repository.GetAllObjects<SuccessfullyExtractedResults>(
$@"WHERE ExtractableDataSet_ID = {ds.ID} AND AutomateExtraction_ID = {ID}").SingleOrDefault();
}

public void ClearBaselines()
{
using (var con = _repository.DiscoveredServer.GetConnection())
{
con.Open();
new SqlCommand(@"Delete From
new SqlCommand($@"Delete From
[ReleaseIdentifiersSeen]
where
AutomateExtraction_ID = " + ID, (SqlConnection) con).ExecuteNonQuery();
AutomateExtraction_ID = {ID}", (SqlConnection) con).ExecuteNonQuery();
}

foreach (SuccessfullyExtractedResults r in _repository.GetAllObjectsWithParent<SuccessfullyExtractedResults>(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,95 +33,77 @@ public class AutomateExtractionSchedule : DatabaseEntity, INamed

public AutomationTimeScale ExecutionTimescale
{
get { return _executionTimescale; }
set { SetField(ref _executionTimescale, value); }
get => _executionTimescale;
set => SetField(ref _executionTimescale, value);
}
public string UserRequestingRefresh
{
get { return _userRequestingRefresh; }
set { SetField(ref _userRequestingRefresh, value); }
get => _userRequestingRefresh;
set => SetField(ref _userRequestingRefresh, value);
}
public DateTime? UserRequestingRefreshDate
{
get { return _userRequestingRefreshDate; }
set { SetField(ref _userRequestingRefreshDate, value); }
get => _userRequestingRefreshDate;
set => SetField(ref _userRequestingRefreshDate, value);
}
public string Ticket
{
get { return _ticket; }
set { SetField(ref _ticket, value); }
get => _ticket;
set => SetField(ref _ticket, value);
}
public string Name
{
get { return _name; }
set { SetField(ref _name, value); }
get => _name;
set => SetField(ref _name, value);
}
public string Comment
{
get { return _comment; }
set { SetField(ref _comment, value); }
get => _comment;
set => SetField(ref _comment, value);
}
public bool Disabled
{
get { return _disabled; }
set { SetField(ref _disabled, value); }
get => _disabled;
set => SetField(ref _disabled, value);
}
public int Project_ID
{
get { return _project_ID; }
set { SetField(ref _project_ID, value); }
get => _project_ID;
set => SetField(ref _project_ID, value);
}
public int? Pipeline_ID
{
get { return _pipeline_ID; }
set { SetField(ref _pipeline_ID, value); }
get => _pipeline_ID;
set => SetField(ref _pipeline_ID, value);
}

public TimeSpan ExecutionTimeOfDay
{
get { return _executionTimeOfDay; }
set { SetField(ref _executionTimeOfDay , value); }
get => _executionTimeOfDay;
set => SetField(ref _executionTimeOfDay , value);
}

public int? ReleasePipeline_ID
{
get { return _releasePipelineId; }
set { SetField(ref _releasePipelineId , value); }
get => _releasePipelineId;
set => SetField(ref _releasePipelineId , value);
}

#endregion

#region Database Relationships

[NoMappingToDatabase]
public IPipeline Pipeline { get
{
return Pipeline_ID != null ? _repository.CatalogueRepository.GetObjectByID<Pipeline>(Pipeline_ID.Value) : null;
} }
public IPipeline Pipeline => Pipeline_ID != null ? _repository.CatalogueRepository.GetObjectByID<Pipeline>(Pipeline_ID.Value) : null;

[NoMappingToDatabase]
public IPipeline ReleasePipeline
{
get
{
return ReleasePipeline_ID != null ? _repository.CatalogueRepository.GetObjectByID<Pipeline>(ReleasePipeline_ID.Value) : null;
}
}
public IPipeline ReleasePipeline => ReleasePipeline_ID != null ? _repository.CatalogueRepository.GetObjectByID<Pipeline>(ReleasePipeline_ID.Value) : null;

[NoMappingToDatabase]
public IProject Project
{
get
{
return _repository.DataExportRepository.GetObjectByID<Project>(Project_ID);
} }
public IProject Project => _repository.DataExportRepository.GetObjectByID<Project>(Project_ID);

[NoMappingToDatabase]
public AutomateExtraction[] AutomateExtractions { get
{
return _repository.GetAllObjectsWithParent<AutomateExtraction>(this);
} }

public AutomateExtraction[] AutomateExtractions => _repository.GetAllObjectsWithParent<AutomateExtraction>(this);

#endregion

Expand All @@ -131,7 +113,7 @@ public AutomateExtractionSchedule(PluginRepository repository, IProject project)
repository.InsertAndHydrate(this, new Dictionary<string, object>()
{
{"Project_ID",project.ID},
{"Name","New Schedule"+Guid.NewGuid()},
{"Name", $"New Schedule{Guid.NewGuid()}" },
{"ExecutionTimescale",AutomationTimeScale.Never},
{"ExecutionTimeOfDay","12:00:00"}
});
Expand Down Expand Up @@ -201,7 +183,7 @@ public void CheckTicketing(ICheckNotifier notifier)

notifier.OnCheckPerformed(
new CheckEventArgs(
"Ticket '" + Ticket + "' is " + evaluation + ". Reason given was:" + Environment.NewLine + reason,
$"Ticket '{Ticket}' is {evaluation}. Reason given was:{Environment.NewLine}{reason}",
CheckResult.Fail, exc));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public override PluginRepository GetRepositoryIfAny()
.Where(e => e.WasCreatedBy(patcher)).ToArray();

if (compatibleServers.Length > 1)
throw new Exception("There are 2+ ExternalDatabaseServers of type '" + patcher.Name +
"'. This is not allowed, you must delete one. The servers were called:" +
string.Join(",", compatibleServers.Select(s => s.ToString())));
throw new Exception(
$"There are 2+ ExternalDatabaseServers of type '{patcher.Name}'. This is not allowed, you must delete one. The servers were called:{string.Join(",", compatibleServers.Select(s => s.ToString()))}");

if (compatibleServers.Length == 0)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public void Check(ICheckNotifier notifier)
if (_automateExtractionPipeline.PipelineComponents.Any(c => c.Class == typeof (SuccessfullyExtractedResultsDocumenter).FullName))
notifier.OnCheckPerformed(new CheckEventArgs("Found SuccessfullyExtractedResultsDocumenter plugin component",CheckResult.Success));
else
notifier.OnCheckPerformed(new CheckEventArgs("Automated Extraction can only take place through Pipelines that include a "+typeof(SuccessfullyExtractedResultsDocumenter).Name+" plugin component", CheckResult.Fail));
notifier.OnCheckPerformed(new CheckEventArgs(
$"Automated Extraction can only take place through Pipelines that include a {typeof(SuccessfullyExtractedResultsDocumenter).Name} plugin component", CheckResult.Fail));

var source = _automateExtractionPipeline.Source;

Expand All @@ -38,14 +39,12 @@ public void Check(ICheckNotifier notifier)
}

if (source.Class == typeof (BaselineHackerExecuteDatasetExtractionSource).FullName)
notifier.OnCheckPerformed(new CheckEventArgs("Found Compatible Source " + source.Class,
notifier.OnCheckPerformed(new CheckEventArgs($"Found Compatible Source {source.Class}",
CheckResult.Success));
else
notifier.OnCheckPerformed(
new CheckEventArgs(
"Source Component " + source.Class + " of Pipeline " + _automateExtractionPipeline +
" is not a " + typeof (BaselineHackerExecuteDatasetExtractionSource).FullName +
" (Deltas will never be created)", CheckResult.Warning));
$"Source Component {source.Class} of Pipeline {_automateExtractionPipeline} is not a {typeof(BaselineHackerExecuteDatasetExtractionSource).FullName} (Deltas will never be created)", CheckResult.Warning));
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public override string HackExtractionSQL(string sql, IDataLoadEventListener list
if (hacker.ExecuteHackIfAllowed(listener, out hackSql) == BaselineHackEvaluation.Allowed)
{
var newSql = sql + hackSql;
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information, "Full Hacked Query is now:" + Environment.NewLine + newSql));
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,
$"Full Hacked Query is now:{Environment.NewLine}{newSql}"));

return newSql;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ public BaselineHackEvaluation ExecuteHackIfAllowed(IDataLoadEventListener listen
var configId = _extractDatasetCommand.Configuration.ID;

//find the automation record
var automateExtraction = _repository.GetAllObjects<AutomateExtraction>("WHERE ExtractionConfiguration_ID = " + configId );
var automateExtraction = _repository.GetAllObjects<AutomateExtraction>(
$"WHERE ExtractionConfiguration_ID = {configId}");

//there should be one! and only 1
if(automateExtraction.Length != 1)
throw new Exception("No AutomateExtraction was found for ExtractionConfiguration '" + _extractDatasetCommand.Configuration +"'");
throw new Exception(
$"No AutomateExtraction was found for ExtractionConfiguration '{_extractDatasetCommand.Configuration}'");

if(automateExtraction[0].BaselineDate == null)
return BaselineHackEvaluation.NoCompatibleBaselineAvailable;
Expand All @@ -62,7 +64,8 @@ public BaselineHackEvaluation ExecuteHackIfAllowed(IDataLoadEventListener listen
//nope, the SQL is different, maybe the user has snuck in an extra column or some other thing
if(!string.Equals(currentSQL.Trim(),oldSQL.Trim(),StringComparison.CurrentCultureIgnoreCase))
{
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Warning, "SQL is out of date for baseline of " + _extractDatasetCommand + ". The old success will be deleted now and a new baseline will be executed",
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Warning,
$"SQL is out of date for baseline of {_extractDatasetCommand}. The old success will be deleted now and a new baseline will be executed",
new ExpectedIdenticalStringsException("SQL strings did not match",currentSQL.Trim().ToLower(),oldSQL.Trim().ToLower())));

//either way the SQL is screwey so lets nuke the baseline and make them do a full baseline
Expand All @@ -81,27 +84,28 @@ public BaselineHackEvaluation ExecuteHackIfAllowed(IDataLoadEventListener listen
var tblForJoin = _repository.DiscoveredServer.GetCurrentDatabase().ExpectTable("ReleaseIdentifiersSeen");

if(!tblForJoin.Exists())
throw new Exception("Table '" + tblForJoin + " did not exist!");
throw new Exception($"Table '{tblForJoin} did not exist!");

var tableForJoinName = tblForJoin.GetFullyQualifiedName();

hackSql = @"
hackSql = $@"
AND
(
(
--new cohorts
" + cohortReleaseIdentifier + @"
not in (Select ReleaseId from " + tableForJoinName + @" where AutomateExtraction_ID = "+ automateExtraction[0].ID+ @")
{cohortReleaseIdentifier}
not in (Select ReleaseId from {tableForJoinName} where AutomateExtraction_ID = {automateExtraction[0].ID})
)
OR
(
--new records
" + validFromField.Name + " > '" + automateExtraction[0].BaselineDate.Value + @"'
{validFromField.Name} > '{automateExtraction[0].BaselineDate.Value}'
)
)
";

listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Generated the following Delta Hack SQL:" + Environment.NewLine + hackSql));
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information,
$"Generated the following Delta Hack SQL:{Environment.NewLine}{hackSql}"));

return BaselineHackEvaluation.Allowed;
}
Expand All @@ -119,7 +123,8 @@ public ColumnInfo GetValidFromField(IDataLoadEventListener listener)
//table doesn't have a
if(col == null)
{
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "TableInfo " + tableInfo + " did not have a ColumnInfo called '" + validFromFieldName + "'"));
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information,
$"TableInfo {tableInfo} did not have a ColumnInfo called '{validFromFieldName}'"));
continue;
}

Expand All @@ -136,8 +141,8 @@ public ColumnInfo GetValidFromField(IDataLoadEventListener listener)
if (tableInfo.IsPrimaryExtractionTable)
{
//should never happen to be honest I'm pretty sure QueryBuilder will be super angry if you have 2+ TableInfos both with IsPrimary and ColumnNames should be unique anyway but who knows
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error,
"There were multiple ColumnInfos called " + validFromFieldName + " both from IsPrimaryExtractionTable TableInfos (" + validFromField + "," + col + ")"
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error,
$"There were multiple ColumnInfos called {validFromFieldName} both from IsPrimaryExtractionTable TableInfos ({validFromField},{col})"
));
return null;
}
Expand All @@ -155,9 +160,8 @@ public ColumnInfo GetValidFromField(IDataLoadEventListener listener)
else
{
//neither the previous or ourselves are primary
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "There were multiple ColumnInfos called " + validFromFieldName +
" (" + validFromField +
"," + col + ") try setting one of your TableInfos to IsPrimaryExtractionTable"));
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error,
$"There were multiple ColumnInfos called {validFromFieldName} ({validFromField},{col}) try setting one of your TableInfos to IsPrimaryExtractionTable"));
return null;
}
}
Expand All @@ -167,11 +171,13 @@ public ColumnInfo GetValidFromField(IDataLoadEventListener listener)

if (validFromField == null)
{
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Warning, "No ColumnInfos were found called '" + validFromFieldName + "'"));
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Warning,
$"No ColumnInfos were found called '{validFromFieldName}'"));
return null;
}

listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Found valid from field '" + validFromField + "'"));
listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information,
$"Found valid from field '{validFromField}'"));
return validFromField;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IdentifierAccumulator GetInstance(DataLoadInfo dataLoadInfo)

private IdentifierAccumulator()
{
_commitTblName = "Temp"+Guid.NewGuid().ToString().Replace("-", "");
_commitTblName = $"Temp{Guid.NewGuid().ToString().Replace("-", "")}";
}

HashSet<string> identifiers = new HashSet<string>();
Expand Down Expand Up @@ -60,7 +60,7 @@ public void CommitCurrentState(AutomateExtractionRepository repository, Automate
using (var con = repository.DiscoveredServer.GetConnection())
{
con.Open();
var query = "SELECT TOP 0 * INTO " + tempTable.GetFullyQualifiedName()+" FROM ReleaseIdentifiersSeen";
var query = $"SELECT TOP 0 * INTO {tempTable.GetFullyQualifiedName()} FROM ReleaseIdentifiersSeen";
repository.DiscoveredServer.GetCommand(query, con).ExecuteNonQuery();
}

Expand All @@ -73,13 +73,13 @@ public void CommitCurrentState(AutomateExtractionRepository repository, Automate
using (SqlConnection con = new SqlConnection(repository.ConnectionString))
{
con.Open();
string sql = @"INSERT ReleaseIdentifiersSeen (AutomateExtraction_ID, ReleaseID)
string sql = $@"INSERT ReleaseIdentifiersSeen (AutomateExtraction_ID, ReleaseID)
SELECT AutomateExtraction_ID, ReleaseID
FROM "+_commitTblName+@"
FROM {_commitTblName}
WHERE NOT EXISTS (SELECT 1 FROM ReleaseIdentifiersSeen A2 WHERE
A2.AutomateExtraction_ID = " + _commitTblName + @".AutomateExtraction_ID
A2.AutomateExtraction_ID = {_commitTblName}.AutomateExtraction_ID
AND
A2.ReleaseID = " + _commitTblName + @".ReleaseID )";
A2.ReleaseID = {_commitTblName}.ReleaseID )";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}
Expand Down
Loading

0 comments on commit a8d7913

Please sign in to comment.