public virtual T GetItem <T>(object primaryKey) where T : class, new() { lock (tableLocks[typeof(T)]) { T itemResult = connection.Find <T>(primaryKey); return(typeof(IEncryptable).IsAssignableFrom(typeof(T)) ? SqliteEncryptHelper.DecryptItem <T>(itemResult) : itemResult); } }
public virtual T GetItem <T>(Expression <Func <T, bool> > predicate) where T : class, new() { lock (tableLocks[typeof(T)]) { T itemResult = connection.Find <T>(predicate); return(typeof(IEncryptable).IsAssignableFrom(typeof(T)) ? SqliteEncryptHelper.DecryptItem <T>(itemResult) : itemResult); } }
public List <T> GetAll <T>(Expression <Func <T, bool> > filter) where T : class, new() { lock (tableLocks[typeof(T)]) { var result = connection.Table <T>().Where(filter).ToList(); return(typeof(IEncryptable).IsAssignableFrom(typeof(T)) ? SqliteEncryptHelper.DecryptList <T>(result) : result); } }
public List <T> GetByQuery <T>(string query, params object[] args) where T : class, new() { lock (tableLocks[typeof(T)]) { var result = connection.Query <T>(query, args); return(typeof(IEncryptable).IsAssignableFrom(typeof(T)) ? SqliteEncryptHelper.DecryptList <T>(result) : result); } }
public int InsertOrReplace <T>(T item) where T : class, new() { lock (tableLocks[typeof(T)]) { if (typeof(IEncryptable).IsAssignableFrom(typeof(T))) { item = SqliteEncryptHelper.EncryptItem <T>(item); } return(connection.InsertOrReplace(item)); } }
public void InsertAll <T>(IEnumerable <T> items) where T : class, new() { lock (tableLocks[typeof(T)]) { if (typeof(IEncryptable).IsAssignableFrom(typeof(T))) { items = SqliteEncryptHelper.EncryptList <T>(items.ToList()); } connection.InsertAll(items); } }
private T DecryptWithChildren <T>(T item) where T : class, new() { if (item == null) { return(item); } var refTypeProperties = typeof(T).GetTypeInfo().DeclaredProperties.Where( x => x.CanWrite && !x.PropertyType.GetTypeInfo().IsValueType&& x.PropertyType != typeof(string)); foreach (var refTypeProperty in refTypeProperties) { var refTypePropertyValue = refTypeProperty.GetValue(item); if (typeof(IEnumerable).IsAssignableFrom(refTypeProperty.PropertyType)) { var seq = (refTypePropertyValue as IEnumerable).GetEnumerator(); while (seq.MoveNext()) { DecryptWithChildren(seq.Current); } } else { DecryptWithChildren(refTypePropertyValue); } } if (typeof(IEncryptable).IsAssignableFrom(item.GetType())) { item = SqliteEncryptHelper.DecryptItem(item); } return(item); }