OperationMessageCollection.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // System.Web.Services.Description.OperationMessageCollection.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.Web.Services;
  30. namespace System.Web.Services.Description {
  31. public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {
  32. #region Constructors
  33. internal OperationMessageCollection (Operation operation)
  34. : base (operation)
  35. {
  36. }
  37. #endregion // Constructors
  38. #region Properties
  39. public OperationFlow Flow {
  40. get {
  41. switch (Count) {
  42. case 1:
  43. if (this[0] is OperationInput)
  44. return OperationFlow.OneWay;
  45. else
  46. return OperationFlow.Notification;
  47. case 2:
  48. if (this[0] is OperationInput)
  49. return OperationFlow.RequestResponse;
  50. else
  51. return OperationFlow.SolicitResponse;
  52. }
  53. return OperationFlow.None;
  54. }
  55. }
  56. public OperationInput Input {
  57. get {
  58. foreach (object message in List)
  59. if (message is OperationInput)
  60. return (OperationInput) message;
  61. return null;
  62. }
  63. }
  64. public OperationMessage this [int index] {
  65. get { return (OperationMessage) List[index]; }
  66. set { List[index] = value; }
  67. }
  68. public OperationOutput Output {
  69. get {
  70. foreach (object message in List)
  71. if (message is OperationOutput)
  72. return (OperationOutput) message;
  73. return null;
  74. }
  75. }
  76. internal OperationFault Fault {
  77. get {
  78. foreach (object message in List)
  79. if (message is OperationFault)
  80. return (OperationFault) message;
  81. return null;
  82. }
  83. }
  84. #endregion // Properties
  85. #region Methods
  86. protected override string GetKey (object value)
  87. {
  88. if (!(value is OperationMessage))
  89. throw new InvalidCastException ();
  90. return ((OperationMessage) value).Name;
  91. }
  92. public int Add (OperationMessage operationMessage)
  93. {
  94. Insert (Count, operationMessage);
  95. return (Count - 1);
  96. }
  97. public bool Contains (OperationMessage operationMessage)
  98. {
  99. return List.Contains (operationMessage);
  100. }
  101. public void CopyTo (OperationMessage[] array, int index)
  102. {
  103. List.CopyTo (array, index);
  104. }
  105. public int IndexOf (OperationMessage operationMessage)
  106. {
  107. return List.IndexOf (operationMessage);
  108. }
  109. public void Insert (int index, OperationMessage operationMessage)
  110. {
  111. List.Insert (index, operationMessage);
  112. }
  113. protected override void OnInsert (int index, object value)
  114. {
  115. if (Count == 0)
  116. return;
  117. if (Count == 1 && value.GetType() != this[0].GetType())
  118. return;
  119. throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
  120. }
  121. protected override void OnSet (int index, object oldValue, object newValue)
  122. {
  123. if (oldValue.GetType () != newValue.GetType ())
  124. throw new InvalidOperationException ("The message types of the old and new value are not the same.");
  125. base.OnSet (index, oldValue, newValue);
  126. }
  127. protected override void OnValidate (object value)
  128. {
  129. if (value == null)
  130. throw new ArgumentException("The message object is a null reference.");
  131. if (!(value is OperationInput || value is OperationOutput))
  132. throw new ArgumentException ("The message object is not an input or an output message.");
  133. }
  134. public void Remove (OperationMessage operationMessage)
  135. {
  136. List.Remove (operationMessage);
  137. }
  138. protected override void SetParent (object value, object parent)
  139. {
  140. ((OperationMessage) value).SetParent ((Operation) parent);
  141. }
  142. #endregion // Methods
  143. }
  144. }