This commit is contained in:
37
CredRepo.cs
37
CredRepo.cs
@@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -7,52 +6,30 @@ namespace raven_integration
|
|||||||
{
|
{
|
||||||
public class CredRepo
|
public class CredRepo
|
||||||
{
|
{
|
||||||
static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1,1);
|
static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1);
|
||||||
// private readonly object valueLock = new object();
|
|
||||||
|
|
||||||
private static Dictionary<string, string> authDict = new Dictionary<string, string>();
|
private static Dictionary<string, string> authDict = new Dictionary<string, string>();
|
||||||
|
public CredRepo() { }
|
||||||
|
|
||||||
public CredRepo()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<string> GetTokenAsync(string login, string password = null)
|
public static async Task<string> GetTokenAsync(string login, string password = null)
|
||||||
{
|
{
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync();
|
||||||
try{
|
try
|
||||||
|
{
|
||||||
if (password == null)
|
if (password == null)
|
||||||
password = login;
|
password = login;
|
||||||
|
|
||||||
if (!authDict.ContainsKey(login))
|
if (!authDict.ContainsKey(login))
|
||||||
{
|
{
|
||||||
dynamic creds = new JObject();
|
dynamic creds = new JObject();
|
||||||
creds.login = login;
|
creds.login = login;
|
||||||
creds.password = password;
|
creds.password = password;
|
||||||
|
|
||||||
ApiResponse a = await Util.PostAsync("auth", null, creds.ToString());
|
ApiResponse a = await Util.PostAsync("auth", null, creds.ToString());
|
||||||
//Put this in when having concurrency issue during auth and old style dl token creation during login
|
|
||||||
// ValidateDataReturnResponseOk(a);
|
|
||||||
|
|
||||||
authDict[login] = a.ObjectResponse["data"]["token"].Value<string>();
|
authDict[login] = a.ObjectResponse["data"]["token"].Value<string>();
|
||||||
}
|
}
|
||||||
return authDict[login];
|
return authDict[login];
|
||||||
}
|
}
|
||||||
finally{
|
finally
|
||||||
semaphoreSlim.Release();
|
{
|
||||||
|
semaphoreSlim.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public uint GetNext()
|
|
||||||
// {
|
|
||||||
// lock (valueLock)
|
|
||||||
// {
|
|
||||||
// currentValue += 1;
|
|
||||||
// if (currentValue == 0)
|
|
||||||
// currentValue += 1;
|
|
||||||
// return currentValue;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user