You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by df...@apache.org on 2021/04/09 20:12:18 UTC

[activemq-nms-msmq] 02/05: Applied patch from Stephane Ramet to implement QueueBrowser and DeleteDestination. Thanks Stephane! Fixes [AMQNET-517]. (See https://issues.apache.org/jira/browse/AMQNET-517)

This is an automated email from the ASF dual-hosted git repository.

dfoulks pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-nms-msmq.git

commit 51ec9a290ca7bc352d50e4d18599776cca8423b9
Author: Jim Gomes <jg...@apache.org>
AuthorDate: Wed Jan 13 23:24:08 2016 +0000

    Applied patch from Stephane Ramet to implement QueueBrowser and DeleteDestination.  Thanks Stephane!
    Fixes [AMQNET-517]. (See https://issues.apache.org/jira/browse/AMQNET-517)
---
 src/main/csharp/QueueBrowser.cs | 141 ++++++++++++++++++++++++++++++++++++++++
 src/main/csharp/Session.cs      |  16 +++--
 vs2008-msmq.csproj              |   1 +
 3 files changed, 152 insertions(+), 6 deletions(-)

diff --git a/src/main/csharp/QueueBrowser.cs b/src/main/csharp/QueueBrowser.cs
new file mode 100644
index 0000000..32752c5
--- /dev/null
+++ b/src/main/csharp/QueueBrowser.cs
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections;
+using System.Messaging;
+using Apache.NMS;
+using Apache.NMS.Util;
+
+namespace Apache.NMS.MSMQ
+{
+	public class QueueBrowser : Apache.NMS.IQueueBrowser
+	{
+		private bool closed = false;
+		private bool disposed = false;
+
+        private readonly Session session;
+        private MessageQueue messageQueue;
+
+		public QueueBrowser(Session session, MessageQueue messageQueue)
+		{
+            this.session = session;
+            this.messageQueue = messageQueue;
+            if(null != this.messageQueue)
+            {
+                this.messageQueue.MessageReadPropertyFilter.SetAll();
+            }
+
+		}
+
+		~QueueBrowser()
+		{
+			Dispose(false);
+		}
+
+		#region IDisposable Members
+
+		///<summary>
+		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+		///</summary>
+		public void Dispose()
+		{
+			Dispose(true);
+			GC.SuppressFinalize(this);
+		}
+
+		protected void Dispose(bool disposing)
+		{
+			if(disposed)
+			{
+				return;
+			}
+
+			if(disposing)
+			{
+				// Dispose managed code here.
+			}
+
+			try
+			{
+				Close();
+			}
+			catch
+			{
+				// Ignore errors.
+			}
+
+			disposed = true;
+		}
+
+		#endregion
+
+		public void  Close()
+		{
+            if(messageQueue != null)
+            {
+                messageQueue.Dispose();
+                messageQueue = null;
+            }
+			closed = true;
+		}
+
+		public string MessageSelector
+		{
+			get { throw new NotSupportedException(); }
+		}
+
+		public IQueue Queue
+		{
+			get { return new Queue(this.messageQueue.Path); }
+		}
+
+		internal class Enumerator : IEnumerator
+		{
+			private readonly Session session;
+			private readonly MessageEnumerator innerEnumerator;
+
+			public Enumerator(Session session, MessageQueue messageQueue)
+			{
+				this.session = session;
+				this.innerEnumerator = messageQueue.GetMessageEnumerator2();
+			}
+
+			public object Current
+			{
+				get
+				{
+					return this.session.MessageConverter.ToNmsMessage(this.innerEnumerator.Current);
+				}
+			}
+
+			public bool MoveNext()
+			{
+				return this.innerEnumerator.MoveNext();
+			}
+
+			public void Reset()
+			{
+				this.innerEnumerator.Reset();
+			}
+		}
+
+		public IEnumerator GetEnumerator()
+		{
+			return new Enumerator(this.session, this.messageQueue);
+		}
+	}
+}
diff --git a/src/main/csharp/Session.cs b/src/main/csharp/Session.cs
index 9ce99f6..5172c08 100644
--- a/src/main/csharp/Session.cs
+++ b/src/main/csharp/Session.cs
@@ -90,12 +90,17 @@ namespace Apache.NMS.MSMQ
 
         public IQueueBrowser CreateBrowser(IQueue queue)
         {
-            throw new NotImplementedException();
+            return CreateBrowser(queue, null);
         }
 
         public IQueueBrowser CreateBrowser(IQueue queue, string selector)
         {
-            throw new NotImplementedException();
+            if(selector != null)
+            {
+                throw new NotSupportedException("Selectors are not supported by MSMQ");
+            }
+            MessageQueue msmqQueue = MessageConverter.ToMsmqDestination(queue);
+            return new QueueBrowser(this, msmqQueue);
         }
 
         public IQueue GetQueue(string name)
@@ -110,12 +115,12 @@ namespace Apache.NMS.MSMQ
 
         public ITemporaryQueue CreateTemporaryQueue()
         {
-            throw new NotSupportedException("Tempoary Queues are not supported by MSMQ");
+            throw new NotSupportedException("Temporary Queues are not supported by MSMQ");
         }
 
         public ITemporaryTopic CreateTemporaryTopic()
         {
-            throw new NotSupportedException("Tempoary Topics are not supported by MSMQ");
+            throw new NotSupportedException("Temporary Topics are not supported by MSMQ");
         }
 
         /// <summary>
@@ -123,8 +128,7 @@ namespace Apache.NMS.MSMQ
         /// </summary>
         public void DeleteDestination(IDestination destination)
         {
-            // TODO: Implement if possible.  If not possible, then change exception to NotSupportedException().
-            throw new NotImplementedException();
+            MessageQueue.Delete(destination.ToString());
         }
 
         public IMessage CreateMessage()
diff --git a/vs2008-msmq.csproj b/vs2008-msmq.csproj
index 6221c67..8a20d12 100644
--- a/vs2008-msmq.csproj
+++ b/vs2008-msmq.csproj
@@ -80,6 +80,7 @@
     <Compile Include="src\main\csharp\MessageProducer.cs" />
     <Compile Include="src\main\csharp\ObjectMessage.cs" />
     <Compile Include="src\main\csharp\Queue.cs" />
+    <Compile Include="src\main\csharp\QueueBrowser.cs" />
     <Compile Include="src\main\csharp\Session.cs" />
     <Compile Include="src\main\csharp\StreamMessage.cs" />
     <Compile Include="src\main\csharp\TextMessage.cs" />