Beispiel #1
0
 public bool Handle(Object obj)
 {
     try
     {
         OperationResponsePart part =
             new OperationResponsePart(null, obj);
         _connection.WriteObject(part);
         _count++;
         if (_count % PAUSE_INTERVAL == 0)
         {
             _connection.WriteObject(new OperationResponsePause());
             Object message =
                 _connection.ReadObject();
             return message is OperationRequestMoreData;
         }
         else
         {
             return true;
         }
     }
     catch (IOException e)
     {
         throw new BrokenConnectionException(e);
     }
 }
Beispiel #2
0
        private bool ProcessRequest()
        {
            CultureInfo locale;
            try
            {
                locale = (CultureInfo)_connection.ReadObject();
            }
            catch (EndOfStreamException)
            {
                return false;
            }

            //We can't set this because C# does not like language-neutral
            //cultures for CurrentCulture - this tends to blow up
            //TODO: think more about this...
            //Thread.CurrentThread.CurrentCulture = locale;
            Thread.CurrentThread.CurrentUICulture = locale;

            GuardedString key = (GuardedString)_connection.ReadObject();

            bool authorized;
            try
            {
                authorized = key.VerifyBase64SHA1Hash(_server.KeyHash);
            }
            finally
            {
                key.Dispose();
            }
            Org.IdentityConnectors.Framework.Common.Exceptions.InvalidCredentialException authException = null;
            if (!authorized)
            {
                authException = new Org.IdentityConnectors.Framework.Common.Exceptions.InvalidCredentialException("Remote framework key is invalid");
            }
            Object requestObject = _connection.ReadObject();
            if (requestObject is HelloRequest)
            {
                if (authException != null)
                {
                    HelloResponse response =
                        new HelloResponse(authException, null, null, null);
                    _connection.WriteObject(response);
                }
                else
                {
                    HelloResponse response =
                        ProcessHelloRequest((HelloRequest)requestObject);
                    _connection.WriteObject(response);
                }
            }
            else if (requestObject is OperationRequest)
            {
                if (authException != null)
                {
                    OperationResponsePart part =
                        new OperationResponsePart(authException, null);
                    _connection.WriteObject(part);
                }
                else
                {
                    OperationRequest opRequest =
                        (OperationRequest)requestObject;
                    OperationResponsePart part =
                        ProcessOperationRequest(opRequest);
                    _connection.WriteObject(part);
                }
            }
            else if (requestObject is EchoMessage)
            {
                if (authException != null)
                {
                    //echo message probably doesn't need auth, but
                    //it couldn't hurt - actually it does for test connection
                    EchoMessage part =
                        new EchoMessage(authException, null);
                    _connection.WriteObject(part);
                }
                else
                {
                    EchoMessage message = (EchoMessage)requestObject;
                    Object obj = message.Object;
                    String xml = message.ObjectXml;
                    if (xml != null)
                    {
                        Console.WriteLine("xml: \n" + xml);
                        Object xmlClone =
                            SerializerUtil.DeserializeXmlObject(xml, true);
                        xml =
                            SerializerUtil.SerializeXmlObject(xmlClone, true);
                    }
                    EchoMessage message2 = new EchoMessage(obj, xml);
                    _connection.WriteObject(message2);
                }
            }
            else
            {
                throw new Exception("Unexpected request: " + requestObject);
            }
            return true;
        }