diff --git a/libraries/MTConnect.NET-Common/Agents/IMTConnectAgent.cs b/libraries/MTConnect.NET-Common/Agents/IMTConnectAgent.cs index 2d39493c..5e8da710 100644 --- a/libraries/MTConnect.NET-Common/Agents/IMTConnectAgent.cs +++ b/libraries/MTConnect.NET-Common/Agents/IMTConnectAgent.cs @@ -138,9 +138,17 @@ public interface IMTConnectAgent #region "Entities" - IDevice GetDevice(string deviceKey, Version mtconnectVersion = null); + IDevice GetDevice(string deviceKey); - IEnumerable GetDevices(Version mtconnectVersion = null); + IDevice GetDevice(string deviceKey, Version mtconnectVersion); + + IEnumerable GetDevices(); + + IEnumerable GetDevices(Version mtconnectVersion); + + IEnumerable GetDevices(string deviceType); + + IEnumerable GetDevices(string deviceType, Version mtconnectVersion); IDataItem GetDataItem(string deviceKey, string dataItemKey); @@ -340,5 +348,6 @@ public interface IMTConnectAgent // Task GetResponseState(string deviceName, string interfaceId); #endregion + } } \ No newline at end of file diff --git a/libraries/MTConnect.NET-Common/Agents/MTConnectAgent.cs b/libraries/MTConnect.NET-Common/Agents/MTConnectAgent.cs index 7907ffa2..93a37bb7 100644 --- a/libraries/MTConnect.NET-Common/Agents/MTConnectAgent.cs +++ b/libraries/MTConnect.NET-Common/Agents/MTConnectAgent.cs @@ -126,8 +126,15 @@ public string Sender /// public DateTime DeviceModelChangeTime => _deviceModelChangeTime.ToDateTime(); + + /// + /// The Function to use to Process Observations. This can be used to transform values or trigger custom actions + /// public Func ProcessObservationFunction { get; set; } + /// + /// The Function to use to Process Assets. This can be used to transform values or trigger custom actions + /// public Func ProcessAssetFunction { get; set; } #endregion @@ -333,7 +340,24 @@ protected List ProcessDevices(IEnumerable 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) @@ -350,7 +374,22 @@ public IDevice GetDevice(string deviceKey, Version mtconnectVersion = null) return null; } - public IEnumerable GetDevices(Version mtconnectVersion = null) + public IEnumerable GetDevices() + { + var allDevices = new List(); + 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 GetDevices(Version mtconnectVersion) { var allDevices = new List(); allDevices.Add(_agent); @@ -365,7 +404,22 @@ public IEnumerable GetDevices(Version mtconnectVersion = null) return null; } - public IEnumerable GetDevices(string deviceType, Version mtconnectVersion = null) + public IEnumerable GetDevices(string deviceType) + { + var allDevices = new List(); + 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 GetDevices(string deviceType, Version mtconnectVersion) { var allDevices = new List(); if (string.IsNullOrEmpty(deviceType) || deviceType.ToLower() == "agent") allDevices.Add(Agent); diff --git a/libraries/MTConnect.NET-Common/Agents/MTConnectAgentBroker.cs b/libraries/MTConnect.NET-Common/Agents/MTConnectAgentBroker.cs index 469c97d6..faf5c00a 100644 --- a/libraries/MTConnect.NET-Common/Agents/MTConnectAgentBroker.cs +++ b/libraries/MTConnect.NET-Common/Agents/MTConnectAgentBroker.cs @@ -1103,7 +1103,11 @@ private IDeviceStreamOutput CreateDeviceStream(IDevice device, ref IObservationB { // Get All DataItems (Component Root DataItems and Composition DataItems) var dataItems = new List(); + + // Add DataItems if (!component.DataItems.IsNullOrEmpty()) dataItems.AddRange(component.DataItems); + + // Add Composition DataItems if (!component.Compositions.IsNullOrEmpty()) { foreach (var composition in component.Compositions) @@ -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(); @@ -1751,5 +1742,6 @@ protected override bool OnNewAssetAdded(IAsset asset) } #endregion + } } \ No newline at end of file