Exemple #1
0
        public static string SerializeListData(List <ObjectAPI> objectAPIs, TypeElementResponseAPI typeElementResponse)
        {
            string xml = null;

            if (objectAPIs != null &&
                objectAPIs.Count > 0)
            {
                xml += "<list currentpointer=\"0\">";

                // Go through each object and serialize it into the list
                foreach (ObjectAPI objectAPI in objectAPIs)
                {
                    xml += SerializeObjectData(objectAPI, typeElementResponse);
                }

                xml += "</list>";
            }

            return(xml);
        }
Exemple #2
0
        public static String GetTypeElementEntryIdForDeveloperName(TypeElementResponseAPI typeElementResponse, String developerName)
        {
            String typeElementEntryId = null;

            if (typeElementResponse != null &&
                typeElementResponse.properties != null &&
                typeElementResponse.properties.Count > 0)
            {
                // Go through each of the type element entries and match by developer name
                foreach (TypeElementPropertyAPI typeElementEntry in typeElementResponse.properties)
                {
                    // Check to see if this is the matching type element entry
                    if (typeElementEntry.developerName.Equals(developerName, StringComparison.InvariantCultureIgnoreCase) == true)
                    {
                        // We have our type element entry - break out of the loop
                        typeElementEntryId = typeElementEntry.id;
                        break;
                    }
                }
            }

            return(typeElementEntryId);
        }
Exemple #3
0
        public TypeElementResponseAPI SaveTypeElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, TypeElementRequestAPI typeElementRequest)
        {
            TypeElementResponseAPI typeElementResponse = null;
            HttpClient             httpClient          = null;
            HttpContent            httpContent         = null;
            HttpResponseMessage    httpResponseMessage = null;
            String endpointUrl = null;

            Policy.Handle <ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
            {
                using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
                {
                    // Use the JSON formatter to create the content of the request body.
                    httpContent = new StringContent(JsonConvert.SerializeObject(typeElementRequest));
                    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    // Construct the URL for the save
                    endpointUrl = manywhoBaseUrl + MANYWHO_DRAW_URI_PART_TYPE_ELEMENT;

                    // Send the type element data to save over to the service
                    httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;

                    // Check the status of the response and respond appropriately
                    if (httpResponseMessage.IsSuccessStatusCode)
                    {
                        // Get the type element response back from the save
                        typeElementResponse = JsonConvert.DeserializeObject <TypeElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
                    }
                    else
                    {
                        throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
                    }
                }
            });

            return(typeElementResponse);
        }
Exemple #4
0
        public static string SerializeObjectData(ObjectAPI objectAPI, TypeElementResponseAPI typeElementResponse)
        {
            string xml        = null;
            string internalId = null;
            string externalId = null;

            if (objectAPI.internalId != null &&
                objectAPI.internalId.Trim().Length > 0)
            {
                internalId = objectAPI.internalId;
            }
            else
            {
                internalId = Fuid.NewGuid().ToString();
            }

            if (objectAPI.externalId != null &&
                objectAPI.externalId.Trim().Length > 0)
            {
                externalId = objectAPI.externalId;
            }
            else
            {
                externalId = Fuid.NewGuid().ToString();
            }

            xml  = "";
            xml += "<complextype internalid=\"" + internalId + "\" externalid=\"" + externalId + "\" typeelementid=\"" + typeElementResponse.id + "\">";

            if (objectAPI.properties != null &&
                objectAPI.properties.Count > 0)
            {
                foreach (PropertyAPI propertyAPI in objectAPI.properties)
                {
                    bool   typeElementEntryFound = false;
                    string typeElementEntryId    = null;
                    string contentType           = null;

                    if (typeElementResponse.properties != null &&
                        typeElementResponse.properties.Count > 0)
                    {
                        foreach (TypeElementPropertyAPI typeElementEntryAPI in typeElementResponse.properties)
                        {
                            if (typeElementEntryAPI.developerName.Equals(propertyAPI.developerName, StringComparison.OrdinalIgnoreCase))
                            {
                                typeElementEntryId = typeElementEntryAPI.id;
                                contentType        = typeElementEntryAPI.contentType;

                                typeElementEntryFound = true;
                                break;
                            }
                        }
                    }

                    Validation.Instance.IsTrue(typeElementEntryFound, "TypeElementEntry", "Type element entry could not be found.");

                    xml += "<complextypeentry typeelemententryid=\"" + typeElementEntryId + "\" contenttype=\"" + contentType + "\">";

                    if (contentType.Equals(ManyWhoConstants.CONTENT_TYPE_OBJECT, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new ArgumentException("contentType", "Object properties not supported yet.");
                    }

                    if (contentType.Equals(ManyWhoConstants.CONTENT_TYPE_LIST, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new ArgumentException("contentType", "List properties not supported yet.");
                    }

                    // Wrap primitive values in cdata so we don't screw up the xml document with invalid markup
                    xml += "<![CDATA[" + propertyAPI.contentValue + "]]>";

                    xml += "</complextypeentry>";
                }
            }

            xml += "</complextype>";

            return(xml);
        }