Пример #1
0
        public async Task <MessageEntry> ProcessRequest(MessageEntry m, CancellationToken cancel)
        {
            DateTime request_start   = DateTime.UtcNow;
            uint     request_timeout = node.RequestTimeout;

            TaskCompletionSource <MessageEntry> rec_source = new TaskCompletionSource <MessageEntry>();
            uint t_id;

            lock (rec_wait)
            {
                request_number++;
                m.RequestID = request_number;
                t_id        = request_number;
                rec_wait.Add(t_id, rec_source);
                if (ProcessRequest_checkconnection_current == null)
                {
                    ProcessRequest_checkconnection_current = ProcessRequest_checkconnection();
                }
            }

            MessageEntry rec_message = null;

            try
            {
                cancel.Register(delegate()
                {
                    rec_source.TrySetCanceled();
                });


                Func <Task> r = async delegate()
                {
                    await SendMessage(m, cancel);

                    rec_message = await rec_source.Task;
                };

                await r().AwaitWithTimeout((int)node.RequestTimeout);
            }
            finally
            {
                lock (rec_wait)
                {
                    rec_wait.Remove(t_id);
                }
            }

            if (rec_message.RequestID != t_id)
            {
                throw new Exception("This should be impossible!");
            }

            if (rec_message.Error != MessageErrorType.None)
            {
                Exception e = RobotRaconteurExceptionUtil.MessageEntryToException(rec_message);
                RobotRaconteurRemoteException e2 = e as RobotRaconteurRemoteException;
                if (e2 != null)
                {
                    Exception e3 = ServiceDef.DownCastException(e2);
                    if (e3 != null)
                    {
                        e = e3;
                    }
                }
                throw e;
            }

            return(rec_message);
        }
Пример #2
0
        public static Exception MessageEntryToException(MessageEntry entry)
        {
            var error_code  = entry.Error;
            var errorname   = entry.FindElement("errorname").CastData <string>();
            var errorstring = entry.FindElement("errorstring").CastData <string>();

            switch (error_code)
            {
            case MessageErrorType.RemoteError:
                RobotRaconteurException e1 = new RobotRaconteurRemoteException(errorname, errorstring);
                return(e1);

            case MessageErrorType.ConnectionError:
                return(new ConnectionException(errorstring));

            case MessageErrorType.ProtocolError:
                return(new ProtocolException(errorstring));

            case MessageErrorType.ServiceNotFound:
                return(new ServiceNotFoundException(errorstring));

            case MessageErrorType.ObjectNotFound:
                return(new ObjectNotFoundException(errorstring));

            case MessageErrorType.InvalidEndpoint:
                return(new InvalidEndpointException(errorstring));

            case MessageErrorType.EndpointCommunicationFatalError:
                return(new EndpointCommunicationFatalException(errorstring));

            case MessageErrorType.NodeNotFound:
                return(new NodeNotFoundException(errorstring));

            case MessageErrorType.ServiceError:
                return(new ServiceException(errorstring));

            case MessageErrorType.MemberNotFound:
                return(new MemberNotFoundException(errorstring));

            case MessageErrorType.MemberFormatMismatch:
                return(new MemberFormatMismatchException(errorstring));

            case MessageErrorType.DataTypeMismatch:
                return(new DataTypeMismatchException(errorstring));

            case MessageErrorType.DataTypeError:
                return(new DataTypeException(errorstring));

            case MessageErrorType.DataSerializationError:
                return(new DataSerializationException(errorstring));

            case MessageErrorType.MessageEntryNotFound:
                return(new MessageEntryNotFoundException(errorstring));

            case MessageErrorType.MessageElementNotFound:
                return(new MessageElementNotFoundException(errorstring));

            case MessageErrorType.UnknownError:
                return(new UnknownException(errorname, errorstring));

            case MessageErrorType.InvalidOperation:
                return(new InvalidOperationException(errorstring));

            case MessageErrorType.InvalidArgument:
                return(new ArgumentException(errorstring));

            case MessageErrorType.OperationFailed:
                return(new OperationFailedException(errorstring));

            case MessageErrorType.NullValue:
                return(new NullReferenceException(errorstring));

            case MessageErrorType.InternalError:
                return(new InternalErrorException(errorstring));

            case MessageErrorType.SystemResourcePermissionDenied:
                return(new SystemResourcePermissionDeniedException(errorstring));

            case MessageErrorType.OutOfSystemResource:
                return(new OutOfSystemResourceException(errorstring));

            case MessageErrorType.SystemResourceError:
                return(new SystemResourceException(errorstring));

            case MessageErrorType.ResourceNotFound:
                return(new ResourceNotFoundException(errorstring));

            case MessageErrorType.IOError:
                return(new System.IO.IOException(errorstring));

            case MessageErrorType.BufferLimitViolation:
                return(new BufferLimitViolationException(errorstring));

            case MessageErrorType.ServiceDefinitionError:
                return(new ServiceDefinitionException(errorstring));

            case MessageErrorType.OutOfRange:
                return(new ArgumentOutOfRangeException(errorstring));

            case MessageErrorType.KeyNotFound:
                return(new KeyNotFoundException(errorstring));

            case MessageErrorType.RequestTimeout:
                return(new RequestTimeoutException(errorstring));

            case MessageErrorType.ReadOnlyMember:
                return(new ReadOnlyMemberException(errorstring));

            case MessageErrorType.WriteOnlyMember:
                return(new WriteOnlyMemberException(errorstring));

            case MessageErrorType.NotImplementedError:
                return(new NotImplementedException(errorstring));

            case MessageErrorType.MemberBusy:
                return(new MemberBusyException(errorstring));

            case MessageErrorType.ValueNotSet:
                return(new ValueNotSetException(errorstring));

            case MessageErrorType.AuthenticationError:
                return(new AuthenticationException(errorstring));

            case MessageErrorType.ObjectLockedError:
                return(new ObjectLockedException(errorstring));

            case MessageErrorType.PermissionDenied:
                return(new PermissionDeniedException(errorstring));

            case MessageErrorType.AbortOperation:
                return(new AbortOperationException(errorstring));

            case MessageErrorType.OperationAborted:
                return(new OperationAbortedException(errorstring));

            case MessageErrorType.StopIteration:
                return(new StopIterationException(errorstring));
            }

            return(new RobotRaconteurException(error_code, errorname, errorstring));
        }