MsmqIntegrationInputMessage.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.MsmqIntegration
  5. {
  6. using System.ServiceModel.Channels;
  7. class MsmqIntegrationInputMessage : MsmqInputMessage
  8. {
  9. ByteProperty acknowledge;
  10. StringProperty adminQueue;
  11. IntProperty adminQueueLength;
  12. IntProperty appSpecific;
  13. IntProperty arrivedTime;
  14. IntProperty senderIdType;
  15. ByteProperty authenticated;
  16. IntProperty bodyType;
  17. BufferProperty correlationId;
  18. StringProperty destinationQueue;
  19. IntProperty destinationQueueLength;
  20. BufferProperty extension;
  21. IntProperty extensionLength;
  22. StringProperty label;
  23. IntProperty labelLength;
  24. ByteProperty priority;
  25. StringProperty responseFormatName;
  26. IntProperty responseFormatNameLength;
  27. IntProperty sentTime;
  28. IntProperty timeToReachQueue;
  29. IntProperty privacyLevel;
  30. const int initialQueueNameLength = 256;
  31. const int initialExtensionLength = 0;
  32. const int initialLabelLength = 128;
  33. const int maxSize = 4 * 1024 * 1024;
  34. public MsmqIntegrationInputMessage()
  35. : this(maxSize)
  36. { }
  37. public MsmqIntegrationInputMessage(int maxBufferSize)
  38. : this(new SizeQuota(maxBufferSize))
  39. { }
  40. protected MsmqIntegrationInputMessage(SizeQuota bufferSizeQuota)
  41. : base(22, bufferSizeQuota)
  42. {
  43. this.acknowledge = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_ACKNOWLEDGE);
  44. this.adminQueue = new StringProperty(this, UnsafeNativeMethods.PROPID_M_ADMIN_QUEUE, initialQueueNameLength);
  45. this.adminQueueLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_ADMIN_QUEUE_LEN, initialQueueNameLength);
  46. this.appSpecific = new IntProperty(this, UnsafeNativeMethods.PROPID_M_APPSPECIFIC);
  47. this.arrivedTime = new IntProperty(this, UnsafeNativeMethods.PROPID_M_ARRIVEDTIME);
  48. this.senderIdType = new IntProperty(this, UnsafeNativeMethods.PROPID_M_SENDERID_TYPE);
  49. this.authenticated = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_AUTHENTICATED);
  50. this.bodyType = new IntProperty(this, UnsafeNativeMethods.PROPID_M_BODY_TYPE);
  51. this.correlationId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_CORRELATIONID,
  52. UnsafeNativeMethods.PROPID_M_CORRELATIONID_SIZE);
  53. this.destinationQueue = new StringProperty(this, UnsafeNativeMethods.PROPID_M_DEST_FORMAT_NAME, initialQueueNameLength);
  54. this.destinationQueueLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_DEST_FORMAT_NAME_LEN, initialQueueNameLength);
  55. this.extension = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_EXTENSION,
  56. bufferSizeQuota.AllocIfAvailable(initialExtensionLength));
  57. this.extensionLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_EXTENSION_LEN, initialExtensionLength);
  58. this.label = new StringProperty(this, UnsafeNativeMethods.PROPID_M_LABEL, initialLabelLength);
  59. this.labelLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_LABEL_LEN, initialLabelLength);
  60. this.priority = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_PRIORITY);
  61. this.responseFormatName = new StringProperty(this, UnsafeNativeMethods.PROPID_M_RESP_FORMAT_NAME, initialQueueNameLength);
  62. this.responseFormatNameLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_RESP_FORMAT_NAME_LEN, initialQueueNameLength);
  63. this.sentTime = new IntProperty(this, UnsafeNativeMethods.PROPID_M_SENTTIME);
  64. this.timeToReachQueue = new IntProperty(this, UnsafeNativeMethods.PROPID_M_TIME_TO_REACH_QUEUE);
  65. this.privacyLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL);
  66. }
  67. protected override void OnGrowBuffers(SizeQuota bufferSizeQuota)
  68. {
  69. base.OnGrowBuffers(bufferSizeQuota);
  70. this.adminQueue.EnsureValueLength(this.adminQueueLength.Value);
  71. this.responseFormatName.EnsureValueLength(this.responseFormatNameLength.Value);
  72. this.destinationQueue.EnsureValueLength(this.destinationQueueLength.Value);
  73. this.label.EnsureValueLength(this.labelLength.Value);
  74. bufferSizeQuota.Alloc(this.extensionLength.Value);
  75. this.extension.EnsureBufferLength(this.extensionLength.Value);
  76. }
  77. public void SetMessageProperties(MsmqIntegrationMessageProperty property)
  78. {
  79. property.AcknowledgeType = (System.Messaging.AcknowledgeTypes)this.acknowledge.Value;
  80. property.Acknowledgment = (System.Messaging.Acknowledgment)this.Class.Value;
  81. property.AdministrationQueue = GetQueueName(this.adminQueue.GetValue(this.adminQueueLength.Value));
  82. property.AppSpecific = this.appSpecific.Value;
  83. property.ArrivedTime = MsmqDateTime.ToDateTime(this.arrivedTime.Value).ToLocalTime();
  84. property.Authenticated = this.authenticated.Value != 0;
  85. property.BodyType = this.bodyType.Value;
  86. property.CorrelationId = MsmqMessageId.ToString(this.correlationId.Buffer);
  87. property.DestinationQueue = GetQueueName(this.destinationQueue.GetValue(this.destinationQueueLength.Value));
  88. property.Extension = this.extension.GetBufferCopy(this.extensionLength.Value);
  89. property.Id = MsmqMessageId.ToString(this.MessageId.Buffer);
  90. property.Label = this.label.GetValue(this.labelLength.Value);
  91. if (this.Class.Value == UnsafeNativeMethods.MQMSG_CLASS_NORMAL)
  92. property.MessageType = System.Messaging.MessageType.Normal;
  93. else if (this.Class.Value == UnsafeNativeMethods.MQMSG_CLASS_REPORT)
  94. property.MessageType = System.Messaging.MessageType.Report;
  95. else
  96. property.MessageType = System.Messaging.MessageType.Acknowledgment;
  97. property.Priority = (System.Messaging.MessagePriority)this.priority.Value;
  98. property.ResponseQueue = GetQueueName(this.responseFormatName.GetValue(this.responseFormatNameLength.Value));
  99. property.SenderId = this.SenderId.GetBufferCopy(this.SenderIdLength.Value);
  100. property.SentTime = MsmqDateTime.ToDateTime(this.sentTime.Value).ToLocalTime();
  101. property.InternalSetTimeToReachQueue(MsmqDuration.ToTimeSpan(this.timeToReachQueue.Value));
  102. }
  103. static Uri GetQueueName(string formatName)
  104. {
  105. if (String.IsNullOrEmpty(formatName))
  106. return null;
  107. else
  108. return new Uri("msmq.formatname:" + formatName);
  109. }
  110. }
  111. }