Hi everybody
I recently needed NAnt tasks for creating and deleting message queues
(MSMQ), and as I couldn't find any I wrote msmqcreate and msmqdelete. Now I
thought you might be interested in adding them to the project (although they
are very simple).
Note that for the tasks to run they need a reference to System.Messaging as
well as MSMQ installed on the machine.
Let me know what you think about it.
Cheers,
Alex
Please reply to: a_boegli at users.sourceforge.net
_________________________________________________________________
Don't just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/
#region GNU General Public License
//
// NAntContrib
// Copyright (C) 2005 Alex Bögli ([EMAIL PROTECTED])
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#endregion
using System;
using System.Globalization;
using System.Messaging;
using NAnt.Core;
using NAnt.Core.Attributes;
namespace NAnt.Contrib.Tasks.Msmq {
/// <summary>
/// Creates a new queue at the specified path on a Message Queuing
server.
/// </summary>
/// <remarks>
/// <para>
/// The syntax for the <I>path</I> parameter depends on the type of queue
it references.
/// </para>
/// <para>
/// Use <I>MachineName</I>\ <I>QueueName</I> for
public Queues and
/// <I>MachineName</I>\Private$\ <I>QueueName</I>
for private queues.
/// </para>
/// </remarks>
/// <example>
/// <code><![CDATA[
///<msmqcreate path=".\newPublicQueue" transactional="true" />
/// ]]></code>
/// </example>
[TaskName("msmqcreate")]
public class CreateTask : Task {
#region Private Instance Properties
private string _path;
private bool _transactional = false;
#endregion
#region Public Instance Properties
/// <summary>
/// Specifies the path of the queue to create.
/// </summary>
[TaskAttribute("path", Required=true)]
[StringValidator(AllowEmpty=false)]
public string Path {
get { return _path; }
set { _path = value; }
}
/// <summary>
/// Determines whether to create a transactional or a nontransactional
queue.
/// The default is <see langword="false" />.
/// </summary>
[TaskAttribute("transactional", Required=false)]
public bool Transactional {
get { return _transactional; }
set { _transactional = value; }
}
#endregion
#region Override implementation of Task
/// <summary>
/// Main task execution method
/// </summary>
protected override void ExecuteTask() {
try {
MessageQueue.Create(_path, _transactional);
Log(Level.Info, "Created message queue '{0}'.",
_path);
} catch(MessageQueueException ex) {
throw new
BuildException(string.Format(CultureInfo.InvariantCulture,
"Failure creating message queue '{0}'",
_path),
Location, ex);
}
}
#endregion
}
}
#region GNU General Public License
//
// NAntContrib
// Copyright (C) 2005 Alex Bögli ([EMAIL PROTECTED])
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#endregion
using System;
using System.Globalization;
using System.Messaging;
using NAnt.Core;
using NAnt.Core.Attributes;
namespace NAnt.Contrib.Tasks.Msmq {
/// <summary>
/// Deletes a queue on a Message Queuing server.
/// </summary>
/// <example>
/// <code><![CDATA[
///<msmqdelete path=".\newPublicQueue" />
/// ]]></code>
/// </example>
[TaskName("msmqdelete")]
public class DeleteTask : Task {
#region Private Instance Properties
private string _path;
#endregion
#region Public Instance Properties
/// <summary>
/// Specifies the path of the queue to delete.
/// </summary>
[TaskAttribute("path", Required=true)]
[StringValidator(AllowEmpty=false)]
public string Path {
get { return _path; }
set { _path = value; }
}
#endregion
#region Override implementation of Task
/// <summary>
/// Main task execution method
/// </summary>
protected override void ExecuteTask() {
try {
MessageQueue.Delete(_path);
Log(Level.Info, "Deleted message queue '{0}'.",
_path);
} catch(MessageQueueException ex) {
throw new
BuildException(string.Format(CultureInfo.InvariantCulture,
"Failure deleting message queue '{0}'",
_path),
Location, ex);
}
}
#endregion
}
}