Ejemplo n.º 1
0
        public void GetContactRoles()
        {
            try
            {
                Console.WriteLine("Fetching Cr's for user - " + SDKInitializer.GetInitializer().User.Email);

                ContactRolesOperations contactRolesOperations = new ContactRolesOperations();

                APIResponse <API.ContactRoles.ResponseHandler> response = contactRolesOperations.GetContactRoles();

                if (response != null)
                {
                    //Get the status code from response
                    Console.WriteLine("Status Code: " + response.StatusCode);

                    if (new List <int>()
                    {
                        204, 304
                    }.Contains(response.StatusCode))
                    {
                        Console.WriteLine(response.StatusCode == 204 ? "No Content" : "Not Modified");

                        return;
                    }

                    //Check if expected response is received
                    if (response.IsExpected)
                    {
                        //Get object from response
                        API.ContactRoles.ResponseHandler responseHandler = response.Object;

                        if (responseHandler is API.ContactRoles.ResponseWrapper)
                        {
                            //Get the received ResponseWrapper instance
                            API.ContactRoles.ResponseWrapper responseWrapper = (API.ContactRoles.ResponseWrapper)responseHandler;

                            //Get the list of obtained Record instances
                            List <ContactRole> contactRoles = responseWrapper.ContactRoles;

                            foreach (ContactRole contactRole in contactRoles)
                            {
                                Console.WriteLine(JsonConvert.SerializeObject(contactRole));
                            }
                        }
                        //Check if the request returned an exception
                        else if (responseHandler is API.ContactRoles.APIException)
                        {
                            //Get the received APIException instance
                            API.ContactRoles.APIException exception = (API.ContactRoles.APIException)responseHandler;

                            //Get the Status
                            Console.WriteLine("Status: " + exception.Status.Value);

                            //Get the Code
                            Console.WriteLine("Code: " + exception.Code.Value);

                            Console.WriteLine("Details: ");

                            //Get the details map
                            foreach (KeyValuePair <string, object> entry in exception.Details)
                            {
                                //Get each value in the map
                                Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                            }

                            //Get the Message
                            Console.WriteLine("Message: " + exception.Message.Value);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(JsonConvert.SerializeObject(ex));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is used to get all the Contact Roles and print the response.
        /// </summary>
        public static void GetContactRoles()
        {
            //Get instance of ContactRolesOperations Class
            ContactRolesOperations contactRolesOperations = new ContactRolesOperations();

            //Call GetContactRoles method
            APIResponse <ResponseHandler> response = contactRolesOperations.GetContactRoles();

            if (response != null)
            {
                //Get the status code from response
                Console.WriteLine("Status Code: " + response.StatusCode);

                if (new List <int>()
                {
                    204, 304
                }.Contains(response.StatusCode))
                {
                    Console.WriteLine(response.StatusCode == 204? "No Content" : "Not Modified");

                    return;
                }

                //Check if expected response is received
                if (response.IsExpected)
                {
                    //Get object from response
                    ResponseHandler responseHandler = response.Object;

                    if (responseHandler is ResponseWrapper)
                    {
                        //Get the received ResponseWrapper instance
                        ResponseWrapper responseWrapper = (ResponseWrapper)responseHandler;

                        //Get the list of obtained ContactRole instances
                        List <ContactRole> contactRoles = responseWrapper.ContactRoles;

                        foreach (ContactRole contactRole in contactRoles)
                        {
                            //Get the ID of each ContactRole
                            Console.WriteLine("ContactRole ID: " + contactRole.Id);

                            //Get the name of each ContactRole
                            Console.WriteLine("ContactRole Name: " + contactRole.Name);

                            //Get the sequence number each ContactRole
                            Console.WriteLine("ContactRole SequenceNumber: " + contactRole.SequenceNumber);
                        }
                    }
                    //Check if the request returned an exception
                    else if (responseHandler is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)responseHandler;

                        //Get the Status
                        Console.WriteLine("Status: " + exception.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + exception.Code.Value);

                        Console.WriteLine("Details: ");

                        //Get the details map
                        foreach (KeyValuePair <string, object> entry in exception.Details)
                        {
                            //Get each value in the map
                            Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + exception.Message.Value);
                    }
                }
                else
                { //If response is not as expected
                    //Get model object from response
                    Model responseObject = response.Model;

                    //Get the response object's class
                    Type type = responseObject.GetType();

                    //Get all declared fields of the response class
                    Console.WriteLine("Type is: {0}", type.Name);

                    PropertyInfo[] props = type.GetProperties();

                    Console.WriteLine("Properties (N = {0}):", props.Length);

                    foreach (var prop in props)
                    {
                        if (prop.GetIndexParameters().Length == 0)
                        {
                            Console.WriteLine("{0} ({1}) in {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
                        }
                        else
                        {
                            Console.WriteLine("{0} ({1}) in <Indexed>", prop.Name, prop.PropertyType.Name);
                        }
                    }
                }
            }
        }