Skip to content

Commit

Permalink
Added GetDevice(), GetDevices(), and GetDevice(string deviceType) met…
Browse files Browse the repository at this point in the history
…hods without Version parameter
  • Loading branch information
PatrickRitchie committed Dec 13, 2023
1 parent ce447c8 commit 3b97913
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 18 deletions.
13 changes: 11 additions & 2 deletions libraries/MTConnect.NET-Common/Agents/IMTConnectAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,17 @@ public interface IMTConnectAgent

#region "Entities"

IDevice GetDevice(string deviceKey, Version mtconnectVersion = null);
IDevice GetDevice(string deviceKey);

IEnumerable<IDevice> GetDevices(Version mtconnectVersion = null);
IDevice GetDevice(string deviceKey, Version mtconnectVersion);

IEnumerable<IDevice> GetDevices();

IEnumerable<IDevice> GetDevices(Version mtconnectVersion);

IEnumerable<IDevice> GetDevices(string deviceType);

IEnumerable<IDevice> GetDevices(string deviceType, Version mtconnectVersion);


IDataItem GetDataItem(string deviceKey, string dataItemKey);
Expand Down Expand Up @@ -340,5 +348,6 @@ public interface IMTConnectAgent
// Task<Interfaces.InterfaceResponseState> GetResponseState(string deviceName, string interfaceId);

#endregion

}
}
60 changes: 57 additions & 3 deletions libraries/MTConnect.NET-Common/Agents/MTConnectAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,15 @@ public string Sender
/// </summary>
public DateTime DeviceModelChangeTime => _deviceModelChangeTime.ToDateTime();


/// <summary>
/// The Function to use to Process Observations. This can be used to transform values or trigger custom actions
/// </summary>
public Func<ProcessObservation, IObservationInput> ProcessObservationFunction { get; set; }

/// <summary>
/// The Function to use to Process Assets. This can be used to transform values or trigger custom actions
/// </summary>
public Func<IAsset, IAsset> ProcessAssetFunction { get; set; }

#endregion
Expand Down Expand Up @@ -333,7 +340,24 @@ protected List<IDevice> ProcessDevices(IEnumerable<IDevice> devices, Version mtc
}


public IDevice GetDevice(string deviceKey, Version mtconnectVersion = null)
public IDevice GetDevice(string deviceKey)
{
var deviceUuid = GetDeviceUuid(deviceKey);
if (deviceUuid != null)
{
IDevice device = null;
if (deviceUuid == _agent.Uuid) device = _agent;
if (device == null) _devices.TryGetValue(deviceUuid, out device);
if (device != null)
{
return device;
}
}

return null;
}

public IDevice GetDevice(string deviceKey, Version mtconnectVersion)
{
var deviceUuid = GetDeviceUuid(deviceKey);
if (deviceUuid != null)
Expand All @@ -350,7 +374,22 @@ public IDevice GetDevice(string deviceKey, Version mtconnectVersion = null)
return null;
}

public IEnumerable<IDevice> GetDevices(Version mtconnectVersion = null)
public IEnumerable<IDevice> GetDevices()
{
var allDevices = new List<IDevice>();
allDevices.Add(_agent);
var devices = _devices.Select(o => o.Value).ToList();
if (!devices.IsNullOrEmpty()) allDevices.AddRange(devices);

if (!allDevices.IsNullOrEmpty())
{
return allDevices;
}

return null;
}

public IEnumerable<IDevice> GetDevices(Version mtconnectVersion)
{
var allDevices = new List<IDevice>();
allDevices.Add(_agent);
Expand All @@ -365,7 +404,22 @@ public IEnumerable<IDevice> GetDevices(Version mtconnectVersion = null)
return null;
}

public IEnumerable<IDevice> GetDevices(string deviceType, Version mtconnectVersion = null)
public IEnumerable<IDevice> GetDevices(string deviceType)
{
var allDevices = new List<IDevice>();
if (string.IsNullOrEmpty(deviceType) || deviceType.ToLower() == "agent") allDevices.Add(Agent);
var devices = _devices.Select(o => o.Value).ToList();
if (!devices.IsNullOrEmpty()) allDevices.AddRange(devices);

if (!allDevices.IsNullOrEmpty())
{
return allDevices;
}

return null;
}

public IEnumerable<IDevice> GetDevices(string deviceType, Version mtconnectVersion)
{
var allDevices = new List<IDevice>();
if (string.IsNullOrEmpty(deviceType) || deviceType.ToLower() == "agent") allDevices.Add(Agent);
Expand Down
18 changes: 5 additions & 13 deletions libraries/MTConnect.NET-Common/Agents/MTConnectAgentBroker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,11 @@ private IDeviceStreamOutput CreateDeviceStream(IDevice device, ref IObservationB
{
// Get All DataItems (Component Root DataItems and Composition DataItems)
var dataItems = new List<IDataItem>();

// Add DataItems
if (!component.DataItems.IsNullOrEmpty()) dataItems.AddRange(component.DataItems);

// Add Composition DataItems
if (!component.Compositions.IsNullOrEmpty())
{
foreach (var composition in component.Compositions)
Expand All @@ -1128,19 +1132,6 @@ private IDeviceStreamOutput CreateDeviceStream(IDevice device, ref IObservationB
}
}

//// Add ComponentStream for Device
//var deviceComponentStream = new ComponentStreamOutput();
//deviceComponentStream.ComponentId = device.Id;
//deviceComponentStream.ComponentType = device.Type;
//deviceComponentStream.Component = device;
//deviceComponentStream.Name = device.Name;
//deviceComponentStream.Uuid = device.Uuid;
//deviceComponentStream.Observations = GetObservations(device.Uuid, ref dataItemResults, device.DataItems, mtconnectVersion);
//if (deviceComponentStream.Observations != null && deviceComponentStream.Observations.Length > 0)
//{
// componentStreams.Add(deviceComponentStream);
//}

if (componentStreams.Count > 0)
{
deviceStream.ComponentStreams = componentStreams.ToArray();
Expand Down Expand Up @@ -1751,5 +1742,6 @@ protected override bool OnNewAssetAdded(IAsset asset)
}

#endregion

}
}

0 comments on commit 3b97913

Please sign in to comment.