示例#1
0
 protected CallbackBase(long id, ICallbackExecutor <TMarshal> executor, BindingDelegate <TMarshal> parameterBinder,
                        Type resultType)
 {
     this.id              = id;
     this.executor        = executor;
     this.parameterBinder = parameterBinder;
     this.resultType      = resultType;
 }
示例#2
0
 public object CreateCallback(long id, Type delegateType, BindingDelegate <TMarshal> parameterBinder)
 {
     if (delegateType == null)
     {
         return(Create(id, parameterBinder));
     }
     else
     {
         return(Create(id, delegateType, parameterBinder));
     }
 }
示例#3
0
        public async Task CallbackExecuted()
        {
            var executor     = Mock.Of <ICallbackExecutor <object> >();
            var executorMock = Mock.Get(executor);
            BindingDelegate <object> parameterBinder = context => { };

            executorMock
            .Setup(_ => _.Execute(It.Is <CallbackExecutionParameters <object> >(o =>
                                                                                o.Parameters.Length == 1 && o.Binder == parameterBinder && o.ResultTargetType == typeof(string)))).Returns(Task.FromResult(new object()));
            executorMock.SetupGet(_ => _.CanExecute).Returns(true);

            var callback = new TestCallback(1, executor, parameterBinder, typeof(string));

            var result = await callback.ExecuteAsync("str");

            Assert.NotNull(result);
        }
示例#4
0
        /// <summary>
        /// この式を評価する。
        /// </summary>
        /// <returns>評価結果</returns>
        /// <param name="binding">変数のバインディング</param>
        public Value Evaluate(BindingDelegate binding)
        {
            var func = binding(_func) as Delegate;
            var p    = func.Method.GetParameters();

            if (_args.Count < p.Length)
            {
                throw new ArgumentException("Wrong number of arguments: " + _func);
            }
            var args = new object[p.Length];

            for (var i = 0; i < _args.Count; i++)
            {
                args[i] = _args[i].Evaluate(binding).As(p[i].ParameterType);
            }
            return(new Value(func.DynamicInvoke(args)));
        }
示例#5
0
 /// <summary>
 /// 数学ライブラリを呼び出すバインディングを生成する。
 /// </summary>
 /// <returns>結果</returns>
 /// <param name="defaultBinding">デフォルトのバインディング</param>
 public static BindingDelegate Binding(BindingDelegate defaultBinding)
 {
     return((name) => {
         if (Constants.ContainsKey(name))
         {
             return Constants[name];
         }
         if (Functions.ContainsKey(name))
         {
             return Functions[name];
         }
         if (defaultBinding != null)
         {
             return defaultBinding(name);
         }
         return 0.0;
     });
 }
示例#6
0
        public void TypedCallbackCallsFactory()
        {
            BindingDelegate <object> bindingDelegate = context =>
            {
            };
            var callbackFactoryMock = new Mock <ICallbackFactory <object> >();

            callbackFactoryMock.Setup(_ => _.CreateCallback(1, typeof(Action), bindingDelegate)).Returns("str");
            var binder = new CallbackBinder <object>(context => {
                context.ObjectValue = new CallbackDescriptor
                {
                    FunctionId = 1
                };
            }, callbackFactoryMock.Object);

            var ctx = new BindingContext <object>(ObjectBindingDirection.In, bindingDelegate);

            ctx.TargetType = typeof(Action);

            binder.Bind(ctx);

            Assert.Equal("str", ctx.ObjectValue);
        }
示例#7
0
        public void FailedCreationSetsNull()
        {
            BindingDelegate <object> bindingDelegate = context =>
            {
            };
            var callbackFactoryMock = new Mock <ICallbackFactory <object> >();

            callbackFactoryMock.Setup(_ => _.CreateCallback(1, typeof(Action), bindingDelegate))
            .Throws(new InvalidOperationException());
            var binder = new CallbackBinder <object>(context => {
                context.ObjectValue = new CallbackDescriptor
                {
                    FunctionId = 1
                };
            }, callbackFactoryMock.Object);

            var ctx = new BindingContext <object>(ObjectBindingDirection.In, bindingDelegate);

            ctx.TargetType = typeof(Action);

            binder.Bind(ctx);

            Assert.Null(ctx.ObjectValue);
        }
        public Delegate Generate(Type delegateType, long id, ICallbackExecutor <TMarshal> callbackExecutor, BindingDelegate <TMarshal> parameterBinder)
        {
            ValidateDelegateType(delegateType);

            if (!typeCache.TryGetValue(delegateType, out var delegateContainerType))
            {
                delegateContainerType = GenerateDelegateContainerType(delegateType);
                typeCache.Add(delegateType, delegateContainerType);
            }

            var created = Activator.CreateInstance(delegateContainerType, id, callbackExecutor, parameterBinder, delegateType);

            return(Delegate.CreateDelegate(delegateType, created, DelegateMethodName, false, true));;
        }
示例#9
0
 public PlatformBinder(BindingDelegate <TMarshal> next, IPlatformBinder <TMarshal> marshal)
 {
     this.marshal = marshal;
 }
示例#10
0
 public Callback(long id, ICallbackExecutor <TMarshal> executor, BindingDelegate <TMarshal> parameterBinder)
     : base(id, executor, parameterBinder, typeof(object))
 {
 }
示例#11
0
 /// <summary>
 /// この式を評価する。
 /// </summary>
 /// <returns>評価結果</returns>
 /// <param name="binding">変数のバインディング</param>
 public Value Evaluate(BindingDelegate binding)
 {
     return(_value);
 }
示例#12
0
 public TestCallback(long id, ICallbackExecutor <object> executor, BindingDelegate <object> parameterBinder, Type resultType) : base(id, executor, parameterBinder, resultType)
 {
 }
示例#13
0
 public MethodExecutor(IReadOnlyDictionary <long, ObjectDescriptor> objects, BindingDelegate <TMarshal> bindingDelegate)
 {
     this.objects         = objects;
     this.bindingDelegate = bindingDelegate;
 }
示例#14
0
 public PropertyExecutor(IReadOnlyDictionary <long, ObjectDescriptor> objects, BindingDelegate <TMarshal> binder)
 {
     this.objects = objects;
     this.binder  = binder;
 }
示例#15
0
 public OutgoingValueBinder(BindingDelegate <TMarshal> next, IBindingRepository bindingRepository)
 {
     this.next = next;
     this.bindingRepository = bindingRepository;
 }
示例#16
0
 private ICallback Create(long id, BindingDelegate <TMarshal> parameterBinder)
 {
     return(new Callback <TMarshal>(id, callbackExecutor, parameterBinder));
 }
 public Binder(BindingDelegate <object> next)
 {
     this.next = next;
 }
示例#18
0
 public DelegateContainerBase(long id, ICallbackExecutor <TMarshal> executor, BindingDelegate <TMarshal> parameterBinder, Type resultType, Type delegateType)
     : base(id, executor, parameterBinder, resultType)
 {
     bindValues = delegateType.GetMethod(nameof(Action.Invoke)).GetParameters()
                  .Select(p => p.GetCustomAttribute <BindValueAttribute>()).ToArray();
 }
示例#19
0
 public CommandBindingExpression(BindingCompilationService service, BindingDelegate command, string id)
     : base(service, new object[] { command, new IdBindingProperty(id), new CommandJavascriptBindingProperty(CreateJsPostbackInvocation(id)) })
 {
 }
示例#20
0
 /// <summary>
 /// このノードを評価する。
 /// </summary>
 /// <returns>評価結果</returns>
 /// <param name="binding">変数のバインディング</param>
 public Value Evaluate(BindingDelegate binding)
 {
     return(new Value(binding(_name)));
 }
示例#21
0
 /// <summary>
 /// この式を評価する。
 /// </summary>
 /// <returns>評価結果</returns>
 /// <param name="binding">変数のバインディング</param>
 public Value Evaluate(BindingDelegate binding)
 {
     return(Value.EvaluateUnaryOperator(_expression.Evaluate(binding), _op));
 }
 public BinderWithCtrArgs(BindingDelegate <object> next, string arg)
 {
     this.next = next;
     this.arg  = arg;
 }
示例#23
0
 public BindingContext(ObjectBindingDirection direction, BindingDelegate <TMarshal> binder)
 {
     Direction = direction;
     Binder    = binder;
 }
示例#24
0
文件: Expression.cs 项目: entap/expr
 /// <summary>
 /// 数式を評価する。
 /// </summary>
 /// <returns>評価結果</returns>
 /// <param name="binding">変数のバインディング</param>
 Value Evaluate(BindingDelegate binding)
 {
     binding = Math.Binding(binding);
     return(_expression.Evaluate(binding));
 }
示例#25
0
 private Delegate Create(long id, Type delegateType, BindingDelegate <TMarshal> parameterBinder)
 {
     return(generator.Generate(delegateType, id, callbackExecutor, parameterBinder));
 }
示例#26
0
文件: Expression.cs 项目: entap/expr
 /// <summary>
 /// 数式を評価する。
 /// </summary>
 /// <returns>評価結果</returns>
 /// <param name="expression">数式</param>
 /// <param name="binding">変数のバインディング</param>
 static public T Evaluate <T>(string expression, BindingDelegate binding)
 {
     return((new Expression(expression)).Evaluate <T>(binding));
 }
示例#27
0
 public CallbackBinder(BindingDelegate <TMarshal> next, ICallbackFactory <TMarshal> callbackFactory)
 {
     this.next            = next;
     this.callbackFactory = callbackFactory;
 }
示例#28
0
文件: Expression.cs 项目: entap/expr
 /// <summary>
 /// 数式を評価する。
 /// </summary>
 /// <returns>評価結果</returns>
 /// <param name="binding">変数のバインディング</param>
 public T Evaluate <T>(BindingDelegate binding)
 {
     binding = Math.Binding(binding);
     return((T)_expression.Evaluate(binding).As(typeof(T)));
 }
示例#29
0
 public FakeCommandBinding(ParametrizedCode commandJavascript, BindingDelegate bindingDelegate)
 {
     this.commandJavascript = commandJavascript;
     this.bindingDelegate   = bindingDelegate;
 }
示例#30
0
 /// <summary>
 /// この式を評価する。
 /// </summary>
 /// <returns>評価結果</returns>
 /// <param name="binding">変数のバインディング</param>
 public Value Evaluate(BindingDelegate binding)
 {
     return(Value.EvaluateBinaryOperator(_left.Evaluate(binding), _right.Evaluate(binding), _op));
 }