2016-01-11 14:11:30 +10:00
|
|
|
// Copyright © 2010-2016 The CefSharp Authors. All rights reserved.
|
2015-08-03 10:41:29 +10:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-04-04 21:44:22 -07:00
|
|
|
using System.Linq;
|
2015-03-12 11:48:42 +10:00
|
|
|
using System.Threading.Tasks;
|
2012-02-24 17:03:55 -08:00
|
|
|
|
|
|
|
|
namespace CefSharp.Example
|
|
|
|
|
{
|
2014-08-27 14:59:27 +10:00
|
|
|
public class BoundObject
|
2012-02-24 17:03:55 -08:00
|
|
|
{
|
2014-06-12 02:41:59 +03:00
|
|
|
public int MyProperty { get; set; }
|
2014-06-07 09:52:45 +02:00
|
|
|
|
2013-05-11 09:44:19 +03:00
|
|
|
public string MyReadOnlyProperty { get; internal set; }
|
2013-05-11 09:29:41 +03:00
|
|
|
public Type MyUnconvertibleProperty { get; set; }
|
2014-08-29 16:50:16 +10:00
|
|
|
public SubBoundObject SubObject { get; set; }
|
2015-09-08 11:20:31 +09:00
|
|
|
public ExceptionTestBoundObject ExceptionTestObject { get; set; }
|
2013-05-07 08:20:41 +03:00
|
|
|
|
2015-04-24 11:57:37 -07:00
|
|
|
public uint[] MyUintArray
|
|
|
|
|
{
|
|
|
|
|
get { return new uint[] { 7, 8 }; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int[] MyIntArray
|
|
|
|
|
{
|
2015-04-25 11:45:43 +10:00
|
|
|
get { return new [] { 1, 2, 3, 4, 5, 6, 7, 8 }; }
|
2015-04-24 11:57:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Array MyArray
|
|
|
|
|
{
|
|
|
|
|
get { return new short[] { 1, 2, 3 }; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] MyBytes
|
|
|
|
|
{
|
|
|
|
|
get { return new byte[] { 3, 4, 5 }; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-07 08:20:41 +03:00
|
|
|
public BoundObject()
|
|
|
|
|
{
|
|
|
|
|
MyProperty = 42;
|
|
|
|
|
MyReadOnlyProperty = "I'm immutable!";
|
2014-10-29 16:52:55 +10:00
|
|
|
IgnoredProperty = "I am an Ignored Property";
|
2013-05-11 09:29:41 +03:00
|
|
|
MyUnconvertibleProperty = GetType();
|
2014-08-29 16:50:16 +10:00
|
|
|
SubObject = new SubBoundObject();
|
2015-09-08 11:20:31 +09:00
|
|
|
ExceptionTestObject = new ExceptionTestBoundObject();
|
2013-05-07 08:20:41 +03:00
|
|
|
}
|
|
|
|
|
|
2015-03-12 11:48:42 +10:00
|
|
|
public void TestCallback(IJavascriptCallback javascriptCallback)
|
2015-03-08 16:23:49 +01:00
|
|
|
{
|
2015-03-12 11:48:42 +10:00
|
|
|
const int taskDelay = 1500;
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
2015-03-08 16:23:49 +01:00
|
|
|
{
|
2015-03-12 11:48:42 +10:00
|
|
|
await Task.Delay(taskDelay);
|
|
|
|
|
|
|
|
|
|
using (javascriptCallback)
|
|
|
|
|
{
|
2015-11-18 09:17:16 +10:00
|
|
|
//NOTE: Classes are not supported, simple structs are
|
|
|
|
|
var response = new CallbackResponseStruct("This callback from C# was delayed " + taskDelay + "ms");
|
|
|
|
|
await javascriptCallback.ExecuteAsync(response);
|
2015-03-12 11:48:42 +10:00
|
|
|
}
|
|
|
|
|
});
|
2015-03-08 16:23:49 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-11 17:00:17 +10:00
|
|
|
public int EchoMyProperty()
|
|
|
|
|
{
|
|
|
|
|
return MyProperty;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 17:03:55 -08:00
|
|
|
public string Repeat(string str, int n)
|
|
|
|
|
{
|
|
|
|
|
string result = String.Empty;
|
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
|
{
|
|
|
|
|
result += str;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 12:54:38 +10:00
|
|
|
public string EchoParamOrDefault(string param = "This is the default value")
|
|
|
|
|
{
|
|
|
|
|
return param;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 17:03:55 -08:00
|
|
|
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;
|
|
|
|
|
}
|
2013-06-05 14:15:37 +03:00
|
|
|
|
2014-06-12 02:41:59 +03:00
|
|
|
// 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.
|
2013-06-05 14:15:37 +03:00
|
|
|
//public String echoString(String arg)
|
|
|
|
|
//{
|
|
|
|
|
// return "Lowercase echo: " + arg;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
public String lowercaseMethod()
|
|
|
|
|
{
|
|
|
|
|
return "lowercase";
|
|
|
|
|
}
|
2014-10-29 16:52:55 +10:00
|
|
|
|
2014-12-16 21:42:09 +10:00
|
|
|
public string ReturnJsonEmployeeList()
|
|
|
|
|
{
|
|
|
|
|
return "{\"employees\":[{\"firstName\":\"John\", \"lastName\":\"Doe\"},{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},{\"firstName\":\"Peter\", \"lastName\":\"Jones\"}]}";
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 16:52:55 +10:00
|
|
|
[JavascriptIgnore]
|
|
|
|
|
public string IgnoredProperty { get; set; }
|
|
|
|
|
|
|
|
|
|
[JavascriptIgnore]
|
|
|
|
|
public string IgnoredMethod()
|
|
|
|
|
{
|
|
|
|
|
return "I am an Ignored Method";
|
|
|
|
|
}
|
2015-01-06 20:47:30 +10:00
|
|
|
|
|
|
|
|
public string ComplexParamObject(object param)
|
|
|
|
|
{
|
|
|
|
|
if (param == null)
|
|
|
|
|
{
|
|
|
|
|
return "param is null";
|
|
|
|
|
}
|
|
|
|
|
return "The param type is:" + param.GetType();
|
|
|
|
|
}
|
2015-01-08 15:03:24 +10:00
|
|
|
|
|
|
|
|
public SubBoundObject GetSubObject()
|
|
|
|
|
{
|
|
|
|
|
return SubObject;
|
|
|
|
|
}
|
2016-04-04 21:44:22 -07:00
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2016-04-05 16:19:55 +10:00
|
|
|
return "Name:" + name + ";Args:" + string.Join(", ", args.ToArray());
|
2016-04-04 21:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string MethodWithoutParams(string name, string arg2)
|
|
|
|
|
{
|
2016-04-05 16:19:55 +10:00
|
|
|
return string.Format("{0}, {1}", name, arg2);
|
2016-04-04 21:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 16:19:55 +10:00
|
|
|
public string MethodWithoutAnything()
|
2016-04-04 21:44:22 -07:00
|
|
|
{
|
|
|
|
|
return "Method without anything called and returned successfully.";
|
|
|
|
|
}
|
2012-02-24 17:03:55 -08:00
|
|
|
}
|
|
|
|
|
}
|