Exemplo n.º 1
0
        public static string ReadAll(this MQMessage @this)
        {
            var message = @this.ReadString(@this.DataLength);

            @this.Seek(0);
            return(message);
        }
        internal override bool IsLast(MQMessage message)
        {
            cfh.Initialize(message);

            String current = null;
            int    count   = this.cfh.ParameterCount;

            while (count > 0)
            {
                PcfParameter p  = PcfParameter.NextParameter(message);
                int          id = p.Parameter;
                if (id == MQC.MQBACF_RESPONSE_SET)
                {
                    this.set.Add(p.GetStringValue());
                }
                else if (id == MQC.MQBACF_RESPONSE_ID)
                {
                    current = p.GetStringValue();
                    this.set.Add(current);
                }
                count--;
            }

            message.Seek(0);

            if ((this.cfh.Control == 1) && (current != null))
            {
                this.set.Remove(current);
            }
            return(this.set.Count == 0);
        }
Exemplo n.º 3
0
        protected MQMessage[] Send(int command, PCFParameter[] parameters)
        {
            if (parameters == null)
            {
                throw new Exception("Must specify parameters!");
            }
            MQQueue   queue   = this.qMgr.AccessQueue("SYSTEM.DEFAULT.MODEL.QUEUE", 0x2021);
            MQMessage message = new MQMessage();

            message.ReplyToQueueName = queue.Name;
            message.MessageType      = 1;
            message.Feedback         = 0;
            message.Format           = "MQADMIN ";
            message.Report           = 0;
            MQCFH.Write(message, command, parameters.Length);
            for (int i = 0; i < parameters.Length; i++)
            {
                parameters[i].Write(message);
            }
            MQQueue             queue2 = this.qMgr.AccessQueue(this.qMgr.CommandInputQueueName, 0x2030);
            MQPutMessageOptions pmo    = new MQPutMessageOptions();

            pmo.Options = 0x40;
            queue2.Put(message, pmo);
            MQGetMessageOptions gmo = new MQGetMessageOptions();

            gmo.Options      = 0x2001;
            gmo.WaitInterval = this.waitInterval;
            gmo.MatchOptions = 2;
            ArrayList list     = new ArrayList();
            MQMessage message2 = null;
            int       compCode = 0;
            int       reason   = 0;
            int       num4     = 1;

            do
            {
                message2 = new MQMessage();
                message2.CorrelationId = message.MessageId;
                queue.Get(message2, gmo);
                message2.SkipBytes(20);
                num4     = message2.ReadInt4();
                compCode = message2.ReadInt4();
                reason   = message2.ReadInt4();
                message2.Seek(0);
                if (compCode != 0)
                {
                    throw new PCFException(compCode, reason);
                }
                list.Add(message2);
            }while (num4 == 0);
            queue2.Close();
            queue.Close();
            return((MQMessage[])list.ToArray(typeof(MQMessage)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Helper method to read a message from an MQ Series queue
        /// </summary>
        ///
        /// <param name="queueManagerName">The name of the MQ Series queue manager</param>
        /// <param name="queueName">The name of the MQ Series queue to read from</param>
        /// <param name="waitDelay">The time to wait for the message to be read from the queue</param>
        /// <param name="context">The BizUnit context object which holds state and is passed between test steps</param>
        /// <param name="msgID">[out] the MQ Series message ID</param>
        /// <returns>String containing the data from the MQ series message</returns>
        static public string ReadMessage(string queueManagerName, string queueName, int waitDelay, Context context, out byte[] msgID)
        {
            MQQueueManager queueManager = null;
            MQQueue        receiveQueue = null;
            string         message      = null;

            try
            {
                context.LogInfo("Opening queue manager: \"{0}\"", queueManagerName);
                queueManager = new MQQueueManager(queueManagerName);

                context.LogInfo("Opening queue: \"{0}\"", queueName);
                receiveQueue = queueManager.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);

                MQMessage           mqMsg     = new MQMessage();
                MQGetMessageOptions mqMsgOpts = new MQGetMessageOptions();
                mqMsgOpts.WaitInterval = waitDelay * 1000;
                mqMsgOpts.Options      = MQC.MQGMO_WAIT;

                context.LogInfo("Reading message from queue '{0}'.", queueName);

                receiveQueue.InhibitGet = MQC.MQQA_GET_ALLOWED;

                receiveQueue.Get(mqMsg, mqMsgOpts);

                if (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) == 0)
                {
                    mqMsg.Seek(0);
                    message = System.Text.UTF8Encoding.UTF8.GetString(mqMsg.ReadBytes(mqMsg.MessageLength));
                    msgID   = mqMsg.MessageId;
                }
                else
                {
                    throw new NotSupportedException(string.Format("Unsupported message format: '{0}' read from queue: {1}.", mqMsg.Format, queueName));
                }
            }
            finally
            {
                if (receiveQueue != null)
                {
                    receiveQueue.Close();
                }

                if (queueManager != null)
                {
                    queueManager.Close();
                }
            }

            return(message);
        }
        internal override bool IsLast(MQMessage message)
        {
            message.SkipBytes(20);
            var end      = message.ReadInt4() != 0;
            var compCode = message.ReadInt4();
            var reason   = message.ReadInt4();

            message.Seek(0);
            if (compCode != 0)
            {
                throw new PcfException(compCode, reason);
            }
            return(end);
        }
Exemplo n.º 6
0
		/// <summary>
		/// Helper method to read a message from an MQ Series queue
		/// </summary>
		/// 
		/// <param name="queueManagerName">The name of the MQ Series queue manager</param>
		/// <param name="queueName">The name of the MQ Series queue to read from</param>
		/// <param name="waitDelay">The time to wait for the message to be read from the queue</param>
		/// <param name="context">The BizUnit context object which holds state and is passed between test steps</param>
		/// <param name="msgID">[out] the MQ Series message ID</param>
		/// <returns>String containing the data from the MQ series message</returns>
		static public string ReadMessage(string queueManagerName, string queueName, int waitDelay, Context context, out byte[] msgID)
		{
			MQQueueManager queueManager = null;
			MQQueue receiveQueue = null;
			string message = null;

			try 
			{
				context.LogInfo("Opening queue manager: \"{0}\"", queueManagerName);
				queueManager = new MQQueueManager(queueManagerName);
				
				context.LogInfo("Opening queue: \"{0}\"", queueName);
				receiveQueue = queueManager.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
			
				MQMessage mqMsg = new MQMessage();
				MQGetMessageOptions mqMsgOpts = new MQGetMessageOptions();
				mqMsgOpts.WaitInterval = waitDelay*1000;  
				mqMsgOpts.Options = MQC.MQGMO_WAIT;

				context.LogInfo("Reading message from queue '{0}'.", queueName);

				receiveQueue.Get(mqMsg,mqMsgOpts);

				if(mqMsg.Format.CompareTo(MQC.MQFMT_STRING)==0)
				{
					mqMsg.Seek(0);
					message = System.Text.UTF8Encoding.UTF8.GetString(mqMsg.ReadBytes(mqMsg.MessageLength));
					msgID = mqMsg.MessageId;
				}
				else
				{
					throw new NotSupportedException(string.Format("Unsupported message format: '{0}' read from queue: {1}.", mqMsg.Format, queueName));
				}
			}
			finally
			{
				if (receiveQueue != null)
				{
					receiveQueue.Close();
				}

				if (queueManager != null)
				{
					queueManager.Close();
				}
			}

			return message;
		}
Exemplo n.º 7
0
        private MQMessage CopyMDFromOldMsgIntoReportMsg(MQMessage oldMsg, MQMessage newMsg, int putOpts)
        {
            MQMessage message;
            uint      method = 0x231;

            this.TrEntry(method, new object[] { oldMsg, newMsg, putOpts });
            try
            {
                if (((oldMsg.Report & 0x4000) != 0) && ((oldMsg.Report & 0x8000000) != 0))
                {
                    newMsg.Report = 0x8000000;
                }
                else
                {
                    newMsg.Report = 0;
                }
                newMsg.MessageType = 4;
                if ((oldMsg.Report & 0x4000) != 0)
                {
                    newMsg.Expiry = oldMsg.Expiry;
                }
                else
                {
                    newMsg.Expiry = -1;
                }
                if ((oldMsg.Report & 0x40) != 0)
                {
                    newMsg.CorrelationId = oldMsg.CorrelationId;
                }
                else if ((putOpts & 0x80) == 0)
                {
                    newMsg.CorrelationId = oldMsg.CorrelationId;
                }
                newMsg.ReplyToQueueName        = "";
                newMsg.ReplyToQueueManagerName = "";
                byte[] b = new byte[oldMsg.MessageLength];
                oldMsg.Seek(0);
                oldMsg.ReadFully(ref b);
                newMsg.Write(b);
                message = newMsg;
            }
            finally
            {
                base.TrExit(method);
            }
            return(message);
        }
Exemplo n.º 8
0
        private MQMessage CopyMDFromOldMsgIntoFwdMsg(MQMessage oldMsg, MQMessage newMsg)
        {
            MQMessage message;
            uint      method = 0x22f;

            this.TrEntry(method, new object[] { oldMsg, newMsg });
            try
            {
                newMsg.AccountingToken       = oldMsg.AccountingToken;
                newMsg.ApplicationIdData     = oldMsg.ApplicationIdData;
                newMsg.ApplicationOriginData = oldMsg.ApplicationOriginData;
                newMsg.CharacterSet          = oldMsg.CharacterSet;
                newMsg.CorrelationId         = oldMsg.CorrelationId;
                newMsg.Encoding                = oldMsg.Encoding;
                newMsg.Expiry                  = oldMsg.Expiry;
                newMsg.Feedback                = oldMsg.Feedback;
                newMsg.Format                  = oldMsg.Format;
                newMsg.GroupId                 = oldMsg.GroupId;
                newMsg.MessageFlags            = oldMsg.MessageFlags;
                newMsg.MessageId               = oldMsg.MessageId;
                newMsg.MessageSequenceNumber   = oldMsg.MessageSequenceNumber;
                newMsg.MessageType             = oldMsg.MessageType;
                newMsg.Offset                  = oldMsg.Offset;
                newMsg.OriginalLength          = oldMsg.OriginalLength;
                newMsg.Persistence             = oldMsg.Persistence;
                newMsg.Priority                = oldMsg.Priority;
                newMsg.PutApplicationName      = oldMsg.PutApplicationName;
                newMsg.PutApplicationType      = oldMsg.PutApplicationType;
                newMsg.PutDateTime             = oldMsg.PutDateTime;
                newMsg.ReplyToQueueManagerName = oldMsg.ReplyToQueueManagerName;
                newMsg.ReplyToQueueName        = oldMsg.ReplyToQueueName;
                newMsg.Report                  = oldMsg.Report;
                newMsg.UserId                  = oldMsg.UserId;
                byte[] b = new byte[oldMsg.MessageLength];
                oldMsg.Seek(0);
                oldMsg.ReadFully(ref b);
                newMsg.Write(b);
                message = newMsg;
            }
            finally
            {
                base.TrExit(method);
            }
            return(message);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Helper method to read a message from an MQ Series queue
        /// </summary>
        /// <param name="queueManagerName">The name of the MQ Series queue manager</param>
        /// <param name="queueName">The name of the MQ Series queue to read from</param>
        /// <param name="waitDelay">The time to wait for the message to be read from the queue</param>
        /// <param name="context">The BizUnit context object which holds state and is passed between test steps</param>
        /// <param name="msgID">[out] the MQ Series message ID</param>
        /// <returns>String containing the data from the MQ series message</returns>
        public static string ReadMessage(string queueManagerName, string queueName, int waitDelay, Context context,
                                         out byte[] msgID)
        {
            string message = null;

            context.LogInfo("Opening queue manager: \"{0}\"", queueManagerName);
            using (var queueManager = new MQQueueManager(queueManagerName))
            {
                context.LogInfo("Opening queue: \"{0}\"", queueName);
                using (
                    var receiveQueue = queueManager.AccessQueue(queueName,
                                                                MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING))
                {
                    var mqMsg     = new MQMessage();
                    var mqMsgOpts = new MQGetMessageOptions
                    {
                        WaitInterval = waitDelay * 1000,
                        Options      = MQC.MQGMO_WAIT
                    };


                    context.LogInfo("Reading message from queue '{0}'.", queueName);

                    receiveQueue.Get(mqMsg, mqMsgOpts);

                    if (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) == 0)
                    {
                        mqMsg.Seek(0);
                        message = Encoding.UTF8.GetString(mqMsg.ReadBytes(mqMsg.MessageLength));
                        msgID   = mqMsg.MessageId;
                    }
                    else
                    {
                        throw new NotSupportedException(
                                  string.Format("Unsupported message format: '{0}' read from queue: {1}.",
                                                mqMsg.Format, queueName));
                    }
                }
            }

            return(message);
        }
Exemplo n.º 10
0
        public void Get(MQMessage message, MQGetMessageOptions gmo, int maxMsgSize)
        {
            uint method = 0x7a;

            this.TrEntry(method, new object[] { message, gmo, maxMsgSize });
            int dataLength = 0;

            byte[] buffer   = null;
            int    options  = -1;
            bool   flag     = true;
            int    compCode = 0;
            int    reason   = 0;

            try
            {
                if (message == null)
                {
                    base.throwNewMQException(2, 0x7ea);
                }
                if (gmo == null)
                {
                    base.throwNewMQException(2, 0x88a);
                }
                if (maxMsgSize < 0)
                {
                    base.throwNewMQException(2, 0x7d5);
                }
                options = gmo.Options;
                if ((gmo.Options & 0x1006) == 0)
                {
                    base.TrText(method, "Setting explicit NO_SYNCPOINT");
                    gmo.Options |= 4;
                }
                if (base.qMgr.CommandLevel >= 700)
                {
                    flag = (options & 0x1e000000) == 0;
                    if (((options & 0x8000000) != 0) || flag)
                    {
                        gmo.Options &= -134217729;
                        gmo.Options |= 0x2000000;
                    }
                }
                if ((Transaction.Current != null) && !base.qMgr.IsXAEnabled)
                {
                    base.qMgr.IsXAEnabled = true;
                }
                int characterSet = message.CharacterSet;
                if (!base.qMgr.IsHconnValid)
                {
                    base.throwNewMQException(2, 0x7e2);
                }
                message.ClearMessage();
                if (maxMsgSize == 0)
                {
                    int         num7       = gmo.Options;
                    MQBase.MQMD targetMqmd = new MQBase.MQMD();
                    this.CopyMQMD(message.md.StructMQMD, ref targetMqmd);
                    maxMsgSize   = defaultMaxMsgSize;
                    buffer       = new byte[maxMsgSize];
                    gmo.Options &= -65;
                    if ((num7 & 0x4000) == 0x4000)
                    {
                        MQLPIGetOpts lpiGetOpts = new MQLPIGetOpts();
                        lpiGetOpts.SetOptions(lpiGetOpts.GetOptions() | MQLPIGetOpts.lpiGETOPT_FULL_MESSAGE);
                        ((NmqiSP)base.qMgr.nmqiConnector).zstMQGET(base.qMgr.hConn, base.objectHandle.HOBJ, ref message.md, ref gmo, maxMsgSize, buffer, out dataLength, lpiGetOpts, out compCode, out reason);
                    }
                    else
                    {
                        base.qMgr.nmqiConnector.MQGET(base.qMgr.hConn, base.hObj, message.md, gmo, maxMsgSize, buffer, out dataLength, out compCode, out reason);
                    }
                    if (0x7da == reason)
                    {
                        maxMsgSize = dataLength;
                        buffer     = new byte[maxMsgSize];
                        base.qMgr.nmqiConnector.MQGET(base.qMgr.hConn, base.hObj, message.md, gmo, maxMsgSize, buffer, out dataLength, out compCode, out reason);
                    }
                    while ((compCode != 0) && (0x820 == reason))
                    {
                        gmo.Options = num7;
                        MQBase.MQMD structMQMD = message.md.StructMQMD;
                        this.CopyMQMD(targetMqmd, ref structMQMD);
                        message.md.StructMQMD = structMQMD;
                        maxMsgSize            = dataLength;
                        buffer       = new byte[maxMsgSize];
                        gmo.Options &= -65;
                        base.qMgr.nmqiConnector.MQGET(base.qMgr.hConn, base.hObj, message.md, gmo, maxMsgSize, buffer, out dataLength, out compCode, out reason);
                    }
                    if ((0x848 == reason) || (0x88e == reason))
                    {
                        string objectId       = "Server Binding convert message";
                        byte[] outString      = null;
                        int    outLength      = 0;
                        uint   bytesConverted = 0;
                        if (CommonServices.ConvertString(objectId, message.md.StructMQMD.CodedCharacterSetId, characterSet, buffer, dataLength, out outString, ref outLength, 0, out bytesConverted) == 0)
                        {
                            buffer     = outString;
                            maxMsgSize = outLength;
                            dataLength = outLength;
                            compCode   = 0;
                            reason     = 0;
                        }
                    }
                }
                else
                {
                    buffer = new byte[maxMsgSize];
                    base.qMgr.nmqiConnector.MQGET(base.qMgr.hConn, base.hObj, message.md, gmo, maxMsgSize, buffer, out dataLength, out compCode, out reason);
                }
                byte[] b = buffer;
                if (compCode == 0)
                {
                    bool flag2 = false;
                    if (base.qMgr.CommandLevel >= 700)
                    {
                        if (flag)
                        {
                            if (this.propControl != 3)
                            {
                                flag2 = true;
                            }
                        }
                        else if ((options & 0x8000000) != 0)
                        {
                            flag2 = true;
                        }
                        if (flag2 && (dataLength > 0x24))
                        {
                            b          = this.PerformMsgProcessingAfterGet(ref message, buffer, (dataLength > buffer.Length) ? buffer.Length : dataLength);
                            dataLength = b.Length;
                        }
                    }
                }
                message.totalMessageLength = dataLength;
                if (dataLength > 0)
                {
                    message.Write(b, 0, (dataLength < maxMsgSize) ? dataLength : maxMsgSize);
                    message.Seek(0);
                }
                if (compCode != 0)
                {
                    base.qMgr.CheckHConnHealth(reason);
                    base.throwNewMQException(compCode, reason);
                }
            }
            catch (MQException exception)
            {
                compCode = exception.CompCode;
                reason   = exception.Reason;
                throw exception;
            }
            catch (Exception exception2)
            {
                base.TrException(method, exception2);
                compCode = 2;
                reason   = 0x893;
                throw exception2;
            }
            finally
            {
                base.unsafe_compCode = compCode;
                base.unsafe_reason   = reason;
                gmo.Options          = options;
                base.TrExit(method);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// ITestStep.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            MQQueueManager queueManager    = null;
            MQQueue        receiveQueue    = null;
            string         message         = null;
            var            bLookForMessage = true;
            var            bFound          = false;
            var            cnt             = 0;

            try
            {
                // Remote or not?
                if (!string.IsNullOrEmpty(HostName))
                {
                    context.LogInfo("Host to connect to: \"{0}\" on port \"{1}\" with channel \"{2}\"", HostName, Port, Channel);
                    MQEnvironment.Hostname = HostName;
                    MQEnvironment.Port     = Port;
                    MQEnvironment.Channel  = Channel;
                }

                context.LogInfo("Opening queue manager: \"{0}\"", QueueManager);
                queueManager = new MQQueueManager(QueueManager);

                context.LogInfo("Opening queue: \"{0}\" - remote queue: \"{1}\"", Queue, RemoteQueue);
                receiveQueue = queueManager.AccessQueue(Queue, MQC.MQOO_INPUT_SHARED + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_BROWSE + MQC.MQOO_SET);

                MQMessage           mqMsg     = new MQMessage();
                MQGetMessageOptions mqMsgOpts = new MQGetMessageOptions();
                mqMsgOpts.WaitInterval = WaitTimeout * 1000;
                mqMsgOpts.Options      = MQC.MQGMO_WAIT + MQC.MQGMO_BROWSE_FIRST;
                mqMsgOpts.MatchOptions = MQC.MQMO_NONE;

                context.LogInfo("Browsing queue '{0}'.", Queue);

                // Loop until the required message is found
                while (!bFound)
                {
                    if (cnt > 0)
                    {
                        mqMsgOpts.Options = MQC.MQGMO_WAIT + MQC.MQGMO_BROWSE_NEXT;
                    }
                    try
                    {
                        receiveQueue.InhibitGet = MQC.MQQA_GET_ALLOWED;
                        receiveQueue.Get(mqMsg, mqMsgOpts);
                        cnt++;
                    }
                    catch (MQException mqe)
                    {
                        if (mqe.ReasonCode == MQC.MQRC_NO_MSG_AVAILABLE)
                        {
                            break;
                        }
                        throw;
                    }

                    if ((mqMsg.Format.CompareTo(MQC.MQFMT_STRING) != 0) &&
                        (mqMsg.Format.CompareTo(MQC.MQFMT_XMIT_Q_HEADER) != 0))
                    {
                        throw new NotSupportedException(
                                  string.Format("Unsupported message format: '{0}' read from queue: {1}.", mqMsg.Format,
                                                Queue));
                    }
                    else
                    {
                        mqMsg.Seek(0);
                        if (mqMsg.Format.CompareTo(MQC.MQFMT_XMIT_Q_HEADER) == 0)
                        {
                            var strucId        = mqMsg.ReadString(4);
                            var version        = mqMsg.ReadInt();
                            var remoteQName    = mqMsg.ReadString(48);
                            var remoteQMgrName = mqMsg.ReadString(48);

                            /*
                             * struct tagMQMD {
                             *              MQCHAR4   StrucId;           // Structure identifier
                             *              MQLONG    Version;           // Structure version number
                             *              MQLONG    Report;            // Options for report messages
                             *              MQLONG    MsgType;           // Message type
                             *              MQLONG    Expiry;            // Message lifetime
                             *              MQLONG    Feedback;          // Feedback or reason code
                             *              MQLONG    Encoding;          // Numeric encoding of message data
                             *              MQLONG    CodedCharSetId;    // Character set identifier of message data
                             *              MQCHAR8   Format;            // Format name of message data
                             *              MQLONG    Priority;          // Message priority
                             *              MQLONG    Persistence;       // Message persistence
                             *              MQBYTE24  MsgId;             // Message identifier
                             *              MQBYTE24  CorrelId;          // Correlation identifier
                             *              MQLONG    BackoutCount;      // Backout counter
                             *              MQCHAR48  ReplyToQ;          // Name of reply queue
                             *              MQCHAR48  ReplyToQMgr;       // Name of reply queue manager
                             *              MQCHAR12  UserIdentifier;    // User identifier
                             *              MQBYTE32  AccountingToken;   // Accounting token
                             *              MQCHAR32  ApplIdentityData;  // Application data relating to identity
                             *              MQLONG    PutApplType;       // Type of application that put the message
                             *              MQCHAR28  PutApplName;       // Name of application that put the message
                             *              MQCHAR8   PutDate;           // Date when message was put
                             *              MQCHAR8   PutTime;           // Time when message was put
                             *              MQCHAR4   ApplOriginData;    // Application data relating to origin
                             * }
                             */
                            var bytesMqmd = mqMsg.ReadBytes(324);
                        }
                        message = mqMsg.ReadLine();
                        //message = System.Text.UTF8Encoding.UTF8.GetString(mqMsg.ReadBytes(mqMsg.MessageLength));
                        context.LogData("MQSeries output message:", message);

                        if ((null == SubSteps) || (SubSteps.Count == 0))
                        {
                            bLookForMessage = false;
                        }
                        else
                        {
                            // Validate data...
                            var msgData = StreamHelper.LoadMemoryStream(message);
                            msgData.Seek(0, SeekOrigin.Begin);
                            // Check it against the validate steps to see if it matches one of them
                            foreach (var subStep in SubSteps)
                            {
                                try
                                {
                                    // Try the validation and catch the exception
                                    var strm = subStep.Execute(msgData, context);
                                    bFound = true;
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (receiveQueue != null)
                {
                    receiveQueue.Close();
                }

                if (queueManager != null)
                {
                    queueManager.Close();
                }
            }

            context.LogInfo("Number of messages found: {0}, in queue '{1}'", cnt, Queue);

            switch (ExpectedNumberOfMessages)
            {
            case -1:
                break;

            default:
                if (ExpectedNumberOfMessages != cnt)
                {
                    throw new Exception(String.Format("Queue '{2}' contained: {0} messages, but the step expected: {1} messages", cnt, ExpectedNumberOfMessages, Queue));
                }
                break;
            }

            if (!bFound && bLookForMessage && (ExpectedNumberOfMessages > 0))
            {
                throw new Exception(string.Format("Message not found in Queue '{0}', found {1} messages", Queue, cnt));
            }
        }
Exemplo n.º 12
0
        public void Get(MQMessage message, MQGetMessageOptions gmo, int maxMsgSize, int spigmo)
        {
            uint method = 550;

            this.TrEntry(method, new object[] { message, gmo, maxMsgSize, spigmo });
            int  num2       = 0;
            bool flag       = false;
            int  dataLength = 0;

            byte[] buffer   = null;
            int    compCode = 0;
            int    reason   = 0;

            try
            {
                NmqiSP nmqiConnector = (NmqiSP)base.qMgr.nmqiConnector;
                if (message == null)
                {
                    base.throwNewMQException(2, 0x7ea);
                }
                if (gmo == null)
                {
                    base.throwNewMQException(2, 0x88a);
                }
                if (maxMsgSize < 0)
                {
                    base.throwNewMQException(2, 0x7d5);
                }
                MQSPIGetOpts spigo        = new MQSPIGetOpts(spigmo);
                int          options      = gmo.Options;
                int          characterSet = message.CharacterSet;
                int          num7         = gmo.Options;
                if ((num7 & 0x8000000) != 0)
                {
                    gmo.Options &= -134217729;
                    gmo.Options |= 0x2000000;
                }
                else if ((((num7 & 0x10000000) == 0) && ((num7 & 0x2000000) == 0)) && ((num7 & 0x4000000) == 0))
                {
                    gmo.Options |= 0x2000000;
                }
                message.ClearMessage();
                num2 = gmo.Options;
                flag = true;
                if ((gmo.Options & 0x1006) == 0)
                {
                    gmo.Options |= 4;
                }
                if (maxMsgSize == 0)
                {
                    int         num8       = gmo.Options;
                    MQBase.MQMD targetMqmd = new MQBase.MQMD();
                    base.CopyMQMD(message.md.StructMQMD, ref targetMqmd);
                    maxMsgSize   = MQDestination.defaultMaxMsgSize;
                    buffer       = new byte[maxMsgSize];
                    gmo.Options &= -65;
                    nmqiConnector.SPIGet(base.qMgr.hConn, base.objectHandle.HOBJ, ref message.md, ref gmo, ref spigo, maxMsgSize, buffer, out dataLength, out compCode, out reason);
                    while ((1 == compCode) && (0x820 == reason))
                    {
                        gmo.Options = num8;
                        MQBase.MQMD structMQMD = message.md.StructMQMD;
                        base.CopyMQMD(targetMqmd, ref structMQMD);
                        message.md.StructMQMD = structMQMD;
                        maxMsgSize            = dataLength;
                        buffer       = new byte[maxMsgSize];
                        gmo.Options &= -65;
                        nmqiConnector.SPIGet(base.qMgr.hConn, base.objectHandle.HOBJ, ref message.md, ref gmo, ref spigo, maxMsgSize, buffer, out dataLength, out compCode, out reason);
                    }
                    gmo.Options = num8;
                }
                else
                {
                    buffer = new byte[maxMsgSize];
                    nmqiConnector.SPIGet(base.qMgr.hConn, base.objectHandle.HOBJ, ref message.md, ref gmo, ref spigo, maxMsgSize, buffer, out dataLength, out compCode, out reason);
                }
                if (compCode != 2)
                {
                    this.spiQueueEmpty   = spigo.QueueEmpty != 0;
                    message.spiInherited = spigo.Inherited != 0;
                    message.spiQTime     = spigo.QTime;
                }
                else
                {
                    this.spiQueueEmpty   = false;
                    message.spiInherited = false;
                    message.spiQTime     = 0L;
                }
                byte[] b = null;
                if (compCode != 2)
                {
                    if ((options & 0x2000000) == 0)
                    {
                        b = base.PerformMsgProcessingAfterGet(ref message, buffer, (dataLength > buffer.Length) ? buffer.Length : dataLength);
                    }
                    else
                    {
                        b = buffer;
                    }
                    dataLength = b.Length;
                }
                gmo.Options = options;
                message.totalMessageLength = dataLength;
                if (dataLength > 0)
                {
                    message.Write(b, 0, (dataLength < maxMsgSize) ? dataLength : maxMsgSize);
                    message.Seek(0);
                }
                if (compCode != 0)
                {
                    base.qMgr.CheckHConnHealth(reason);
                    base.throwNewMQException(compCode, reason);
                }
            }
            catch (MQException exception)
            {
                compCode = exception.CompCode;
                reason   = exception.Reason;
                throw exception;
            }
            finally
            {
                if (flag)
                {
                    gmo.Options = num2;
                }
                base.unsafe_compCode = compCode;
                base.unsafe_reason   = reason;
                base.TrExit(method);
            }
        }
Exemplo n.º 13
0
        private MQMessage CopyMDFromOldMsgIntoReplyMsg(MQMessage oldMsg, MQMessage newMsg, int putOpts)
        {
            MQMessage message;
            uint      method = 560;

            this.TrEntry(method, new object[] { oldMsg, newMsg, putOpts });
            try
            {
                if (((oldMsg.Report & 0x4000) != 0) && ((oldMsg.Report & 0x8000000) != 0))
                {
                    newMsg.Report = 0x8000000;
                }
                else
                {
                    newMsg.Report = 0;
                }
                newMsg.MessageType = 2;
                if ((oldMsg.Report & 0x4000) != 0)
                {
                    newMsg.Expiry = oldMsg.Expiry;
                }
                else
                {
                    newMsg.Expiry = -1;
                }
                newMsg.Feedback = 0;
                if ((oldMsg.Report & 0x80) != 0)
                {
                    newMsg.MessageId = oldMsg.MessageId;
                }
                else if ((putOpts & 0x40) == 0)
                {
                    newMsg.MessageId = MQC.MQMI_NONE;
                }
                if ((oldMsg.Report & 0x40) != 0)
                {
                    newMsg.CorrelationId = oldMsg.CorrelationId;
                }
                else if ((putOpts & 0x80) == 0)
                {
                    newMsg.CorrelationId = oldMsg.CorrelationId;
                }
                newMsg.ReplyToQueueName        = "";
                newMsg.ReplyToQueueManagerName = "";
                newMsg.GroupId = MQC.MQGI_NONE;
                newMsg.MessageSequenceNumber = 1;
                newMsg.Offset         = 0;
                newMsg.MessageFlags   = 0;
                newMsg.OriginalLength = -1;
                byte[] b = new byte[oldMsg.MessageLength];
                oldMsg.Seek(0);
                oldMsg.ReadFully(ref b);
                newMsg.Write(b);
                message = newMsg;
            }
            finally
            {
                base.TrExit(method);
            }
            return(message);
        }