Esempio n. 1
0
        protected MsmqOutputMessage(MsmqChannelFactoryBase <TChannel> factory, int bodySize, EndpointAddress remoteAddress, int additionalPropertyCount) : base(15 + additionalPropertyCount)
        {
            this.body      = new NativeMsmqMessage.BufferProperty(this, 9, bodySize);
            this.messageId = new NativeMsmqMessage.BufferProperty(this, 2, 20);
            this.EnsureBodyTypeProperty(0x1011);
            this.EnsureJournalProperty(2, factory.UseSourceJournal);
            this.delivery = new NativeMsmqMessage.ByteProperty(this, 5);
            if (factory.Durable)
            {
                this.delivery.Value = 1;
            }
            else
            {
                this.delivery.Value = 0;
            }
            if (factory.TimeToLive != TimeSpan.MaxValue)
            {
                int num = MsmqDuration.FromTimeSpan(factory.TimeToLive);
                this.EnsureTimeToReachQueueProperty(num);
                this.timeToBeReceived = new NativeMsmqMessage.IntProperty(this, 14, num);
            }
            switch (factory.DeadLetterQueue)
            {
            case DeadLetterQueue.None:
                this.EnsureJournalProperty(1, false);
                break;

            case DeadLetterQueue.System:
                this.EnsureJournalProperty(1, true);
                break;

            case DeadLetterQueue.Custom:
                this.EnsureJournalProperty(1, true);
                this.EnsureDeadLetterQueueProperty(factory.DeadLetterQueuePathName);
                break;
            }
            if (MsmqAuthenticationMode.WindowsDomain == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                this.EnsureSenderIdTypeProperty(1);
                this.authLevel     = new NativeMsmqMessage.IntProperty(this, 0x18, 1);
                this.hashAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1a, MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));
                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel           = new NativeMsmqMessage.IntProperty(this, 0x17, 3);
                    this.encryptionAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1b, MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }
            }
            else if (MsmqAuthenticationMode.Certificate == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                this.authLevel     = new NativeMsmqMessage.IntProperty(this, 0x18, 1);
                this.hashAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1a, MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));
                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel           = new NativeMsmqMessage.IntProperty(this, 0x17, 3);
                    this.encryptionAlgorithm = new NativeMsmqMessage.IntProperty(this, 0x1b, MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }
                this.EnsureSenderIdTypeProperty(0);
                this.senderCert = new NativeMsmqMessage.BufferProperty(this, 0x1c);
            }
            else
            {
                this.authLevel = new NativeMsmqMessage.IntProperty(this, 0x18, 0);
                this.EnsureSenderIdTypeProperty(0);
            }
            this.trace = new NativeMsmqMessage.ByteProperty(this, 0x29, factory.UseMsmqTracing ? ((byte)1) : ((byte)0));
        }
Esempio n. 2
0
        protected MsmqOutputMessage(MsmqChannelFactoryBase <TChannel> factory, int bodySize, EndpointAddress remoteAddress, int additionalPropertyCount)
            : base(15 + additionalPropertyCount)
        {
            this.body      = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_BODY, bodySize);
            this.messageId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_MSGID, UnsafeNativeMethods.PROPID_M_MSGID_SIZE);

            EnsureBodyTypeProperty(UnsafeNativeMethods.VT_VECTOR | UnsafeNativeMethods.VT_UI1);
            EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_JOURNAL, factory.UseSourceJournal);

            this.delivery = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_DELIVERY);
            if (factory.Durable)
            {
                this.delivery.Value = (byte)UnsafeNativeMethods.MQMSG_DELIVERY_RECOVERABLE;
            }
            else
            {
                this.delivery.Value = (byte)UnsafeNativeMethods.MQMSG_DELIVERY_EXPRESS;
            }

            if (factory.TimeToLive != TimeSpan.MaxValue)
            {
                int totalSeconds = MsmqDuration.FromTimeSpan(factory.TimeToLive);

                EnsureTimeToReachQueueProperty(totalSeconds);

                this.timeToBeReceived = new IntProperty(this,
                                                        UnsafeNativeMethods.PROPID_M_TIME_TO_BE_RECEIVED, totalSeconds);
            }

            switch (factory.DeadLetterQueue)
            {
            case DeadLetterQueue.None:
                EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, false);
                break;

            case DeadLetterQueue.System:
                EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, true);
                break;

            case DeadLetterQueue.Custom:
                EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, true);
                EnsureDeadLetterQueueProperty(factory.DeadLetterQueuePathName);
                break;
            }

            if (MsmqAuthenticationMode.WindowsDomain == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_SID);

                this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL,
                                                 UnsafeNativeMethods.MQMSG_AUTH_LEVEL_ALWAYS);

                this.hashAlgorithm = new IntProperty(
                    this,
                    UnsafeNativeMethods.PROPID_M_HASH_ALG,
                    MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));

                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL,
                                                     UnsafeNativeMethods.MQMSG_PRIV_LEVEL_BODY_ENHANCED);

                    this.encryptionAlgorithm = new IntProperty(
                        this,
                        UnsafeNativeMethods.PROPID_M_ENCRYPTION_ALG,
                        MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }
            }
            else if (MsmqAuthenticationMode.Certificate == factory.MsmqTransportSecurity.MsmqAuthenticationMode)
            {
                this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL,
                                                 UnsafeNativeMethods.MQMSG_AUTH_LEVEL_ALWAYS);

                this.hashAlgorithm = new IntProperty(
                    this,
                    UnsafeNativeMethods.PROPID_M_HASH_ALG,
                    MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm));

                if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel)
                {
                    this.privLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL,
                                                     UnsafeNativeMethods.MQMSG_PRIV_LEVEL_BODY_ENHANCED);

                    this.encryptionAlgorithm = new IntProperty(
                        this,
                        UnsafeNativeMethods.PROPID_M_ENCRYPTION_ALG,
                        MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm));
                }

                EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_NONE);
                this.senderCert = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_SENDER_CERT);
            }
            else
            {
                this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL,
                                                 UnsafeNativeMethods.MQMSG_AUTH_LEVEL_NONE);

                EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_NONE);
            }

            this.trace = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_TRACE, (byte)(factory.UseMsmqTracing ?
                                                                                           UnsafeNativeMethods.MQMSG_SEND_ROUTE_TO_REPORT_QUEUE : UnsafeNativeMethods.MQMSG_TRACE_NONE));
        }