Skip to content
Snippets Groups Projects
Commit 217d7fdf authored by L. Ellenbeck's avatar L. Ellenbeck
Browse files

Merge branch 'Product/119-refineVueWebPart' into 'master'

Product/119 refine vue web part

See merge request coscine/cs/configuration!13
parents d92e0101 a5d1e5a5
Branches
Tags
1 merge request!13Product/119 refine vue web part
......@@ -40,6 +40,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......
......@@ -17,7 +17,6 @@ namespace Coscine.Configuration.Tests
[Test]
public void ConsulConfigurationAsyncTest()
{
DefaultTester.ConfigurationAsyncTest(_configuration);
}
......
......@@ -31,7 +31,7 @@ namespace Coscine.Configuration
Value = value
};
using (var client = new ConsulClient())
using (var client = new ConsulClient(Configuration))
{
var putAttempt = await client.KV.Put(putPair);
......@@ -39,9 +39,27 @@ namespace Coscine.Configuration
}
}
public bool PutAndWait(string key, byte[] value)
{
var putPair = new KVPair(key)
{
Value = value
};
using (var client = new ConsulClient(Configuration))
{
var putAttempt = client.KV.Put(putPair);
putAttempt.Wait();
return putAttempt.Result.Response;
}
}
public async Task<byte[]> GetAsync(string key)
{
using (var client = new ConsulClient())
using (var client = new ConsulClient(Configuration))
{
var getPair = await client.KV.Get(key);
......@@ -57,6 +75,26 @@ namespace Coscine.Configuration
}
}
public byte[] GetAndWait(string key)
{
using (var client = new ConsulClient(Configuration))
{
var getPair = client.KV.Get(key);
getPair.Wait();
if (getPair.Result.Response?.Value != null)
{
return getPair.Result.Response.Value;
}
else
{
return null;
}
}
}
public async Task<string> GetStringAsync(string key)
{
var value = await GetAsync(key);
......@@ -70,24 +108,57 @@ namespace Coscine.Configuration
}
}
public string GetStringAndWait(string key)
{
var value = GetAndWait(key);
if (value != null)
{
return Encoding.UTF8.GetString(value, 0, value.Length);
}
else
{
return null;
}
}
public async Task<string[]> KeysAsync(string prefix)
{
using (var client = new ConsulClient())
using (var client = new ConsulClient(Configuration))
{
var keys = await client.KV.Keys(prefix);
return keys.Response;
}
}
public string[] KeysAndWait(string prefix)
{
using (var client = new ConsulClient(Configuration))
{
var keys = client.KV.Keys(prefix);
keys.Wait();
return keys.Result.Response;
}
}
public async Task<bool> DeleteAsync(string key)
{
using (var client = new ConsulClient())
using (var client = new ConsulClient(Configuration))
{
var deleteRequest = await client.KV.Delete(key);
return deleteRequest.Response;
}
}
public bool DeleteAndWait(string key)
{
using (var client = new ConsulClient(Configuration))
{
var deleteRequest = client.KV.Delete(key);
deleteRequest.Wait();
return deleteRequest.Result.Response;
}
}
public bool Put(string key, string value)
{
return PutAsync(key, value).GetAwaiter().GetResult();
......
......@@ -34,6 +34,11 @@ namespace Coscine.Configuration
return true;
}
public bool DeleteAndWait(string key)
{
return Delete(key);
}
public Task<bool> DeleteAsync(string key)
{
return Task.Factory.StartNew(() =>
......@@ -55,6 +60,11 @@ namespace Coscine.Configuration
}
}
public byte[] GetAndWait(string key)
{
return Get(key);
}
public Task<byte[]> GetAsync(string key)
{
return Task.Factory.StartNew(() =>
......@@ -75,6 +85,11 @@ namespace Coscine.Configuration
}
}
public string GetStringAndWait(string key)
{
return GetString(key);
}
public Task<string> GetStringAsync(string key)
{
return Task.Factory.StartNew(() =>
......@@ -97,6 +112,11 @@ namespace Coscine.Configuration
return filteredKeys.ToArray();
}
public string[] KeysAndWait(string prefix)
{
return Keys(prefix);
}
public Task<string[]> KeysAsync(string prefix)
{
return Task.Factory.StartNew(() =>
......@@ -123,6 +143,11 @@ namespace Coscine.Configuration
return Put(key, new System.Text.ASCIIEncoding().GetString(value));
}
public bool PutAndWait(string key, byte[] value)
{
return Put(key, value);
}
public Task<bool> PutAsync(string key, string value)
{
return Task.Factory.StartNew(() =>
......
......@@ -8,14 +8,24 @@ namespace Coscine.Configuration
Task<bool> PutAsync(string key, byte[] value);
bool PutAndWait(string key, byte[] value);
Task<byte[]> GetAsync(string key);
byte[] GetAndWait(string key);
Task<string> GetStringAsync(string key);
string GetStringAndWait(string key);
Task<string[]> KeysAsync(string prefix);
string[] KeysAndWait(string prefix);
Task<bool> DeleteAsync(string key);
bool DeleteAndWait(string key);
bool Put(string key, string value);
bool Put(string key, byte[] value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment