@@ -38,7 +38,8 @@ public class Module : MTConnectAgentModule
3838 private static readonly object _lastSentSequenceLock = new object ( ) ;
3939 private long _totalIncomingObservations = 0 ;
4040 private long _lastSentSequence = 0 ;
41-
41+ private const string DirectoryBuffer = "buffer" ;
42+ private const string LastSentSequenceFileName = "mqttrelay_last_sent.seq" ;
4243
4344 public Module ( IMTConnectAgentBroker mtconnectAgent , object configuration ) : base ( mtconnectAgent )
4445 {
@@ -334,17 +335,25 @@ private async Task RelayBufferedObservations()
334335 }
335336 }
336337
337- private static string GetLastSentSequenceFilePath ( )
338+ private static string GetLastSentSequenceFilePath ( IAgentApplicationConfiguration agentConfig = null )
338339 {
339- var bufferDir = Path . Combine ( AppContext . BaseDirectory , "buffer" ) ;
340- Directory . CreateDirectory ( bufferDir ) ;
341- return Path . Combine ( bufferDir , "mqttrelay_last_sent.seq" ) ;
340+ string baseDir = ! string . IsNullOrEmpty ( agentConfig ? . DurableBufferPath )
341+ ? agentConfig . DurableBufferPath
342+ : DirectoryBuffer ;
343+
344+ if ( ! Path . IsPathRooted ( baseDir ) )
345+ {
346+ baseDir = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , baseDir ) ;
347+ }
348+ Directory . CreateDirectory ( baseDir ) ;
349+ return Path . Combine ( baseDir , LastSentSequenceFileName ) ;
342350 }
343351
344352 private ulong GetLastSentSequence ( )
345353 {
346- if ( ! _configuration . DurableRelay ) return 0 ; // Default
347- var path = GetLastSentSequenceFilePath ( ) ;
354+ if ( ! _configuration . DurableRelay ) return 0 ;
355+ var agentConfig = Agent ? . Configuration as IAgentApplicationConfiguration ;
356+ var path = GetLastSentSequenceFilePath ( agentConfig ) ;
348357 lock ( _lastSentSequenceLock )
349358 {
350359 if ( File . Exists ( path ) )
@@ -359,7 +368,8 @@ private ulong GetLastSentSequence()
359368 private void SetLastSentSequence ( ulong seq )
360369 {
361370 if ( ! _configuration . DurableRelay ) return ; // Default
362- var path = GetLastSentSequenceFilePath ( ) ;
371+ var agentConfig = Agent ? . Configuration as IAgentApplicationConfiguration ;
372+ var path = GetLastSentSequenceFilePath ( agentConfig ) ;
363373 lock ( _lastSentSequenceLock )
364374 {
365375 File . WriteAllText ( path , seq . ToString ( ) ) ;
0 commit comments