Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
1nf0rmagician committed Dec 4, 2024
2 parents 2abb4e5 + 5d1a509 commit 2c4ac8f
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 5 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; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) 2024, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
Expand Down Expand Up @@ -182,5 +185,19 @@ private static VisualInstruction[] GetInstructions(ActivityStart activity)

return parameters.Instructions;
}

/// <summary>
/// Returns a text instruction for the given string.
/// </summary>
/// <param name="text">Instruction text</param>
/// <returns><see cref="VisualInstruction"/> with type `Text` the given string as content</returns>
public static VisualInstruction AsInstruction(this string text)
{
return new VisualInstruction
{
Content = text,
Type = InstructionContentType.Text,
};
}
}
}
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));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using Moq;
using Moryx.ControlSystem.VisualInstructions;
using NUnit.Framework;
using System;

namespace Moryx.ControlSystem.Tests.VisualInstructions
{
[TestFixture]

public class VisualInstructorExtensionsTests
{
[Test]
public void ExtensionCreatesStringAsInstruction()
{
var str = "text instruction";

var instruction = str.AsInstruction();

Assert.That(instruction.Type, Is.EqualTo(InstructionContentType.Text));
Assert.That(instruction.Content, Is.EqualTo(str));
}

}
}

0 comments on commit 2c4ac8f

Please sign in to comment.