private static TypeElementPropertyAPI GetTypeElementPropertyAPIFromDictionary(Dictionary <String, TypeElementRequestAPI> typeElementRequestAPIs, PropertyInfo propertyInfo) { TypeElementRequestAPI typeElementRequestAPI = null; TypeElementBindingAPI typeElementBindingAPI = null; TypeElementPropertyAPI typeElementPropertyAPI = null; String name = "KeyPair"; typeElementPropertyAPI = new TypeElementPropertyAPI(); typeElementPropertyAPI.developerName = GetCleanPropertyName(propertyInfo.Name); typeElementPropertyAPI.contentType = ManyWhoConstants.CONTENT_TYPE_LIST; typeElementPropertyAPI.typeElementDeveloperName = name; if (typeElementRequestAPIs.ContainsKey(name) == false) { // Now create the type for the key pair typeElementRequestAPI = new TypeElementRequestAPI(); typeElementRequestAPI.developerName = name; typeElementRequestAPI.developerSummary = "Type for " + name + " Draw API objects."; typeElementRequestAPI.elementType = ManyWhoConstants.TYPE_ELEMENT_TYPE_IMPLEMENTATION_TYPE; typeElementRequestAPI.bindings = new List <TypeElementBindingAPI>(); typeElementRequestAPI.properties = new List <TypeElementPropertyAPI>(); typeElementRequestAPI.properties.Add(new TypeElementPropertyAPI() { developerName = "Key", contentType = ManyWhoConstants.CONTENT_TYPE_STRING, }); typeElementRequestAPI.properties.Add(new TypeElementPropertyAPI() { developerName = "Value", contentType = ManyWhoConstants.CONTENT_TYPE_STRING, }); typeElementBindingAPI = new TypeElementBindingAPI(); typeElementBindingAPI.databaseTableName = name; typeElementBindingAPI.developerName = name; typeElementBindingAPI.developerSummary = "Binding for " + name + " Draw API objects."; typeElementBindingAPI.propertyBindings = new List <TypeElementPropertyBindingAPI>(); typeElementBindingAPI.propertyBindings.Add(new TypeElementPropertyBindingAPI() { databaseFieldName = "Key", typeElementPropertyDeveloperName = "Key", databaseContentType = ManyWhoConstants.CONTENT_TYPE_STRING }); typeElementBindingAPI.propertyBindings.Add(new TypeElementPropertyBindingAPI() { databaseFieldName = "Value", typeElementPropertyDeveloperName = "Value", databaseContentType = ManyWhoConstants.CONTENT_TYPE_STRING }); // Add the binding to the type request typeElementRequestAPI.bindings.Add(typeElementBindingAPI); // Add this type element request typeElementRequestAPIs[typeElementRequestAPI.developerName] = typeElementRequestAPI; } return(typeElementPropertyAPI); }
public static TypeElementRequestAPI CreateDropDownType(String developerName) { TypeElementRequestAPI typeElementRequest = null; typeElementRequest = new TypeElementRequestAPI(); typeElementRequest.developerName = developerName; typeElementRequest.elementType = ManyWhoConstants.TYPE_ELEMENT_TYPE_IMPLEMENTATION_TYPE; typeElementRequest.updateByName = true; typeElementRequest.properties = new List <TypeElementPropertyAPI>(); typeElementRequest.properties.Add(new TypeElementPropertyAPI() { contentType = ManyWhoConstants.CONTENT_TYPE_STRING, developerName = "Label" }); typeElementRequest.properties.Add(new TypeElementPropertyAPI() { contentType = ManyWhoConstants.CONTENT_TYPE_STRING, developerName = "Value" }); return(typeElementRequest); }
private static String Convert(Type type, Dictionary <String, TypeElementRequestAPI> typeElementRequestAPIs, IEnumerable <TypeElementPropertyAPI> properties) { String name = GetCleanObjectName(type.Name); // If we've converted this type already, we just return the type name if (typeElementRequestAPIs.ContainsKey(name) == true) { return(name); } TypeElementRequestAPI typeElementRequestAPI = new TypeElementRequestAPI(); typeElementRequestAPI.developerName = name; typeElementRequestAPI.developerSummary = "Type for " + name + " Draw API objects."; typeElementRequestAPI.elementType = ManyWhoConstants.TYPE_ELEMENT_TYPE_IMPLEMENTATION_TYPE; typeElementRequestAPI.bindings = new List <TypeElementBindingAPI>(); typeElementRequestAPI.properties = new List <TypeElementPropertyAPI>(); TypeElementBindingAPI typeElementBindingAPI = new TypeElementBindingAPI(); typeElementBindingAPI.databaseTableName = name; typeElementBindingAPI.developerName = name; typeElementBindingAPI.developerSummary = "Binding for " + name + " Draw API objects."; typeElementBindingAPI.propertyBindings = new List <TypeElementPropertyBindingAPI>(); // Add the binding to the type request typeElementRequestAPI.bindings.Add(typeElementBindingAPI); // Set the type element request into our dictionary of types - so we don't accidentally repeat a developer name but also // so we don't get stuck in an infinite loop for self-referencing situations typeElementRequestAPIs[typeElementRequestAPI.developerName] = typeElementRequestAPI; // Get the properties for the root type foreach (PropertyInfo propertyInfo in type.GetRuntimeProperties()) { TypeElementPropertyAPI typeElementPropertyAPI = Convert(typeElementRequestAPIs, propertyInfo); if (typeElementPropertyAPI != null) { TypeElementPropertyBindingAPI typeElementPropertyBindingAPI = new TypeElementPropertyBindingAPI(); typeElementPropertyBindingAPI.databaseContentType = typeElementPropertyAPI.contentType; typeElementPropertyBindingAPI.databaseFieldName = typeElementPropertyAPI.developerName; typeElementPropertyBindingAPI.typeElementPropertyDeveloperName = typeElementPropertyAPI.developerName; // Add the property and binding typeElementBindingAPI.propertyBindings.Add(typeElementPropertyBindingAPI); typeElementRequestAPI.properties.Add(typeElementPropertyAPI); } } if (properties != null) { foreach (TypeElementPropertyAPI property in properties) { TypeElementPropertyBindingAPI typeElementPropertyBindingAPI = new TypeElementPropertyBindingAPI(); typeElementPropertyBindingAPI.databaseContentType = property.contentType; typeElementPropertyBindingAPI.databaseFieldName = property.developerName; typeElementPropertyBindingAPI.typeElementPropertyDeveloperName = property.developerName; // Add the property and binding typeElementBindingAPI.propertyBindings.Add(typeElementPropertyBindingAPI); typeElementRequestAPI.properties.Add(property); } } return(typeElementRequestAPI.developerName); }
public List<TypeElementRequestAPI> GetTypeElements(String authenticationUrl, String username, String password, String ebikkoSessionID, String jSessionID) { List<TypeElementRequestAPI> typeElements = new List<TypeElementRequestAPI>(); IDocordoService docordoService = DocordoService.GetInstance(); Trace.TraceInformation("// Login to the service"); DocordoLoginResponse docordoLoginResponse = docordoService.Login(authenticationUrl, username, password); System.Diagnostics.Trace.TraceInformation("// Get all the objects available in the org"); DocordoNodeTypeListResponse describeGlobalResult = docordoService.LoadNodeTypes(authenticationUrl, docordoLoginResponse.EbikkoSessionId, docordoLoginResponse.CookieJSESSIONID); Trace.TraceInformation("// Get the names of all of the objects so we can then do a full object query"); foreach (DocordoNodeTypeDetail docordoNodeTypeStub in describeGlobalResult.Results) { Trace.TraceInformation("//DocordoNodeTypeDetail docordoNodeTypeStub in describeGlobalResult.Results"); DocordoNodeTypeDetailResponse docordoNodeTypeDetailResponse = docordoService.LoadNodeTypeDetail(authenticationUrl, docordoLoginResponse.EbikkoSessionId, docordoLoginResponse.CookieJSESSIONID, docordoNodeTypeStub.NodeTypeId); if (docordoNodeTypeDetailResponse.Results != null) { foreach (DocordoNodeTypeDetail docordoNodeTypeDetail in docordoNodeTypeDetailResponse.Results) { Trace.TraceInformation("DocordoNodeTypeDetail docordoNodeTypeDetail in docordoNodeTypeDetailResponse.Results"); Trace.TraceInformation(JsonConvert.SerializeObject(docordoNodeTypeDetail)); TypeElementRequestAPI typeElement = new TypeElementRequestAPI(); typeElement.developerName = docordoNodeTypeDetail.Name; typeElement.developerSummary = docordoNodeTypeDetail.Name; typeElement.bindings = new List<TypeElementBindingAPI>(); TypeElementBindingAPI typeElementBinding = new TypeElementBindingAPI(); typeElementBinding.databaseTableName = docordoNodeTypeDetail.Name; typeElementBinding.developerName = authenticationUrl + " " + docordoNodeTypeDetail.Name + " Binding"; typeElementBinding.developerSummary = "The binding to save " + docordoNodeTypeDetail.Name + " objects into " + authenticationUrl; typeElementBinding.propertyBindings = new List<TypeElementPropertyBindingAPI>(); typeElement.bindings.Add(typeElementBinding); typeElement.properties = new List<TypeElementPropertyAPI>(); if (docordoNodeTypeDetail.Properties != null) { foreach (DocordoProperty docordoProperty in docordoNodeTypeDetail.Properties) { Trace.TraceInformation("DocordoProperty docordoProperty in docordoNodeTypeDetail.Properties"); Trace.TraceInformation(JsonConvert.SerializeObject(docordoProperty)); TypeElementPropertyBindingAPI typeElementFieldBinding = new TypeElementPropertyBindingAPI(); typeElementFieldBinding.databaseFieldName = docordoProperty.Name; typeElementFieldBinding.databaseContentType = docordoProperty.Type.ToString(); typeElementFieldBinding.typeElementPropertyDeveloperName = docordoProperty.Name; typeElementBinding.propertyBindings.Add(typeElementFieldBinding); TypeElementPropertyAPI typeElementEntry = new TypeElementPropertyAPI(); typeElementEntry.contentType = this.TranslateToManyWhoContentType(docordoProperty.Type); typeElementEntry.developerName = docordoProperty.Name; typeElementEntry.typeElementDeveloperName = docordoProperty.Name; typeElement.properties.Add(typeElementEntry); } } else { Trace.TraceInformation("docordoNodeTypeDetail.Properties == null"); Trace.TraceInformation(JsonConvert.SerializeObject(docordoNodeTypeDetail)); } DocordoAttributesResponse docordoAttributesResponse = docordoService.LoadAttributesByNodeType(authenticationUrl, docordoLoginResponse.EbikkoSessionId, docordoLoginResponse.CookieJSESSIONID, docordoNodeTypeDetail.NodeTypeId); if (docordoAttributesResponse.Results != null) { foreach (DocordoAttribute docordoAttribute in docordoAttributesResponse.Results) { Trace.TraceInformation("DocordoAttribute docordoAttribute in docordoAttributesResponse.Results"); Trace.TraceInformation(JsonConvert.SerializeObject(docordoAttribute)); TypeElementPropertyBindingAPI typeElementFieldBinding = new TypeElementPropertyBindingAPI(); typeElementFieldBinding.databaseFieldName = docordoAttribute.Name; typeElementFieldBinding.databaseContentType = docordoAttribute.Type; typeElementFieldBinding.typeElementPropertyDeveloperName = docordoAttribute.Name; typeElementBinding.propertyBindings.Add(typeElementFieldBinding); TypeElementPropertyAPI typeElementEntry = new TypeElementPropertyAPI(); typeElementEntry.contentType = docordoAttribute.Type; typeElementEntry.developerName = docordoAttribute.Name; typeElementEntry.typeElementDeveloperName = docordoAttribute.Name; typeElement.properties.Add(typeElementEntry); } } else { Trace.TraceInformation("docordoAttributesResponse.Results == null"); Trace.TraceInformation(JsonConvert.SerializeObject(docordoAttributesResponse)); } typeElements.Add(typeElement); } } else { Trace.TraceInformation("docordoNodeTypeDetailResponse.Results == null"); Trace.TraceInformation(JsonConvert.SerializeObject(describeGlobalResult)); } } return typeElements; }
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); }