TerminateSequence.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System;
  7. using System.Runtime;
  8. using System.ServiceModel;
  9. using System.Xml;
  10. sealed class TerminateSequence : BodyWriter
  11. {
  12. UniqueId identifier;
  13. Int64 lastMsgNumber;
  14. ReliableMessagingVersion reliableMessagingVersion;
  15. public TerminateSequence()
  16. : base(true)
  17. {
  18. }
  19. public TerminateSequence(ReliableMessagingVersion reliableMessagingVersion, UniqueId identifier, Int64 last)
  20. : base(true)
  21. {
  22. this.reliableMessagingVersion = reliableMessagingVersion;
  23. this.identifier = identifier;
  24. this.lastMsgNumber = last;
  25. }
  26. public static TerminateSequenceInfo Create(ReliableMessagingVersion reliableMessagingVersion,
  27. XmlDictionaryReader reader)
  28. {
  29. if (reader == null)
  30. {
  31. Fx.Assert("Argument reader cannot be null.");
  32. }
  33. TerminateSequenceInfo terminateSequenceInfo = new TerminateSequenceInfo();
  34. WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
  35. XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);
  36. reader.ReadStartElement(wsrmFeb2005Dictionary.TerminateSequence, wsrmNs);
  37. reader.ReadStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
  38. terminateSequenceInfo.Identifier = reader.ReadContentAsUniqueId();
  39. reader.ReadEndElement();
  40. if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
  41. {
  42. if (reader.IsStartElement(DXD.Wsrm11Dictionary.LastMsgNumber, wsrmNs))
  43. {
  44. reader.ReadStartElement();
  45. terminateSequenceInfo.LastMsgNumber = WsrmUtilities.ReadSequenceNumber(reader, false);
  46. reader.ReadEndElement();
  47. }
  48. }
  49. while (reader.IsStartElement())
  50. {
  51. reader.Skip();
  52. }
  53. reader.ReadEndElement();
  54. return terminateSequenceInfo;
  55. }
  56. protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
  57. {
  58. WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
  59. XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(this.reliableMessagingVersion);
  60. writer.WriteStartElement(wsrmFeb2005Dictionary.TerminateSequence, wsrmNs);
  61. writer.WriteStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
  62. writer.WriteValue(this.identifier);
  63. writer.WriteEndElement();
  64. if (this.reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
  65. {
  66. if (this.lastMsgNumber > 0)
  67. {
  68. writer.WriteStartElement(DXD.Wsrm11Dictionary.LastMsgNumber, wsrmNs);
  69. writer.WriteValue(this.lastMsgNumber);
  70. writer.WriteEndElement();
  71. }
  72. }
  73. writer.WriteEndElement();
  74. }
  75. }
  76. }