public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post
        (
            [FromBody] mmria.common.model.couchdb.jurisdiction_tree jurisdiction_tree
        )
        {
            string jurisdiction_json;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                jurisdiction_json          = Newtonsoft.Json.JsonConvert.SerializeObject(jurisdiction_tree, settings);

                string jurisdiction_tree_url = Program.config_couchdb_url + "/jurisdiction/jurisdiction_tree";

                cURL document_curl = new cURL("PUT", null, jurisdiction_tree_url, jurisdiction_json, Program.config_timer_user_name, Program.config_timer_password);

                if (!string.IsNullOrWhiteSpace(this.Request.Cookies["AuthSession"]))
                {
                    string auth_session_value = this.Request.Cookies["AuthSession"];
                    document_curl.AddHeader("Cookie", "AuthSession=" + auth_session_value);
                    document_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_value);
                }

                try
                {
                    string responseFromServer = await document_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);
                }
                catch (Exception ex)
                {
                    Log.Information($"jurisdiction_treeController:{ex}");
                }

                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
示例#2
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> PutCheckCode
        (

        )
        {
            string check_code_json;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                System.IO.Stream dataStream0 = this.Request.Body;
                // Open the stream using a StreamReader for easy access.
                //dataStream0.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader reader0 = new System.IO.StreamReader(dataStream0);
                // Read the content.
                check_code_json = await reader0.ReadToEndAsync();

                string metadata_url = Program.config_couchdb_url + "/metadata/2016-06-12T13:49:24.759Z/mmria-check-code.js";

                var metadata_curl = new cURL("PUT", null, metadata_url, check_code_json, Program.config_timer_user_name, Program.config_timer_password, "text/*");

                if (!string.IsNullOrWhiteSpace(this.Request.Headers["If-Match"]))
                {
                    string If_Match = this.Request.Headers["If-Match"];
                    metadata_curl.AddHeader("If-Match", If_Match);
                }

                string responseFromServer = await metadata_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);

                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
示例#3
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post()
        {
            //bool valid_login = false;
            //mmria.common.data.api.Set_Queue_Request queue_request = null;
            export_queue_item queue_item         = null;
            string            auth_session_token = null;

            string object_string = null;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                System.IO.Stream dataStream0 = await this.Request.Content.ReadAsStreamAsync();

                // Open the stream using a StreamReader for easy access.
                //dataStream0.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader reader0 = new System.IO.StreamReader(dataStream0);
                // Read the content.
                object_string = reader0.ReadToEnd();

                queue_item = Newtonsoft.Json.JsonConvert.DeserializeObject <export_queue_item>(object_string);
            }
            catch (Exception ex)
            {
                //Console.WriteLine (ex);
            }

            //if(queue_request.case_list.Length == 1)
            try
            {
                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                object_string = Newtonsoft.Json.JsonConvert.SerializeObject(queue_item, settings);

                string export_queue_request_url = Program.config_couchdb_url + "/export_queue/" + queue_item._id;

                var export_queue_curl = new cURL("PUT", null, export_queue_request_url, object_string, null, null);

                if (this.Request.Headers.Contains("Cookie") && this.Request.Headers.GetValues("Cookie").Count() > 0)
                {
                    string[] cookie_set = this.Request.Headers.GetValues("Cookie").First().Split(';');
                    for (int i = 0; i < cookie_set.Length; i++)
                    {
                        string[] auth_session_token_item = cookie_set[i].Split('=');
                        if (auth_session_token_item[0].Trim() == "AuthSession")
                        {
                            auth_session_token = auth_session_token_item[1];
                            export_queue_curl.AddHeader("Cookie", "AuthSession=" + auth_session_token);
                            export_queue_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_token);


                            break;
                        }
                    }
                }


                string responseFromServer = await export_queue_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);


                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                //Console.Write("auth_session_token: {0}", auth_session_token);
                //Console.WriteLine (ex);
            }

            return(result);
        }
示例#4
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post()
        {
            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            //if(!string.IsNullOrWhiteSpace(json))
            try
            {
                System.IO.Stream dataStream0 = this.Request.Body;
                // Open the stream using a StreamReader for easy access.
                //dataStream0.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader reader0 = new System.IO.StreamReader(dataStream0);
                // Read the content.
                string validator_js_text = await reader0.ReadToEndAsync();

                string metadata_url = Program.config_couchdb_url + "/metadata/2016-06-12T13:49:24.759Z/validator.js";

                var validator_curl = new cURL("PUT", null, metadata_url, validator_js_text, Program.config_timer_user_name, Program.config_timer_password, "text/*");

/*
 *                              System.Net.WebRequest request = System.Net.WebRequest.Create(new System.Uri(metadata_url));
 *                              request.Method = "PUT";
 *                              request.ContentType = "text/*";
 *                              request.ContentLength = validator_js_text.Length;
 *                              request.PreAuthenticate = false;
 *
 *                              if (!string.IsNullOrWhiteSpace(this.Request.Cookies["AuthSession"]))
 *                              {
 *                                      string auth_session_value = this.Request.Cookies["AuthSession"];
 *                                      request.Headers.Add("Cookie", "AuthSession=" + auth_session_value);
 *                                      request.Headers.Add("X-CouchDB-WWW-Authenticate", auth_session_value);
 *                                      request.Headers.Add("X-CouchDB-WWW-Authenticate", auth_session_value);
 *                              }
 */
                if (!string.IsNullOrWhiteSpace(this.Request.Headers["If-Match"]))
                {
                    string If_Match = this.Request.Headers["If-Match"];
                    validator_curl.AddHeader("If-Match", If_Match);
                }

                try
                {
                    /*
                     * streamWriter.Write(validator_js_text);
                     * streamWriter.Flush();
                     * streamWriter.Close();
                     *
                     * System.Net.WebResponse response = (System.Net.HttpWebResponse) await request.GetResponseAsync();
                     * System.IO.Stream dataStream = response.GetResponseStream ();
                     * System.IO.StreamReader reader = new System.IO.StreamReader (dataStream);
                     *
                     *                                      if(response.Headers["Set-Cookie"] != null)
                     * {
                     *      this.Response.Headers.Add("Set-Cookie", response.Headers["Set-Cookie"]);
                     * }
                     */
                    string responseFromServer = await validator_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);



                    //System.Threading.Tasks.Task.Run( new Action(()=> { var f = new GenerateSwaggerFile(); System.IO.File.WriteAllText(Program.config_file_root_folder + "/api-docs/api.json", f.generate(metadata)); }));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }



                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
示例#5
0
        /*
         * DELETE /recipes/FishStew?rev=1-9c65296036141e575d32ba9c034dd3ee HTTP/1.1
         * Accept: application/json
         * Host: localhost:5984
         * or
         *
         * DELETE /recipes/FishStew HTTP/1.1
         * Accept: application/json
         * If-Match: 1-9c65296036141e575d32ba9c034dd3ee
         * Host: localhost:5984
         *
         *
         * HTTP/1.1 200 OK
         * Cache-Control: must-revalidate
         * Content-Length: 71
         * Content-Type: application/json
         * Date: Wed, 14 Aug 2013 12:23:13 GMT
         * ETag: "2-056f5f44046ecafc08a2bc2b9c229e20"
         * Server: CouchDB (Erlang/OTP)
         *
         * {
         * "id": "FishStew",
         * "ok": true,
         * "rev": "2-056f5f44046ecafc08a2bc2b9c229e20"
         * }
         *
         *
         */
        public async System.Threading.Tasks.Task <System.Dynamic.ExpandoObject> Delete(string case_id = null, string rev = null)
        {
            try
            {
                string request_string = null;

                if (!string.IsNullOrWhiteSpace(case_id) && !string.IsNullOrWhiteSpace(rev))
                {
                    request_string = Program.config_couchdb_url + "/mmrds/" + case_id + "?rev=" + rev;
                }
                else
                {
                    return(null);
                }

                var delete_report_curl  = new cURL("DELETE", null, request_string, null);
                var check_document_curl = new cURL("GET", null, Program.config_couchdb_url + "/mmrds/" + case_id, null, null, null);

                if (this.Request.Headers.Contains("Cookie") && this.Request.Headers.GetValues("Cookie").Count() > 0)
                {
                    string[] cookie_set = this.Request.Headers.GetValues("Cookie").First().Split(';');
                    for (int i = 0; i < cookie_set.Length; i++)
                    {
                        string[] auth_session_token = cookie_set[i].Split('=');
                        if (auth_session_token[0].Trim() == "AuthSession")
                        {
                            delete_report_curl.AddHeader("Cookie", "AuthSession=" + auth_session_token[1]);
                            delete_report_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_token[1]);
                            check_document_curl.AddHeader("Cookie", "AuthSession=" + auth_session_token [1]);
                            check_document_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_token [1]);
                            break;
                        }
                    }
                }


                // check if doc exists

                try
                {
                    string document_json = null;
                    document_json = await check_document_curl.executeAsync();

                    var check_docuement_curl_result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (document_json);
                    IDictionary <string, object> result_dictionary = check_docuement_curl_result as IDictionary <string, object>;
                    if (result_dictionary.ContainsKey("_rev"))
                    {
                        request_string = Program.config_couchdb_url + "/mmrds/" + case_id + "?rev=" + result_dictionary ["_rev"];
                        //System.Console.WriteLine ("json\n{0}", object_string);
                    }
                }
                catch (Exception ex)
                {
                    // do nothing for now document doesn't exsist.
                    System.Console.Write($" caseController Delete 1 Error {ex}");
                }



                string responseFromServer = await delete_report_curl.executeAsync();

                var result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (responseFromServer);

                return(result);
            }
            catch (Exception ex)
            {
                System.Console.Write($" caseController Delete 2 Error {ex}");
            }

            return(null);
        }
示例#6
0
        public async System.Threading.Tasks.Task <HttpResponseMessage> Get(string id)
        {
            HttpResponseMessage result = new HttpResponseMessage(System.Net.HttpStatusCode.NoContent);

            try
            {
                string request_string = Program.config_couchdb_url + "/_session";
                cURL   session_curl   = new cURL("GET", null, request_string, null);

                if (this.Request.Headers.Contains("Cookie") && this.Request.Headers.GetValues("Cookie").Count() > 0)
                {
                    string[] cookie_set = this.Request.Headers.GetValues("Cookie").First().Split(';');
                    for (int i = 0; i < cookie_set.Length; i++)
                    {
                        string[] auth_session_token = cookie_set [i].Split('=');
                        if (auth_session_token [0].Trim() == "AuthSession")
                        {
                            session_curl.AddHeader("Cookie", "AuthSession=" + auth_session_token [1]);
                            session_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_token [1]);
                            break;
                        }
                    }
                }


                string session_curl_resonse = await session_curl.executeAsync();

                mmria.common.model.couchdb.session_response json_result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.session_response> (session_curl_resonse);


                if (json_result.userCTX.roles.Contains("abstractor", StringComparer.OrdinalIgnoreCase))
                {
                    var    get_item_curl      = new cURL("GET", null, Program.config_couchdb_url + "/export_queue/" + id, null, Program.config_timer_user_name, Program.config_timer_password);
                    string responseFromServer = await get_item_curl.executeAsync();

                    export_queue_item export_queue_item = Newtonsoft.Json.JsonConvert.DeserializeObject <export_queue_item> (responseFromServer);



                    var path = System.IO.Path.Combine(System.Configuration.ConfigurationManager.AppSettings ["export_directory"], export_queue_item.file_name);
                    result = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
                    var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                    result.Content = new StreamContent(stream);
                    result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

                    export_queue_item.status = "Downloaded";

                    Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                    settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                    string object_string = Newtonsoft.Json.JsonConvert.SerializeObject(export_queue_item, settings);
                    var    set_item_curl = new cURL("PUT", null, Program.config_couchdb_url + "/export_queue/" + export_queue_item._id, object_string, Program.config_timer_user_name, Program.config_timer_password);
                    responseFromServer = await set_item_curl.executeAsync();
                }
            }
            catch (Exception ex)
            {
                System.Console.Write($"ZipController Error:\n {ex}");
            }

            return(result);
        }