protected MultipartFormDataContent BuildPostPayload(KapiRequest request, SearchRequest searchRequest) // This method builds the entire request as a form
        {
            MultipartFormDataContent retVal = new MultipartFormDataContent();

            // Part #1 - Add binary image file if using a local image
            if (searchRequest.LocalTransformedQueryImageUri != null)
            {
                string path = searchRequest.LocalTransformedQueryImageUri.LocalPath;

                FileStream    fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                StreamContent sc = new StreamContent(fs);
                retVal.Add(
                    sc,             // binay image path
                    "image",        // name = image
                    "image"         // filename = image
                    );
            }

            // Part #2 - Add KnowledgeRequest JSON object
            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(request);

            retVal.Add(new StringContent(requestJson), "knowledgeRequest");

            return(retVal);
        }
        protected KapiResponse AddJson(KapiRequest kapiRequest, KapiResponse kapiRespose) // This method converts the response into a JSON object
        {
            var root = new JObject();

            root.Add("object",
                     // .NET object --> JSON string --> JObject graph (so that it can be rendered)
                     Newtonsoft.Json.Linq.JObject.Parse(
                         Newtonsoft.Json.JsonConvert.SerializeObject(kapiRequest)
                         ));
            kapiRespose.KapiRequestJson = root;
            return(kapiRespose);
        }
        protected KapiRequest BuildKapiRequest(SearchRequest searchRequest) // This method fills a KapiRequest from a passed SearchRequest
        {
            KapiRequest kapiRequestObject = new KapiRequest();

            if (searchRequest.ScaledBB.HasValue) // Crops the image if a bounding box was placed on it
            {
                kapiRequestObject.imageInfo.cropArea.top    = searchRequest.ScaledBB.Value.ct;
                kapiRequestObject.imageInfo.cropArea.left   = searchRequest.ScaledBB.Value.cl;
                kapiRequestObject.imageInfo.cropArea.bottom = searchRequest.ScaledBB.Value.cb;
                kapiRequestObject.imageInfo.cropArea.right  = searchRequest.ScaledBB.Value.cr;
            }

            if (string.IsNullOrEmpty(this.subscriptionId) == false) // Checks if the subscription ID exists
            {
                kapiRequestObject.knowledgeRequest = new KapiRequest.KnowledgeRequest()
                {
                    subscriptionId = subscriptionId
                }
            }
            ;

            if (searchRequest.QueryImageUri != null) // Checks if the queryimage url exists
            {
                kapiRequestObject.imageInfo.url = searchRequest.QueryImageUri.ToString();
            }

            if (searchRequest.CustomProperties.ContainsKey("site")) // If we have specified a Filter Site url, add it to our request
            {
                kapiRequestObject.knowledgeRequest.filters = new KapiRequest.KnowledgeRequest.Filters()
                {
                    site = searchRequest.CustomProperties["site"]
                };
            }

            return(kapiRequestObject);
        }