OperationMessageCollection.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. public int Add (OperationMessage operationMessage)
  59. {
  60. Insert (Count, operationMessage);
  61. return (Count - 1);
  62. }
  63. public bool Contains (OperationMessage operationMessage)
  64. {
  65. return List.Contains (operationMessage);
  66. }
  67. public void CopyTo (OperationMessage[] array, int index)
  68. {
  69. List.CopyTo (array, index);
  70. }
  71. public int IndexOf (OperationMessage operationMessage)
  72. {
  73. return List.IndexOf (operationMessage);
  74. }
  75. public void Insert (int index, OperationMessage operationMessage)
  76. {
  77. List.Insert (index, operationMessage);
  78. }
  79. protected override void OnInsert (int index, object value)
  80. {
  81. if (Count > 2 || value.GetType () == this [0].GetType ())
  82. throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
  83. }
  84. protected override void OnSet (int index, object oldValue, object newValue)
  85. {
  86. if (oldValue.GetType () != newValue.GetType ())
  87. throw new InvalidOperationException ("The message types of the old and new value are not the same.");
  88. base.OnSet (index, oldValue, newValue);
  89. }
  90. protected override void OnValidate (object value)
  91. {
  92. if (value == null)
  93. throw new NullReferenceException ("The message object is a null reference.");
  94. if (!(value is OperationInput || value is OperationOutput))
  95. throw new ArgumentException ("The message object is not an input or an output message.");
  96. }
  97. public void Remove (OperationMessage operationMessage)
  98. {
  99. List.Remove (operationMessage);
  100. }
  101. protected override void SetParent (object value, object parent)
  102. {
  103. ((OperationMessage) value).SetParent ((Operation) parent);
  104. }
  105. #endregion // Methods
  106. }
  107. }