Exemplo n.º 1
0
 public async Task<SerializedEvaluation> InvokeRemoteAsync(SerializedEvaluation visited)
 {
     // this is supposed to be handled server-side... let's fake it.
     return RpcEvaluator.HandleIncomingRequest(visited, reference =>
     {
         INode val;
         _nodes.TryGetValue(reference, out val);
         return val;
     });
 }
Exemplo n.º 2
0
 public async Task<SerializedEvaluation> Evaluate(SerializedEvaluation toEvaluate)
 {
     return RpcEvaluator.HandleIncomingRequest(toEvaluate, reference =>
     {
         if (reference.StartsWith("dir:"))
             return new ServerDirectory(reference.Substring("dir:".Length));
         if (reference.StartsWith("file:"))
             return new ServerFile(reference.Substring("file:".Length));
         return null;
     });
 }
Exemplo n.º 3
0
 internal static object HandleResult(SerializedEvaluation evaluation, Func<string, IRpcRoot> referenceResolver)
 {
     if (evaluation == null || string.IsNullOrEmpty(evaluation.Evaluation))
         return null;
     
     var reg = new TypeRegistry();
     for (int i = 0; i < evaluation.References.Length; i++)
     {
         reg.RegisterSymbol("r" + (i + 1), referenceResolver(evaluation.References[i]));
     }
     var p = new CompiledExpression(evaluation.Evaluation)
     {
         TypeRegistry = reg
     };
     return p.Eval();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Function to call when a server request is received
 /// </summary>
 /// <param name="evaluation">The incoming request</param>
 /// <param name="referenceResolver">Your reference loader: Resolves references to server-side objects</param>
 /// <returns></returns>
 public static SerializedEvaluation HandleIncomingRequest(SerializedEvaluation evaluation, Func<string, IRpcRoot> referenceResolver)
 {
     var reg = new TypeRegistry();
     for (int i = 0; i < evaluation.References.Length; i++)
     {
         reg.RegisterSymbol("r" + (i + 1), referenceResolver(evaluation.References[i]));
     }
     var p = new CompiledExpression(evaluation.Evaluation)
     {
         TypeRegistry = reg
     };
     var ret = p.Eval();
     if (ret == null)
         return null;
     return new RpcCallVisitor().Serialize(Expression.Constant(ret));
 }
Exemplo n.º 5
0
        internal static async Task<object> HandleResultAsync(SerializedEvaluation evaluation, Func<string, Task<IRpcRoot>> referenceResolver)
        {
            if (evaluation == null || string.IsNullOrEmpty(evaluation.Evaluation))
                return null;
            
            var reg = new TypeRegistry();

            for (int i = 0; i < evaluation.References.Length; i++)
            {
                reg.RegisterSymbol("r" + (i + 1), await referenceResolver(evaluation.References[i]).ConfigureAwait(false));
            }
            var p = new CompiledExpression(evaluation.Evaluation)
            {
                TypeRegistry = reg
            };
            return p.Eval();
        }
Exemplo n.º 6
0
        internal static object HandleResult(SerializedEvaluation evaluation, Func <string, IRpcRoot> referenceResolver)
        {
            if (evaluation == null || string.IsNullOrEmpty(evaluation.Evaluation))
            {
                return(null);
            }

            var reg = new TypeRegistry();

            for (int i = 0; i < evaluation.References.Length; i++)
            {
                reg.RegisterSymbol("r" + (i + 1), referenceResolver(evaluation.References[i]));
            }
            var p = new CompiledExpression(evaluation.Evaluation)
            {
                TypeRegistry = reg
            };

            return(p.Eval());
        }
Exemplo n.º 7
0
        internal static async Task <object> HandleResultAsync(SerializedEvaluation evaluation, Func <string, Task <IRpcRoot> > referenceResolver)
        {
            if (evaluation == null || string.IsNullOrEmpty(evaluation.Evaluation))
            {
                return(null);
            }

            var reg = new TypeRegistry();

            for (int i = 0; i < evaluation.References.Length; i++)
            {
                reg.RegisterSymbol("r" + (i + 1), await referenceResolver(evaluation.References[i]).ConfigureAwait(false));
            }
            var p = new CompiledExpression(evaluation.Evaluation)
            {
                TypeRegistry = reg
            };

            return(p.Eval());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Function to call when a server request is received
        /// </summary>
        /// <param name="evaluation">The incoming request</param>
        /// <param name="referenceResolver">Your reference loader: Resolves references to server-side objects</param>
        /// <returns></returns>
        public static SerializedEvaluation HandleIncomingRequest(SerializedEvaluation evaluation, Func <string, IRpcRoot> referenceResolver)
        {
            var reg = new TypeRegistry();

            for (int i = 0; i < evaluation.References.Length; i++)
            {
                reg.RegisterSymbol("r" + (i + 1), referenceResolver(evaluation.References[i]));
            }
            var p = new CompiledExpression(evaluation.Evaluation)
            {
                TypeRegistry = reg
            };
            var ret = p.Eval();

            if (ret == null)
            {
                return(null);
            }
            return(new RpcCallVisitor().Serialize(Expression.Constant(ret)));
        }
Exemplo n.º 9
0
        public Task<SerializedEvaluation> InvokeRemoteAsync(SerializedEvaluation visited)
        {
            Assert.IsFalse(++CallCount > _expectCallCount, "Called > " + _expectCallCount + " times");

            var ret = RpcEvaluator.HandleIncomingRequest(visited, r =>
            {
                if (r == "ClassRootRef")
                    return new ClassRootServer();
                return new InterfaceRootServerImpl();
            });

            return Task.FromResult(ret);
        }