DefaultPropertiesToSend.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. //------------------------------------------------------------------------------
  2. // <copyright file="DefaultPropertiesToSend.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. //------------------------------------------------------------------------------
  6. using System;
  7. using System.ComponentModel;
  8. using System.Diagnostics.CodeAnalysis;
  9. namespace Experimental.System.Messaging
  10. {
  11. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend"]/*' />
  12. /// <devdoc>
  13. /// <para>
  14. /// Specifies the default property values that will be used when
  15. /// sending objects using the message queue.
  16. /// </para>
  17. /// </devdoc>
  18. [TypeConverter(typeof(ExpandableObjectConverter))]
  19. public class DefaultPropertiesToSend
  20. {
  21. private Message cachedMessage = new Message();
  22. private bool designMode;
  23. private MessageQueue cachedAdminQueue;
  24. private MessageQueue cachedResponseQueue;
  25. private MessageQueue cachedTransactionStatusQueue;
  26. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.DefaultPropertiesToSend"]/*' />
  27. /// <devdoc>
  28. /// <para>
  29. /// Initializes a new instance of the <see cref='System.Messaging.DefaultPropertiesToSend'/>
  30. /// class.
  31. /// </para>
  32. /// </devdoc>
  33. public DefaultPropertiesToSend()
  34. {
  35. }
  36. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.DefaultPropertiesToSend1"]/*' />
  37. /// <internalonly/>
  38. internal DefaultPropertiesToSend(bool designMode)
  39. {
  40. this.designMode = designMode;
  41. }
  42. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.AcknowledgeTypes"]/*' />
  43. /// <devdoc>
  44. /// <para>
  45. /// Gets
  46. /// or sets the type of acknowledgement message to be returned to the sending
  47. /// application.
  48. /// </para>
  49. /// </devdoc>
  50. [DefaultValueAttribute(AcknowledgeTypes.None), MessagingDescription(Res.MsgAcknowledgeType)]
  51. public AcknowledgeTypes AcknowledgeType
  52. {
  53. get
  54. {
  55. return this.cachedMessage.AcknowledgeType;
  56. }
  57. set
  58. {
  59. this.cachedMessage.AcknowledgeType = value;
  60. }
  61. }
  62. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.AdministrationQueue"]/*' />
  63. /// <devdoc>
  64. /// <para>
  65. /// Gets or sets the queue used for acknowledgement messages
  66. /// generated by the application. This is the queue that
  67. /// will receive the acknowledgment message for the message you are about to
  68. /// send.
  69. /// </para>
  70. /// </devdoc>
  71. [DefaultValueAttribute(null), MessagingDescription(Res.MsgAdministrationQueue)]
  72. public MessageQueue AdministrationQueue
  73. {
  74. get
  75. {
  76. if (this.designMode)
  77. {
  78. if (this.cachedAdminQueue != null && this.cachedAdminQueue.Site == null)
  79. this.cachedAdminQueue = null;
  80. return this.cachedAdminQueue;
  81. }
  82. return this.cachedMessage.AdministrationQueue;
  83. }
  84. set
  85. {
  86. //The format name of this queue shouldn't be
  87. //resolved at desgin time, but it should at runtime.
  88. if (this.designMode)
  89. this.cachedAdminQueue = value;
  90. else
  91. this.cachedMessage.AdministrationQueue = value;
  92. }
  93. }
  94. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.AppSpecific"]/*' />
  95. /// <devdoc>
  96. /// <para>
  97. /// Gets or sets application-generated information.
  98. ///
  99. /// </para>
  100. /// </devdoc>
  101. [DefaultValueAttribute(0), MessagingDescription(Res.MsgAppSpecific)]
  102. public int AppSpecific
  103. {
  104. get
  105. {
  106. return this.cachedMessage.AppSpecific;
  107. }
  108. set
  109. {
  110. this.cachedMessage.AppSpecific = value;
  111. }
  112. }
  113. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.AttachSenderId"]/*' />
  114. /// <devdoc>
  115. /// <para>
  116. /// Gets or sets a value indicating if the sender ID is to be attached to the
  117. /// message.
  118. ///
  119. /// </para>
  120. /// </devdoc>
  121. [DefaultValueAttribute(true), MessagingDescription(Res.MsgAttachSenderId)]
  122. public bool AttachSenderId
  123. {
  124. get
  125. {
  126. return this.cachedMessage.AttachSenderId;
  127. }
  128. set
  129. {
  130. this.cachedMessage.AttachSenderId = value;
  131. }
  132. }
  133. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.CachedMessage"]/*' />
  134. /// <internalonly/>
  135. internal Message CachedMessage
  136. {
  137. get
  138. {
  139. return this.cachedMessage;
  140. }
  141. }
  142. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.EncryptionAlgorithm"]/*' />
  143. /// <devdoc>
  144. /// <para>
  145. /// Gets or sets the encryption algorithm used to encrypt the body of a
  146. /// private message.
  147. ///
  148. /// </para>
  149. /// </devdoc>
  150. [DefaultValueAttribute(EncryptionAlgorithm.Rc2), MessagingDescription(Res.MsgEncryptionAlgorithm)]
  151. public EncryptionAlgorithm EncryptionAlgorithm
  152. {
  153. get
  154. {
  155. return this.cachedMessage.EncryptionAlgorithm;
  156. }
  157. set
  158. {
  159. this.cachedMessage.EncryptionAlgorithm = value;
  160. }
  161. }
  162. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.Extension"]/*' />
  163. /// <devdoc>
  164. /// <para>
  165. /// Gets or sets additional information associated with the message.
  166. ///
  167. /// </para>
  168. /// </devdoc>
  169. [Editor("System.ComponentModel.Design.ArrayEditor, " + AssemblyRef.SystemDesign, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
  170. MessagingDescription(Res.MsgExtension)]
  171. [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
  172. [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
  173. public byte[] Extension
  174. {
  175. get
  176. {
  177. return this.cachedMessage.Extension;
  178. }
  179. set
  180. {
  181. this.cachedMessage.Extension = value;
  182. }
  183. }
  184. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.HashAlgorithm"]/*' />
  185. /// <devdoc>
  186. /// <para>
  187. /// Gets or sets the hashing algorithm used when
  188. /// authenticating
  189. /// messages.
  190. ///
  191. /// </para>
  192. /// </devdoc>
  193. [DefaultValueAttribute(HashAlgorithm.Md5), MessagingDescription(Res.MsgHashAlgorithm)]
  194. public HashAlgorithm HashAlgorithm
  195. {
  196. get
  197. {
  198. return this.cachedMessage.HashAlgorithm;
  199. }
  200. set
  201. {
  202. this.cachedMessage.HashAlgorithm = value;
  203. }
  204. }
  205. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.Label"]/*' />
  206. /// <devdoc>
  207. /// <para>
  208. /// Gets or sets the message label.
  209. ///
  210. /// </para>
  211. /// </devdoc>
  212. [DefaultValueAttribute(""), MessagingDescription(Res.MsgLabel)]
  213. public string Label
  214. {
  215. get
  216. {
  217. return this.cachedMessage.Label;
  218. }
  219. set
  220. {
  221. this.cachedMessage.Label = value;
  222. }
  223. }
  224. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.Priority"]/*' />
  225. /// <devdoc>
  226. /// <para>
  227. /// Gets or sets the message priority.
  228. /// </para>
  229. /// </devdoc>
  230. [DefaultValueAttribute(MessagePriority.Normal), MessagingDescription(Res.MsgPriority)]
  231. public MessagePriority Priority
  232. {
  233. get
  234. {
  235. return this.cachedMessage.Priority;
  236. }
  237. set
  238. {
  239. this.cachedMessage.Priority = value;
  240. }
  241. }
  242. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.Recoverable"]/*' />
  243. /// <devdoc>
  244. /// <para>
  245. /// Gets or sets a value indicating whether the message is
  246. /// guaranteed to be delivered in the event
  247. /// of a computer failure or network problem.
  248. ///
  249. /// </para>
  250. /// </devdoc>
  251. [DefaultValueAttribute(false), MessagingDescription(Res.MsgRecoverable)]
  252. public bool Recoverable
  253. {
  254. get
  255. {
  256. return this.cachedMessage.Recoverable;
  257. }
  258. set
  259. {
  260. this.cachedMessage.Recoverable = value;
  261. }
  262. }
  263. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.ResponseQueue"]/*' />
  264. /// <devdoc>
  265. /// <para>
  266. /// Gets or sets the queue which receives application-generated response
  267. /// messages.
  268. ///
  269. /// </para>
  270. /// </devdoc>
  271. [DefaultValueAttribute(null), MessagingDescription(Res.MsgResponseQueue)]
  272. public MessageQueue ResponseQueue
  273. {
  274. get
  275. {
  276. if (this.designMode)
  277. return this.cachedResponseQueue;
  278. return this.cachedMessage.ResponseQueue;
  279. }
  280. set
  281. {
  282. //The format name of this queue shouldn't be
  283. //resolved at desgin time, but it should at runtime.
  284. if (this.designMode)
  285. this.cachedResponseQueue = value;
  286. else
  287. this.cachedMessage.ResponseQueue = value;
  288. }
  289. }
  290. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.TimeToBeReceived"]/*' />
  291. /// <devdoc>
  292. /// <para>
  293. /// Gets or sets the time limit for the message to be
  294. /// retrieved from
  295. /// the target queue.
  296. /// </para>
  297. /// </devdoc>
  298. [TypeConverter(typeof(System.Messaging.Design.TimeoutConverter)),
  299. MessagingDescription(Res.MsgTimeToBeReceived)]
  300. public TimeSpan TimeToBeReceived
  301. {
  302. get
  303. {
  304. return this.cachedMessage.TimeToBeReceived;
  305. }
  306. set
  307. {
  308. this.cachedMessage.TimeToBeReceived = value;
  309. }
  310. }
  311. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.TimeToReachQueue"]/*' />
  312. /// <devdoc>
  313. /// <para>
  314. /// Gets or sets the time limit for the message to
  315. /// reach the queue.
  316. ///
  317. /// </para>
  318. /// </devdoc>
  319. [TypeConverter(typeof(System.Messaging.Design.TimeoutConverter)),
  320. MessagingDescription(Res.MsgTimeToReachQueue)]
  321. public TimeSpan TimeToReachQueue
  322. {
  323. get
  324. {
  325. return this.cachedMessage.TimeToReachQueue;
  326. }
  327. set
  328. {
  329. this.cachedMessage.TimeToReachQueue = value;
  330. }
  331. }
  332. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.TransactionStatusQueue"]/*' />
  333. /// <devdoc>
  334. /// <para>
  335. /// Gets the transaction status queue on the source computer.
  336. ///
  337. /// </para>
  338. /// </devdoc>
  339. [DefaultValueAttribute(null), MessagingDescription(Res.MsgTransactionStatusQueue)]
  340. public MessageQueue TransactionStatusQueue
  341. {
  342. get
  343. {
  344. if (this.designMode)
  345. return this.cachedTransactionStatusQueue;
  346. return this.cachedMessage.TransactionStatusQueue;
  347. }
  348. set
  349. {
  350. //The format name of this queue shouldn't be
  351. //resolved at desgin time, but it should at runtime.
  352. if (this.designMode)
  353. this.cachedTransactionStatusQueue = value;
  354. else
  355. this.cachedMessage.TransactionStatusQueue = value;
  356. }
  357. }
  358. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.UseAuthentication"]/*' />
  359. /// <devdoc>
  360. /// <para>
  361. /// Gets or sets a value indicating whether the message must be authenticated.
  362. /// </para>
  363. /// </devdoc>
  364. [DefaultValueAttribute(false), MessagingDescription(Res.MsgUseAuthentication)]
  365. public bool UseAuthentication
  366. {
  367. get
  368. {
  369. return this.cachedMessage.UseAuthentication;
  370. }
  371. set
  372. {
  373. this.cachedMessage.UseAuthentication = value;
  374. }
  375. }
  376. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.UseDeadLetterQueue"]/*' />
  377. /// <devdoc>
  378. /// <para>
  379. /// Gets or sets a value indicating whether a copy of the message that could not
  380. /// be delivered should be sent to a dead-letter queue.
  381. /// </para>
  382. /// </devdoc>
  383. [DefaultValueAttribute(false), MessagingDescription(Res.MsgUseDeadLetterQueue)]
  384. public bool UseDeadLetterQueue
  385. {
  386. get
  387. {
  388. return this.cachedMessage.UseDeadLetterQueue;
  389. }
  390. set
  391. {
  392. this.cachedMessage.UseDeadLetterQueue = value;
  393. }
  394. }
  395. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.UseEncryption"]/*' />
  396. /// <devdoc>
  397. /// <para>
  398. /// Gets or sets a value indicating whether to encrypt private messages.
  399. /// </para>
  400. /// </devdoc>
  401. [DefaultValueAttribute(false), MessagingDescription(Res.MsgUseEncryption)]
  402. public bool UseEncryption
  403. {
  404. get
  405. {
  406. return this.cachedMessage.UseEncryption;
  407. }
  408. set
  409. {
  410. this.cachedMessage.UseEncryption = value;
  411. }
  412. }
  413. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.UseJournalQueue"]/*' />
  414. /// <devdoc>
  415. /// <para>
  416. /// Gets or sets a value indicating whether a copy of the message should be kept
  417. /// in a machine journal on the originating computer.
  418. /// </para>
  419. /// </devdoc>
  420. [DefaultValueAttribute(false), MessagingDescription(Res.MsgUseJournalQueue)]
  421. public bool UseJournalQueue
  422. {
  423. get
  424. {
  425. return this.cachedMessage.UseJournalQueue;
  426. }
  427. set
  428. {
  429. this.cachedMessage.UseJournalQueue = value;
  430. }
  431. }
  432. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.UseTracing"]/*' />
  433. /// <devdoc>
  434. /// <para>
  435. /// Gets or sets a value indicating whether to trace a message as it moves toward
  436. /// its destination queue.
  437. /// </para>
  438. /// </devdoc>
  439. [DefaultValueAttribute(false), MessagingDescription(Res.MsgUseTracing)]
  440. public bool UseTracing
  441. {
  442. get
  443. {
  444. return this.cachedMessage.UseTracing;
  445. }
  446. set
  447. {
  448. this.cachedMessage.UseTracing = value;
  449. }
  450. }
  451. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.ShouldSerializeTimeToBeReceived"]/*' />
  452. /// <internalonly/>
  453. private bool ShouldSerializeTimeToBeReceived()
  454. {
  455. if (TimeToBeReceived == Message.InfiniteTimeout)
  456. return false;
  457. return true;
  458. }
  459. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.ShouldSerializeTimeToReachQueue"]/*' />
  460. /// <internalonly/>
  461. private bool ShouldSerializeTimeToReachQueue()
  462. {
  463. if (TimeToReachQueue == Message.InfiniteTimeout)
  464. return false;
  465. return true;
  466. }
  467. /// <include file='doc\DefaultPropertiesToSend.uex' path='docs/doc[@for="DefaultPropertiesToSend.ShouldSerializeExtension"]/*' />
  468. /// <internalonly/>
  469. private bool ShouldSerializeExtension()
  470. {
  471. if (Extension != null && Extension.Length > 0)
  472. {
  473. return true;
  474. }
  475. return false;
  476. }
  477. }
  478. }