public void PutMessageWithNoSyncPoint( ref string queueName, ref IBM.WMQ.MQMessage mqMessage )
        {
            if( false == _existingQueues.ContainsKey( queueName ) )
                return;

            try
            {
                IBM.WMQ.MQPutMessageOptions mqPutMessageOptions         = new IBM.WMQ.MQPutMessageOptions();
                mqPutMessageOptions.Options|= IBM.WMQ.MQC.MQPMO_NO_SYNCPOINT;

                IBM.WMQ.MQQueue	queue = (IBM.WMQ.MQQueue) _existingQueues[ queueName ];
                queue.Put( mqMessage, mqPutMessageOptions );
            }

                // some nasty error 1
            catch( IBM.WMQ.MQException mqException )
            {
                String errorMessage = mqException.ToString();
                throw new Exception( errorMessage, mqException );
            }

                // some nasty error 2
            catch( Exception exception )
            {
                String errorMessage = exception.ToString();
                throw new Exception( errorMessage, exception );
            }
        }
        public override bool Execute()
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();

            Log.LogMessage("Starting Websphere MQ transfer with " + TotalBatches.ToString() + " batchs with " + BatchSize.ToString() + " items each");

            queueManager = new IBM.WMQ.MQQueueManager(QueueManagerName);
            messageCount = TotalBatches;

            inputQueue = queueManager.AccessQueue(InputQueueName, IBM.WMQ.MQC.MQOO_INPUT_SHARED);
            Thread t = new Thread(ProcessMQQueue);
            t.Start();

            int count = 1;
            for (int i = 0; i < TotalBatches; i++)
            {
                IBM.WMQ.MQMessage msg = new IBM.WMQ.MQMessage();

                MemoryStream ms = new MemoryStream();
                StreamUtil.GenerateBigRequest(ms, false, count, count + (BatchSize - 1));
                MQUtil.StreamToMQMessage(ms, msg);
                queueManager.Put(OutputQueueName, msg);
                count += BatchSize;
                Log.LogMessage("Sent " + count.ToString());
            }

            while (!finished)
                Thread.Sleep(250);

            watch.Stop();
            Log.LogMessage("Total processing time: " + watch.Elapsed.TotalSeconds.ToString("0.00") + " seconds");

            return true;
        }
        public void CloseQueue(string queueName)
        {
            if(!_existingQueues.ContainsKey(queueName))
                return;

            IBM.WMQ.MQQueue	queue = (IBM.WMQ.MQQueue) _existingQueues[ queueName ];
            queue.Close();

            _existingQueues.Remove(queueName);
        }
        public int GetQueuBackoutLimit( ref string queueName )
        {
            if( false == _existingQueues.ContainsKey( queueName ) )
                return -1;

            int[]   selectors   = { IBM.WMQ.MQC.MQIA_BACKOUT_THRESHOLD, IBM.WMQ.MQC.MQCA_BACKOUT_REQ_Q_NAME };
            int[]   intAttrs    = new int[ 1 ];
            byte[]  charAttrs   = new byte[ IBM.WMQ.MQC.MQ_Q_NAME_LENGTH ];

            IBM.WMQ.MQQueue	queue = (IBM.WMQ.MQQueue) _existingQueues[ queueName ];
            queue.Inquire( selectors, intAttrs, charAttrs );

            return intAttrs[ 0 ];
        }
        public string GetBackoutQueueNameForQueue( ref string queueName )
        {
            if( false == _existingQueues.ContainsKey( queueName ) )
                return string.Empty;

            int[]   selectors   = { IBM.WMQ.MQC.MQIA_BACKOUT_THRESHOLD, IBM.WMQ.MQC.MQCA_BACKOUT_REQ_Q_NAME };
            int[]   intAttrs    = new int[ 1 ];
            byte[]  charAttrs   = new byte[ IBM.WMQ.MQC.MQ_Q_NAME_LENGTH ];

            IBM.WMQ.MQQueue	queue = (IBM.WMQ.MQQueue) _existingQueues[ queueName ];
            queue.Inquire( selectors, intAttrs, charAttrs );

            string qBackoutName = NovadisTools.PdfFactory.BiteToString( charAttrs ).Trim();

            return qBackoutName;
        }
        public bool OpenQueueForWrite(string queueName)
        {
            if(_existingQueues.Contains(queueName))
                return true;

            bool result = true;
            try
            {
                int queueOpenOptions    = IBM.WMQ.MQC.MQOO_OUTPUT;
                IBM.WMQ.MQQueue mqQueue = _mqQueueManager.AccessQueue(queueName, queueOpenOptions);

                _existingQueues.Add(queueName, mqQueue);
            }
            catch(IBM.WMQ.MQException mqException)
            {
                if( IBM.WMQ.MQC.MQRC_UNKNOWN_OBJECT_NAME == mqException.ReasonCode ) // there is no such queue
                {
                    // ... log or throw an exception of some type
                }
                else
                {
                    string errorMessage = String.Format // this line here is make more evident what is important to know about the error
                    (
                        "OpenQueueForWrite(): reasonCode={0}, details={1}",
                        mqException.ReasonCode,
                        mqException.ToString()
                    );

                    throw new Exception( errorMessage );
                }

                result = false;
            }
            catch( Exception exception )
            {
                _existingQueues.Remove( queueName );

                result = false;
            }

            return result;
        }
        public void DeleteMessageWithSyncPoint( ref string queueName, ref byte[] corelationId )
        {
            if( false == _existingQueues.ContainsKey( queueName ) )
                return;

            try
            {
                IBM.WMQ.MQGetMessageOptions mqGetMessageOptions = new IBM.WMQ.MQGetMessageOptions();
                mqGetMessageOptions.Options|= IBM.WMQ.MQC.MQGMO_SYNCPOINT;
                mqGetMessageOptions.Options|= IBM.WMQ.MQC.MQGMO_WAIT;
                mqGetMessageOptions.WaitInterval = 1000;
                mqGetMessageOptions.Options|= IBM.WMQ.MQC.MQMO_MATCH_CORREL_ID;

                IBM.WMQ.MQMessage   mqMessage = new IBM.WMQ.MQMessage();
                mqMessage.CorrelationId = corelationId;

                IBM.WMQ.MQQueue	queue = (IBM.WMQ.MQQueue) _existingQueues[ queueName ];
                queue.Get( mqMessage, mqGetMessageOptions );
            }
            catch( IBM.WMQ.MQException mqException ) // some nasty error 1
            {
                string errorMessage = mqException.ToString();

                if( 2033 == mqException.ReasonCode ) // there is no message on the queue
                    throw new MqNoMessageException( errorMessage );
                else
                {
                    errorMessage = String.Format
                    (
                        "getMessageWithSyncPoint(): reasonCode={0}, details={1}",
                        mqException.ReasonCode,
                        mqException.ToString()
                    );

                    throw new Exception( errorMessage );
                }
            }
            catch( Exception exception ) // some nasty error 2
            {
                throw new Exception( exception );
            }
        }