Skip to content

Commit

Permalink
Renamed WatchTag Scope to ScopeName to avoid conflicting property names.
Browse files Browse the repository at this point in the history
  • Loading branch information
tnunnink committed Dec 9, 2023
1 parent feb4b1e commit 80a6ee4
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 40 deletions.
19 changes: 13 additions & 6 deletions src/.idea/.idea.L5Sharp/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/L5Sharp.Core/Common/Revision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public Revision()
}

/// <summary>
///
/// Creates a new <see cref="Revision"/> with the specified value.
/// </summary>
/// <param name="value"></param>
/// <param name="value">The Major.Minor revision value to initialize the type with.</param>
/// <exception cref="ArgumentException"><paramref name="value"/> is null or empty.</exception>
/// <exception cref="FormatException"><paramref name="value"/> is not in a valid format Major.Minor.</exception>
public Revision(string value)
{
if (string.IsNullOrEmpty(value))
Expand Down
13 changes: 9 additions & 4 deletions src/L5Sharp.Core/Elements/WatchTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WatchTag : LogixElement
public WatchTag()
{
Specifier = TagName.Empty;
Scope = string.Empty;
ScopeName = string.Empty;
}

/// <summary>
Expand All @@ -44,9 +44,14 @@ public TagName Specifier
/// Specify the name of program, equipment phase, or Add-On Instruction that contains the watch tag.
/// </summary>
/// <value>A <see cref="string"/> representing the scope of the tag. If controller scope set to empty.</value>
public string Scope
/// <remarks>
/// This property internally (in the L5X) is named Scope, but we are renaming it to ScopeName to avoid
/// the property name issues. I wanted Scope to remain the same at the logix element level since more types will
/// make use of that property.
/// </remarks>
public string ScopeName
{
get => GetRequiredValue<string>();
set => SetRequiredValue(value);
get => GetRequiredValue<string>(nameof(Scope));
set => SetRequiredValue(value, nameof(Scope));
}
}
13 changes: 3 additions & 10 deletions src/L5Sharp.Core/Enums/ComponentType.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
namespace L5Sharp.Core;

/// <summary>
/// Represents a component type.
/// </summary>
public class ComponentType : LogixEnum<ComponentType, string>
{
private ComponentType(string name, string value) : base(name, value)
{
}

/// <summary>
///
/// </summary>
public virtual string ContainerName => $"{Name}s";

/// <summary>
///
/// </summary>
public virtual bool IsTopLevel => Name != Routine.Name;

/// <summary>
/// Represents a <b>DataType</b> <see cref="ComponentType"/>.
/// </summary>
Expand Down
9 changes: 4 additions & 5 deletions src/L5Sharp.Core/L5Sharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Title>L5Sharp</Title>
<Authors>Timothy Nunnink</Authors>
<Version>0.17.0</Version>
<AssemblyVersion>0.17.0</AssemblyVersion>
<FileVersion>0.17.0.0</FileVersion>
<Version>0.18.0</Version>
<AssemblyVersion>0.18.0</AssemblyVersion>
<FileVersion>0.18.0.0</FileVersion>
<Description>A library for intuitively interacting with Rockwell's L5X import/export files.</Description>
<RepositoryUrl>https://github.com/tnunnink/L5Sharp</RepositoryUrl>
<PackageTags>csharp allen-bradely l5x logix plc-programming rockwell-automation logix5000</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!--<PackageIcon>icon.png</PackageIcon>-->
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>Merged library into single namespace L5Sharp.Core</PackageReleaseNotes>
<PackageReleaseNotes>Renamed conflicting properties in WatchTag. Documentation updates.</PackageReleaseNotes>
<Copyright>Copyright (c) Timothy Nunnink 2022</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageId>L5Sharp</PackageId>
<PackageProjectUrl>https://github.com/tnunnink/L5Sharp</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>

Expand Down
27 changes: 20 additions & 7 deletions src/L5Sharp.Core/L5X.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ public static L5X New(string name, string processor, Revision? revision = null)
{
if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name can not be null or empty.");
if (string.IsNullOrEmpty(processor)) throw new ArgumentException("Name can not be null or empty.");

var content = NewContent(name, nameof(Controller), revision);

var controller = new XElement(L5XName.Controller,
new XAttribute(L5XName.Name, name),
new XAttribute(L5XName.ProcessorType, processor)
);

content.Add(controller);
return new L5X(content);
}
Expand Down Expand Up @@ -1030,8 +1030,21 @@ public void Remove<TComponent>(string name, string container) where TComponent :
}

/// <summary>
/// Retrieves a collection of <see cref="CrossReference"/> objects that reference the specified <paramref
/// name="component"/>.
/// Retrieves all <see cref="CrossReference"/> objects found in the L5X file.
/// </summary>
/// <returns>A collection of all <see cref="CrossReference"/> objects found in the L5X.</returns>
/// <remarks>
/// <para>
/// A cross reference object contains information about the element and location of the object that has a reference
/// to a given component. This library has a built in mechanism for parsing and indexing both tag and logic references
/// to various components for efficient lookup. This can allow the caller to find references for many objects at a time
/// without having to iterate the L5X multiple times.
/// </para>
/// </remarks>
public IEnumerable<CrossReference> References() => Index.References.SelectMany(r => r.Value);

/// <summary>
/// Retrieves a collection of <see cref="CrossReference"/> objects that reference the specified <paramref name="component"/>.
/// </summary>
/// <param name="component">The <see cref="LogixComponent"/> to retrieve references for.</param>
/// <returns>A collection of <see cref="CrossReference"/> objects that reference the specified <paramref name="component"/>.</returns>
Expand All @@ -1044,7 +1057,7 @@ public void Remove<TComponent>(string name, string container) where TComponent :
/// without having to iterate the L5X multiple times.
/// </para>
/// </remarks>
public IEnumerable<CrossReference> ReferencesTo(LogixComponent component)
public IEnumerable<CrossReference> References(LogixComponent component)
{
if (component is null) throw new ArgumentNullException(nameof(component));

Expand All @@ -1069,7 +1082,7 @@ public IEnumerable<CrossReference> ReferencesTo(LogixComponent component)
/// without having to iterate the L5X multiple times.
/// </para>
/// </remarks>
public IEnumerable<CrossReference> ReferencesTo<TComponent>(string name) where TComponent : LogixComponent
public IEnumerable<CrossReference> References<TComponent>(string name) where TComponent : LogixComponent
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Name can not be null or empty.", nameof(name));
Expand Down
2 changes: 1 addition & 1 deletion src/L5Sharp.Core/LogixComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public virtual L5X Export(Revision? softwareRevision = null)
/// at least one property value referencing this component's name.
/// </returns>
public IEnumerable<CrossReference> References() =>
L5X is not null ? L5X.ReferencesTo(this) : Enumerable.Empty<CrossReference>();
L5X is not null ? L5X.References(this) : Enumerable.Empty<CrossReference>();

/// <inheritdoc />
/// <remarks>This override returns the component name of the type.</remarks>
Expand Down
13 changes: 12 additions & 1 deletion tests/L5Sharp.Tests/Common/RevisionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace L5Sharp.Tests.Common
[TestFixture]
public class RevisionTests
{
private Fixture _fixture;
private Fixture? _fixture;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -167,6 +167,17 @@ public void OperatorGreaterThan_FirstGreaterThanSecond_ShouldBeTrue()

result.Should().BeTrue();
}

[Test]
public void OperatorGreaterThanForString_FirstGreaterThanSecond_ShouldBeTrue()
{
var first = new Revision("1.02");
var second = new Revision("1.01");

var result = first > second;

result.Should().BeTrue();
}

[Test]
public void OperatorLessThan_FirstGreaterThanSecond_ShouldBeFalse()
Expand Down
2 changes: 1 addition & 1 deletion tests/L5Sharp.Tests/L5XBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void ReferencesTo_ValidComponent_ShouldHaveExpectedCount()
var content = L5X.Load(Known.Test);
var tag = content.Get(Known.Tag);

var references = content.ReferencesTo(tag).ToList();
var references = content.References(tag).ToList();

references.Should().NotBeEmpty();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/L5Sharp.Tests/L5XReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void FindReferences_ComponentWithKnownReference_ShouldNotBeEmpty()
{
var content = L5X.Load(Known.Test);

var references = content.ReferencesTo<Tag>("TestSimpleTag").ToList();
var references = content.References<Tag>("TestSimpleTag").ToList();

references.Should().NotBeEmpty();
}
Expand All @@ -20,7 +20,7 @@ public void FindReferences_ComponentWithKnownReference_ShouldNotBeEmpty()
public void UpdatingTextForKnownRungWithTagReferenceShouldUpdateAndReturnEmptyReferences()
{
var content = L5X.Load(Known.Test);
var initialReferences = content.ReferencesTo<Tag>("TestSimpleTag").ToList();
var initialReferences = content.References<Tag>("TestSimpleTag").ToList();
initialReferences.Should().NotBeEmpty();
var rung = initialReferences.First(r =>
r.Container == "MainProgram" && r.Routine == "Main" && r.ElementId == "2")
Expand All @@ -31,7 +31,7 @@ public void UpdatingTextForKnownRungWithTagReferenceShouldUpdateAndReturnEmptyRe
//It should update the index internally an recalling FindReferences should return an empty collection.
rung!.Text = "This is me fucking with the text.";

var finalReferences = content.ReferencesTo<Tag>("TestSimpleTag").ToList();
var finalReferences = content.References<Tag>("TestSimpleTag").ToList();
finalReferences.Should().BeEmpty();
}
}

0 comments on commit 80a6ee4

Please sign in to comment.