-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MTConnectAgentProcessor base class and added Log() method for p…
…rocessors
- Loading branch information
1 parent
cbb53e2
commit 37b131e
Showing
5 changed files
with
91 additions
and
0 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
48 changes: 48 additions & 0 deletions
48
libraries/MTConnect.NET-Common/Agents/MTConnectAgentProcessor.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,48 @@ | ||
// Copyright(c) 2023 TrakHound Inc., All Rights Reserved. | ||
// TrakHound Inc. licenses this file to you under the MIT license. | ||
|
||
using MTConnect.Assets; | ||
using MTConnect.Input; | ||
using MTConnect.Logging; | ||
|
||
namespace MTConnect.Agents | ||
{ | ||
public abstract class MTConnectAgentProcessor : IMTConnectAgentProcessor | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Description { get; set; } | ||
|
||
|
||
public event MTConnectLogEventHandler LogReceived; | ||
|
||
|
||
public IObservationInput Process(ProcessObservation observation) => OnProcess(observation); | ||
|
||
public IAsset Process(IAsset asset) => OnProcess(asset); | ||
|
||
|
||
protected virtual IObservationInput OnProcess(ProcessObservation observation) | ||
{ | ||
if (observation != null) | ||
{ | ||
var observationInput = new ObservationInput(); | ||
observationInput.DeviceKey = observation.DataItem?.Device?.Uuid; | ||
observationInput.DataItemKey = observation.DataItem?.Id; | ||
observationInput.Timestamp = observation.Timestamp.ToUnixTime(); | ||
observationInput.Values = observation.Values; | ||
return observationInput; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected virtual IAsset OnProcess(IAsset asset) => asset; | ||
|
||
|
||
protected void Log(MTConnectLogLevel logLevel, string message) | ||
{ | ||
if (LogReceived != null) LogReceived.Invoke(this, logLevel, message); | ||
} | ||
} | ||
} |
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