Beispiel #1
0
        /// <summary>
        /// Get a specified document from the database server
        /// </summary>
        /// <param name="log">The log that stores your document</param>
        /// <param name="file">The key of your document</param>
        /// <returns>A document</returns>
        public Document GetDocument(UuidObject log, UuidObject file)
        {
            string response = NetworkHandler.Get(this.NodeLocation.HttpAddress(), $"document/{log.Id}/{file.Id}");
            var    doc      = JsonConvert.DeserializeObject <Document>(response);

            return(doc);
        }
Beispiel #2
0
        /// <summary>
        /// Get all the keys on a specified log on this database server
        /// </summary>
        /// <param name="log">The log you want the keys from</param>
        /// <returns>A list of all keys that are currently available on the specified log on the database server</returns>
        public List <string> GetKeys(UuidObject log)
        {
            string response = NetworkHandler.Get(this.NodeLocation.HttpAddress(), $"meta/log/{log.Id}/documents");

            Console.WriteLine(response);
            List <string> keys = JsonConvert.DeserializeObject <List <string> >(response);

            return(keys);
        }
Beispiel #3
0
        /// <summary>
        /// Start a database transaction
        /// </summary>
        /// <param name="log">The log you want your transaction to target</param>
        /// <param name="command">The transaction function</param>
        public void Transaction(UuidObject log, Command command)
        {
            string resp = NetworkHandler.Send(this.NodeLocation.HttpAddress(), $"transaction/{command.ToString("g").ToLower()}/{log.Id}", "", "POST");

            if (command == Command.Begin)
            {
                CurrentTransaction = resp;
            }
            else
            {
                CurrentTransaction = "NONE";
            }
        }
Beispiel #4
0
        /// <summary>
        /// Send a document to the database server
        /// </summary>
        /// <param name="doc">The document you want to send</param>
        /// <param name="log">The log you want to send your document to</param>
        /// <param name="addedUuidDescription">The description that the automatically generated UuidObject in the Manager will get</param>
        /// <param name="method">Sending method</param>
        public void PostDocument(Document doc, UuidObject log, string addedUuidDescription, Method method = Method.Post)
        {
            string transaction = (CurrentTransaction == "NONE") ? "" : $"/transaction/{CurrentTransaction}";
            string json        = JsonConvert.SerializeObject(doc);
            string resp;

            if (method == Method.Post)
            {
                resp = NetworkHandler.Send(this.NodeLocation.HttpAddress(), $"document/{log.Id}{transaction}", json, "POST");
            }
            else
            {
                resp = NetworkHandler.Send(this.NodeLocation.HttpAddress(), $"document/{log.Id}{transaction}", json, "PUT");
            }
            UuidManager.Add(resp, addedUuidDescription, UuidObject.UuidType.Key);
        }
Beispiel #5
0
 /// <summary>
 /// Get all the keys on a specified log on this database server asynchronously
 /// </summary>
 /// <param name="log">The log you want the keys from</param>
 /// <returns>A list of all keys that are currently available on the specified log on the database server</returns>
 async public Task <List <string> > GetKeysAsync(UuidObject log)
 {
     return(await Task.Factory.StartNew <List <string> >(() => GetKeys(log)));
 }
Beispiel #6
0
 /// <summary>
 /// Send a document to the database server asynchronously
 /// </summary>
 /// <param name="doc">The document you want to send</param>
 /// <param name="log">The log you want to send your document to</param>
 /// <param name="addedUuidDescription">The description that the automatically generated UuidObject in the Manager will get</param>
 /// <param name="method">Sending method</param>
 async public Task PostDocumentAsync(Document doc, UuidObject log, string addedUuidDescription, Method method = Method.Post)
 {
     await Task.Factory.StartNew(() => PostDocument(doc, log, addedUuidDescription, method));
 }
Beispiel #7
0
 /// <summary>
 /// Delete a specified document from the database server asynchronously
 /// </summary>
 /// <param name="log">The log that stores your document</param>
 /// <param name="file">The key of your document</param>
 /// <returns>The server response</returns>
 async public Task <string> DeleteDocumentAsync(UuidObject log, UuidObject file)
 {
     return(await Task.Factory.StartNew <string>(() => DeleteDocument(log, file)));
 }
Beispiel #8
0
 /// <summary>
 /// Delete a specified document from the database server
 /// </summary>
 /// <param name="log">The log that stores your document</param>
 /// <param name="file">The key of your document</param>
 /// <returns>The server response</returns>
 public string DeleteDocument(UuidObject log, UuidObject file)
 {
     return(NetworkHandler.Delete(this.NodeLocation.HttpAddress(), $"document/{log.Id}/{file.Id}"));
 }
Beispiel #9
0
 /// <summary>
 /// Get a specified document from the database server asynchronously
 /// </summary>
 /// <param name="log">The log that stores your document</param>
 /// <param name="file">The key of your document</param>
 /// <returns>A document</returns>
 async public Task <Document> GetDocumentAsync(UuidObject log, UuidObject file)
 {
     return(await Task.Factory.StartNew <Document>(() => GetDocument(log, file)));
 }