PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Web.Services/System.Web.Services.Description/OperationMessageCollection.cs

https://bitbucket.org/danipen/mono
C# | 173 lines | 117 code | 28 blank | 28 comment | 20 complexity | 026dd1049c79a0900ff5eac2eb8e3d1d MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //
  2. // System.Web.Services.Description.OperationMessageCollection.cs
  3. //
  4. // Author:
  5. // Tim Coleman (tim@timcoleman.com)
  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. public int Add (OperationMessage operationMessage)
  87. {
  88. Insert (Count, operationMessage);
  89. return (Count - 1);
  90. }
  91. public bool Contains (OperationMessage operationMessage)
  92. {
  93. return List.Contains (operationMessage);
  94. }
  95. public void CopyTo (OperationMessage[] array, int index)
  96. {
  97. List.CopyTo (array, index);
  98. }
  99. internal OperationMessage Find (string name)
  100. {
  101. foreach (OperationMessage m in List)
  102. if (m.Name == name)
  103. return m;
  104. return null;
  105. }
  106. public int IndexOf (OperationMessage operationMessage)
  107. {
  108. return List.IndexOf (operationMessage);
  109. }
  110. public void Insert (int index, OperationMessage operationMessage)
  111. {
  112. List.Insert (index, operationMessage);
  113. }
  114. protected override void OnInsert (int index, object value)
  115. {
  116. if (Count == 0)
  117. return;
  118. if (Count == 1 && value.GetType() != this[0].GetType())
  119. return;
  120. throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
  121. }
  122. protected override void OnSet (int index, object oldValue, object newValue)
  123. {
  124. if (oldValue.GetType () != newValue.GetType ())
  125. throw new InvalidOperationException ("The message types of the old and new value are not the same.");
  126. base.OnSet (index, oldValue, newValue);
  127. }
  128. protected override void OnValidate (object value)
  129. {
  130. if (value == null)
  131. throw new ArgumentException("The message object is a null reference.");
  132. if (!(value is OperationInput || value is OperationOutput))
  133. throw new ArgumentException ("The message object is not an input or an output message.");
  134. }
  135. public void Remove (OperationMessage operationMessage)
  136. {
  137. List.Remove (operationMessage);
  138. }
  139. protected override void SetParent (object value, object parent)
  140. {
  141. ((OperationMessage) value).SetParent ((Operation) parent);
  142. }
  143. #endregion // Methods
  144. }
  145. }