public IGlueMapable GetGlueConvertible(IJavascriptObject javascriptObject, Type targetType) { if (javascriptObject == null) { return(new RawGlueMapable(null, null)); } if (_JsUpdateHelper.GetSimpleValue(javascriptObject, out var targetValue, targetType)) { return(new RawGlueMapable(targetValue, javascriptObject)); } if (targetType?.IsEnum == true) { var intValue = javascriptObject.GetValue("intValue")?.GetIntValue(); return(new RawGlueMapable(intValue.HasValue ? Enum.ToObject(targetType, intValue.Value) : null, javascriptObject)); } var res = _SessionCache.GetCached(javascriptObject); if (res != null) { return(new SolvedGlueMapable(res)); } var message = $"Unable to convert javascript object: {javascriptObject} to C# session. Value will be default to null. Please check javascript bindings."; _JsUpdateHelper.Logger.Info(message); throw new ArgumentException(message); }
public CSharpToGlueMapperTests(ITestOutputHelper testOutputHelper) { _TestOutputHelper = testOutputHelper; _Cacher = Substitute.For <ISessionCache>(); _Cacher.When(c => c.CacheFromCSharpValue(Arg.Any <object>(), Arg.Any <IJsCsGlue>())) .Do(callInfo => _Cache.Add(callInfo[0], (IJsCsGlue)callInfo[1])); _Cacher.GetCached(Arg.Any <object>()).Returns(callInfo => _Cache.GetOrDefault(callInfo[0])); _ObjectChangesListener = new ObjectChangesListener(_ => { }, _ => { }, _ => { }, _ => { }); _GlueFactory = new GlueFactory(null, _Cacher, null, _ObjectChangesListener); _Logger = Substitute.For <IWebSessionLogger>(); _CSharpToGlueMapper = new CSharpToGlueMapper(_Cacher, _GlueFactory, _Logger); }
protected override void Init() { _CSharpMapper = Substitute.For <ISessionCache>(); _ObjectChangesListener = new ObjectChangesListener(_ => { }, _ => { }, _ => { }, _ => { }); _GlueFactory = new GlueFactory(null, _CSharpMapper, null, _ObjectChangesListener); _CSharpMapper.GetCached(Arg.Any <object>()).Returns((IJsCsGlue)null); _JavascriptFrameworkManager = Substitute.For <IJavascriptFrameworkManager>(); _HtmlViewContext = new HtmlViewContext(WebBrowserWindow, GetTestUIDispacther(), _JavascriptFrameworkManager, _Logger); _ConverTOJSO = new CSharpToGlueMapper(_CSharpMapper, _GlueFactory, _Logger); _Test = new TestClass { S1 = "string", I1 = 25 }; _Tests = new List <TestClass> { new TestClass() { S1 = "string1", I1 = 1 }, new TestClass() { S1 = "string2", I1 = 2 } }; _Test2 = new Test2() { T1 = _Test, T2 = _Test }; _TestsNg = new ArrayList { _Tests[0], _Tests[0] }; _CircularSimple = new Circular1(); _CircularSimple.Reference = _CircularSimple; _CircularComplex = new Circular2(); var circularChild = new Circular2 { Reference = _CircularComplex }; _CircularComplex.List.Add(circularChild); }
private T GetFromArgument <T>(IJavascriptObject[] arguments) where T : class { var id = (uint)arguments[0].GetIntValue(); return(_Cache.GetCached(id) as T); }
public T GetCached <T>(object value) where T : class { return(_SessionCache.GetCached(value) as T); }