| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- using CefSharp;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UAS_Web.tool
- {
- class BoundObject
- {
- public int MyProperty { get; set; }
- public string MyReadOnlyProperty { get; internal set; }
- public Type MyUnconvertibleProperty { get; set; }
- public SubBoundObject SubObject { get; set; }
- public ExceptionTestBoundObject ExceptionTestObject { get; set; }
- public int this[int i]
- {
- get { return i; }
- set { }
- }
- public uint[] MyUintArray
- {
- get { return new uint[] { 7, 8 }; }
- }
- public int[] MyIntArray
- {
- get { return new[] { 1, 2, 3, 4, 5, 6, 7, 8 }; }
- }
- public Array MyArray
- {
- get { return new short[] { 1, 2, 3 }; }
- }
- public byte[] MyBytes
- {
- get { return new byte[] { 3, 4, 5 }; }
- }
- public BoundObject()
- {
- MyProperty = 42;
- MyReadOnlyProperty = "I'm immutable!";
- IgnoredProperty = "I am an Ignored Property";
- MyUnconvertibleProperty = GetType();
- SubObject = new SubBoundObject();
- ExceptionTestObject = new ExceptionTestBoundObject();
- }
- public void TestCallback(IJavascriptCallback javascriptCallback)
- {
- //Task.Factory.StartNew(async () =>
- //{
- // using (javascriptCallback)
- // {
- // //Computer computer = new Computer();
- // string response = JsonConvert.SerializeObject(new
- // {
- // //cpu_id = computer.CPU_Id,
- // //disk_id = computer.Disk_Id,
- // //host_name = computer.HostName,
- // //networkcard = computer.NetworkCard,
- // //serialNumber = computer.SerialNumber_Manufacturer_Product.Item1,
- // //manufacturer = computer.SerialNumber_Manufacturer_Product.Item2,
- // //product = computer.SerialNumber_Manufacturer_Product.Item3,
- // });
- // //await javascriptCallback.ExecuteAsync(null);
- // }
- //});
- //const int taskDelay = 1500;
- //Task.Factory.StartNew(async () =>
- //{
- // await TaskEx.Delay(taskDelay);
- // using (javascriptCallback)
- // {
- // //NOTE: Classes are not supported, simple structs are
- // var response = new CallbackResponseStruct("This callback from C# was delayed " + taskDelay + "ms");
- // await javascriptCallback.ExecuteAsync(response);
- // }
- //});
- }
- //public string TestCallbackFromObject(SimpleClass simpleClass)
- //{
- // if (simpleClass == null)
- // {
- // return "TestCallbackFromObject dictionary param is null";
- // }
- // IJavascriptCallback javascriptCallback = simpleClass.Callback;
- // if (javascriptCallback == null)
- // {
- // return "callback property not found or property is not a function";
- // }
- // const int taskDelay = 1500;
- // TaskEx.Run(async () =>
- // {
- // await TaskEx.Delay(taskDelay);
- // if (javascriptCallback != null)
- // {
- // using (javascriptCallback)
- // {
- // await javascriptCallback.ExecuteAsync("message from C# " + simpleClass.TestString + " - " + simpleClass.SubClasses[0].PropertyOne);
- // }
- // }
- // });
- // return "waiting for callback execution...";
- //}
- public int EchoMyProperty()
- {
- return MyProperty;
- }
- public string Repeat(string str, int n)
- {
- string result = String.Empty;
- for (int i = 0; i < n; i++)
- {
- result += str;
- }
- return result;
- }
- public string EchoParamOrDefault(string param = "This is the default value")
- {
- return param;
- }
- public void EchoVoid()
- {
- }
- public Boolean EchoBoolean(Boolean arg0)
- {
- return arg0;
- }
- public Boolean? EchoNullableBoolean(Boolean? arg0)
- {
- return arg0;
- }
- public SByte EchoSByte(SByte arg0)
- {
- return arg0;
- }
- public SByte? EchoNullableSByte(SByte? arg0)
- {
- return arg0;
- }
- public Int16 EchoInt16(Int16 arg0)
- {
- return arg0;
- }
- public Int16? EchoNullableInt16(Int16? arg0)
- {
- return arg0;
- }
- public Int32 EchoInt32(Int32 arg0)
- {
- return arg0;
- }
- public Int32? EchoNullableInt32(Int32? arg0)
- {
- return arg0;
- }
- public Int64 EchoInt64(Int64 arg0)
- {
- return arg0;
- }
- public Int64? EchoNullableInt64(Int64? arg0)
- {
- return arg0;
- }
- public Byte EchoByte(Byte arg0)
- {
- return arg0;
- }
- public Byte? EchoNullableByte(Byte? arg0)
- {
- return arg0;
- }
- public UInt16 EchoUInt16(UInt16 arg0)
- {
- return arg0;
- }
- public UInt16? EchoNullableUInt16(UInt16? arg0)
- {
- return arg0;
- }
- public UInt32 EchoUInt32(UInt32 arg0)
- {
- return arg0;
- }
- public UInt32? EchoNullableUInt32(UInt32? arg0)
- {
- return arg0;
- }
- public UInt64 EchoUInt64(UInt64 arg0)
- {
- return arg0;
- }
- public UInt64? EchoNullableUInt64(UInt64? arg0)
- {
- return arg0;
- }
- public Single EchoSingle(Single arg0)
- {
- return arg0;
- }
- public Single? EchoNullableSingle(Single? arg0)
- {
- return arg0;
- }
- public Double EchoDouble(Double arg0)
- {
- return arg0;
- }
- public Double? EchoNullableDouble(Double? arg0)
- {
- return arg0;
- }
- public Char EchoChar(Char arg0)
- {
- return arg0;
- }
- public Char? EchoNullableChar(Char? arg0)
- {
- return arg0;
- }
- public DateTime EchoDateTime(DateTime arg0)
- {
- return arg0;
- }
- public DateTime? EchoNullableDateTime(DateTime? arg0)
- {
- return arg0;
- }
- public Decimal EchoDecimal(Decimal arg0)
- {
- return arg0;
- }
- public Decimal? EchoNullableDecimal(Decimal? arg0)
- {
- return arg0;
- }
- public String EchoString(String arg0)
- {
- return arg0;
- }
- // 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.
- //public String echoString(String arg)
- //{
- // return "Lowercase echo: " + arg;
- //}
- public String lowercaseMethod()
- {
- return "lowercase";
- }
- public string ReturnJsonEmployeeList()
- {
- return "{\"employees\":[{\"firstName\":\"John\", \"lastName\":\"Doe\"},{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},{\"firstName\":\"Peter\", \"lastName\":\"Jones\"}]}";
- }
- [JavascriptIgnore]
- public string IgnoredProperty { get; set; }
- [JavascriptIgnore]
- public string IgnoredMethod()
- {
- return "I am an Ignored Method";
- }
- public string ComplexParamObject(object param)
- {
- if (param == null)
- {
- return "param is null";
- }
- return "The param type is:" + param.GetType();
- }
- public SubBoundObject GetSubObject()
- {
- return SubObject;
- }
- /// <summary>
- /// Demonstrates the use of params as an argument in a bound object
- /// </summary>
- /// <param name="name">Dummy Argument</param>
- /// <param name="args">Params Argument</param>
- public string MethodWithParams(string name, params object[] args)
- {
- return "Name:" + name + ";Args:" + string.Join(", ", args.ToArray());
- }
- public string MethodWithoutParams(string name, string arg2)
- {
- return string.Format("{0}, {1}", name, arg2);
- }
- public string MethodWithoutAnything()
- {
- return "Method without anything called and returned successfully.";
- }
- public string MethodWithThreeParamsOneOptionalOneArray(string name, string optionalParam = null, params object[] args)
- {
- return "MethodWithThreeParamsOneOptionalOneArray:" + (name ?? "No Name Specified") + " - " + (optionalParam ?? "No Optional Param Specified") + ";Args:" + string.Join(", ", args.ToArray());
- }
- }
- }
|