public DirectoryQueueMessage GetMessage(TimeSpan?retrieveVisibilityTimeout = null) { if (!System.IO.Directory.Exists(this.queuePath)) { return(null); } try { this.AcquireLock(); System.Diagnostics.Debug.WriteLine("Get Message"); string msgpath = null; System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(this.queuePath); foreach (var t in dInfo.GetFileSystemInfos($"*{msgExtension}").OrderBy(p => p.CreationTime)) { if ((t.Attributes & System.IO.FileAttributes.Hidden) != System.IO.FileAttributes.Hidden) { msgpath = t.FullName; } } if (null == msgpath) { return(null); } DirectoryQueueMessage nextMessage = DirectoryQueueMessage.FromQueueFile(msgpath); System.Diagnostics.Debug.WriteLine(msgpath); // NOTE: we release the lock after we have the message because we update the visibility for the file nextMessage.DequeueCount++; nextMessage.Hide(retrieveVisibilityTimeout); nextMessage.Store(); // make sure dequeue count has been stored correctly. return(nextMessage); } finally { this.ReleaseLock(); } }
public void AddMessage(DirectoryQueueMessage msg, TimeSpan?timeToLive, TimeSpan?initialVisibilityDelay) { try { this.AcquireLock(); System.Diagnostics.Debug.WriteLine("Add Message"); // set the msg name; string fileNameAndPath = System.IO.Path.Combine(this.queuePath, DateTime.Now.Ticks.ToString("0000000000") + msgExtension); while (System.IO.File.Exists(fileNameAndPath)) { fileNameAndPath = System.IO.Path.Combine(this.queuePath, DateTime.Now.Ticks.ToString("0000000000") + msgExtension); } msg.SetTimeToLive(timeToLive); msg.SetInitialVisibilityDelay(initialVisibilityDelay); msg.LocalPathToQueuedMessage = fileNameAndPath; msg.Store(); } finally { this.ReleaseLock(); } }