TransactionFormatter.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Transactions
  5. {
  6. using System;
  7. using System.ServiceModel.Channels;
  8. using System.Diagnostics;
  9. using System.ServiceModel;
  10. using System.Transactions;
  11. abstract class TransactionFormatter
  12. {
  13. static TransactionFormatter oleTxFormatter = new OleTxTransactionFormatter();
  14. static object syncRoot = new object();
  15. public static TransactionFormatter OleTxFormatter
  16. {
  17. get { return oleTxFormatter; }
  18. }
  19. // Double-checked locking pattern requires volatile for read/write synchronization
  20. static volatile TransactionFormatter wsatFormatter10;
  21. public static TransactionFormatter WsatFormatter10
  22. {
  23. get
  24. {
  25. if (wsatFormatter10 == null)
  26. {
  27. lock (syncRoot)
  28. {
  29. if (wsatFormatter10 == null)
  30. {
  31. wsatFormatter10 = new WsatTransactionFormatter10();
  32. }
  33. }
  34. }
  35. return wsatFormatter10;
  36. }
  37. }
  38. // Double-checked locking pattern requires volatile for read/write synchronization
  39. static volatile TransactionFormatter wsatFormatter11;
  40. public static TransactionFormatter WsatFormatter11
  41. {
  42. get
  43. {
  44. if (wsatFormatter11 == null)
  45. {
  46. lock (syncRoot)
  47. {
  48. if (wsatFormatter11 == null)
  49. {
  50. wsatFormatter11 = new WsatTransactionFormatter11();
  51. }
  52. }
  53. }
  54. return wsatFormatter11;
  55. }
  56. }
  57. public abstract MessageHeader EmptyTransactionHeader
  58. {
  59. get;
  60. }
  61. // Write transaction information to a message
  62. //
  63. // Return the transaction protocols that were successfully written to the message
  64. // Throw TransactionException if something goes wrong (e.g., TM comms failure)
  65. public abstract void WriteTransaction(Transaction transaction, Message message);
  66. // Read transaction information from a message
  67. //
  68. // Return a TransactionInfo instance if transaction headers are present in the message
  69. // Return null if no transaction headers are present in the message
  70. // Throw TransactionException if something goes wrong (e.g., malformed XML)
  71. public abstract TransactionInfo ReadTransaction(Message message);
  72. }
  73. abstract class TransactionInfo
  74. {
  75. // Convert transaction information from a message into an actual transaction
  76. //
  77. // Return a transaction instance if successful (fallback down the list of protocols as needed)
  78. // Throw TransactionException if a could not be unmarshaled.
  79. //
  80. // Should not throw an exception
  81. public abstract Transaction UnmarshalTransaction();
  82. }
  83. }