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

Draft: Port: Add UnknownActivityAborted session #98

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion src/Moryx.ControlSystem/Activities/ActivityClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace Moryx.ControlSystem.Activities
[Flags]
public enum ActivityClassification
{
/// <summary>
/// Use in case the activity classification is unkown
/// </summary>
Unknown = 0x00,

/// <summary>
/// Default classification is production
/// </summary>
Expand All @@ -33,6 +38,6 @@ public enum ActivityClassification
/// <summary>
/// Activity performs a preparation, for example for a <see cref="Production"/> activity
/// </summary>
Preparation = 0x08
Preparation = 0x08,
}
}
3 changes: 0 additions & 3 deletions src/Moryx.ControlSystem/Cells/ActivityCompleted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace Moryx.ControlSystem.Cells
/// </summary>
public class ActivityCompleted : Session, ICompletableSession
{
/// <summary>
/// Initialize a new resource request for a certain resource
/// </summary>
internal ActivityCompleted(IActivity completed, Session currentSession)
: base(currentSession)
{
Expand Down
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
31 changes: 24 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 @@ -125,6 +125,20 @@ public static ReadyToWork StartSession(ActivityClassification classification, Re
return CreateSession(classification, type, ProcessReference.InstanceIdentity(identity), constraints);
}


/// <summary>
/// Creates a new <see cref="Session"/> for the <paramref name="unknown"/> activity
/// with a new session context and marks the activity as failed.
/// </summary>
/// <param name="unknown"></param>
public static UnknownActivityAborted WrapUnknownActivity(IActivity unknown)
{
unknown.Fail();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the unknown activity failed here and also in the UnknownActivityAborted constructor?

var wrapper = StartSession(ActivityClassification.Unknown, ReadyToWorkType.Unset, unknown.Process.Id)
.CompleteSequence(null, false, new long[] { });
return new UnknownActivityAborted(unknown, wrapper);
}

private static ReadyToWork CreateSession(ActivityClassification classification, ReadyToWorkType type, ProcessReference reference, IConstraint[] constraints)
{
if (constraints == null)
Expand All @@ -134,24 +148,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;
}
}
}
26 changes: 26 additions & 0 deletions src/Moryx.ControlSystem/Cells/UnknownActivityAborted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using Moryx.AbstractionLayer;

namespace Moryx.ControlSystem.Cells
{
/// <summary>
/// Message send by the resource managment when it aborted an activity for an
/// unkown session.
/// </summary>
public class UnknownActivityAborted : ActivityCompleted
{
internal UnknownActivityAborted(IActivity aborted, Session wrapper)
: base(aborted, wrapper)
{
aborted.Fail();
AbortedActivity = aborted;
}

/// <summary>
/// Activity that was aborted
/// </summary>
public IActivity AbortedActivity { get; }
}
}
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 } });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change and is the UnknownActivityAborted tested somewhere?


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