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

Fix modify dev name variations C-device #1395

Merged
merged 1 commit into from
Jun 14, 2024
Merged
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
12 changes: 11 additions & 1 deletion EasyEplanner.Tests/EplanDevice.Test/Device.Test.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using EplanDevice;
using NUnit.Framework;

namespace Tests.EplanDevices
{
Expand Down Expand Up @@ -195,5 +196,14 @@ public void GetChannels_Test(string channelName, string comment, int expectedCha
var channels = dev.GetChannels(IO.IOModuleInfo.ADDRESS_SPACE_TYPE.AOAIDODI, channelName, comment);
Assert.AreEqual(expectedChannelsCount, channels.Count);
}

[TestCase("OBJ1" ,"V1")]
[TestCase("" , "V1")]
public void DeviceDesignationTest(string obj, string expectedDesignation)
{
var dev = new V($"{obj}V1", $"+{obj}-V1", "", 1, "OBJ", 1, "");

Assert.AreEqual("V1", dev.DeviceDesignation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private void SetupDeviceManagerMock()
var DO1 = new DO("DO1", "DO1", "desc", 1, "", 0);
var LS1 = new LS("LS1", "LS1", "desc", 1, "", 0, "");
var TANK1V1 = new V("TANK1V1", "+TANK1-V1", "desc", 1, "TANK", 1, "");
var TANK2V1 = new V("TANK2V1", "+TANK2V-1", "desc", 1, "TANK", 2, "");
var TANK2V1 = new V("TANK2V1", "+TANK2-V1", "desc", 1, "TANK", 2, "");


deviceManagerMock.Setup(m => m.GetDeviceByEplanName("LS1")).Returns(LS1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ private static EplanDevice.IDevice MakeMockedDevice(string objName,
EplanDevice.DeviceSubType deviceSubType, int devNumber, string devName)
{
var devMock = new Mock<EplanDevice.IDevice>();
devMock.SetupGet(x => x.DeviceDesignation).Returns($"{devType}{devNumber}");
devMock.SetupGet(x => x.ObjectName).Returns(objName);
devMock.SetupGet(x => x.ObjectNumber).Returns(objNum);
devMock.SetupGet(x => x.DeviceType).Returns(devType);
Expand Down
3 changes: 3 additions & 0 deletions src/Device/Device.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;

namespace EplanDevice
{
Expand Down Expand Up @@ -176,6 +177,8 @@ public string EplanName
}
}

public string DeviceDesignation => EplanName.Split('-').LastOrDefault() ?? string.Empty;

public long DeviceNumber
{
get
Expand Down
6 changes: 6 additions & 0 deletions src/Device/IDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public interface IDevice
/// </summary>
string EplanName { get; }

/// <summary>
/// Обозначение устройства без объекта. Пример: V1 <br/>
/// Используется если обозначение устройства не соответствует типу: "FC1" (подтип "C")
/// </summary>
string DeviceDesignation { get; }

/// <summary>
/// Описание устройства.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/TechObject/Base/Properties/ActionParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public void ModifyDevName(int newID, int oldID, string objName)

if (dev.ObjectNumber == newID && oldID != -1)
{
SetNewValue($"{objName}{oldID}{dev.DeviceType}{dev.DeviceNumber}");
SetNewValue($"{objName}{oldID}{dev.DeviceDesignation}");
}
if (oldID == -1 || oldID == dev.ObjectNumber)
{
SetNewValue($"{objName}{newID}{dev.DeviceType}{dev.DeviceNumber}");
SetNewValue($"{objName}{newID}{dev.DeviceDesignation}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ private string ModifyDevNameChangeTechNumber(string techObjectName, int index, i
//Для устройств в пределах объекта меняем номер объекта.
if (objNum == newID && oldID != -1)
{ // 1 -> 2 - COAG2V1 --> COAG1V1
return $"{objName}{oldID}{device.DeviceType}{device.DeviceNumber}";
return $"{objName}{oldID}{device.DeviceDesignation}";
}
if (oldID == -1 || oldID == objNum)
{ // COAG1V1 --> COAG(new_id)V1; COAGxV1 -> COAG1V1, COAG2V1 ...
return $"{objName}{newID}{device.DeviceType}{device.DeviceNumber}";
return $"{objName}{newID}{device.DeviceDesignation}";
}

return string.Empty;
Expand Down