Exemplo n.º 1
0
        public mmria.common.model.couchdb.document_put_response set_case(string case_json)
        {
            mmria.common.model.couchdb.document_put_response result = null;

            string  URL           = this.mmria_url + "/api/case";
            dynamic json_response = null;

            var curl = new cURL("GET", null, URL, null, null);

            var byteArray = System.Text.Encoding.ASCII.GetBytes(string.Format("{0}:{1}", this.user_name, this.password));

            curl.AddHeader("Basic", Convert.ToBase64String(byteArray));

            //curl.AddHeader ("AuthSession", this.auth_token);

            try
            {
                string json_result = curl.execute();
                json_response = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response> (json_result);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}", ex);
            }



            if (json_response.ok == true)
            {
                if (json_response.auth_session != null && !string.IsNullOrWhiteSpace(json_response.auth_session))
                {
                    this.auth_token = json_response.auth_session;
                }
            }
            else
            {
            }

            return(json_response);
        }
Exemplo n.º 2
0
        public dynamic get_all_cases(string p_database_url)
        {
            bool is_offline_mode = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["is_offline_mode"]);

            if (is_offline_mode)
            {
                return(get_all_cases());
            }

            this.database_url = p_database_url;

            /*
             * var credential = new System.Net.NetworkCredential
             * {
             *      UserName = "******",
             *      Password = "******"
             * };
             *
             * var httpClientHandler = new System.Net.Http.HttpClientHandler
             * {
             *      Credentials = credential,
             *      PreAuthenticate = false,
             *      Proxy = new WebProxy("http://127.0.0.1:8888"),
             * UseProxy = true,
             * };
             *
             * HttpClient client = new HttpClient(httpClientHandler);
             */

            System.Dynamic.ExpandoObject result = null;
            string URL           = this.database_url + "/mmrds/_all_docs";
            string urlParameters = "?include_docs=true";



            var curl = new cURL("GET", null, URL, null, null);

            var byteArray = System.Text.Encoding.ASCII.GetBytes(string.Format("{0}:{1}", this.user_name, this.password));

            curl.AddHeader("Basic", Convert.ToBase64String(byteArray));
            //curl.AddHeader ("AuthSession", this.auth_token);

            try
            {
                string json_result = curl.execute();
                result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (json_result);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}", ex);
            }

            /*
             *
             * HttpClient client = new HttpClient();
             * client.BaseAddress = new Uri(URL);
             *
             * var byteArray = System.Text.Encoding.ASCII.GetBytes(string.Format("{0}:{1}", this.user_name, this.password));
             * client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
             *
             *
             * // Add an Accept header for JSON format.
             * client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             *
             * // List data response.
             * HttpResponseMessage response = client.GetAsync(urlParameters).Result;  // Blocking call!
             * if (response.IsSuccessStatusCode)
             * {
             *      // Parse the response body. Blocking!
             *      result = response.Content.ReadAsAsync<System.Dynamic.ExpandoObject>().Result;
             * }
             * else
             * {
             *      Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
             * }*/

            return(result);
        }