Beispiel #1
0
        /// <summary>
        /// A utility method for quickly creating value elements.
        /// </summary>
        public static ValueElementResponseAPI CreateValueElement(String developerName, String contentType)
        {
            ValueElementResponseAPI valueElementRequest = null;

            valueElementRequest               = new ValueElementResponseAPI();
            valueElementRequest.access        = ManyWhoConstants.ACCESS_INPUT_OUTPUT;
            valueElementRequest.contentType   = contentType;
            valueElementRequest.developerName = developerName;
            valueElementRequest.elementType   = ManyWhoConstants.SHARED_ELEMENT_TYPE_IMPLEMENTATION_VARIABLE;
            valueElementRequest.updateByName  = true;

            return(valueElementRequest);
        }
Beispiel #2
0
        /// <summary>
        /// This method allows you to save value elements back to the service.
        /// </summary>
        public ValueElementResponseAPI SaveValueElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, ValueElementRequestAPI valueElementRequest)
        {
            ValueElementResponseAPI valueElementResponse = 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(valueElementRequest));
                    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

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

                    // Send the value 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 value element response back from the save
                        valueElementResponse = JsonConvert.DeserializeObject <ValueElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
                    }
                    else
                    {
                        throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
                    }
                }
            });

            return(valueElementResponse);
        }
Beispiel #3
0
        public static MapElementRequestAPI CreateInputElement(String developerName, String pageElementId, String groupElementId, String serviceElementId, ValueElementResponseAPI notificationValueElementResponse, Int32 x, Int32 y)
        {
            MapElementRequestAPI mapElementRequest = null;
            MessageActionAPI     messageAction     = null;
            MessageInputAPI      messageInput      = null;

            // Create the map element request for the input
            mapElementRequest = new MapElementRequestAPI();
            mapElementRequest.developerName  = developerName;
            mapElementRequest.elementType    = ManyWhoConstants.MAP_ELEMENT_TYPE_IMPLEMENTATION_INPUT;
            mapElementRequest.groupElementId = groupElementId;
            mapElementRequest.pageElementId  = pageElementId;
            mapElementRequest.x                  = x;
            mapElementRequest.y                  = y;
            mapElementRequest.updateByName       = true;
            mapElementRequest.postUpdateToStream = true;

            // Only add the notification if we have the service element id
            if (serviceElementId != null &&
                serviceElementId.Trim().Length > 0)
            {
                mapElementRequest.messageActions = new List <MessageActionAPI>();

                // Create the notification message action
                messageAction = new MessageActionAPI();
                messageAction.developerName    = "Notify";
                messageAction.uriPart          = "notify";
                messageAction.serviceElementId = serviceElementId;
                messageAction.inputs           = new List <MessageInputAPI>();

                // Create the post input
                messageInput = new MessageInputAPI();
                messageInput.developerName             = "Post";
                messageInput.valueElementToReferenceId = new ValueElementIdAPI(notificationValueElementResponse.id, null, null);

                // Add the input to the action
                messageAction.inputs.Add(messageInput);

                // Add the action to the request
                mapElementRequest.messageActions.Add(messageAction);
            }

            return(mapElementRequest);
        }