BoundObject.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. using CefSharp;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace UAS_Web.tool
  9. {
  10. class BoundObject
  11. {
  12. public int MyProperty { get; set; }
  13. public string MyReadOnlyProperty { get; internal set; }
  14. public Type MyUnconvertibleProperty { get; set; }
  15. public SubBoundObject SubObject { get; set; }
  16. public ExceptionTestBoundObject ExceptionTestObject { get; set; }
  17. public int this[int i]
  18. {
  19. get { return i; }
  20. set { }
  21. }
  22. public uint[] MyUintArray
  23. {
  24. get { return new uint[] { 7, 8 }; }
  25. }
  26. public int[] MyIntArray
  27. {
  28. get { return new[] { 1, 2, 3, 4, 5, 6, 7, 8 }; }
  29. }
  30. public Array MyArray
  31. {
  32. get { return new short[] { 1, 2, 3 }; }
  33. }
  34. public byte[] MyBytes
  35. {
  36. get { return new byte[] { 3, 4, 5 }; }
  37. }
  38. public BoundObject()
  39. {
  40. MyProperty = 42;
  41. MyReadOnlyProperty = "I'm immutable!";
  42. IgnoredProperty = "I am an Ignored Property";
  43. MyUnconvertibleProperty = GetType();
  44. SubObject = new SubBoundObject();
  45. ExceptionTestObject = new ExceptionTestBoundObject();
  46. }
  47. public void TestCallback(IJavascriptCallback javascriptCallback)
  48. {
  49. //Task.Factory.StartNew(async () =>
  50. //{
  51. // using (javascriptCallback)
  52. // {
  53. // //Computer computer = new Computer();
  54. // string response = JsonConvert.SerializeObject(new
  55. // {
  56. // //cpu_id = computer.CPU_Id,
  57. // //disk_id = computer.Disk_Id,
  58. // //host_name = computer.HostName,
  59. // //networkcard = computer.NetworkCard,
  60. // //serialNumber = computer.SerialNumber_Manufacturer_Product.Item1,
  61. // //manufacturer = computer.SerialNumber_Manufacturer_Product.Item2,
  62. // //product = computer.SerialNumber_Manufacturer_Product.Item3,
  63. // });
  64. // //await javascriptCallback.ExecuteAsync(null);
  65. // }
  66. //});
  67. //const int taskDelay = 1500;
  68. //Task.Factory.StartNew(async () =>
  69. //{
  70. // await TaskEx.Delay(taskDelay);
  71. // using (javascriptCallback)
  72. // {
  73. // //NOTE: Classes are not supported, simple structs are
  74. // var response = new CallbackResponseStruct("This callback from C# was delayed " + taskDelay + "ms");
  75. // await javascriptCallback.ExecuteAsync(response);
  76. // }
  77. //});
  78. }
  79. //public string TestCallbackFromObject(SimpleClass simpleClass)
  80. //{
  81. // if (simpleClass == null)
  82. // {
  83. // return "TestCallbackFromObject dictionary param is null";
  84. // }
  85. // IJavascriptCallback javascriptCallback = simpleClass.Callback;
  86. // if (javascriptCallback == null)
  87. // {
  88. // return "callback property not found or property is not a function";
  89. // }
  90. // const int taskDelay = 1500;
  91. // TaskEx.Run(async () =>
  92. // {
  93. // await TaskEx.Delay(taskDelay);
  94. // if (javascriptCallback != null)
  95. // {
  96. // using (javascriptCallback)
  97. // {
  98. // await javascriptCallback.ExecuteAsync("message from C# " + simpleClass.TestString + " - " + simpleClass.SubClasses[0].PropertyOne);
  99. // }
  100. // }
  101. // });
  102. // return "waiting for callback execution...";
  103. //}
  104. public int EchoMyProperty()
  105. {
  106. return MyProperty;
  107. }
  108. public string Repeat(string str, int n)
  109. {
  110. string result = String.Empty;
  111. for (int i = 0; i < n; i++)
  112. {
  113. result += str;
  114. }
  115. return result;
  116. }
  117. public string EchoParamOrDefault(string param = "This is the default value")
  118. {
  119. return param;
  120. }
  121. public void EchoVoid()
  122. {
  123. }
  124. public Boolean EchoBoolean(Boolean arg0)
  125. {
  126. return arg0;
  127. }
  128. public Boolean? EchoNullableBoolean(Boolean? arg0)
  129. {
  130. return arg0;
  131. }
  132. public SByte EchoSByte(SByte arg0)
  133. {
  134. return arg0;
  135. }
  136. public SByte? EchoNullableSByte(SByte? arg0)
  137. {
  138. return arg0;
  139. }
  140. public Int16 EchoInt16(Int16 arg0)
  141. {
  142. return arg0;
  143. }
  144. public Int16? EchoNullableInt16(Int16? arg0)
  145. {
  146. return arg0;
  147. }
  148. public Int32 EchoInt32(Int32 arg0)
  149. {
  150. return arg0;
  151. }
  152. public Int32? EchoNullableInt32(Int32? arg0)
  153. {
  154. return arg0;
  155. }
  156. public Int64 EchoInt64(Int64 arg0)
  157. {
  158. return arg0;
  159. }
  160. public Int64? EchoNullableInt64(Int64? arg0)
  161. {
  162. return arg0;
  163. }
  164. public Byte EchoByte(Byte arg0)
  165. {
  166. return arg0;
  167. }
  168. public Byte? EchoNullableByte(Byte? arg0)
  169. {
  170. return arg0;
  171. }
  172. public UInt16 EchoUInt16(UInt16 arg0)
  173. {
  174. return arg0;
  175. }
  176. public UInt16? EchoNullableUInt16(UInt16? arg0)
  177. {
  178. return arg0;
  179. }
  180. public UInt32 EchoUInt32(UInt32 arg0)
  181. {
  182. return arg0;
  183. }
  184. public UInt32? EchoNullableUInt32(UInt32? arg0)
  185. {
  186. return arg0;
  187. }
  188. public UInt64 EchoUInt64(UInt64 arg0)
  189. {
  190. return arg0;
  191. }
  192. public UInt64? EchoNullableUInt64(UInt64? arg0)
  193. {
  194. return arg0;
  195. }
  196. public Single EchoSingle(Single arg0)
  197. {
  198. return arg0;
  199. }
  200. public Single? EchoNullableSingle(Single? arg0)
  201. {
  202. return arg0;
  203. }
  204. public Double EchoDouble(Double arg0)
  205. {
  206. return arg0;
  207. }
  208. public Double? EchoNullableDouble(Double? arg0)
  209. {
  210. return arg0;
  211. }
  212. public Char EchoChar(Char arg0)
  213. {
  214. return arg0;
  215. }
  216. public Char? EchoNullableChar(Char? arg0)
  217. {
  218. return arg0;
  219. }
  220. public DateTime EchoDateTime(DateTime arg0)
  221. {
  222. return arg0;
  223. }
  224. public DateTime? EchoNullableDateTime(DateTime? arg0)
  225. {
  226. return arg0;
  227. }
  228. public Decimal EchoDecimal(Decimal arg0)
  229. {
  230. return arg0;
  231. }
  232. public Decimal? EchoNullableDecimal(Decimal? arg0)
  233. {
  234. return arg0;
  235. }
  236. public String EchoString(String arg0)
  237. {
  238. return arg0;
  239. }
  240. // TODO: This will currently not work, as it causes a collision w/ the EchoString() method. We need to find a way around that I guess.
  241. //public String echoString(String arg)
  242. //{
  243. // return "Lowercase echo: " + arg;
  244. //}
  245. public String lowercaseMethod()
  246. {
  247. return "lowercase";
  248. }
  249. public string ReturnJsonEmployeeList()
  250. {
  251. return "{\"employees\":[{\"firstName\":\"John\", \"lastName\":\"Doe\"},{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},{\"firstName\":\"Peter\", \"lastName\":\"Jones\"}]}";
  252. }
  253. [JavascriptIgnore]
  254. public string IgnoredProperty { get; set; }
  255. [JavascriptIgnore]
  256. public string IgnoredMethod()
  257. {
  258. return "I am an Ignored Method";
  259. }
  260. public string ComplexParamObject(object param)
  261. {
  262. if (param == null)
  263. {
  264. return "param is null";
  265. }
  266. return "The param type is:" + param.GetType();
  267. }
  268. public SubBoundObject GetSubObject()
  269. {
  270. return SubObject;
  271. }
  272. /// <summary>
  273. /// Demonstrates the use of params as an argument in a bound object
  274. /// </summary>
  275. /// <param name="name">Dummy Argument</param>
  276. /// <param name="args">Params Argument</param>
  277. public string MethodWithParams(string name, params object[] args)
  278. {
  279. return "Name:" + name + ";Args:" + string.Join(", ", args.ToArray());
  280. }
  281. public string MethodWithoutParams(string name, string arg2)
  282. {
  283. return string.Format("{0}, {1}", name, arg2);
  284. }
  285. public string MethodWithoutAnything()
  286. {
  287. return "Method without anything called and returned successfully.";
  288. }
  289. public string MethodWithThreeParamsOneOptionalOneArray(string name, string optionalParam = null, params object[] args)
  290. {
  291. return "MethodWithThreeParamsOneOptionalOneArray:" + (name ?? "No Name Specified") + " - " + (optionalParam ?? "No Optional Param Specified") + ";Args:" + string.Join(", ", args.ToArray());
  292. }
  293. }
  294. }