Пример #1
0
        public Object Invoke(Object proxy, MethodInfo method, Object[] args)
        {
            //don't proxy toString, hashCode, or equals
            if (method.DeclaringType.Equals(typeof(object)))
            {
                return(method.Invoke(this, args));
            }

            //partition arguments into arguments that can
            //be simply marshalled as part of the request and
            //those that are response handlers
            IList <Object> simpleMarshallArgs =
                CollectionUtil.NewList(args);
            ObjectStreamHandler streamHandlerArg =
                ExtractStreamHandler(ReflectionUtil.GetParameterTypes(method), simpleMarshallArgs);

            //build the request object
            RemoteConnectorInfoImpl connectorInfo =
                (RemoteConnectorInfoImpl)_configuration.ConnectorInfo;
            RemoteFrameworkConnectionInfo connectionInfo =
                connectorInfo.RemoteConnectionInfo;
            OperationRequest request = new OperationRequest(
                connectorInfo.ConnectorKey,
                _configuration,
                _operation,
                method.Name,
                simpleMarshallArgs);

            //create the connection
            RemoteFrameworkConnection connection =
                new RemoteFrameworkConnection(connectionInfo);

            try
            {
                connection.WriteObject(CultureInfo.CurrentUICulture);
                connection.WriteObject(connectionInfo.Key);
                //send the request
                connection.WriteObject(request);

                //now process each response stream (if any)
                if (streamHandlerArg != null)
                {
                    HandleStreamResponse(connection, streamHandlerArg);
                }

                //finally return the actual return value
                OperationResponsePart response =
                    (OperationResponsePart)connection.ReadObject();
                if (response.Exception != null)
                {
                    throw response.Exception;
                }
                return(response.Result);
            }
            finally
            {
                connection.Dispose();
            }
        }
Пример #2
0
        /// <summary>
        /// Handles a stream response until the end of the stream
        /// </summary>
        private static void HandleStreamResponse(RemoteFrameworkConnection connection, ObjectStreamHandler streamHandler)
        {
            Object response;
            bool   handleMore = true;

            while (true)
            {
                response = connection.ReadObject();
                if (response is OperationResponsePart)
                {
                    OperationResponsePart part = (OperationResponsePart)response;
                    if (part.Exception != null)
                    {
                        throw part.Exception;
                    }
                    object obj =
                        part.Result;
                    if (handleMore)
                    {
                        handleMore = streamHandler.Handle(obj);
                    }
                }
                else if (response is OperationResponsePause)
                {
                    if (handleMore)
                    {
                        connection.WriteObject(new OperationRequestMoreData());
                    }
                    else
                    {
                        connection.WriteObject(new OperationRequestStopData());
                    }
                }
                else if (response is OperationResponseEnd)
                {
                    break;
                }
                else
                {
                    throw new ConnectorException("Unexpected response: " + response);
                }
            }
        }
Пример #3
0
 public RemoteConnectorInfoManagerImpl(RemoteFrameworkConnectionInfo info)
 {
     using (RemoteFrameworkConnection connection =
                new RemoteFrameworkConnection(info))
     {
         connection.WriteObject(CultureInfo.CurrentUICulture);
         connection.WriteObject(info.Key);
         connection.WriteObject(new HelloRequest(HelloRequest.CONNECTOR_INFO));
         HelloResponse response = (HelloResponse)connection.ReadObject();
         if (response.Exception != null)
         {
             throw response.Exception;
         }
         IList <RemoteConnectorInfoImpl> remoteInfos =
             response.ConnectorInfos;
         //populate transient fields not serialized
         foreach (RemoteConnectorInfoImpl remoteInfo in remoteInfos)
         {
             remoteInfo.RemoteConnectionInfo = info;
         }
         _connectorInfo =
             CollectionUtil.NewReadOnlyList <RemoteConnectorInfoImpl, ConnectorInfo>(remoteInfos);
     }
 }
Пример #4
0
 /// <summary>
 /// Handles a stream response until the end of the stream
 /// </summary>
 private static void HandleStreamResponse(RemoteFrameworkConnection connection, ObjectStreamHandler streamHandler)
 {
     Object response;
     bool handleMore = true;
     while (true)
     {
         response = connection.ReadObject();
         if (response is OperationResponsePart)
         {
             OperationResponsePart part = (OperationResponsePart)response;
             if (part.Exception != null)
             {
                 throw part.Exception;
             }
             object obj =
                 part.Result;
             if (handleMore)
             {
                 handleMore = streamHandler.Handle(obj);
             }
         }
         else if (response is OperationResponsePause)
         {
             if (handleMore)
             {
                 connection.WriteObject(new OperationRequestMoreData());
             }
             else
             {
                 connection.WriteObject(new OperationRequestStopData());
             }
         }
         else if (response is OperationResponseEnd)
         {
             break;
         }
         else
         {
             throw new ConnectorException("Unexpected response: " + response);
         }
     }
 }
Пример #5
0
        public Object Invoke(Object proxy, MethodInfo method, Object[] args)
        {
            //don't proxy toString, hashCode, or equals
            if (method.DeclaringType.Equals(typeof(object)))
            {
                return method.Invoke(this, args);
            }

            //partition arguments into arguments that can
            //be simply marshalled as part of the request and
            //those that are response handlers
            IList<Object> simpleMarshallArgs =
                CollectionUtil.NewList(args);
            ObjectStreamHandler streamHandlerArg =
                ExtractStreamHandler(ReflectionUtil.GetParameterTypes(method), simpleMarshallArgs);

            //build the request object
            RemoteFrameworkConnectionInfo connectionInfo =
                _connectorInfo.RemoteConnectionInfo;
            OperationRequest request = new OperationRequest(
                    _connectorInfo.ConnectorKey, _connectorFacadeKey,
                    _operation,
                    method.Name,
                    simpleMarshallArgs);

            //create the connection
            RemoteFrameworkConnection connection =
                new RemoteFrameworkConnection(connectionInfo);
            try
            {
                connection.WriteObject(CultureInfo.CurrentUICulture);
                connection.WriteObject(connectionInfo.Key);
                //send the request
                connection.WriteObject(request);

                //now process each response stream (if any)
                if (streamHandlerArg != null)
                {
                    HandleStreamResponse(connection, streamHandlerArg);
                }

                //finally return the actual return value
                OperationResponsePart response =
                    (OperationResponsePart)connection.ReadObject();
                if (response.Exception != null)
                {
                    throw response.Exception;
                }
                return response.Result;
            }
            finally
            {
                connection.Dispose();
            }
        }
Пример #6
0
 public RemoteConnectorInfoManagerImpl(RemoteFrameworkConnectionInfo info)
 {
     using (RemoteFrameworkConnection connection =
            new RemoteFrameworkConnection(info))
     {
         connection.WriteObject(CultureInfo.CurrentUICulture);
         connection.WriteObject(info.Key);
         connection.WriteObject(new HelloRequest(HelloRequest.CONNECTOR_INFO));
         HelloResponse response = (HelloResponse)connection.ReadObject();
         if (response.Exception != null)
         {
             throw response.Exception;
         }
         IList<RemoteConnectorInfoImpl> remoteInfos =
         response.ConnectorInfos;
         //populate transient fields not serialized
         foreach (RemoteConnectorInfoImpl remoteInfo in remoteInfos)
         {
             remoteInfo.RemoteConnectionInfo = info;
         }
         _connectorInfo =
      CollectionUtil.NewReadOnlyList<RemoteConnectorInfoImpl, ConnectorInfo>(remoteInfos);
     }
 }