1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4 namespace System.ServiceModel.MsmqIntegration
5 {
6     using System.ComponentModel;
7     using System.Messaging;
8     using System.Runtime;
9 
10     public sealed class MsmqIntegrationMessageProperty
11     {
12         public const string Name = "MsmqIntegrationMessageProperty";
13 
Get(System.ServiceModel.Channels.Message message)14         public static MsmqIntegrationMessageProperty Get(System.ServiceModel.Channels.Message message)
15         {
16             if (null == message)
17                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
18             if (null == message.Properties)
19                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message.Properties");
20 
21             return message.Properties[Name] as MsmqIntegrationMessageProperty;
22         }
23 
24         object body;
25         public object Body
26         {
27             get { return this.body; }
28             set { this.body = value; }
29         }
30 
31         AcknowledgeTypes? acknowledgeType = null;
32         public AcknowledgeTypes? AcknowledgeType
33         {
34             get { return this.acknowledgeType; }
35             set { this.acknowledgeType = value; }
36         }
37 
38         Acknowledgment? acknowledgment = null;
39         public Acknowledgment? Acknowledgment
40         {
41             get { return this.acknowledgment; }
42             internal set { this.acknowledgment = value; }
43         }
44 
45         Uri administrationQueue = null;
46         public Uri AdministrationQueue
47         {
48             get { return this.administrationQueue; }
49             set { this.administrationQueue = value; }
50         }
51 
52         int? appSpecific = null;
53         public int? AppSpecific
54         {
55             get { return this.appSpecific; }
56             set { this.appSpecific = value; }
57         }
58 
59         DateTime? arrivedTime = null;
60         public DateTime? ArrivedTime
61         {
62             get { return this.arrivedTime; }
63             internal set { this.arrivedTime = value; }
64         }
65 
66         bool? authenticated = null;
67         public bool? Authenticated
68         {
69             get { return this.authenticated; }
70             internal set { this.authenticated = value; }
71         }
72 
73         int? bodyType = null;
74         public int? BodyType
75         {
76             get { return this.bodyType; }
77             set { this.bodyType = value; }
78         }
79 
80         string correlationId = null;
81         public string CorrelationId
82         {
83             get { return this.correlationId; }
84             set { this.correlationId = value; }
85         }
86 
87         Uri destinationQueue = null;
88         public Uri DestinationQueue
89         {
90             get { return this.destinationQueue; }
91             internal set { this.destinationQueue = value; }
92         }
93 
94         byte[] extension = null;
95         public byte[] Extension
96         {
97             get { return this.extension; }
98             set { this.extension = value; }
99         }
100 
101         string id = null;
102         public string Id
103         {
104             get { return this.id; }
105             internal set { this.id = value; }
106         }
107 
108         string label = null;
109         public string Label
110         {
111             get { return this.label; }
112             set { this.label = value; }
113         }
114 
115         MessageType? messageType = null;
116         public MessageType? MessageType
117         {
118             get { return this.messageType; }
119             internal set { this.messageType = value; }
120         }
121 
122         MessagePriority? priority = null;
123         public MessagePriority? Priority
124         {
125             get { return this.priority; }
126             set
127             {
128                 ValidateMessagePriority(value);
129                 this.priority = value;
130             }
131         }
132 
133         Uri responseQueue = null;
134         public Uri ResponseQueue
135         {
136             get { return this.responseQueue; }
137             set { this.responseQueue = value; }
138         }
139 
140         byte[] senderId = null;
141         public byte[] SenderId
142         {
143             get { return this.senderId; }
144             internal set { this.senderId = value; }
145         }
146 
147         DateTime? sentTime = null;
148         public DateTime? SentTime
149         {
150             get { return this.sentTime; }
151             internal set { this.sentTime = value; }
152         }
153 
154         TimeSpan? timeToReachQueue = null;
155         public TimeSpan? TimeToReachQueue
156         {
157             get { return this.timeToReachQueue; }
158             set
159             {
160                 ValidateTimeToReachQueue(value);
161                 this.timeToReachQueue = value;
162             }
163         }
164 
InternalSetTimeToReachQueue(TimeSpan timeout)165         internal void InternalSetTimeToReachQueue(TimeSpan timeout)
166         {
167             this.timeToReachQueue = timeout;
168         }
169 
170         static void ValidateMessagePriority(MessagePriority? priority)
171         {
172             if (priority.HasValue && (priority.Value < MessagePriority.Lowest || priority.Value > MessagePriority.Highest))
173                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException("priority", (int)priority, typeof(MessagePriority)));
174         }
175 
176         static void ValidateTimeToReachQueue(TimeSpan? timeout)
177         {
178             if (timeout.HasValue && timeout.Value < TimeSpan.Zero)
179             {
180                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", timeout,
181                     SR.GetString(SR.SFxTimeoutOutOfRange0)));
182             }
183 
184             if (timeout.HasValue && TimeoutHelper.IsTooLarge(timeout.Value))
185             {
186                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", timeout,
187                     SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
188             }
189 
190         }
191     }
192 }
193