-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fbd4a9
commit af634c5
Showing
15 changed files
with
433 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/MTConnect.NET-Common/Agents/IMTConnectAgentProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved. | ||
// TrakHound Inc. licenses this file to you under the MIT license. | ||
|
||
using MTConnect.Assets; | ||
using MTConnect.Observations.Input; | ||
|
||
namespace MTConnect.Agents | ||
{ | ||
public interface IMTConnectAgentProcessor | ||
{ | ||
IObservationInput Process(ProcessObservation observation); | ||
|
||
IAsset Process(IAsset asset); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/MTConnect.NET-Common/Agents/MTConnectAgentProcessors.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved. | ||
// TrakHound Inc. licenses this file to you under the MIT license. | ||
|
||
using MTConnect.Assets; | ||
using MTConnect.Observations.Input; | ||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
namespace MTConnect.Agents | ||
{ | ||
public class MTConnectAgentProcessors | ||
{ | ||
private static readonly ConcurrentBag<Type> _processorTypes = new ConcurrentBag<Type>(); | ||
private static readonly ConcurrentDictionary<string, IMTConnectAgentProcessor> _processors = new ConcurrentDictionary<string, IMTConnectAgentProcessor>(); | ||
|
||
|
||
public void Load() | ||
{ | ||
InitializeProcessors(); | ||
|
||
var processorTypes = _processorTypes.ToArray(); | ||
if (!processorTypes.IsNullOrEmpty()) | ||
{ | ||
foreach (var processorType in processorTypes) | ||
{ | ||
try | ||
{ | ||
// Create new Instance of the Controller and add to cached dictionary | ||
var processor = (IMTConnectAgentProcessor)Activator.CreateInstance(processorType, new object[] { }); | ||
|
||
var processorId = Guid.NewGuid().ToString(); | ||
|
||
_processors.TryAdd(processorId, processor); | ||
} | ||
catch { } | ||
} | ||
} | ||
} | ||
|
||
|
||
public IObservationInput Process(ProcessObservation observation) | ||
{ | ||
IObservationInput outputObservation = null; | ||
|
||
if (observation != null && !_processors.IsNullOrEmpty()) | ||
{ | ||
foreach (var processor in _processors) | ||
{ | ||
outputObservation = processor.Value.Process(observation); | ||
} | ||
} | ||
|
||
|
||
//outputObservation = new ObservationInput(); | ||
//outputObservation.DeviceKey = observation.DataItem.Device.Uuid; | ||
//outputObservation.DataItemKey = observation.DataItem.Id; | ||
//outputObservation.Values = observation.Values; | ||
//outputObservation.Timestamp = observation.Timestamp.ToUnixTime(); | ||
|
||
return outputObservation; | ||
} | ||
|
||
public IAsset Process(IAsset asset) | ||
{ | ||
var outputAsset = asset; | ||
|
||
if (asset != null && !_processors.IsNullOrEmpty()) | ||
{ | ||
foreach (var processor in _processors) | ||
{ | ||
outputAsset = processor.Value.Process(outputAsset); | ||
} | ||
} | ||
|
||
return outputAsset; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
//if (!_processors.IsNullOrEmpty()) | ||
//{ | ||
// foreach (var processor in _processors) | ||
// { | ||
// processor.Value.Stop(); | ||
// } | ||
|
||
// _processors.Clear(); | ||
//} | ||
} | ||
|
||
|
||
private static void InitializeProcessors() | ||
{ | ||
_processorTypes.Clear(); | ||
|
||
var assemblies = Assemblies.Get(); | ||
if (!assemblies.IsNullOrEmpty()) | ||
{ | ||
foreach (var assembly in assemblies) | ||
{ | ||
try | ||
{ | ||
var assemblyTypes = assembly.GetTypes(); | ||
if (!assemblyTypes.IsNullOrEmpty()) | ||
{ | ||
foreach (var type in assemblyTypes) | ||
{ | ||
if (typeof(IMTConnectAgentProcessor).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) | ||
{ | ||
_processorTypes.Add(type); | ||
} | ||
} | ||
} | ||
} | ||
catch { } | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.