Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Session context struct avoids changes on previos sequence to MORYX 8 #89

Merged
merged 7 commits into from
Sep 9, 2024
10 changes: 3 additions & 7 deletions src/Moryx.ControlSystem/Cells/ReadyToWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,16 @@ internal ReadyToWork(Session currentSession)
/// </summary>
/// <param name="activity">The activity.</param>
public ActivityStart StartActivity(IActivity activity)
{
// Update process before next stage
Process = activity.Process;
return new ActivityStart(this, activity);
{
return new ActivityStart(this, activity) { Process = activity.Process };
}

/// <summary>
/// Creates the SequenceCompleted message
/// </summary>
public SequenceCompleted CompleteSequence(IProcess process, bool processActive, params long[] nextCells)
{
// Update process before next stage
Process = process;
return new SequenceCompleted(this, processActive, nextCells);
return new SequenceCompleted(this, processActive, nextCells) { Process = process };
}

/// <summary>
Expand Down
17 changes: 10 additions & 7 deletions src/Moryx.ControlSystem/Cells/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected Session(Session currentSession)
/// <summary>
/// Context class holding all session information
/// </summary>
private readonly SessionContext _context;
private SessionContext _context;

/// <summary>
/// Unique id of the current production transaction
Expand Down Expand Up @@ -134,24 +134,27 @@ private static ReadyToWork CreateSession(ActivityClassification classification,

#endregion

private class SessionContext
private struct SessionContext
{
internal SessionContext(ActivityClassification classification, Guid sessionId, ProcessReference reference)
{
Classification = classification;
SessionId = sessionId;
Reference = reference;

Tag = null;
Process = null;
}

public Guid SessionId { get; }
public Guid SessionId;

public IProcess Process { get; set; }
public IProcess Process;

public ProcessReference Reference { get; set; }
public ProcessReference Reference;

public ActivityClassification Classification { get; }
public ActivityClassification Classification;

public object Tag { get; set; }
public object Tag;
}
}
}
9 changes: 5 additions & 4 deletions src/Tests/Moryx.ControlSystem.Tests/ProductionSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public void TestCreateActivityStart()
{
var readyToWork = Session.StartSession(ActivityClassification.Production, ReadyToWorkType.Pull, 4242);

var activityStart = readyToWork.StartActivity(new DummyActivity { Process = new Process() });
var activityStart = readyToWork.StartActivity(new DummyActivity { Process = new Process { Id = 4242 } });

Assert.AreEqual(readyToWork.Reference, activityStart.Reference);
Assert.AreEqual(readyToWork.Id, activityStart.Id);
Assert.AreNotEqual(readyToWork.Process, activityStart.Process); // Make sure process is not populated back to RTW
}

[Test]
Expand Down Expand Up @@ -82,7 +83,7 @@ public void TestCreateActivityResult()
{
var readyToWork = Session.StartSession(ActivityClassification.Production, ReadyToWorkType.Pull, 4242);

var activityStart = readyToWork.StartActivity(new DummyActivity { Process = new Process() });
var activityStart = readyToWork.StartActivity(new DummyActivity { Process = new Process { Id = 4242 } });
activityStart.Activity.Complete(1);

var activityCompleted = activityStart.CreateResult();
Expand All @@ -96,7 +97,7 @@ public void TestCompleteSequence()
{
var readyToWork = Session.StartSession(ActivityClassification.Production, ReadyToWorkType.Pull, 4242);

var activityStart = readyToWork.StartActivity(new DummyActivity {Process = new Process()});
var activityStart = readyToWork.StartActivity(new DummyActivity { Process = new Process { Id = 4242 } });
activityStart.Activity.Complete(1);

var activityCompleted = activityStart.CreateResult();
Expand All @@ -123,7 +124,7 @@ public void TestContinueSession(ReadyToWorkType readyToWorkType)
{
var readyToWork = Session.StartSession(ActivityClassification.Production, readyToWorkType, 4242);

var activityStart = readyToWork.StartActivity(new DummyActivity { Process = new Process() });
var activityStart = readyToWork.StartActivity(new DummyActivity { Process = new Process { Id = 4242 } });
activityStart.Activity.Complete(1);

var activityCompleted = activityStart.CreateResult();
Expand Down
Loading