public RequestTask(AmqpServiceClient <T> client, MethodData md, MethodCallMessage mcm, int argCount)
 {
     this.client   = client;
     this.md       = md;
     this.mcm      = mcm;
     this.argCount = argCount;
 }
            protected override ReturnMessage Invoke(MethodCallMessage mcm)
            {
                MethodData md;

                if (!this.methodCache.TryGetValue(mcm.MethodBase.Name, out md))
                {
                    throw new NotImplementedException();
                }

                object result;

                if (md.Operation.AsyncPattern == AsyncPattern.None)
                {
                    result = this.client.RequestAsync(md, mcm, mcm.InArgs.Length).GetAwaiter().GetResult();
                }
                else if (md.Operation.AsyncPattern == AsyncPattern.Task)
                {
                    Fx.Assert(md.TcsType != null, "Must be a task method");
                    Type tcsType = md.TcsType;
                    if (md.ReturnType.Type.IsGenericParameter)
                    {
                        tcsType = typeof(TaskSource <>).MakeGenericType(typeof(T),
                                                                        mcm.GenericTypes[md.ReturnType.Type.GenericParameterPosition]);
                    }

                    ITaskSource ts = (ITaskSource)Activator.CreateInstance(tcsType);
                    ts.Proxy       = this;
                    ts.MethodData  = md;
                    ts.CallMessage = mcm;
                    this.client.RequestAsync(md, mcm, mcm.InArgs.Length)
                    .ContinueWith(t =>
                    {
                        if (t.Status == TaskStatus.RanToCompletion)
                        {
                            ts.Complete(t.Result, null);
                        }
                        else
                        {
                            ts.Complete(null, t.Exception);
                        }
                    });
                    result = ts.TaskObject;
                }
                else
                {
                    throw new InvalidOperationException();
                }

                return(new ReturnMessage(result, null, 0, mcm));
            }
示例#3
0
        // this method is the callback from the RealProxy
        static void Invoke(object[] args)
        {
            PackedArgs packed = new PackedArgs(args);
            MethodBase method = proxyAssembly.ResolveMethodToken(packed.DeclaringType, packed.MethodToken);

            if (method.IsGenericMethodDefinition)
            {
                method = ((MethodInfo)method).MakeGenericMethod(packed.GenericTypes);
            }

            MethodCallMessage mcm = new MethodCallMessage(method, packed.Args, packed.GenericTypes);

            ReturnMessage mrm = (ReturnMessage)packed.RealProxy.Invoke(mcm);

            if (mrm.Exception != null)
            {
                throw mrm.Exception;
            }
            else
            {
                packed.ReturnValue = mrm.ReturnValue;
            }
        }
 Task <object> RequestAsync(MethodData md, MethodCallMessage mcm, int argCount)
 {
     return(new RequestTask(this, md, mcm, argCount).Start());
 }
示例#5
0
 protected abstract ReturnMessage Invoke(MethodCallMessage mcm);
示例#6
0
 public ReturnMessage(Exception e, MethodCallMessage mcm)
     : base(mcm.MethodBase)
 {
     this.Exception = e;
 }
示例#7
0
 public ReturnMessage(object ret, object[] outArgs, int outArgsCount, MethodCallMessage mcm)
     : base(mcm.MethodBase)
 {
     this.ReturnValue = ret;
 }