Skip to content

Commit

Permalink
Cleanup syntax and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Jun 27, 2023
1 parent a8d7913 commit ad793f1
Show file tree
Hide file tree
Showing 26 changed files with 241 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,23 @@ public override Image<Rgba32> GetImage(object concept, OverlayKind kind = Overla

public override object[] GetChildren(object model)
{
if (model is IProject p)
switch (model)
{
var schedule = GetScheduleIfAny(p);
case IProject p:
{
var schedule = GetScheduleIfAny(p);

if(schedule != null)
return new[] { schedule };
}

if(model is IExtractionConfiguration ec)
{
var automate = GetAutomateExtractionIfAny(ec);
if (automate != null)
return new[] { automate };
if(schedule != null)
return new[] { schedule };
break;
}
case IExtractionConfiguration ec:
{
var automate = GetAutomateExtractionIfAny(ec);
if (automate != null)
return new[] { automate };
break;
}
}

return base.GetChildren(model);
Expand All @@ -78,35 +82,25 @@ private AutomateExtractionSchedule GetScheduleIfAny(IProject p)
{
TryGettingAutomationRepository();

if (AutomationRepository == null)
{
return null;
}

return AllSchedules.FirstOrDefault(aes => aes.Project_ID == p.ID);
return AutomationRepository == null ? null : AllSchedules.FirstOrDefault(aes => aes.Project_ID == p.ID);
}

private AutomateExtraction GetAutomateExtractionIfAny(IExtractionConfiguration ec)
{
TryGettingAutomationRepository();

if (AutomationRepository == null)
{
return null;
}

return AllAutomateExtractions.FirstOrDefault(ae => ae.ExtractionConfiguration_ID == ec.ID);
return AutomationRepository == null ? null : AllAutomateExtractions.FirstOrDefault(ae => ae.ExtractionConfigurationId == ec.ID);
}

DateTime lastLook = DateTime.MinValue;
private IconOverlayProvider _overlayProvider;
private Image<Rgba32> _scheduleIcon;
private Image<Rgba32> _automateExtractionIcon;
DateTime _lastLook = DateTime.MinValue;
private readonly IconOverlayProvider _overlayProvider;
private readonly Image<Rgba32> _scheduleIcon;
private readonly Image<Rgba32> _automateExtractionIcon;

private void TryGettingAutomationRepository()
{
// we looked recently already dont spam that thing
if (DateTime.Now - lastLook < TimeSpan.FromSeconds(5))
// we looked recently already don't spam that thing
if (DateTime.Now - _lastLook < TimeSpan.FromSeconds(5))
return;

if (AutomationRepository != null)
Expand All @@ -120,39 +114,34 @@ private void TryGettingAutomationRepository()
AllAutomateExtractions = AutomationRepository.GetAllObjects<AutomateExtraction>();
AllSchedules = AutomationRepository.GetAllObjects<AutomateExtractionSchedule>();

lastLook = DateTime.Now;
_lastLook = DateTime.Now;
}
catch (Exception)
{
AutomationRepository = null;
lastLook = DateTime.Now;
_lastLook = DateTime.Now;
}
}

public override IEnumerable<IAtomicCommand> GetAdditionalRightClickMenuItems(object o)
{
if (o is AllExternalServersNode)
{
yield return new ExecuteCommandCreateNewExternalDatabaseServer(BasicActivator, new AutomateExtractionPluginPatcher(), PermissableDefaults.None);
}


if(o is IProject p)
switch (o)
{
yield return new ExecuteCommandCreateNewAutomateExtractionSchedule(BasicActivator, p);
}
if(o is IExtractionConfiguration ec)
{
yield return new ExecuteCommandCreateNewAutomateExtraction(BasicActivator, ec);
}

if(o is AutomateExtraction ae)
{
yield return new ExecuteCommandSet(BasicActivator, ae, typeof(AutomateExtraction).GetProperty(nameof(AutomateExtraction.BaselineDate)))
{
OverrideCommandName = "Set Baseline Date"
};
case AllExternalServersNode:
yield return new ExecuteCommandCreateNewExternalDatabaseServer(BasicActivator, new AutomateExtractionPluginPatcher(), PermissableDefaults.None);
break;
case IProject p:
yield return new ExecuteCommandCreateNewAutomateExtractionSchedule(BasicActivator, p);
break;
case IExtractionConfiguration ec:
yield return new ExecuteCommandCreateNewAutomateExtraction(BasicActivator, ec);
break;
case AutomateExtraction ae:
yield return new ExecuteCommandSet(BasicActivator, ae, typeof(AutomateExtraction).GetProperty(nameof(AutomateExtraction.BaselineDate)))
{
OverrideCommandName = "Set Baseline Date"
};
break;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public BasicAutomationCommandExecution(IBasicActivateItems activator):base(activ
if (AutomationRepository == null)
{
SetImpossible("There is no Automation Repository configured");
return;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,73 @@

namespace LoadModules.Extensions.AutomationPlugins.Data;

public class AutomateExtraction : DatabaseEntity, IMapsDirectlyToDatabaseTable
public class AutomateExtraction : DatabaseEntity
{
private readonly AutomateExtractionRepository _repository;

#region Database Properties

private int _extractionConfiguration_ID;
private int _automateExtractionSchedule_ID;
private int _extractionConfigurationId;
private int _automateExtractionScheduleId;
private bool _disabled;
private DateTime? _baselineDate;
private bool _refreshCohort;
private bool _release;

public int ExtractionConfiguration_ID
public int ExtractionConfigurationId
{
get { return _extractionConfiguration_ID; }
set { SetField(ref _extractionConfiguration_ID, value); }
get => _extractionConfigurationId;
set => SetField(ref _extractionConfigurationId, value);
}
public int AutomateExtractionSchedule_ID
public int AutomateExtractionScheduleId
{
get { return _automateExtractionSchedule_ID; }
set { SetField(ref _automateExtractionSchedule_ID, value); }
get => _automateExtractionScheduleId;
set => SetField(ref _automateExtractionScheduleId, value);
}
public bool Disabled
{
get { return _disabled; }
set { SetField(ref _disabled, value); }
get => _disabled;
set => SetField(ref _disabled, value);
}
public DateTime? BaselineDate
{
get { return _baselineDate; }
set { SetField(ref _baselineDate, value); }
get => _baselineDate;
set => SetField(ref _baselineDate, value);
}

public bool RefreshCohort
{
get { return _refreshCohort; }
set {SetField(ref _refreshCohort , value); }
get => _refreshCohort;
set => SetField(ref _refreshCohort , value);
}

public bool Release
{
get { return _release; }
set { SetField(ref _release , value);}
get => _release;
set => SetField(ref _release , value);
}

#endregion

#region Relationships

[NoMappingToDatabase]
public IExtractionConfiguration ExtractionConfiguration { get
{
return _repository.DataExportRepository.GetObjectByID<ExtractionConfiguration>(ExtractionConfiguration_ID);
} }
public IExtractionConfiguration ExtractionConfiguration => _repository.DataExportRepository.GetObjectByID<ExtractionConfiguration>(ExtractionConfigurationId);

[NoMappingToDatabase]
public AutomateExtractionSchedule AutomateExtractionSchedule { get
{
return _repository.GetObjectByID<AutomateExtractionSchedule>(AutomateExtractionSchedule_ID);
}}
public AutomateExtractionSchedule AutomateExtractionSchedule => _repository.GetObjectByID<AutomateExtractionSchedule>(AutomateExtractionScheduleId);

#endregion

public AutomateExtraction(PluginRepository repository, AutomateExtractionSchedule schedule, IExtractionConfiguration config)
{
_repository = (AutomateExtractionRepository) repository;
repository.InsertAndHydrate(this, new Dictionary<string, object>()
repository.InsertAndHydrate(this, new Dictionary<string, object>
{
{"AutomateExtractionSchedule_ID",schedule.ID},
{"ExtractionConfiguration_ID",config.ID},
{"RefreshCohort",false},
{"Release",false},
{"Release",false}

});

Expand All @@ -95,8 +89,8 @@ public AutomateExtraction(PluginRepository repository, DbDataReader r)
: base(repository, r)
{
_repository = (AutomateExtractionRepository) repository;
ExtractionConfiguration_ID = Convert.ToInt32(r["ExtractionConfiguration_ID"]);
AutomateExtractionSchedule_ID = Convert.ToInt32(r["AutomateExtractionSchedule_ID"]);
ExtractionConfigurationId = Convert.ToInt32(r["ExtractionConfiguration_ID"]);
AutomateExtractionScheduleId = Convert.ToInt32(r["AutomateExtractionSchedule_ID"]);
Disabled = Convert.ToBoolean(r["Disabled"]);
BaselineDate = ObjectToNullableDateTime(r["BaselineDate"]);

Expand All @@ -110,25 +104,25 @@ public AutomateExtraction(PluginRepository repository, DbDataReader r)
public override string ToString()
{
_cachedExtractionConfiguration ??=
_repository.DataExportRepository.GetObjectByID<ExtractionConfiguration>(ExtractionConfiguration_ID);
_repository.DataExportRepository.GetObjectByID<ExtractionConfiguration>(ExtractionConfigurationId);

return _cachedExtractionConfiguration.Name;
}

public DataTable GetIdentifiersTable()
{
var dt = new DataTable();
dt.BeginLoadData();

var repo = (TableRepository)Repository;
var server = repo.DiscoveredServer;

using (var con = server.GetConnection())
{
con.Open();
var cmd = server.GetCommand("Select ReleaseID from ReleaseIdentifiersSeen", con);
var da = server.GetDataAdapter(cmd);
da.Fill(dt);
}
using var con = server.GetConnection();
con.Open();
var cmd = server.GetCommand("Select ReleaseID from ReleaseIdentifiersSeen", con);
var da = server.GetDataAdapter(cmd);
da.Fill(dt);
dt.EndLoadData();

return dt;
}
Expand All @@ -150,7 +144,7 @@ public void ClearBaselines()
AutomateExtraction_ID = {ID}", (SqlConnection) con).ExecuteNonQuery();
}

foreach (SuccessfullyExtractedResults r in _repository.GetAllObjectsWithParent<SuccessfullyExtractedResults>(this))
foreach (var r in _repository.GetAllObjectsWithParent<SuccessfullyExtractedResults>(this))
r.DeleteInDatabase();

BaselineDate = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public int? ReleasePipeline_ID
public AutomateExtractionSchedule(PluginRepository repository, IProject project)
{
_repository = (AutomateExtractionRepository) repository;
repository.InsertAndHydrate(this, new Dictionary<string, object>()
repository.InsertAndHydrate(this, new Dictionary<string, object>
{
{"Project_ID",project.ID},
{"Name", $"New Schedule{Guid.NewGuid()}" },
Expand Down Expand Up @@ -173,10 +173,7 @@ public void CheckTicketing(ICheckNotifier notifier)
return;
}

Exception exc;
string reason;

var evaluation = config.GetDataReleaseabilityOfTicket(Ticket, null, null, out reason, out exc);
var evaluation = config.GetDataReleaseabilityOfTicket(Ticket, null, null, out var reason, out var exc);

if(evaluation == TicketingReleaseabilityEvaluation.Releaseable)
return;
Expand All @@ -189,7 +186,7 @@ public void CheckTicketing(ICheckNotifier notifier)

public IExtractionConfiguration[] GetImportableExtractionConfigurations()
{
var idsAlreadyPartOfSchedule = AutomateExtractions.Select(e => e.ExtractionConfiguration_ID);
var idsAlreadyPartOfSchedule = AutomateExtractions.Select(e => e.ExtractionConfigurationId);

var available = Project.ExtractionConfigurations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,43 @@ public class QueuedExtraction : DatabaseEntity

public int ExtractionConfiguration_ID
{
get { return _extractionConfiguration_ID; }
set { SetField(ref _extractionConfiguration_ID, value); }
get => _extractionConfiguration_ID;
set => SetField(ref _extractionConfiguration_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 DateTime DueDate
{
get { return _dueDate; }
set { SetField(ref _dueDate, value); }
get => _dueDate;
set => SetField(ref _dueDate, value);
}
public string Requester
{
get { return _requester; }
set { SetField(ref _requester, value); }
get => _requester;
set => SetField(ref _requester, value);
}
public DateTime RequestDate
{
get { return _requestDate; }
set { SetField(ref _requestDate, value); }
get => _requestDate;
set => SetField(ref _requestDate, value);
}
#endregion

#region Relationships
[NoMappingToDatabase]
public IExtractionConfiguration ExtractionConfiguration
{
get
{
return ((AutomateExtractionRepository)Repository).DataExportRepository.GetObjectByID<ExtractionConfiguration>(ExtractionConfiguration_ID);
}
}
public IExtractionConfiguration ExtractionConfiguration => ((AutomateExtractionRepository)Repository).DataExportRepository.GetObjectByID<ExtractionConfiguration>(ExtractionConfiguration_ID);

[NoMappingToDatabase]
public Pipeline Pipeline
{
get
{
return ((AutomateExtractionRepository)Repository).CatalogueRepository.GetObjectByID<Pipeline>(Pipeline_ID);
}
}
public Pipeline Pipeline => ((AutomateExtractionRepository)Repository).CatalogueRepository.GetObjectByID<Pipeline>(Pipeline_ID);

#endregion

public QueuedExtraction(PluginRepository repository, ExtractionConfiguration configuration, IPipeline extractionPipeline, DateTime dueDate)
{
repository.InsertAndHydrate(this, new Dictionary<string, object>()
repository.InsertAndHydrate(this, new Dictionary<string, object>
{
{"ExtractionConfiguration_ID",configuration.ID},
{"Pipeline_ID",extractionPipeline.ID},
Expand Down
Loading

0 comments on commit ad793f1

Please sign in to comment.