SharedDatabase.WorkflowSummary added.
This commit is contained in:
parent
7facefb305
commit
0b400fcbd0
@ -141,6 +141,7 @@
|
||||
<Compile Include="Output\SensusTestInfo.cs" />
|
||||
<Compile Include="Output\Table.cs" />
|
||||
<Compile Include="Output\WMChart.cs" />
|
||||
<Compile Include="WorkflowSummary.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
||||
129
SharedDatabase/WorkflowSummary.cs
Normal file
129
SharedDatabase/WorkflowSummary.cs
Normal file
@ -0,0 +1,129 @@
|
||||
///
|
||||
/// Copyright (c) 2022 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Linq;
|
||||
using log4net;
|
||||
using NHibernate;
|
||||
using SharedDatabase.Entities;
|
||||
|
||||
namespace SharedDatabase
|
||||
{
|
||||
public class WorkflowSummary
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(WorkflowSummary));
|
||||
|
||||
public Entities.Process Workflow; /// Selected production tracing workflow
|
||||
public string WorkstepName; /// Selected production tracing workstep
|
||||
public string PreviousWorkstepName; /// Previous workstep name
|
||||
public string Part1Name; /// 1st reference part name
|
||||
public string Part2Name; /// 2nd reference part name or null
|
||||
|
||||
WorkflowSummary() { }
|
||||
|
||||
public WorkflowSummary(Entities.Process workflow)
|
||||
{
|
||||
Workflow = workflow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read specified workflow and workstep from the production tracing database
|
||||
/// and set WorkflowSummary members accordingly.
|
||||
/// </summary>
|
||||
/// <param name="workflowName">Workflow name</param>
|
||||
/// <param name="workstepPattern">Part of a workstep name (not case sensitive)</param>
|
||||
/// <param name="session">Database session or null</param>
|
||||
/// <returns>Workflow summary or null</returns>
|
||||
public static WorkflowSummary ReadFromDB(string workflowName, string workstepPattern = "test", ISession session = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(workflowName))
|
||||
{
|
||||
log.ErrorFormat("ReadFromDB() ... workflowName argument is null or empty");
|
||||
return null;
|
||||
}
|
||||
|
||||
bool openAndCloseSession = (session == null) || !session.IsOpen;
|
||||
|
||||
try
|
||||
{
|
||||
WorkflowSummary wSum = null;
|
||||
|
||||
if (openAndCloseSession) session = TracingDB.SessionFactory.OpenSession();
|
||||
|
||||
var wflows = session.QueryOver<Process>()
|
||||
.Where(x => x.Name == workflowName)
|
||||
.And(x => (x.ReleaseStatus == ReleaseStatus.ToBeApproved ||
|
||||
x.ReleaseStatus == ReleaseStatus.Released ||
|
||||
x.ReleaseStatus == ReleaseStatus.ReleasedActive))
|
||||
.List();
|
||||
|
||||
if (wflows.Count == 1)
|
||||
{
|
||||
Process wf = wflows[0];
|
||||
wSum = new WorkflowSummary(wf);
|
||||
var workstep = wf.Worksteps.FirstOrDefault(x => x.Name.ToLower().Contains(workstepPattern.ToLower()));
|
||||
if (workstep != null)
|
||||
{
|
||||
wSum.WorkstepName = workstep.Name;
|
||||
int previousStepNr = workstep.WorkstepNr - 1;
|
||||
var previousStep = (previousStepNr < 1) ? null : wf.Worksteps.FirstOrDefault(x => x.WorkstepNr == previousStepNr);
|
||||
if (previousStep != null) wSum.PreviousWorkstepName = previousStep.Name;
|
||||
}
|
||||
var part1 = wf.Parts.FirstOrDefault(x => x.StepNumber == 1);
|
||||
var part2 = wf.Parts.FirstOrDefault(x => x.StepNumber == 2);
|
||||
if (part1 != null) wSum.Part1Name = part1.Name;
|
||||
if (part2 != null) wSum.Part2Name = part2.Name;
|
||||
}
|
||||
|
||||
if (openAndCloseSession) session.Close();
|
||||
|
||||
log.InfoFormat("ReadFromDB({0}, {1}) returns {2}", (wSum != null) ? wSum.ToString() : "<null>");
|
||||
return wSum;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
if (session != null && session.IsOpen) session.Close();
|
||||
log.ErrorFormat("ReadFromDB({0}, {1}) failed: {2}", workflowName, workstepPattern, exc.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Compares two workflows, determines whether they are compatible.
|
||||
/// Minimal requirement is Part1 and Part2 names are the same (both Part2 names might be null).
|
||||
/// </summary>
|
||||
/// <param name="wfs">Anothe workflow summary</param>
|
||||
/// <param name="strict">true = strict comparison</param>
|
||||
/// <returns>true when compatible</returns>
|
||||
public bool IsCompatibleWith(WorkflowSummary wfs, bool strict = false)
|
||||
{
|
||||
if (strict)
|
||||
{
|
||||
return wfs != null &&
|
||||
Part1Name == wfs.Part1Name &&
|
||||
Part2Name == wfs.Part2Name &&
|
||||
WorkstepName == wfs.WorkstepName &&
|
||||
PreviousWorkstepName == wfs.PreviousWorkstepName &&
|
||||
Workflow.Name == wfs.Workflow.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfs != null &&
|
||||
Part1Name == wfs.Part1Name &&
|
||||
Part2Name == wfs.Part2Name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("workflow={0} workstep={1} previousWS={2} part1={3} part2={4}",
|
||||
Workflow != null ? Workflow.Name : "<none>",
|
||||
WorkstepName != null ? WorkstepName : "<none>",
|
||||
PreviousWorkstepName != null ? PreviousWorkstepName : "<none>",
|
||||
Part1Name != null ? Part1Name : "<none>",
|
||||
Part2Name != null ? Part2Name : "<none>");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user