Exemplo n.º 1
0
        public async Task <HttpResponseMessage> SubscribeCommand(string thinkp, string thinkpInstance, string token,
                                                                 SSAPCommandType type, string endpoint)
        {
            //data validation
            if (String.IsNullOrWhiteSpace(thinkp) || String.IsNullOrWhiteSpace(thinkpInstance) || String.IsNullOrWhiteSpace(token))
            {
                return new HttpResponseMessage(HttpStatusCode.BadRequest)
                       {
                           Content = new StringContent(STR_BAD_REQUEST_KP)
                       }
            }
            ;

            if (String.IsNullOrWhiteSpace(token))
            {
                return new HttpResponseMessage(HttpStatusCode.BadRequest)
                       {
                           Content = new StringContent(STR_BAD_REQUEST_TOKEN)
                       }
            }
            ;

            using (var client = new HttpClient())
            {
                //client config
                client.BaseAddress = new Uri(_serviceBaseUrl);

                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(STR_APPLICATION_HEADER));

                //Config URI
                var queryParams = HttpUtility.ParseQueryString(string.Empty);
                if (!String.IsNullOrWhiteSpace(thinkp))
                {
                    queryParams.Add("$thinkp", thinkp);
                }
                if (!String.IsNullOrWhiteSpace(thinkpInstance))
                {
                    queryParams.Add("$kp", thinkpInstance);
                }
                if (!String.IsNullOrWhiteSpace(token))
                {
                    queryParams.Add("$token", token);
                }
                if (!String.IsNullOrWhiteSpace(endpoint))
                {
                    queryParams.Add("$endpoint", endpoint);
                }

                queryParams.Add("$type", type.ToString());

                UriBuilder builder = new UriBuilder(String.Format("{0}{1}/subscribe_command", _serviceBaseUrl, STR_PATH));
                builder.Query = queryParams.ToString();

                return(await client.GetAsync(builder.ToString()));
            }
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> Command(string sessionKey, string thinkp, string thinkpInstance,
                                                        SSAPCommandType type, Dictionary <string, string> args)
        {
            using (var client = new HttpClient())
            {
                //client config
                client.BaseAddress = new Uri(_serviceBaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(STR_APPLICATION_HEADER));

                //Config URI
                var queryParams = HttpUtility.ParseQueryString(string.Empty);
                if (!String.IsNullOrWhiteSpace(sessionKey))
                {
                    queryParams.Add("$sessionKey", sessionKey);
                }
                if (!String.IsNullOrWhiteSpace(thinkp))
                {
                    queryParams.Add("$thinkp", thinkp);
                }
                if (!String.IsNullOrWhiteSpace(thinkpInstance))
                {
                    queryParams.Add("$kp", thinkpInstance);
                }

                queryParams.Add("$type", type.ToString());

                UriBuilder builder = new UriBuilder(String.Format("{0}{1}/command", _serviceBaseUrl, STR_PATH));
                builder.Query = queryParams.ToString();

                if (args == null)
                {
                    args = new Dictionary <string, string>();
                }

                return(await client.PostAsJsonAsync <Dictionary <string, string> >(builder.ToString(), args));
            }
        }