Skip to content

Commit

Permalink
Merge pull request #97 from PHOENIXCONTACT/feature/unknown-activity-a…
Browse files Browse the repository at this point in the history
…borted

Port: Add UnknownActivityAborted session
  • Loading branch information
1nf0rmagician authored Dec 4, 2024
2 parents 9e8ea40 + 71fb404 commit 2fe355e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
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
13 changes: 13 additions & 0 deletions src/Moryx.ControlSystem/Cells/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ 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)
{
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 Down
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; }
}
}
15 changes: 15 additions & 0 deletions src/Tests/Moryx.ControlSystem.Tests/ProductionSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,20 @@ public void TestContinueSession(ReadyToWorkType readyToWorkType)
Assert.AreEqual(ReadyToWorkType.Pull, readyToWork2.ReadyToWorkType);
}

[Test]
public void TestUnknownActivityAborted()
{
// Arrange
var process = new Process { Id = 4242 };
var activity = new DummyActivity { Process = process };

// Act
var session = Session.WrapUnknownActivity(activity);

// Assert
Assert.That(session.AcceptedClassification, Is.EqualTo(ActivityClassification.Unknown));
Assert.That(session.AbortedActivity, Is.EqualTo(activity));
Assert.That(session.Reference.Matches(process));
}
}
}

0 comments on commit 2fe355e

Please sign in to comment.