Exemplo n.º 1
0
        /// <summary>
        /// Retrieve and display some user details.
        /// <returns>Returns true if getUsersDetail is successful, and false otherwise.</returns>
        /// </summary>
        public static bool DisplayUserDetails()
        {
            const string methodName = "DisplayUserDetails()";
            const string bwsApiName = "bwsService.getUsersDetail()";

            logMessage("Entering {0}", methodName);
            bool returnValue = false;

            logMessage("Displaying details for user with email address \"{0}\"",
                       DisplayUserDetailsEmail);

            // Getting the user object.
            User user = GetUser();

            if (user == null)
            {
                logMessage("'user' is null");
                logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
                return(returnValue);
            }

            List <User> users = new List <User>();

            users.Add(user);

            GetUsersDetailRequest request = new GetUsersDetailRequest();

            request.metadata = Metadata;

            /*
             * To help improve API performance, load only the required details.
             * By default all load flags are set to false.
             */
            request.loadAccounts   = true;
            request.loadDevices    = true;
            request.loadITPolicies = true;
            request.users          = users.ToArray();

            GetUsersDetailResponse response = null;

            try
            {
                logRequest(bwsApiName);
                response = bwsService.getUsersDetail(request);
                logResponse(bwsApiName, response.returnStatus.code, response.metadata);
            }
            catch (WebException e)
            {
                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message);
                throw e;
            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.individualResponses != null && response.individualResponses.Length == 1)
                {
                    foreach (GetUsersDetailIndividualResponse individualResponse in response.individualResponses)
                    {
                        UserDetail userDetail = individualResponse.userDetail;

                        displayResult("User details:");

                        displayResult("Display Name: {0}", userDetail.displayName);
                        displayResult("User UID: {0}", individualResponse.userUid);

                        // Displays time in UTC format.
                        displayResult("Last Login Time: {0}", userDetail.lastLoginTime);
                        if (userDetail.indirectITPolicies != null && userDetail.indirectITPolicies.Length > 0)
                        {
                            StringBuilder policyString = new StringBuilder();
                            foreach (IndirectITPolicy indirectITPolicy in userDetail.indirectITPolicies)
                            {
                                if (policyString.Length > 0)
                                {
                                    policyString.Append(", ");
                                }
                                policyString.Append(indirectITPolicy.itPolicy.policy.name);
                            }
                            displayResult("Indirect IT policy names: {0}", policyString.ToString());
                        }

                        if (userDetail.directITPolicy != null && userDetail.directITPolicy.policy != null)
                        {
                            displayResult("Direct IT policy name: {0}", userDetail.directITPolicy.policy.name);
                        }

                        /*
                         * The BWS object model supports multiple accounts and devices. However, BlackBerry Enterprise
                         * Server 5.0.x or later will only return at most one object in the userDetail.devices array, and
                         * at most one object in the userDetail.accounts array.
                         */
                        if (userDetail.devices != null && userDetail.devices.Length > 0)
                        {
                            displayResult("User's device details:");

                            int deviceIndex = 1;
                            foreach (Device device in userDetail.devices)
                            {
                                displayResult("Device {0} data", (deviceIndex++));
                                displayResult("---------------");
                                displayResult("PIN: {0}", device.pin);
                                displayResult("Model: {0}", device.model);
                                displayResult("Phone Number: {0}", device.phoneNumber);
                                displayResult("Active Carrier: {0}", device.activeCarrier);
                                displayResult("Serial Number: {0}", device.serialNumber);
                                displayResult("State: {0}", device.state.value);
                                displayResult("IT Policy Name: {0}", device.itPolicyName);
                                displayResult("Platform Version: {0}", device.platformVersion);
                                displayResult("---------------");
                            }
                        }

                        if (userDetail.accounts != null && userDetail.accounts.Length > 0)
                        {
                            displayResult("User's account details:");

                            int accountIndex = 1;
                            foreach (Account account in userDetail.accounts)
                            {
                                displayResult("Account {0} data", (accountIndex++));
                                displayResult("---------------");
                                displayResult("Email Address: {0}", account.emailAddress);
                                displayResult("---------------");
                            }
                        }
                    }

                    returnValue = true;
                }
                else if (response.individualResponses != null && response.individualResponses.Length > 1)
                {
                    logMessage("More than one user was found with userUid \"{0}\"",
                               user.uid);
                }
                else
                {
                    logMessage("No user was found with userUid \"{0}\"", user.uid);
                }
            }
            else
            {
                logMessage("Error Message: \"{0}\"", response.returnStatus.message);
                if (response.individualResponses != null)
                {
                    foreach (GetUsersDetailIndividualResponse individualResponse in response.individualResponses)
                    {
                        logMessage("User UID: \"{0}\"", individualResponse.userUid);
                        logMessage("Individual Response - Code: \"{0}\", Message: \"{1}\"",
                                   individualResponse.returnStatus.code, individualResponse.returnStatus.message);
                    }
                }
            }

            logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
            return(returnValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve and display some user details.
        /// <returns>Returns true if getUsersDetail is successful, and false otherwise.</returns>
        /// </summary>
        public static bool DisplayUserDetails()
        {
            const string methodName = "DisplayUserDetails()";
            const string bwsApiName = "bwsService.getUsersDetail()";
            logMessage("Entering {0}", methodName);
            bool returnValue = false;

            logMessage("Displaying details for user with email address \"{0}\"",
                DisplayUserDetailsEmail);

            // Getting the user object.
            User user = GetUser();

            if (user == null)
            {
                logMessage("'user' is null");
                logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
                return returnValue;
            }

            List<User> users = new List<User>();
            users.Add(user);

            GetUsersDetailRequest request = new GetUsersDetailRequest();
            request.metadata = Metadata;

            /*
             * To help improve API performance, load only the required details.
             * By default all load flags are set to false.
             */
            request.loadAccounts = true;
            request.loadDevices = true;
            request.loadITPolicies = true;
            request.users = users.ToArray();

            GetUsersDetailResponse response = null;
            try
            {
                logRequest(bwsApiName);
                response = bwsService.getUsersDetail(request);
                logResponse(bwsApiName, response.returnStatus.code, response.metadata);
            }
            catch (WebException e)
            {
                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message);
                throw e;
            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.individualResponses != null && response.individualResponses.Length == 1)
                {
                    foreach (GetUsersDetailIndividualResponse individualResponse in response.individualResponses)
                    {
                        UserDetail userDetail = individualResponse.userDetail;

                        displayResult("User details:");

                        displayResult("Display Name: {0}", userDetail.displayName);
                        displayResult("User UID: {0}", individualResponse.userUid);

                        // Displays time in UTC format.
                        displayResult("Last Login Time: {0}", userDetail.lastLoginTime);
                        if (userDetail.indirectITPolicies != null && userDetail.indirectITPolicies.Length > 0)
                        {
                            StringBuilder policyString = new StringBuilder();
                            foreach (IndirectITPolicy indirectITPolicy in userDetail.indirectITPolicies)
                            {
                                if (policyString.Length > 0)
                                {
                                    policyString.Append(", ");
                                }
                                policyString.Append(indirectITPolicy.itPolicy.policy.name);
                            }
                            displayResult("Indirect IT policy names: {0}", policyString.ToString());
                        }

                        if (userDetail.directITPolicy != null && userDetail.directITPolicy.policy != null)
                        {
                            displayResult("Direct IT policy name: {0}", userDetail.directITPolicy.policy.name);
                        }

                        /*
                         * The BWS object model supports multiple accounts and devices. However, BlackBerry Enterprise
                         * Server 5.0.3 or later will only return at most one object in the userDetail.devices array, and
                         * at most one object in the userDetail.accounts array.
                         */
                        if (userDetail.devices != null && userDetail.devices.Length > 0)
                        {
                            displayResult("User's device details:");

                            int deviceIndex = 1;
                            foreach (Device device in userDetail.devices)
                            {
                                displayResult("Device {0} data", (deviceIndex++));
                                displayResult("---------------");
                                displayResult("PIN: {0}", device.pin);
                                displayResult("Model: {0}", device.model);
                                displayResult("Phone Number: {0}", device.phoneNumber);
                                displayResult("Active Carrier: {0}", device.activeCarrier);
                                displayResult("Network: {0}", device.network);
                                displayResult("Serial Number: {0}", device.serialNumber);
                                displayResult("State: {0}", device.state.value);
                                displayResult("IT Policy Name: {0}", device.itPolicyName);
                                displayResult("Platform Version: {0}", device.platformVersion);
                                displayResult("Total Messages Expired: {0}", device.totalMessagesExpired);
                                displayResult("Total Messages Filtered: {0}", device.totalMessagesFiltered);
                                displayResult("Total Messages Forwarded: {0}", device.totalMessagesForwarded);
                                displayResult("Total Messages Pending: {0}", device.totalMessagesPending);
                                displayResult("Total Messages Sent: {0}", device.totalMessagesSent);
                                displayResult("---------------");
                            }
                        }

                        if (userDetail.accounts != null && userDetail.accounts.Length > 0)
                        {
                            displayResult("User's account details:");

                            int accountIndex = 1;
                            foreach (Account account in userDetail.accounts)
                            {
                                displayResult("Account {0} data", (accountIndex++));
                                displayResult("---------------");
                                displayResult("Email Address: {0}", account.emailAddress);
                                displayResult("---------------");
                            }
                        }
                    }

                    returnValue = true;
                }
                else if (response.individualResponses != null && response.individualResponses.Length > 1)
                {
                    logMessage("More than one user was found with userUid \"{0}\"",
                        user.uid);
                }
                else
                {
                    logMessage("No user was found with userUid \"{0}\"", user.uid);
                }
            }
            else
            {
                logMessage("Error Message: \"{0}\"", response.returnStatus.message);
                if (response.individualResponses != null)
                {
                    foreach (GetUsersDetailIndividualResponse individualResponse in response.individualResponses)
                    {
                        logMessage("User UID: \"{0}\"", individualResponse.userUid);
                        logMessage("Individual Response - Code: \"{0}\", Message: \"{1}\"",
                            individualResponse.returnStatus.code, individualResponse.returnStatus.message);
                    }
                }
            }

            logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
            return returnValue;
        }