Beispiel #1
0
 private void HandleX2XServiceInvocation(X2XServiceInvocation x)
 {
     logger.Trace($"{nameof(HandleX2XServiceInvocation)} for service {x.ServiceGuid} iid {x.InvocationId} method {x.MethodName}");
     Task.Factory.StartNew((dummy) => {
         object result;
         try {
             if (localServiceContainer.TryInvoke(x.ServiceGuid, x.MethodName, x.GenericArguments, x.MethodArguments, out result))
             {
                 logger.Trace($"Successfully locally invoked service {x.ServiceGuid} method {x.MethodName} for iid {x.InvocationId}.");
             }
             else
             {
                 logger.Trace($"Could not locally find service {x.ServiceGuid} method {x.MethodName} for iid {x.InvocationId}.");
                 result = new PortableException(new ServiceUnavailableException(x.ServiceGuid, x.MethodName));
             }
         } catch (Exception e) {
             logger.Trace($"Local invocation for service {x.ServiceGuid} method {x.MethodName} for iid {x.InvocationId} threw ", e);
             if (e is IPortableObject)
             {
                 result = e;
             }
             else
             {
                 result = new PortableException(e);
             }
         }
         messageSender.SendInvocationResultAsync(x.InvocationId, result);
     }, CancellationToken.None, TaskCreationOptions.LongRunning);
 }
Beispiel #2
0
        /** <inheritDoc /> */
        protected override void CheckError(Exception err)
        {
            Assert.IsTrue(err != null);

            PortableException err0 = err as PortableException;

            Assert.IsTrue(err0 != null);
            Assert.AreEqual(ErrMsg, err0.Msg);
        }
Beispiel #3
0
        public async Task <object> Invoke(Guid serviceGuid, string methodName, PortableObjectBox genericArgumentsDto, PortableObjectBox methodArgumentsDto)
        {
            logger.Trace($"Invoke called for service {serviceGuid} method {methodName} with {methodArgumentsDto.Length} bytes of arguments.");
            object result = null;

            try {
                Type[]   genericArguments;
                object[] methodArguments;
                if (portableObjectBoxConverter.TryConvertFromDataTransferObject(genericArgumentsDto, out genericArguments) &&
                    portableObjectBoxConverter.TryConvertFromDataTransferObject(methodArgumentsDto, out methodArguments) &&
                    localServiceContainer.TryInvoke(serviceGuid, methodName, genericArguments, methodArguments, out result))
                {
                    logger.Trace($"Invoke succeeded at local service container for service {serviceGuid} method {methodName} with {methodArgumentsDto.Length} bytes of arguments.");
                }
                else
                {
                    logger.Trace($"Trying remote invocation for service {serviceGuid} method {methodName} with {methodArgumentsDto.Length} bytes of arguments against {remoteInvokables.Count} remote invokables.");
                    bool invocationSuccessful = false;
                    foreach (var remoteInvokable in remoteInvokables)
                    {
                        var invocation = await remoteInvokable.TryRemoteInvoke(serviceGuid, methodName, genericArgumentsDto, methodArgumentsDto);

                        if (invocation.Success)
                        {
                            logger.Trace($"Successfully remotely invoked service {serviceGuid} method {methodName} with {methodArgumentsDto.Length} bytes of arguments.");
                            result = invocation.ReturnValue;
                            invocationSuccessful = true;
                            break;
                        }
                    }

                    if (!invocationSuccessful)
                    {
                        logger.Trace($"Could not remotely invoke service {serviceGuid} method {methodName} with {methodArgumentsDto.Length} bytes of arguments.");
                        throw new ServiceUnavailableException(serviceGuid, methodName);
                    }
                }
            } catch (Exception e) {
                logger.Trace($"Remove invocation of service {serviceGuid} method {methodName} with {methodArgumentsDto.Length} bytes of arguments threw", e);
                if (e is IPortableObject)
                {
                    result = e;
                }
                else
                {
                    result = new PortableException(e);
                }
            }
            return(result);
        }
Beispiel #4
0
        public async Task <object> Invoke(Guid serviceGuid, string methodName, Type[] genericArguments, object[] methodArguments)
        {
            logger.Trace($"Invoke called for service {serviceGuid} method {methodName} with {genericArguments.Length} generic arguments and {methodArguments.Length} arguments.");
            object result;

            try {
                if (localServiceContainer.TryInvoke(serviceGuid, methodName, genericArguments, methodArguments, out result))
                {
                    logger.Trace($"LocalServiceContainer successfully invoked service {serviceGuid} method {methodName} with {genericArguments.Length} generic arguments and {methodArguments.Length} arguments.");
                }
                else
                {
                    logger.Trace($"LocalServiceContainer failed to invoke service {serviceGuid} method {methodName} with {genericArguments.Length} generic arguments and {methodArguments.Length} arguments.");
                    bool invocationSuccessful = false;
                    foreach (var remoteInvokable in remoteInvokables)
                    {
                        var invocation = await remoteInvokable.TryRemoteInvoke(serviceGuid, methodName, genericArguments, methodArguments);

                        if (invocation.Success)
                        {
                            result = invocation.ReturnValue;
                            invocationSuccessful = true;
                            break;
                        }
                    }
                    if (!invocationSuccessful)
                    {
                        logger.Trace($"All remote invokables failed to invoke service {serviceGuid} method {methodName} with{genericArguments.Length} generic arguments and {methodArguments.Length} arguments.");
                        throw new ServiceUnavailableException(serviceGuid, methodName);
                    }
                }
                logger.Trace($"Successfully invoked service {serviceGuid} method {methodName} with {genericArguments.Length} generic arguments and {methodArguments.Length} arguments!");
            } catch (Exception e) {
                logger.Trace($"Invocation of service {serviceGuid} method {methodName} with {genericArguments.Length} generic arguments and {methodArguments.Length} arguments, {e}");
                if (e is IPortableObject)
                {
                    result = e;
                }
                else
                {
                    result = new PortableException(e);
                }
            }
            return(result);
        }