public Task <RemoteInvocationResult> TryRemoteInvoke(Guid serviceGuid, string methodName, Type[] genericArguments, object[] arguments) { logger.Trace($"Remote invoking service {serviceGuid} method {methodName} with {genericArguments.Length} generic arguments and {arguments.Length} arguments."); if (!remotelyHostedServices.Contains(serviceGuid)) { return(Task.FromResult(new RemoteInvocationResult(false, null))); } else { return(Task.Factory.StartNew(async(throwaway) => { var invocationId = availableInvocationIds.TakeUniqueID(); var asyncValueBox = invocationResponseBoxesById.GetOrAdd(invocationId, id => new AsyncValueBoxImpl()); await messageSender.SendServiceInvocationAsync(invocationId, serviceGuid, methodName, genericArguments, arguments); var returnValue = await asyncValueBox.GetResultAsync(); var removed = invocationResponseBoxesById.Remove(new KeyValuePair <uint, AsyncValueBox>(invocationId, asyncValueBox)); Trace.Assert(removed, "Failed to remove AsyncValueBox from dict"); return new RemoteInvocationResult(true, returnValue); }, CancellationToken.None, TaskCreationOptions.LongRunning).Unwrap()); } }
public Task <object> InvokeServiceCall(Guid serviceGuid, string methodName, Type[] genericArguments, object[] methodArguments) { logger.Trace($"Invoking service {serviceGuid} method {methodName} with {methodArguments.Length} arguments"); return(Task.Factory.StartNew(async(throwaway) => { object localResult; if (localServiceContainer.TryInvoke(serviceGuid, methodName, genericArguments, methodArguments, out localResult)) { return localResult; } else { // Code looks different than in host session - if an exception has been thrown var invocationId = availableInvocationIds.TakeUniqueID(); logger.Trace($"Took invocationId {invocationId} for {serviceGuid} method {methodName} call."); var asyncValueBox = invocationResponseBoxesById.GetOrAdd(invocationId, (id) => new AsyncValueBoxImpl()); await messageSender.SendServiceInvocationAsync(invocationId, serviceGuid, methodName, genericArguments, methodArguments); var returnValue = await asyncValueBox.GetResultAsync(); var removed = invocationResponseBoxesById.Remove(invocationId.PairValue(asyncValueBox)); Trace.Assert(removed, "Failed to remove AsyncValueBox from dict"); return returnValue; } }, CancellationToken.None, TaskCreationOptions.LongRunning).Unwrap()); }