public async Task AddDocumentAsync(string key, Document document, BucketNamespace bucketNamespace = BucketNamespace.Document) { try { string @namespace = GetNamespaceAsString(bucketNamespace); var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/{key}"), Method = CommandMethod.Set, Resource = document }; var envelopeResult = await RunCommandAsync(command); EnsureCommandSuccess(envelopeResult); } catch (HttpRequestException e) { _logger.LogError(e, "\nException Caught!"); _logger.LogError(e, "Message :{0} ", e.Message); } }
public async Task <DocumentCollection> GetAllDocumentKeysAsync(BucketNamespace bucketNamespace = BucketNamespace.Document) { string @namespace = GetNamespaceAsString(bucketNamespace); try { var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/"), Method = CommandMethod.Get }; var envelopeResult = await RunCommandAsync(command); return(envelopeResult.Resource as DocumentCollection); } catch (HttpRequestException e) { _logger.LogError(e, "\nException Caught!"); _logger.LogError(e, "Message :{0} ", e.Message); return(null); } }
private static string GetNamespaceAsString(BucketNamespace bucketNamespace) { string @namespace; switch (bucketNamespace) { case BucketNamespace.Document: @namespace = "buckets"; break; case BucketNamespace.Resource: @namespace = "resources"; break; case BucketNamespace.Profile: @namespace = "profile"; break; default: @namespace = "buckets"; break; } return(@namespace); }
public async Task <DocumentCollection> GetAllDocumentKeysAsync(BucketNamespace bucketNamespace = BucketNamespace.Document) { string @namespace; switch (bucketNamespace) { case BucketNamespace.Document: @namespace = "buckets"; break; case BucketNamespace.Resource: @namespace = "resources"; break; case BucketNamespace.Profile: @namespace = "profile"; break; default: @namespace = "buckets"; break; } try { var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/"), Method = CommandMethod.Get }; var documentSerializer = new DocumentSerializer(); var envelopeSerializer = new JsonNetSerializer(); var commandString = envelopeSerializer.Serialize(command); var httpContent = new StringContent(commandString, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PostAsync("/commands", httpContent); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); var envelopeResult = (Command)envelopeSerializer.Deserialize(responseBody); return(envelopeResult.Resource as DocumentCollection); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); return(null); } }
public async Task <DocumentCollection> GetAllDocumentKeysAsync(BucketNamespace bucketNamespace = BucketNamespace.Document) { string @namespace; switch (bucketNamespace) { case BucketNamespace.Document: @namespace = "buckets"; break; case BucketNamespace.Resource: @namespace = "resources"; break; case BucketNamespace.Profile: @namespace = "profile"; break; default: @namespace = "buckets"; break; } try { var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/"), Method = CommandMethod.Get }; var envelopeResult = await RunCommandAsync(command); return(envelopeResult.Resource as DocumentCollection); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); return(null); } }
public async Task AddDocumentAsync(string key, Document document, BucketNamespace bucketNamespace = BucketNamespace.Document) { try { string @namespace; switch (bucketNamespace) { case BucketNamespace.Document: @namespace = "buckets"; break; case BucketNamespace.Resource: @namespace = "resources"; break; case BucketNamespace.Profile: @namespace = "profile"; break; default: @namespace = "buckets"; break; } var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/{key}"), Method = CommandMethod.Set, Resource = document }; var envelopeResult = await RunCommandAsync(command); EnsureCommandSuccess(envelopeResult); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); } }
public async Task <IEnumerable <KeyValuePair <string, Document> > > GetAllDocumentsAsync(DocumentCollection keysCollection, BucketNamespace bucketNamespace) { if (keysCollection.Total == 0) { return(null); } try { string @namespace; switch (bucketNamespace) { case BucketNamespace.Document: @namespace = "buckets"; break; case BucketNamespace.Resource: @namespace = "resources"; break; case BucketNamespace.Profile: @namespace = "profile"; break; default: @namespace = "buckets"; break; } var pairsCollection = new List <KeyValuePair <string, Document> >(); foreach (var key in keysCollection.Items) { var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/{key}"), Method = CommandMethod.Get }; var documentSerializer = new DocumentSerializer(); var envelopeSerializer = new JsonNetSerializer(); var commandString = envelopeSerializer.Serialize(command); var httpContent = new StringContent(commandString, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PostAsync("/commands", httpContent); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); var envelopeResult = (Command)envelopeSerializer.Deserialize(responseBody); var document = envelopeResult.Resource; pairsCollection.Add(new KeyValuePair <string, Document>(key.ToString(), document)); } return(pairsCollection); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); return(null); } }
public async Task <KeyValuePair <string, Document>?> GetDocumentAsync(string key, BucketNamespace bucketNamespace) { try { string @namespace = GetNamespaceAsString(bucketNamespace); var pairsCollection = new List <KeyValuePair <string, Document> >(); var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/{key}"), Method = CommandMethod.Get }; var envelopeResult = await RunCommandAsync(command); var document = envelopeResult.Resource; var value = new KeyValuePair <string, Document>(key.ToString(), document); return(value); } catch (HttpRequestException e) { _logger.LogError(e, "\nException Caught!"); _logger.LogError(e, "Message :{0} ", e.Message); return(null); } }
public async Task <IEnumerable <KeyValuePair <string, Document> > > GetAllDocumentsAsync(DocumentCollection keysCollection, BucketNamespace bucketNamespace) { if (keysCollection.Total == 0) { return(null); } try { string @namespace = GetNamespaceAsString(bucketNamespace); var pairsCollection = new List <KeyValuePair <string, Document> >(); foreach (var key in keysCollection.Items) { var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/{key}"), Method = CommandMethod.Get }; var envelopeResult = await RunCommandAsync(command); var document = envelopeResult.Resource; pairsCollection.Add(new KeyValuePair <string, Document>(key.ToString(), document)); } return(pairsCollection); } catch (HttpRequestException e) { _logger.LogError(e, "\nException Caught!"); _logger.LogError(e, "Message :{0} ", e.Message); return(null); } }
public async Task <IEnumerable <KeyValuePair <string, Document> > > GetAllDocumentsAsync(DocumentCollection keysCollection, BucketNamespace bucketNamespace) { if (keysCollection.Total == 0) { return(null); } try { string @namespace; switch (bucketNamespace) { case BucketNamespace.Document: @namespace = "buckets"; break; case BucketNamespace.Resource: @namespace = "resources"; break; case BucketNamespace.Profile: @namespace = "profile"; break; default: @namespace = "buckets"; break; } var pairsCollection = new List <KeyValuePair <string, Document> >(); foreach (var key in keysCollection.Items) { var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri($"/{@namespace}/{key}"), Method = CommandMethod.Get }; var envelopeResult = await RunCommandAsync(command); var document = envelopeResult.Resource; pairsCollection.Add(new KeyValuePair <string, Document>(key.ToString(), document)); } return(pairsCollection); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); return(null); } }