ServerObject.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // MonoTests.Remoting.ServerObject.cs
  3. //
  4. // Author: Lluis Sanchez Gual ([email protected])
  5. //
  6. // 2003 (C) Copyright, Ximian, Inc.
  7. //
  8. using System;
  9. using System.Runtime.Remoting;
  10. using System.Runtime.Remoting.Lifetime;
  11. using System.Collections;
  12. namespace MonoTests.Remoting
  13. {
  14. // A list of ServerObject instances
  15. [ContextHook("x", false)]
  16. public class ServerList:
  17. ContextBoundObject,
  18. IDisposable
  19. {
  20. ArrayList values = new ArrayList();
  21. public int NumVal = 0;
  22. public string StrVal = "val";
  23. public ServerList()
  24. {
  25. CallSeq.Add ("List created");
  26. }
  27. public void Dispose()
  28. {
  29. CallSeq.Add ("List disposed");
  30. }
  31. public void Add (ServerObject v)
  32. {
  33. values.Add (v);
  34. CallSeq.Add ("Added " + v.Name);
  35. }
  36. public void ProcessItems ()
  37. {
  38. CallSeq.Add ("Processing");
  39. int total = 0;
  40. foreach (ServerObject ob in values)
  41. total += ob.GetValue();
  42. CallSeq.Add ("Total: " + total);
  43. }
  44. public void Clear()
  45. {
  46. CallSeq.Add ("Clearing");
  47. values.Clear();
  48. }
  49. public void ParameterTest1 (int a, out string b)
  50. {
  51. b = "adeu " + a;
  52. }
  53. public void ParameterTest2 (int a, out int b)
  54. {
  55. b = a+1;
  56. }
  57. public ServerObject NewItem(string name)
  58. {
  59. ServerObject obj = new ServerObject(name);
  60. Add (obj);
  61. return obj;
  62. }
  63. public ServerObject CreateItem(string name, int val)
  64. {
  65. ServerObject obj = new ServerObject(name);
  66. obj.SetValue (val);
  67. return obj;
  68. }
  69. public ComplexData SetComplexData (ComplexData data)
  70. {
  71. CallSeq.Add ("Showing content of ComplexData");
  72. data.Dump ();
  73. return data;
  74. }
  75. public override ObjRef CreateObjRef (Type type)
  76. {
  77. CallSeq.Add ("### ServerList.CreateObjRef");
  78. return base.CreateObjRef (type);
  79. }
  80. }
  81. // A remotable object
  82. public class ServerObject:
  83. // ContextBoundObject
  84. MarshalByRefObject
  85. {
  86. int _value;
  87. string _name;
  88. public ServerObject (string name)
  89. {
  90. _name = name;
  91. }
  92. public string Name
  93. {
  94. get { return _name; }
  95. }
  96. public void SetValue (int v)
  97. {
  98. CallSeq.Add ("ServerObject " + _name + ": setting " + v);
  99. _value = v;
  100. }
  101. public int GetValue ()
  102. {
  103. CallSeq.Add ("ServerObject " + _name + ": getting " + _value);
  104. return _value;
  105. }
  106. public override ObjRef CreateObjRef (Type type)
  107. {
  108. CallSeq.Add ("### ServerObject.CreateObjRef");
  109. return base.CreateObjRef (type);
  110. }
  111. }
  112. // Some complex data for testing serialization
  113. public enum AnEnum { a,b,c,d,e };
  114. [Serializable]
  115. public class ComplexData
  116. {
  117. public AnEnum Val = AnEnum.a;
  118. public object[] Info;
  119. public ComplexData (AnEnum va, object[] info)
  120. {
  121. Info = info;
  122. Val = va;
  123. }
  124. public void Dump ()
  125. {
  126. CallSeq.Add ("Content:");
  127. CallSeq.Add ("Val: " + Val);
  128. foreach (object ob in Info)
  129. CallSeq.Add ("Array item: " + ob);
  130. }
  131. }
  132. }