Esempio n. 1
0
        public static void updateUserTest(Client client, String uid)
        {
            // send the request to retrieve the user
            HttpWebResponse response = client.retrieveUser(uid);

            // build a node reader from the response
            XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

            try
            {
                // verify the response code indicates success
                //int status =  response.getStatusCode();
                //assert(status == 200);

                /*
                // get the response stream to read the user
                Stream stream = response.GetResponseStream();

                // create a user deserializer
                XmlSerializer deserializer = new XmlSerializer(typeof(User));

                // retrieve the returned user entry
                User user = (User)deserializer.Deserialize(stream);
                */

                // get the user object from the response
                User user = client.getUserFromResponse(xmlNodeReader);

                // update the users name
                user.name.givenName = "Matthew";
                user.name.familyName = "Crooke";
                user.nickName = "Matt";
                user.name.formatted = "Mr Matthew Crooke";

                // update the users groups            
                PluralAttribute group = new PluralAttribute();
                group.value = "gid=nerds,ou=groups,dc=hackerypokery,dc=com";
                PluralAttribute[] memberOfs = new PluralAttribute[] { group };
                user.memberOf = memberOfs;

                // send the request to update the user
                response = client.updateUser(user);

                // verify the response code indicates success
                //status =  response.getStatusCode();
                //assert(status == 200);

                /*
                // get the response stream to update user
                stream = response.GetResponseStream();

                // retrieve the returned user entry
                user = (User)deserializer.Deserialize(stream);
                */

                // build a node reader from the response
                xmlNodeReader = client.buildReaderFromResponse(response);

                // get the user object from the response
                user = client.getUserFromResponse(xmlNodeReader);

                Console.WriteLine("updated user - " + user.id);
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be updated, error returned - " + error.code + " " + error.description);
            }           
        }
Esempio n. 2
0
        public static void retrieveUserTest(Client client, String uid)
        {
            // send the request to retrieve the user
            HttpWebResponse response = client.retrieveUser(uid);

            // build a node reader from the response
            XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

            try
            {
                // get the user object from the response
                User user = client.getUserFromResponse(xmlNodeReader);

                Console.WriteLine("retrieved user - " + user.id);
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be retrieved, error returned - " + error.code + " " + error.description);
            }
        }