Example #1
0
        /*---------------------------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        /// Gets a package.
        /// </summary>
        /// <param name="packageId">The package identifier.</param>
        public void getPackage(string packageId)
        {
            RestRequest request = new RestRequest("getPackage", Method.POST);

            request.AddParameter("sessionId", this.sessionId);
            request.AddParameter("packageId", packageId);

            try
            {
                RestResponse response = (RestResponse)this.client.Execute(request);

                //GetPackageOutputWS output = new GetPackageOutputWS();
                //output = JsonConvert.DeserializeObject<GetPackageOutputWS>(response.Content);
                //int returnCode = output.returnCode;
                //System.IO.File.WriteAllText(@"C:\Users\Raine\Desktop\output.txt", response.Content.ToString());

                JObject o          = JObject.Parse(response.Content.ToString());
                int     returnCode = Convert.ToInt32((string)o.SelectToken("returnCode"));

                //Message according to the return code. Only most frequent cases are shown
                StringBuilder message = new StringBuilder();
                switch (returnCode)
                {
                case 0:
                    message.AppendLine("The package is retrieved successfully.");
                    var extPackageVOJSON = o.SelectToken("extPackageVO");
                    if (extPackageVOJSON != null)
                    {
                        message.AppendLine("Package VO : ");
                        ExtPackageVOWS packageVOWS = extPackageVOJSON.ToObject <ExtPackageVOWS>();
                        message.AppendLine(packageVOWS.toString());
                    }

                    break;

                case -1: message.AppendLine("Requester does not have sufficient privileges."); break;

                case -2: message.AppendLine("Package not found."); break;

                case -99: message.AppendLine("System error occurred."); break;

                default: message.AppendLine("Couldn't retrieve package."); break;
                }
                Console.Out.WriteLine("Return code: " + returnCode + ". " + message.ToString());
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Exception Occured from getPackage() method: " + e.Message);
            }
        }
Example #2
0
        /*---------------------------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        /// Gets the packages of a user.
        /// </summary>
        public void getUserPackages()
        {
            String      contextName = "Package.getUserPackages()";
            RestRequest request     = new RestRequest("getUserPackages", Method.POST);

            request.AddParameter("sessionId", this.sessionId);
            try
            {
                RestResponse response = (RestResponse)this.client.Execute(request);
                //Util.log(contextName, response.Content.ToString());

                //GetUserPackagesOutputWS output = new GetUserPackagesOutputWS();
                //output = JsonConvert.DeserializeObject<GetUserPackagesOutputWS>(response.Content);
                //int returnCode = output.returnCode;

                JObject o             = JObject.Parse(response.Content.ToString());
                int     returnCode    = Convert.ToInt32((string)o.SelectToken("returnCode"));
                int     totalRowCount = Convert.ToInt32((string)o.SelectToken("totalRowCount"));

                //Message according to the return code. Only most frequent cases are shown
                string message = "";
                switch (returnCode)
                {
                case 0:
                {
                    // If the user has no packages
                    if (totalRowCount < 1)
                    {
                        message = "The user has no packages.";
                    }

                    else
                    {
                        message = "Got user packages successfully.\n";


                        var extPackageVOJSON = o.SelectToken("extPackageVOWss");
                        if (extPackageVOJSON != null)
                        {
                            // If the user has one package
                            if (totalRowCount == 1)
                            {
                                ExtPackageVOWS packageVOWS = extPackageVOJSON.ToObject <ExtPackageVOWS>();
                                message = message + "\n" + packageVOWS.toString();
                            }

                            // If the user has multiple packages
                            else
                            {
                                List <ExtPackageVOWS> extPackageVOWss = JsonConvert.DeserializeObject <List <ExtPackageVOWS> >(extPackageVOJSON.ToString());
                                foreach (ExtPackageVOWS package in extPackageVOWss)
                                {
                                    message = message + "\n" + package.toString();
                                }
                            }
                        }
                    }
                }; break;

                case -1: message = "Requester does not have sufficient privileges."; break;

                case -2: message = "User not found."; break;

                case -99: message = "System error occurred."; break;

                default: message = "Couldn't retrieve packages of the user."; break;
                }
                Console.Out.WriteLine("\nReturn code: " + returnCode);
                Console.Out.WriteLine(message);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Exception Occured from getUserPackages() method: " + e.Message);
            }
        }