Exemple #1
0
        /// <summary>
        /// Async: Get a new, randomly generated UUID from the CouchDB itself for use in new documents.
        /// </summary>
        /// <returns></returns>
        private async Task <string> getNewUUID()
        {
            string url           = _databaseurl + "_uuids";
            string retrievedJSON = await HTTPRequests.getRequestAsync(url);

            Dictionary <string, string[]> json;
            string newUUID = "";

            try
            {
                json    = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(retrievedJSON);
                newUUID = json["uuids"][0];
            }
            catch
            { return(""); }

            return(newUUID);
        }
Exemple #2
0
        /// <summary>
        /// Upload a new document to Couch.
        /// </summary>
        /// <param name="json">The JSON to upload as a new document</param>
        /// <param name="id">The ID of the new document</param>
        public async void uploadDocument(string json, string id = "")
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                _status = false; return;
            }

            if (id == "")
            {
                id = await getNewUUID();
            }

            string url = _databaseurl + _databasename + "/" + id;

            try
            {
                string result = await HTTPRequests.putRequestAsync(url, json);

                Dictionary <string, object> resultJSON = JsonConvert.DeserializeObject <Dictionary <string, object> >(result);
                _status = (bool)resultJSON["ok"];
            }
            catch { _status = false; }
        }