1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Channels
{
class MsmqInputMessage : NativeMsmqMessage
{
BufferProperty senderId;
IntProperty senderIdLength;
LongProperty lookupId;
IntProperty abortCount;
IntProperty moveCount;
BufferProperty senderCertificate;
IntProperty senderCertificateLength;
IntProperty lastMovedTime;
BufferProperty body;
IntProperty bodyLength;
BufferProperty messageId;
ShortProperty cls;
int maxBufferSize;
const int maxSize = 4 * 1024 * 1024;
const int initialBodySize = 4096;
const int initialSenderIdSize = 256;
const int initialCertificateSize = 4096;
public MsmqInputMessage()
: this(0, maxSize)
{
}
public MsmqInputMessage(int maxBufferSize)
: this(0, maxBufferSize)
{
}
protected MsmqInputMessage(int additionalPropertyCount, int maxBufferSize)
: this(additionalPropertyCount, new SizeQuota(maxBufferSize))
{
}
protected MsmqInputMessage(int additionalPropertyCount, SizeQuota bufferSizeQuota)
: base(12 + additionalPropertyCount)
{
this.maxBufferSize = bufferSizeQuota.MaxSize;
this.body = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_BODY,
bufferSizeQuota.AllocIfAvailable(initialBodySize));
this.bodyLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_BODY_SIZE);
this.messageId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_MSGID,
UnsafeNativeMethods.PROPID_M_MSGID_SIZE);
this.lookupId = new LongProperty(this, UnsafeNativeMethods.PROPID_M_LOOKUPID);
this.cls = new ShortProperty(this, UnsafeNativeMethods.PROPID_M_CLASS);
this.senderId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_SENDERID, initialSenderIdSize);
this.senderIdLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_SENDERID_LEN);
this.senderCertificate = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_SENDER_CERT,
bufferSizeQuota.AllocIfAvailable(initialCertificateSize));
this.senderCertificateLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_SENDER_CERT_LEN);
if (Msmq.IsAdvancedPoisonHandlingSupported)
{
this.lastMovedTime = new IntProperty(this, UnsafeNativeMethods.PROPID_M_LAST_MOVE_TIME);
this.abortCount = new IntProperty(this, UnsafeNativeMethods.PROPID_M_ABORT_COUNT);
this.moveCount = new IntProperty(this, UnsafeNativeMethods.PROPID_M_MOVE_COUNT);
}
}
public override void GrowBuffers()
{
OnGrowBuffers(new SizeQuota(this.maxBufferSize));
}
protected virtual void OnGrowBuffers(SizeQuota bufferSizeQuota)
{
bufferSizeQuota.Alloc(this.senderIdLength.Value);
this.senderId.EnsureBufferLength(this.senderIdLength.Value);
bufferSizeQuota.Alloc(this.senderCertificateLength.Value);
this.senderCertificate.EnsureBufferLength(this.senderCertificateLength.Value);
bufferSizeQuota.Alloc(this.bodyLength.Value);
this.body.EnsureBufferLength(this.bodyLength.Value);
}
public BufferProperty SenderId
{
get { return this.senderId; }
}
public IntProperty SenderIdLength
{
get { return this.senderIdLength; }
}
public LongProperty LookupId
{
get { return this.lookupId; }
}
public IntProperty AbortCount
{
get { return this.abortCount; }
}
public IntProperty MoveCount
{
get { return this.moveCount; }
}
public BufferProperty SenderCertificate
{
get { return this.senderCertificate; }
}
public IntProperty SenderCertificateLength
{
get { return this.senderCertificateLength; }
}
public IntProperty LastMovedTime
{
get { return this.lastMovedTime; }
}
public BufferProperty Body
{
get { return this.body; }
}
public IntProperty BodyLength
{
get { return this.bodyLength; }
}
public BufferProperty MessageId
{
get { return this.messageId; }
}
public ShortProperty Class
{
get { return this.cls; }
}
protected class SizeQuota
{
int remainingSize;
int maxSize;
public SizeQuota(int maxSize)
{
this.maxSize = maxSize;
this.remainingSize = maxSize;
}
public int MaxSize
{
get { return this.maxSize; }
}
public void Alloc(int requiredSize)
{
if (requiredSize > this.remainingSize)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(this.maxSize));
}
this.remainingSize -= requiredSize;
}
public int AllocIfAvailable(int desiredSize)
{
int availableSize = Math.Min(desiredSize, this.remainingSize);
this.remainingSize -= availableSize;
return availableSize;
}
}
}
}
|