private void MQRMIXAStart()
        {
            uint method = 0x50f;

            this.TrEntry(method);
            int num2 = 0;

            try
            {
                base.TrText(method, "Hconn value = " + this.hconn.Value + " issuing xa_start");
                this.xid.TraceFields();
                num2 = this.hconn.Session.MQFap.XA_Start(this.hconn, this.xid, this.hconn.Rmid, 0);
                if ((num2 != 0) && (num2 != 3))
                {
                    TransactionException innerException = new TransactionException(NmqiTools.GetTranslatedExceptionMessage(this.ToString(), 0x20008385, (uint)num2));
                    MQException          exception2     = new MQException(2, 0x893, innerException);
                    CommonServices.SetValidInserts();
                    CommonServices.ArithInsert1   = (uint)this.hconn.Rmid;
                    CommonServices.CommentInsert1 = "xa_start call has failed with return code = " + num2;
                    base.FFST("%Z% %W%  %I% %E% %U%", "%C%", method, 1, 0x20009213, 0);
                    throw exception2;
                }
            }
            finally
            {
                base.TrExit(method);
            }
        }
        internal void EnlistTransactionIntoDtc()
        {
            uint method = 0x4f8;

            this.TrEntry(method);
            try
            {
                base.TrText(method, "ResourceManager Id:- " + NmqiTools.ArrayToHexString(this.myGuid.ToByteArray()));
                base.TrText(method, "Hconn = " + base.hconn.Value);
                base.TrText(method, "Enlisting as Durable Resource manager into Current Transaction");
                base.InitializeMQRMI();
                Transaction.Current.EnlistDurable(base.myGuid, (ISinglePhaseNotification)this, EnlistmentOptions.EnlistDuringPrepareRequired);
                base.TrText(method, "WMQ .NET Enlisted as Resource Manager with Transaction Co-ordinator");
                base.hconn.currentTransaction = Transaction.Current;
                base.TrText(method, "Current Transaction's Information");
                base.TrText(method, "DistributedIdentifier:- " + NmqiTools.ArrayToHexString(Transaction.Current.TransactionInformation.DistributedIdentifier.ToByteArray()));
                base.TrText(method, "LocalIdentifier:- " + Transaction.Current.TransactionInformation.LocalIdentifier);
            }
            catch (MQException exception)
            {
                base.TrException(method, exception, 1);
                throw exception;
            }
            catch (TransactionException exception2)
            {
                base.TrException(method, exception2, 2);
                MQException exception3 = new MQException(2, 0x932, exception2);
                throw exception3;
            }
            finally
            {
                base.TrExit(method);
            }
        }
Exemple #3
0
        public bool ClientValidatingServerCertificate(object sender, X509Certificate peerCertificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            bool flag;
            uint method = 0x635;

            this.TrEntry(method);
            try
            {
                if ((this.sslPeerName != null) && (this.sslPeerName.Length > 0))
                {
                    if (peerCertificate == null)
                    {
                        MQException exception = new MQException(2, 0x95e);
                        throw exception;
                    }
                    return(this.CheckSSLPeerNameMatching(peerCertificate));
                }
                if (sslPolicyErrors != SslPolicyErrors.None)
                {
                    base.TrText(method, "SSL Server Certificate validation failed - " + sslPolicyErrors.ToString());
                }
                base.TrText(method, "Ignoring Server certificate validation. Accepting any certificate as Client did not specify a SSLPEERNAME");
                flag = true;
            }
            finally
            {
                base.TrExit(method);
            }
            return(flag);
        }
        public void MQRMIXARollback()
        {
            uint method = 0x514;

            this.TrEntry(method);
            int flags = 0;

            try
            {
                base.TrText(method, "Hconn value = " + this.hconn.Value + " issuing xa_rollback");
                this.xid.TraceFields();
                int num2 = this.hconn.Session.MQFap.XA_Rollback(this.hconn, this.xid, this.hconn.Rmid, flags);
                if (num2 != 0)
                {
                    TransactionException innerException = new TransactionException(NmqiTools.GetTranslatedExceptionMessage(this.ToString(), 0x20008385, (uint)num2));
                    MQException          exception2     = new MQException(2, 0x893, innerException);
                    CommonServices.SetValidInserts();
                    CommonServices.ArithInsert1   = (uint)this.hconn.Rmid;
                    CommonServices.CommentInsert1 = "xa_rollback call has failed with return code = " + num2;
                    base.FFST("%Z% %W%  %I% %E% %U%", "%C%", method, 1, 0x20009213, 0);
                    throw exception2;
                }
                base.TrText(method, "Hconn value = " + this.hconn.Value + " issuing MQGET to remove recovery message.");
                this.hconn.XARecoveryBridge.LogCurrentTransactionEnd(this.xid, this.hconn.Rmid);
            }
            finally
            {
                base.TrExit(method);
            }
        }
        public void MQRMIXACommit(bool onephase)
        {
            uint method = 0x513;

            this.TrEntry(method, new object[] { onephase });
            int flags = onephase ? 0x40000000 : 0;

            try
            {
                base.TrText(method, "Hconn value = " + this.hconn.Value + " issuing xa_commit");
                this.xid.TraceFields();
                int num3 = this.hconn.Session.MQFap.XA_Commit(this.hconn, this.xid, this.hconn.Rmid, flags);
                if ((num3 != 0) && (num3 != 3))
                {
                    TransactionException innerException = new TransactionException(NmqiTools.GetTranslatedExceptionMessage(this.ToString(), 0x20008385, (uint)num3));
                    MQException          exception2     = new MQException(2, 0x893, innerException);
                    CommonServices.SetValidInserts();
                    CommonServices.ArithInsert1   = (uint)this.hconn.Rmid;
                    CommonServices.CommentInsert1 = "xa_commit call has failed with return code = " + num3;
                    base.FFST("%Z% %W%  %I% %E% %U%", "%C%", method, 1, 0x20009213, 0);
                    throw exception2;
                }
                if (!onephase)
                {
                    base.TrText(method, "Hconn value = " + this.hconn.Value + " issuing MQGET to remove recovery message.");
                    this.hconn.XARecoveryBridge.LogCurrentTransactionEnd(this.xid, this.hconn.Rmid);
                }
            }
            finally
            {
                base.TrExit(method);
            }
        }
        private void ReportQueueEmpty(MQException ex)
        {
            var timeSpan = DateTimeOffset.UtcNow.Subtract(LastQueueEmptyWarningReported);

            if (timeSpan.TotalMinutes > QueueEmptyReportTimeIntervalMinutes)
            {
                _logger.LogWarning($"Queue is empty error getting the message.{ex.ToString()} {ex.GetErrorCodeDescription()}");
                LastQueueEmptyWarningReported = DateTimeOffset.UtcNow;
            }
        }
        public void Rollback(Enlistment enlistment)
        {
            uint method = 0x526;

            this.TrEntry(method, new object[] { enlistment });
            MQTransactionRecovery.log.WriteLog("Outcome of the transaction(as per DTC):", "Rollback");
            int num2 = 0;
            int num3 = 0;

            try
            {
                num3 = 0;
                while (num3 < this.incompleteXids.Count)
                {
                    if (this.recoveryXid.Equals(this.incompleteXids[num3]))
                    {
                        if (MQTransactionRecovery.userMode)
                        {
                            num2 = this.HeuristicTransactionCompletion();
                        }
                        else
                        {
                            num2 = this.recoveryHconn.GetMQFAP.XA_Rollback(this.recoveryHconn, this.recoveryXid, this.rmid_, 0);
                            MQTransactionRecovery.log.WriteLog("Transaction Rollback was successful with Returncode:  " + num2);
                        }
                        if (num2 < 0)
                        {
                            TransactionException innerException = new TransactionException(NmqiTools.GetTranslatedExceptionMessage(this.ToString(), 0x20008385, (uint)num2));
                            MQException          exception2     = new MQException(2, 0x893, innerException);
                            throw exception2;
                        }
                        this.success = true;
                        enlistment.Done();
                        break;
                    }
                    num3++;
                }
                if (num3 == this.incompleteXids.Count)
                {
                    MQTransactionRecovery.log.WriteLog("This particular Tx is not listed as in-doubt with WMQ. Releasing it now.");
                    enlistment.Done();
                    this.success = true;
                }
            }
            catch (Exception exception3)
            {
                base.TrException(method, exception3);
                MQTransactionRecovery.log.WriteLog("Actual state of the Transaction:", "Unknown/Indoubt");
                throw exception3;
            }
            finally
            {
                base.TrExit(method);
            }
        }
Exemple #8
0
        public static string GetErrorCodeDescription(this MQException mqException)
        {
            string description = "See IBM site for description";

            if (MQErrorDescription.ContainsKey(mqException.ReasonCode) == true)
            {
                description = MQErrorDescription[mqException.ReasonCode].ToString();
            }

            return(description);
        }
Exemple #9
0
        internal void AsyncFailureNotify(Exception e)
        {
            uint method = 0x61b;

            this.TrEntry(method, new object[] { e });
            try
            {
                base.TrText(method, "We received an asyncfailure exception");
                MQException ex = null;
                if (e is MQException)
                {
                    ex = (MQException)e;
                }
                else
                {
                    ex = new MQException(2, 0x7d9, e);
                }
                base.TrException(method, ex);
                if ((ex.ReasonCode == 0x89a) || (ex.ReasonCode == 0x871))
                {
                    base.TrText(method, "This is a " + ex.Reason + " exception, setting the flag on hconn");
                    this.Hconn.SetQuiescing();
                }
                else
                {
                    base.TrText(method, "Pulsing all the data waiters");
                    lock (this.asyncTshLock)
                    {
                        this.asyncFailure = ex;
                        this.asyncTshLock.PulseAll();
                    }
                }
            }
            finally
            {
                base.TrExit(method);
            }
        }
        public int MQRMIXAPrepare(byte[] recoveryInformation)
        {
            uint method = 0x512;

            this.TrEntry(method, new object[] { recoveryInformation });
            int num2 = 0;

            try
            {
                byte[] buffer = null;
                buffer = new byte[this.xid.GetRoundedLength()];
                this.xid.WriteStruct(buffer, 0);
                this.xid.TraceFields();
                base.TrText(method, "Hconn value = " + this.hconn.Value + " issuing xa_prepare");
                num2 = this.hconn.Session.MQFap.XA_Prepare(this.hconn, this.xid, this.hconn.Rmid, this.flags);
                if ((num2 != 0) && (num2 != 3))
                {
                    TransactionException innerException = new TransactionException(NmqiTools.GetTranslatedExceptionMessage(this.ToString(), 0x20008385, (uint)num2));
                    MQException          exception2     = new MQException(2, 0x893, innerException);
                    CommonServices.SetValidInserts();
                    CommonServices.ArithInsert1   = (uint)this.hconn.Rmid;
                    CommonServices.CommentInsert1 = "xa_prepare call has failed with return code = " + num2;
                    base.FFST("%Z% %W%  %I% %E% %U%", "%C%", method, 1, 0x20009213, 0);
                    throw exception2;
                }
                if (num2 == 0)
                {
                    base.TrText(method, "Hconn value = " + this.hconn.Value + " issuing MQPUT for tx recovery.");
                    this.hconn.XARecoveryBridge.LogCurrentTransactionStart(buffer, this.xid, this.myGuid, this.hconn.Rmid, recoveryInformation);
                }
            }
            finally
            {
                base.TrExit(method);
            }
            return(num2);
        }
Exemple #11
0
        public IEnumerable <IMessage> BrowseMessages(int numberOfMessages, CancellationToken ct, byte[] startingPointMessageId = null, IBrowseFilter filter = null, IProgress <int> progress = null)
        {
            SetupBrowseConnectionPool();

            var workers = new List <Task>();

            var pipeline = new BlockingCollection <WsMessage>();
            var cts      = new CancellationTokenSource();


            Exception workerException = null;


            var     qm = _browseConnectionPool[0];
            MQQueue q  = qm.OpenQueueCore(this.Name, OpenQueueMode.ForBrowse);

            workers.Add(Task.Run(() => BrowseMessagesWorker(pipeline, filter, cts.Token, q, startingPointMessageId)));


            Task.WhenAll(workers)
            .ContinueWith((t) =>
            {
                pipeline.CompleteAdding();     // Inform that there are no more messages to read from the queue

                if (t.IsFaulted)
                {
                    workerException = t.Exception.InnerException;
                }
            });

            List <WsMessage> yieldBuffer = new List <WsMessage>();
            int count = 0;

            while (!pipeline.IsCompleted)
            {
                if (ct != CancellationToken.None && ct.IsCancellationRequested)
                {
                    cts.Cancel();
                    break;
                }
                ;


                WsMessage msg;
                if (pipeline.TryTake(out msg, 100))
                {
                    count++;
                    if (msg != null)
                    {
                        yieldBuffer.Add(msg);

                        msg.Index = count;
                        yield return(msg);

                        numberOfMessages--;
                        if (numberOfMessages == 0)
                        {
                            cts.Cancel();
                            break;
                        }
                    }

                    progress.Report(count);
                }
            }

            q?.Close();

            if (workerException != null)
            {
                MQException ibmEx = workerException as MQException;
                if (ibmEx != null)
                {
                    throw ibmEx.ToMqException(AddExtraInfoToError);
                }
                else
                {
                    throw workerException;
                }
            }
        }
Exemple #12
0
        private void MakeSecuredConnection()
        {
            uint method = 0x63c;

            this.TrEntry(method);
            try
            {
                StoreLocation localMachine;
                this.stream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(this.ClientValidatingServerCertificate), new LocalCertificateSelectionCallback(this.FixClientCertificate));
                base.TrText(method, "Created an instance of SSLStreams");
                if (this.keyStore == "*SYSTEM")
                {
                    localMachine = StoreLocation.LocalMachine;
                    base.TrText(method, "Setting current certificate store as 'Computer'");
                }
                else
                {
                    localMachine = StoreLocation.CurrentUser;
                    base.TrText(method, "Setting current certificate store as 'User'");
                }
                X509Store store = new X509Store(StoreName.My, localMachine);
                base.TrText(method, "Created store object to access certificates");
                store.Open(OpenFlags.OpenExistingOnly);
                base.TrText(method, "Opened store");
                base.TrText(method, "Accessing certificate - " + this.clientCertName);
                X509Certificate2Collection clientCertificates = new X509Certificate2Collection();
                X509Certificate2Enumerator enumerator         = store.Certificates.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    X509Certificate2 current = enumerator.Current;
                    if (current.FriendlyName.ToLower() == this.clientCertName)
                    {
                        clientCertificates.Add(current);
                    }
                }
                Array values = Enum.GetValues(typeof(SslProtocols));
                bool  flag   = Enum.IsDefined(typeof(SslProtocols), "Tls12");
                base.TrText(method, "TLS12 supported - " + flag);
                if (((this.cipherSpec == null) || (this.cipherSpec == "*NEGOTIATE")) || (this.cipherSpec == string.Empty))
                {
                    if (flag)
                    {
                        foreach (SslProtocols protocols in values)
                        {
                            if (protocols.ToString() == "Tls12")
                            {
                                base.TrText(method, "Setting SslProtcol as TSL12");
                                this.sslProtocol = protocols;
                                break;
                            }
                        }
                    }
                    else
                    {
                        base.TrText(method, "Setting SslProtocol as TLS");
                        this.sslProtocol = SslProtocols.Tls;
                    }
                }
                else
                {
                    values = Enum.GetValues(typeof(SslProtocols));
                    string sSLPrtocolVersionForCipher = MQCipherMappingTable.GetSSLPrtocolVersionForCipher(this.cipherSpec);
                    if (sSLPrtocolVersionForCipher == null)
                    {
                        goto Label_02E8;
                    }
                    if (!(sSLPrtocolVersionForCipher == "SSL 3.0"))
                    {
                        if (sSLPrtocolVersionForCipher == "TLS 1.0")
                        {
                            goto Label_0263;
                        }
                        if (sSLPrtocolVersionForCipher == "TLS 1.2")
                        {
                            goto Label_027F;
                        }
                        goto Label_02E8;
                    }
                    this.sslProtocol = SslProtocols.Ssl3;
                    base.TrText(method, "Setting SslProtol as Ssl3");
                }
                goto Label_02FF;
Label_0263:
                this.sslProtocol = SslProtocols.Tls;
                base.TrText(method, "Setting SslProtol as Tls");
                goto Label_02FF;
Label_027F:
                foreach (SslProtocols protocols2 in values)
                {
                    if (protocols2.ToString() == "Tls12")
                    {
                        this.sslProtocol = protocols2;
                        break;
                    }
                }
                base.TrText(method, "Setting SslProtol as Tls12");
                goto Label_02FF;
Label_02E8:
                this.sslProtocol = SslProtocols.Default;
                base.TrText(method, "Setting SslProtocol as Default");
Label_02FF:
                base.TrText(method, "Starting SSL Authentication");
                this.stream.AuthenticateAsClient("*", clientCertificates, this.sslProtocol, this.sslCertRevocationCheck);
                if (!this.stream.IsAuthenticated || !this.stream.IsEncrypted)
                {
                    MQException exception = new MQException(2, 0x80b);
                    this.client.Close();
                    throw exception;
                }
                store.Close();
                store = null;
                clientCertificates.Clear();
                clientCertificates = null;
                values             = null;
                base.TrText(method, "SSL Authentication completed");
            }
            catch (Exception exception2)
            {
                base.TrException(method, exception2);
                throw exception2;
            }
            finally
            {
                base.TrExit(method);
            }
        }
        /**
         * 统一处理MQException
         *
         * @param e
         * @return int return 0 success; return 1 timeout; return -1 connection
         *         broken; return 2 unknown exception.
         */
        public static int handleMQException(MQException e)
        {
            int ret = MQ_UNKNOW_EXCEPTION;

            // if (e.completionCode == MQException.MQCC_OK    && e.reasonCode == MQException.MQRC_NONE)
            if (e.CompletionCode == 0 && e.ReasonCode == 0)
            {
                ret = MQ_OK;
            }
            //else if (e.CompletionCode == MQException.MQCC_FAILED)
            else if (e.CompletionCode == 2)
            {
                switch (e.ReasonCode)
                {
                //case MQException.MQRC_NO_MSG_AVAILABLE:
                //    ret = MQ_TIME_OUT;
                //    break;
                //case MQException.MQRC_CONNECTION_QUIESCING:
                //case MQException.MQRC_Q_MGR_NAME_ERROR:
                //case MQException.MQRC_Q_MGR_NOT_AVAILABLE:
                //case MQException.MQRC_SECURITY_ERROR:
                //case MQException.MQRC_CONNECTION_STOPPING:
                //    ret = MQ_CONNECTION_BROKER;
                //    break;
                //case MQException.MQRC_CONNECTION_BROKEN:
                //    ret = MQ_CONNECTION_BROKEN_2009;
                //    break;
                //default:
                //    ret = MQ_UNKNOW_EXCEPTION;

                case 2033:
                    ret = MQ_TIME_OUT;
                    break;

                case 2202:
                    break;

                case 2058:
                    break;

                case 2059:
                    break;

                case 2063:
                    break;

                case 2203:
                    ret = MQ_CONNECTION_BROKER;
                    break;

                case 2009:
                    ret = MQ_CONNECTION_BROKEN_2009;
                    break;

                default:
                    ret = MQ_UNKNOW_EXCEPTION;
                    break;
                }
            }
            return(ret);
        }// end of method