@@ -22,6 +22,7 @@ public class Module : MTConnectAdapterModule
2222
2323 private readonly object _lock = new object ( ) ;
2424 private readonly ModuleConfiguration _configuration ;
25+ private readonly TimeZoneInfo _timeZoneInfo ;
2526 private readonly AgentClientConnectionListener _connectionListener ;
2627 private readonly Dictionary < string , AgentClient > _clients = new Dictionary < string , AgentClient > ( ) ;
2728 private CancellationTokenSource _stop ;
@@ -34,6 +35,8 @@ public Module(string id, object moduleConfiguration) : base(id)
3435 _configuration = AdapterApplicationConfiguration . GetConfiguration < ModuleConfiguration > ( moduleConfiguration ) ;
3536 if ( _configuration == null ) _configuration = new ModuleConfiguration ( ) ;
3637
38+ _timeZoneInfo = GetTimeZone ( _configuration ) ;
39+
3740 _connectionListener = new AgentClientConnectionListener ( _configuration . Port , _configuration . Heartbeat ) ;
3841 _connectionListener . ClientConnected += AgentClientConnected ;
3942 _connectionListener . ClientDisconnected += AgentClientDisconnected ;
@@ -66,8 +69,12 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
6669 if ( ! dataItems . IsNullOrEmpty ( ) )
6770 {
6871 var shdrDataItems = new List < ShdrDataItem > ( ) ;
69- foreach ( var x in dataItems ) shdrDataItems . Add ( new ShdrDataItem ( x ) ) ;
70- var shdrLine = ShdrDataItem . ToString ( shdrDataItems ) ;
72+ foreach ( var x in dataItems )
73+ {
74+ shdrDataItems . Add ( new ShdrDataItem ( x ) ) ;
75+ }
76+
77+ var shdrLine = ShdrDataItem . ToString ( shdrDataItems , timeZoneInfo : _timeZoneInfo ) ;
7178 WriteLine ( shdrLine ) ;
7279 }
7380
@@ -78,6 +85,8 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
7885 foreach ( var x in messages )
7986 {
8087 var shdrModel = new ShdrMessage ( x ) ;
88+ shdrModel . TimeZoneInfo = _timeZoneInfo ;
89+
8190 var shdrLine = shdrModel . ToString ( ) ;
8291 WriteLine ( shdrLine ) ;
8392 }
@@ -90,6 +99,8 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
9099 foreach ( var x in conditions )
91100 {
92101 var shdrModel = new ShdrFaultState ( new ConditionFaultStateObservationInput ( x ) ) ;
102+ shdrModel . TimeZoneInfo = _timeZoneInfo ;
103+
93104 var shdrLine = shdrModel . ToString ( ) ;
94105 WriteLine ( shdrLine ) ;
95106 }
@@ -102,6 +113,8 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
102113 foreach ( var x in dataSets )
103114 {
104115 var shdrModel = new ShdrDataSet ( new DataSetObservationInput ( x ) ) ;
116+ shdrModel . TimeZoneInfo = _timeZoneInfo ;
117+
105118 var shdrLine = shdrModel . ToString ( ) ;
106119 WriteLine ( shdrLine ) ;
107120 }
@@ -114,6 +127,8 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
114127 foreach ( var x in tables )
115128 {
116129 var shdrModel = new ShdrTable ( new TableObservationInput ( x ) ) ;
130+ shdrModel . TimeZoneInfo = _timeZoneInfo ;
131+
117132 var shdrLine = shdrModel . ToString ( ) ;
118133 WriteLine ( shdrLine ) ;
119134 }
@@ -126,6 +141,8 @@ public override bool AddObservations(IEnumerable<IObservationInput> observations
126141 foreach ( var x in timeSeries )
127142 {
128143 var shdrModel = new ShdrTimeSeries ( new TimeSeriesObservationInput ( x ) ) ;
144+ shdrModel . TimeZoneInfo = _timeZoneInfo ;
145+
129146 var shdrLine = shdrModel . ToString ( ) ;
130147 WriteLine ( shdrLine ) ;
131148 }
@@ -359,5 +376,27 @@ private static IEnumerable<string> SplitLines(string line)
359376
360377 #endregion
361378
379+
380+ private static TimeZoneInfo GetTimeZone ( ModuleConfiguration configuration )
381+ {
382+ if ( configuration != null )
383+ {
384+ if ( ! string . IsNullOrEmpty ( configuration . TimeZoneOutput ) )
385+ {
386+ var timeZoneDefinition = MTConnectTimeZone . Get ( configuration . TimeZoneOutput ) ;
387+ if ( timeZoneDefinition != null )
388+ {
389+ var timeZoneInfo = timeZoneDefinition . ToTimeZoneInfo ( ) ;
390+ if ( timeZoneInfo != null )
391+ {
392+ return timeZoneInfo ;
393+ }
394+ }
395+ }
396+ }
397+
398+ return TimeZoneInfo . Utc ;
399+ }
400+
362401 }
363402}
0 commit comments