1 |
using System;
|
2 |
|
3 |
using IBM.WMQ;
|
4 |
using System.Collections;
|
5 |
|
6 |
namespace DaoCommon
|
7 |
{
|
8 |
public class MQHelper
|
9 |
{
|
10 |
/*
|
11 |
* MQ's egne exceptions er ikke så sigende - så ved at bruge denne wrapper får man en mere beskrivende Exception.Message
|
12 |
*/
|
13 |
public static MQQueue openQueueHelper(string queueName, MQQueueManager mqMgr, int openOptions)
|
14 |
{
|
15 |
try
|
16 |
{
|
17 |
return mqMgr.AccessQueue(queueName, openOptions);
|
18 |
} catch (MQException e) {
|
19 |
throw new Exception("Error opening queue " + queueName + ": " + e.Message, e);
|
20 |
}
|
21 |
}
|
22 |
|
23 |
public static void closeQueueSafe(MQQueue queue)
|
24 |
{
|
25 |
if (queue != null && queue.IsOpen)
|
26 |
{
|
27 |
try
|
28 |
{
|
29 |
queue.Close();
|
30 |
}
|
31 |
catch (Exception e)
|
32 |
{
|
33 |
Console.WriteLine("Error cleaning up queue " + e.Message);
|
34 |
}
|
35 |
}
|
36 |
|
37 |
}
|
38 |
|
39 |
public static void closeQueueManagerSafe(MQQueueManager mqMgr)
|
40 |
{
|
41 |
if (mqMgr != null && mqMgr.IsOpen)
|
42 |
{
|
43 |
try
|
44 |
{
|
45 |
mqMgr.Close();
|
46 |
}
|
47 |
catch (Exception e)
|
48 |
{
|
49 |
Console.WriteLine("Error cleaning up qmgr " + e.Message);
|
50 |
}
|
51 |
}
|
52 |
}
|
53 |
|
54 |
public static Hashtable getConnectionProperties(string mqHost, string mqChannel)
|
55 |
{
|
56 |
Hashtable connProperties = new Hashtable();
|
57 |
connProperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
|
58 |
connProperties.Add(MQC.HOST_NAME_PROPERTY, mqHost);
|
59 |
connProperties.Add(MQC.CHANNEL_PROPERTY, mqChannel);
|
60 |
return connProperties;
|
61 |
}
|
62 |
}
|
63 |
}
|