OperationMessageCollection.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. using System.Web.Services;
  10. namespace System.Web.Services.Description {
  11. public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {
  12. #region Constructors
  13. internal OperationMessageCollection (Operation operation)
  14. : base (operation)
  15. {
  16. }
  17. #endregion // Constructors
  18. #region Properties
  19. public OperationFlow Flow {
  20. get {
  21. switch (Count) {
  22. case 1:
  23. if (this[0] is OperationInput)
  24. return OperationFlow.OneWay;
  25. else
  26. return OperationFlow.Notification;
  27. case 2:
  28. if (this[0] is OperationInput)
  29. return OperationFlow.RequestResponse;
  30. else
  31. return OperationFlow.SolicitResponse;
  32. }
  33. return OperationFlow.None;
  34. }
  35. }
  36. public OperationInput Input {
  37. get {
  38. foreach (object message in List)
  39. if (message is OperationInput)
  40. return (OperationInput) message;
  41. return null;
  42. }
  43. }
  44. public OperationMessage this [int index] {
  45. get { return (OperationMessage) List[index]; }
  46. set { List[index] = value; }
  47. }
  48. public OperationOutput Output {
  49. get {
  50. foreach (object message in List)
  51. if (message is OperationOutput)
  52. return (OperationOutput) message;
  53. return null;
  54. }
  55. }
  56. #endregion // Properties
  57. #region Methods
  58. protected override string GetKey (object value)
  59. {
  60. if (!(value is OperationMessage))
  61. throw new InvalidCastException ();
  62. return ((OperationMessage) value).Name;
  63. }
  64. public int Add (OperationMessage operationMessage)
  65. {
  66. Insert (Count, operationMessage);
  67. return (Count - 1);
  68. }
  69. public bool Contains (OperationMessage operationMessage)
  70. {
  71. return List.Contains (operationMessage);
  72. }
  73. public void CopyTo (OperationMessage[] array, int index)
  74. {
  75. List.CopyTo (array, index);
  76. }
  77. public int IndexOf (OperationMessage operationMessage)
  78. {
  79. return List.IndexOf (operationMessage);
  80. }
  81. public void Insert (int index, OperationMessage operationMessage)
  82. {
  83. List.Insert (index, operationMessage);
  84. }
  85. protected override void OnInsert (int index, object value)
  86. {
  87. if (Count == 0)
  88. return;
  89. if (Count == 1 && value.GetType() != this[0].GetType())
  90. return;
  91. throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
  92. }
  93. protected override void OnSet (int index, object oldValue, object newValue)
  94. {
  95. if (oldValue.GetType () != newValue.GetType ())
  96. throw new InvalidOperationException ("The message types of the old and new value are not the same.");
  97. base.OnSet (index, oldValue, newValue);
  98. }
  99. protected override void OnValidate (object value)
  100. {
  101. if (value == null)
  102. throw new ArgumentException("The message object is a null reference.");
  103. if (!(value is OperationInput || value is OperationOutput))
  104. throw new ArgumentException ("The message object is not an input or an output message.");
  105. }
  106. public void Remove (OperationMessage operationMessage)
  107. {
  108. List.Remove (operationMessage);
  109. }
  110. protected override void SetParent (object value, object parent)
  111. {
  112. ((OperationMessage) value).SetParent ((Operation) parent);
  113. }
  114. #endregion // Methods
  115. }
  116. }