Beispiel #1
0
        public void Execute(CallbackExecution <ICefValue> execution)
        {
            ICefV8Exception exception = null;

            using (new ContextHelper(context))
            {
                var cefV8Values = execution.Parameters.Select(s => (ICefV8Value)v8Serializer.Deserialize(s, typeof(ICefV8Value))).ToArray();
                var result      = function.ExecuteFunction(null, cefV8Values);


                var browser = context.GetBrowser();

                if (result == null && function.HasException)
                {
                    exception = function.GetException();
                    function.ClearException();
                }

                if (promiseService.IsPromise(result, context))
                {
                    promiseService.Then(result, context, a => CallbackDone(a, browser, execution.ExecutionId));
                }
                else
                {
                    CallbackDone(new PromiseResult
                    {
                        Success = result != null,
                        Result  = result,
                        Error   = exception?.Message
                    }, browser, execution.ExecutionId);
                }
            }
        }
Beispiel #2
0
 private void OnCallbackExecution(CallbackExecution <TMarshal> callbackExecution)
 {
     connection.Send(new RpcRequest <TMarshal>()
     {
         CallbackExecution = callbackExecution
     });
 }
        public void ParametersBoundAndAnalyzed()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(true);
            var executor = new CallbackExecutor <object>(Mock.Of <IIdGenerator>(), mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            CallbackExecution <object> exec = null;

            ((IObservable <CallbackExecution <object> >)executor).Subscribe(
                callbackExecution => exec = callbackExecution);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            void Binder(BindingContext <object> context)
            {
                if (context.BindValue != null)
                {
                    context.NativeValue = "str";
                }
                else
                {
                    context.NativeValue = "str2";
                }
            }

            executor.Execute(new CallbackExecutionParameters <object>()
            {
                Binder     = Binder,
                Id         = 2,
                Parameters = new[] { new CallbackParameter {
                                         Value = new object(), Bindable = new BindValueAttribute()
                                     }, new CallbackParameter {
                                         Value = new object()
                                     } },
                ResultTargetType = null
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            Assert.Collection(exec.Parameters, s => Assert.Equal("str", (string)s), s => Assert.Equal("str2", (string)s));
        }
        public void ExecuteSent()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(true);
            var idGenerator = Mock.Of <IIdGenerator>();

            Mock.Get(idGenerator).Setup(_ => _.GetNextId()).Returns(1);

            var executor = new CallbackExecutor <object>(idGenerator, mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            CallbackExecution <object> exec = null;

            ((IObservable <CallbackExecution <object> >)executor).Subscribe(
                callbackExecution => exec = callbackExecution);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            executor.Execute(new CallbackExecutionParameters <object>()
            {
                Binder = context => {
                    if (context.Direction == ObjectBindingDirection.In)
                    {
                        context.ObjectValue = context.NativeValue;
                    }
                    else
                    {
                        context.NativeValue = context.ObjectValue;
                    }
                },
                Id               = 2,
                Parameters       = new CallbackParameter[] { },
                ResultTargetType = null
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            Assert.Equal(1, exec.ExecutionId);
            Assert.Equal(2, exec.FunctionId);
        }
        public async Task ExecuteFails()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(false);
            var idGenerator = Mock.Of <IIdGenerator>();

            Mock.Get(idGenerator).Setup(_ => _.GetNextId()).Returns(1);

            var executor = new CallbackExecutor <object>(idGenerator, mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            CallbackExecution <object> exec = null;

            ((IObservable <CallbackExecution <object> >)executor).Subscribe(
                callbackExecution => exec = callbackExecution);

            await Assert.ThrowsAsync <InvalidOperationException>(() => executor.Execute(new CallbackExecutionParameters <object>
            {
                Binder           = context => { },
                Id               = 2,
                Parameters       = new CallbackParameter[] { },
                ResultTargetType = null
            }));
        }