Exemple #1
0
        public SystemInfo GetSystemInfo(Int32 deviceId)
        {
            Log.Info("Invoke WebSocketOperation...");
            var operation            = new WebSocketOperation(deviceId);
            var getSystemInfoRequest = new GetSystemInfoRequest()
            {
                Token = operation.Token
            };
            string rawRequest = DataContractSerializationHelper.Serialize(getSystemInfoRequest);

            Log.DebugFormat("Request: {0}", rawRequest);
            var rawResponse = operation.Execute(rawRequest);

            Log.DebugFormat("Response: {0}", rawResponse);

            var response = DataContractSerializationHelper.Deserialize <GetSystemInfoResponse>(rawResponse);

            Log.InfoFormat("Get system info for device id:[{0}], result:[{1}]", deviceId, response.ResultType);

            if (response.ResultType != ResultType.OK)
            {
                throw new Exception(string.Format("Get system info for device id:[{0}], result:[{1}]", deviceId, response.ResultType));
            }

            return(response.SystemInfo);
        }
Exemple #2
0
        public GetSystemInfoResponse Process(GetSystemInfoRequest request)
        {
            try
            {
                var dao         = new SystemInfoDao();
                var systemData  = dao.GetSystemData();
                var serviceData = SystemInfoMapper.ToModel(systemData);

                return(new GetSystemInfoResponse()
                {
                    Token = request.Token, ResultType = ResultType.OK, SystemInfo = serviceData
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(new GetSystemInfoResponse()
                {
                    Token = request.Token, ResultType = ResultType.Error
                });
            }
        }
        /// <summary>
        /// Call bwsService.getSystemInfo() and display the returned properties.
        /// <returns>Returns true if getSystemInfo is successful, and false otherwise.</returns>
        /// </summary>
        public static bool GetSystemInfo()
        {
            const string methodName = "GetSystemInfo()";
            const string bwsApiName = "bwsService.getSystemInfo()";

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

            GetSystemInfoRequest request = new GetSystemInfoRequest();

            /*
             * Setting the value of loadAuthenticatedUserProperties to true will cause the API to return additional
             * properties about the current user, like the Authenticated User Uid property. The Authenticated User Uid
             * property is often used to make calls to APIs like getUsersDetail(), assignSWConfigsToGroup() and
             * others.
             */
            request.loadAuthenticatedUserProperties = true;
            request.metadata = Metadata;

            GetSystemInfoResponse response = null;

            /*
             * The try catch block here is used to illustrate how to handle a specific type of exception.
             * For example, in this case we check to see if the error was caused by invalid credentials.
             */
            try
            {
                logRequest(bwsApiName);
                response = bwsService.getSystemInfo(request);
                logResponse(bwsApiName, response.returnStatus.code, response.metadata);
            }
            catch (WebException e)
            {
                HttpWebResponse webResponse = e.Response as HttpWebResponse;
                // Handle authentication failure.
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    logMessage("Failed to authenticate with the BWS web service");
                    logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
                    return(returnValue);
                }
                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message);
                throw e;
            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.properties != null && response.properties.Length > 0)
                {
                    logMessage("{0} returned the following properties:", bwsApiName);
                    foreach (Property property in response.properties)
                    {
                        displayResult("{0}: {1}", property.name, property.value);
                    }

                    returnValue = true;
                }
                else
                {
                    logMessage("No properties in response");
                }
            }
            else
            {
                logMessage("Error Message: \"{0}\"", response.returnStatus.message);
            }

            logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
            return(returnValue);
        }
        /// <summary>
        /// Call bwsService.getSystemInfo() and display the returned properties.
        /// <returns>Returns true if getSystemInfo is successful, and false otherwise.</returns>
        /// </summary>
        public static bool GetSystemInfo()
        {
            const string methodName = "GetSystemInfo()";
            const string bwsApiName = "bwsService.getSystemInfo()";
            logMessage("Entering {0}", methodName);
            bool returnValue = false;

            GetSystemInfoRequest request = new GetSystemInfoRequest();

            /*
             * Setting the value of loadAuthenticatedUserProperties to true will cause the API to return additional
             * properties about the current user, like the Authenticated User Uid property. The Authenticated User Uid
             * property is often used to make self-service calls to APIs like getUsersDetail(), setUsersAutoSignature()
             * and others.
             */
            request.loadAuthenticatedUserProperties = true;
            request.metadata = Metadata;

            GetSystemInfoResponse response = null;

            /*
             * The try catch block here is used to illustrate how to handle a specific type of exception.
             * For example, in this case we check to see if the error was caused by invalid credentials.
             */
            try
            {
                logRequest(bwsApiName);
                response = bwsService.getSystemInfo(request);
                logResponse(bwsApiName, response.returnStatus.code, response.metadata);
            }
            catch (WebException e)
            {
                HttpWebResponse webResponse = e.Response as HttpWebResponse;
                // Handle authentication failure.
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    logMessage("Failed to authenticate with the BWS web service");
                    logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
                    return returnValue;
                }
                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message);
                throw e;

            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.properties != null && response.properties.Length > 0)
                {
                    logMessage("{0} returned the following properties:", bwsApiName);
                    foreach (Property property in response.properties)
                    {
                        displayResult("{0}: {1}", property.name, property.value);
                    }

                    returnValue = true;
                }
                else
                {
                    logMessage("No properties in response");
                }
            }
            else
            {
                logMessage("Error Message: \"{0}\"", response.returnStatus.message);
            }

            logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
            return returnValue;
        }
        /// <summary>
        /// Call bwsService.getSystemInfo() and display the returned properties.
        /// <returns>Returns true if getSystemInfo is successful, and false otherwise.</returns>
        /// </summary>
        public static bool GetSystemInfo()
        {
            const string methodName = "GetSystemInfo()";
            const string bwsApiName = "bwsService.getSystemInfo()";
            Console.Error.WriteLine("Entering {0}", methodName);
            bool returnValue = false;

            GetSystemInfoRequest request = new GetSystemInfoRequest();

            /*
             * Setting the value of loadAuthenticatedUserProperties to true will cause the API to return additional
             * properties about the current user, like the Authenticated User Uid property. The Authenticated User Uid
             * property is often used to make self-service calls to APIs like getUsersDetail(), setUsersAutoSignature()
             * and others.
             */
            request.loadAuthenticatedUserProperties = true;
            request.metadata = Metadata;

            GetSystemInfoResponse response = null;

            /*
             * The try catch block here is used to illustrate how to handle a specific type of exception.
             * For example, in this case we check to see if the error was caused by invalid credentials.
             */
            try
            {
                Console.Error.WriteLine("Calling {0}...", bwsApiName);
                response = bwsService.getSystemInfo(request);
                Console.Error.WriteLine("...{0} returned \"{1}\"", bwsApiName, response.returnStatus.code);
            }
            catch (WebException e)
            {
                HttpWebResponse webResponse = e.Response as HttpWebResponse;
                // Handle authentication failure.
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    Console.Error.WriteLine("Failed to authenticate with the BWS web service");
                    Console.Error.WriteLine("Exiting {0} with value \"{1}\"", methodName, returnValue);
                    return returnValue;
                }
                else
                {
                    // Re-throw other exceptions.
                    throw e;
                }
            }

            if (response.metadata != null)
            {
                /*
                 * Converting response.metadata.executionTime (which is in nano-seconds) into seconds by
                 * multiplying it by 10^-9.
                 */
                Console.Error.WriteLine("{0} Execution Time: {1:0.0000} seconds", bwsApiName,
                    (response.metadata.executionTime * Math.Pow(10, -9)));
                Console.Error.WriteLine("{0} Request UID: {1}", bwsApiName, response.metadata.requestUid);
            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.properties != null && response.properties.Length > 0)
                {
                    Console.Error.WriteLine("{0} returned the following properties:", bwsApiName);
                    foreach (Property property in response.properties)
                    {
                        Console.WriteLine("{0}: {1}", property.name, property.value);
                    }

                    returnValue = true;
                }
                else
                {
                    Console.Error.WriteLine("No properties in response");
                }
            }
            else
            {
                Console.Error.WriteLine("Error: Code: \"{0}\", Message: \"{1}\"", response.returnStatus.code,
                    response.returnStatus.message);
            }

            Console.Error.WriteLine("Exiting {0} with value \"{1}\"", methodName, returnValue);
            return returnValue;
        }
        /// <summary>
        /// Call bwsService.getSystemInfo() and set the serverType member.
        /// </summary>
        public static void GetSystemInfo()
        {
            const string methodName = "GetSystemInfo()";
            const string bwsApiName = "bwsService.getSystemInfo()";

            logMessage("Entering {0}", methodName);

            GetSystemInfoRequest request = new GetSystemInfoRequest();

            request.metadata = REQUEST_METADATA;

            GetSystemInfoResponse response = null;

            /*
             * The try catch block here is used to illustrate how to handle a specific type of exception.
             * For example, in this case we check to see if the error was caused by invalid credentials.
             */
            try
            {
                logRequest(bwsApiName);
                response = bwsService.getSystemInfo(request);
                logResponse(bwsApiName, response.returnStatus.code, response.metadata);
            }
            catch (WebException e)
            {
                HttpWebResponse webResponse = e.Response as HttpWebResponse;
                // Handle authentication failure.
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    logMessage("Failed to authenticate with the BWS web service");
                }

                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message);
                throw e;
            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.properties != null && response.properties.Length > 0)
                {
                    foreach (Property property in response.properties)
                    {
                        if (property.name.ToUpper().Equals("BWS VERSION"))
                        {
                            serverType = ServerType.BDS;
                            break;
                        }
                        if(property.name.ToUpper().Equals("BUDS VERSION"))
                        {
                            serverType = ServerType.UDS;
                            break;
                        }
                    }
                }
                else
                {
                    logMessage("No properties in response");
                }
            }
            else
            {
                logMessage("Error Message: \"{0}\"", response.returnStatus.message);
            }

            logMessage("Exiting {0}", methodName);
        }
Exemple #7
0
        /// <summary>
        /// Call bwsService.getSystemInfo() and set the serverType member.
        /// </summary>
        public static void GetSystemInfo()
        {
            const string methodName = "GetSystemInfo()";
            const string bwsApiName = "bwsService.getSystemInfo()";

            logMessage("Entering {0}", methodName);

            GetSystemInfoRequest request = new GetSystemInfoRequest();

            request.metadata = REQUEST_METADATA;

            GetSystemInfoResponse response = null;

            /*
             * The try catch block here is used to illustrate how to handle a specific type of exception.
             * For example, in this case we check to see if the error was caused by invalid credentials.
             */
            try
            {
                logRequest(bwsApiName);
                response = bwsService.getSystemInfo(request);
                logResponse(bwsApiName, response.returnStatus.code, response.metadata);
            }
            catch (WebException e)
            {
                HttpWebResponse webResponse = e.Response as HttpWebResponse;
                // Handle authentication failure.
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    logMessage("Failed to authenticate with the BWS web service");
                }

                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message);
                throw e;
            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.properties != null && response.properties.Length > 0)
                {
                    foreach (Property property in response.properties)
                    {
                        if (property.name.ToUpper().Equals("BAS VERSION"))
                        {
                            if (property.value.Split('.')[0].Equals("12"))
                            {
                                serverType = ServerType.BES12;
                                logMessage("ServerType found: BES12");
                            }
                            else
                            {
                                serverType = ServerType.BDS;
                                logMessage("ServerType found: BDS");
                            }
                            break;
                        }
                        if (property.name.ToUpper().Equals("BUDS VERSION"))
                        {
                            serverType = ServerType.UDS;
                            logMessage("ServerType found: UDS");
                            break;
                        }
                    }
                }
                else
                {
                    logMessage("No properties in response");
                }
            }
            else
            {
                logMessage("Error Message: \"{0}\"", response.returnStatus.message);
            }

            logMessage("Exiting {0}", methodName);
        }