Applied patch from Stephane Ramet to implement QueueBrowser and DeleteDestination. Thanks Stephane!
Fixes [AMQNET-517]. (See https://issues.apache.org/jira/browse/AMQNET-517)
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 @@
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 @@
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 @@
/// </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" />