ServerObject.cs 3.6 KB

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