|
@@ -41,67 +41,133 @@ namespace InABox.Clients
|
|
|
|
|
|
public static Dictionary<string, CoreTable> QueryMultiple(Dictionary<string, IQueryDef> queries)
|
|
|
{
|
|
|
- using (var timer = new Profiler(false))
|
|
|
+ try
|
|
|
{
|
|
|
+ using var timer = new Profiler(false);
|
|
|
var result = CheckClient().QueryMultiple(queries);
|
|
|
timer.Log(result.Sum(x => x.Value.Rows.Count));
|
|
|
return result;
|
|
|
}
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static QueryMultipleResults QueryMultiple(params IKeyedQueryDef[] queries)
|
|
|
{
|
|
|
- using (var timer = new Profiler(false))
|
|
|
+ try
|
|
|
{
|
|
|
+ using var timer = new Profiler(false);
|
|
|
var result = CheckClient().QueryMultiple(queries.ToDictionary(x => x.Key, x => x as IQueryDef));
|
|
|
timer.Log(result.Sum(x => x.Value.Rows.Count));
|
|
|
return new QueryMultipleResults(result);
|
|
|
}
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
public static QueryMultipleResults QueryMultiple(IEnumerable<IKeyedQueryDef> queries)
|
|
|
{
|
|
|
- using (var timer = new Profiler(false))
|
|
|
+ try
|
|
|
{
|
|
|
+ using var timer = new Profiler(false);
|
|
|
var result = CheckClient().QueryMultiple(queries.ToDictionary(x => x.Key, x => x as IQueryDef));
|
|
|
timer.Log(result.Sum(x => x.Value.Rows.Count));
|
|
|
return new QueryMultipleResults(result);
|
|
|
}
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static ValidationData Validate(Guid session)
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return CheckClient().Validate(session);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return CheckClient().Validate(session);
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static ValidationData Validate(string pin, Guid session = default)
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return CheckClient().Validate(pin, session);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return CheckClient().Validate(pin, session);
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static ValidationData Validate(string userid, string password, Guid session = default)
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return CheckClient().Validate(userid, password, session);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return CheckClient().Validate(userid, password, session);
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static bool Check2FA(string code, Guid? session = null)
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return CheckClient().Check2FA(code, session);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return CheckClient().Check2FA(code, session);
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static bool Ping()
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return CheckClient().Ping();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return CheckClient().Ping();
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static DatabaseInfo Info()
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return CheckClient().Info();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return CheckClient().Info();
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static Client Create(Type TEntity) =>
|
|
@@ -141,12 +207,20 @@ namespace InABox.Clients
|
|
|
|
|
|
public CoreTable Query(Filter<TEntity>? filter = null, Columns<TEntity>? columns = null, SortOrder<TEntity>? orderby = null)
|
|
|
{
|
|
|
- using (var timer = new Profiler<TEntity>(false))
|
|
|
+ try
|
|
|
{
|
|
|
- CheckSupported();
|
|
|
- var result = _client.Query(filter, columns, orderby);
|
|
|
- timer.Log(result.Rows.Count);
|
|
|
- return result;
|
|
|
+ using (var timer = new Profiler<TEntity>(false))
|
|
|
+ {
|
|
|
+ CheckSupported();
|
|
|
+ var result = _client.Query(filter, columns, orderby);
|
|
|
+ timer.Log(result.Rows.Count);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
}
|
|
|
}
|
|
|
public override CoreTable Query(IFilter? filter, IColumns? columns, ISortOrder? sortOrder)
|
|
@@ -156,143 +230,251 @@ namespace InABox.Clients
|
|
|
|
|
|
public void Query(Filter<TEntity>? filter, Columns<TEntity>? columns, SortOrder<TEntity>? sort, Action<CoreTable?, Exception?> callback)
|
|
|
{
|
|
|
- var timer = new Profiler<TEntity>(false);
|
|
|
- CheckSupported();
|
|
|
- _client.Query(filter, columns, sort, (c, e) =>
|
|
|
+ try
|
|
|
{
|
|
|
- timer.Dispose(c != null ? c.Rows.Count : -1);
|
|
|
- callback?.Invoke(c, e);
|
|
|
- });
|
|
|
-
|
|
|
+ var timer = new Profiler<TEntity>(false);
|
|
|
+ CheckSupported();
|
|
|
+ _client.Query(filter, columns, sort, (c, e) =>
|
|
|
+ {
|
|
|
+ timer.Dispose(c != null ? c.Rows.Count : -1);
|
|
|
+ callback?.Invoke(c, e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public TEntity[] Load(Filter<TEntity>? filter = null, SortOrder<TEntity>? sort = null)
|
|
|
{
|
|
|
- using (var timer = new Profiler<TEntity>(false))
|
|
|
+ try
|
|
|
{
|
|
|
- CheckSupported();
|
|
|
- var result = _client.Load(filter, sort);
|
|
|
- foreach (var entity in result)
|
|
|
- entity.CommitChanges();
|
|
|
- timer.Log(result.Length);
|
|
|
- return result;
|
|
|
+
|
|
|
+ using (var timer = new Profiler<TEntity>(false))
|
|
|
+ {
|
|
|
+ CheckSupported();
|
|
|
+ var result = _client.Load(filter, sort);
|
|
|
+ foreach (var entity in result)
|
|
|
+ entity.CommitChanges();
|
|
|
+ timer.Log(result.Length);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Load(Filter<TEntity> filter, SortOrder<TEntity> sort, Action<TEntity[]?, Exception?> callback)
|
|
|
{
|
|
|
- var timer = new Profiler<TEntity>(false);
|
|
|
- CheckSupported();
|
|
|
- _client.Load(filter, sort, (i,e) =>
|
|
|
+ try
|
|
|
{
|
|
|
- timer.Dispose(i != null ? i.Length : -1);
|
|
|
- callback?.Invoke(i, e);
|
|
|
- });
|
|
|
-
|
|
|
+ var timer = new Profiler<TEntity>(false);
|
|
|
+ CheckSupported();
|
|
|
+ _client.Load(filter, sort, (i, e) =>
|
|
|
+ {
|
|
|
+ timer.Dispose(i != null ? i.Length : -1);
|
|
|
+ callback?.Invoke(i, e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public override void Save(Entity entity, string auditNote)
|
|
|
{
|
|
|
- Save((entity as TEntity)!, auditNote);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Save((entity as TEntity)!, auditNote);
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
public void Save(TEntity entity, string auditnote)
|
|
|
{
|
|
|
- using (new Profiler<TEntity>(true))
|
|
|
+ try
|
|
|
{
|
|
|
- CheckSupported();
|
|
|
- entity.LastUpdate = DateTime.Now;
|
|
|
- entity.LastUpdateBy = ClientFactory.UserID;
|
|
|
- _client.Save(entity, auditnote);
|
|
|
- entity.CommitChanges();
|
|
|
+
|
|
|
+ using (new Profiler<TEntity>(true))
|
|
|
+ {
|
|
|
+ CheckSupported();
|
|
|
+ entity.LastUpdate = DateTime.Now;
|
|
|
+ entity.LastUpdateBy = ClientFactory.UserID;
|
|
|
+ _client.Save(entity, auditnote);
|
|
|
+ entity.CommitChanges();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Save(TEntity entity, string auditnote, Action<TEntity, Exception?> callback)
|
|
|
{
|
|
|
- var timer = new Profiler<TEntity>(false);
|
|
|
- CheckSupported();
|
|
|
- _client.Save(entity, auditnote, (i,c) =>
|
|
|
+ try
|
|
|
{
|
|
|
- timer.Dispose();
|
|
|
- callback?.Invoke(i, c);
|
|
|
- });
|
|
|
+ var timer = new Profiler<TEntity>(false);
|
|
|
+ CheckSupported();
|
|
|
+ _client.Save(entity, auditnote, (i, c) =>
|
|
|
+ {
|
|
|
+ timer.Dispose();
|
|
|
+ callback?.Invoke(i, c);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Save(IEnumerable<TEntity> entities, string auditnote)
|
|
|
{
|
|
|
- using (var timer = new Profiler<TEntity>(false))
|
|
|
+ try
|
|
|
{
|
|
|
+ using var timer = new Profiler<TEntity>(false);
|
|
|
CheckSupported();
|
|
|
if (entities.Any())
|
|
|
_client.Save(entities, auditnote);
|
|
|
timer.Log(entities.Count());
|
|
|
}
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Save(IEnumerable<TEntity> entities, string auditnote, Action<IEnumerable<TEntity>, Exception?> callback)
|
|
|
{
|
|
|
- var timer = new Profiler<TEntity>(false);
|
|
|
- CheckSupported();
|
|
|
- if (entities.Any())
|
|
|
- _client.Save(entities, auditnote, (i,e) =>
|
|
|
- {
|
|
|
- timer.Dispose(i.Count());
|
|
|
- callback?.Invoke(i,e);
|
|
|
- });
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var timer = new Profiler<TEntity>(false);
|
|
|
+ CheckSupported();
|
|
|
+ if (entities.Any())
|
|
|
+ _client.Save(entities, auditnote, (i, e) =>
|
|
|
+ {
|
|
|
+ timer.Dispose(i.Count());
|
|
|
+ callback?.Invoke(i, e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
public void Delete(TEntity entity, string auditnote)
|
|
|
{
|
|
|
- using (new Profiler<TEntity>(true))
|
|
|
+ try
|
|
|
{
|
|
|
- CheckSupported();
|
|
|
- _client.Delete(entity, auditnote);
|
|
|
+ using (new Profiler<TEntity>(true))
|
|
|
+ {
|
|
|
+ CheckSupported();
|
|
|
+ _client.Delete(entity, auditnote);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Delete(TEntity entity, string auditnote, Action<TEntity, Exception?> callback)
|
|
|
{
|
|
|
- var timer = new Profiler<TEntity>(true);
|
|
|
- CheckSupported();
|
|
|
- _client.Delete(entity, auditnote, (i,e) =>
|
|
|
+ try
|
|
|
{
|
|
|
- timer.Dispose();
|
|
|
- callback?.Invoke(i, e);
|
|
|
- });
|
|
|
+ var timer = new Profiler<TEntity>(true);
|
|
|
+ CheckSupported();
|
|
|
+ _client.Delete(entity, auditnote, (i, e) =>
|
|
|
+ {
|
|
|
+ timer.Dispose();
|
|
|
+ callback?.Invoke(i, e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Delete(IList<TEntity> entities, string auditnote)
|
|
|
{
|
|
|
- using (var timer = new Profiler<TEntity>(false))
|
|
|
+ try
|
|
|
{
|
|
|
+ using var timer = new Profiler<TEntity>(false);
|
|
|
CheckSupported();
|
|
|
_client.Delete(entities, auditnote);
|
|
|
timer.Log(entities.Count());
|
|
|
}
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Delete(IList<TEntity> entities, string auditnote, Action<IList<TEntity>, Exception?> callback)
|
|
|
{
|
|
|
- var timer = new Profiler<TEntity>(false);
|
|
|
- CheckSupported();
|
|
|
- _client.Delete(entities, auditnote, (i,e) =>
|
|
|
+ try
|
|
|
{
|
|
|
- timer.Dispose(entities.Count());
|
|
|
- callback?.Invoke(i,e);
|
|
|
- });
|
|
|
+ var timer = new Profiler<TEntity>(false);
|
|
|
+ CheckSupported();
|
|
|
+ _client.Delete(entities, auditnote, (i, e) =>
|
|
|
+ {
|
|
|
+ timer.Dispose(entities.Count());
|
|
|
+ callback?.Invoke(i, e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public IEnumerable<string> SupportedTypes()
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return _client.SupportedTypes();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return _client.SupportedTypes();
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public new DatabaseInfo Info()
|
|
|
{
|
|
|
- using (new Profiler(true))
|
|
|
- return _client.Info();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (new Profiler(true))
|
|
|
+ return _client.Info();
|
|
|
+ }
|
|
|
+ catch (RequestException e)
|
|
|
+ {
|
|
|
+ ClientFactory.RaiseRequestError(e);
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|