static void Add(this DBColum colum, long time, object newvalue, out Exception exp) { exp = null; try { if (!CoreResolver.CanUse(colum, newvalue)) { throw new WrongParameterCodeType("{0} type isn't acceptable in colum {1}.", CoreResolver.ReturnType(newvalue.GetType()).ToString(), colum.Name); } if (CoreResolver.UniqueDBKey(colum)) { if (colum.Values.Contains(newvalue)) { throw new DuplicatedUniqueValue("{0} unique value {1} existed already.", colum.Name, newvalue); } } colum.Records.Add(DBColumOrderRecord.Create(DBColumOrderRecordType.Add, time, colum, newvalue)); colum.UpdatedValue = newvalue; colum.Values.Add(newvalue); } catch (Exception e) { exp = e; } }
public static DBTableStruct Create(string name, bool Crypted = false) { var table = new DBTableStruct() { Name = name, CryptoGraphieKey = string.Empty, Colums = new ConcurrentDictionary <string, DBColum>() }; if (Crypted) { table.CryptoGraphieKey = CoreResolver.RandomizedCryptionKey(name); } return(table); }
public static T ValidateDB <T>(this T obj) where T : new() { List <Tuple <PropertyInfo, CoreProperty, object> > items = new List <Tuple <PropertyInfo, CoreProperty, object> >(); if (obj.GetType().GetCustomAttributes(typeof(CoreStruct), false).Length > 0) { foreach (var properity in obj.GetType().GetProperties()) { if (properity.IsDefined(typeof(CoreProperty), false)) { var pattribute = properity.GetCustomAttributes <CoreProperty>(false).Where(p => CoreResolver.DefinedAttribute(p)); if (pattribute.Count() > 0) { items.Add(Tuple.Create(properity, pattribute.FirstOrDefault(), properity.GetValue(obj))); } } } int index = constructors.FindIndex(0, e => e.Item1.Equals(obj)); if (index == -1) {//add to constructors constructors.Add(Tuple.Create(obj.GetType(), (CoreStruct)obj.GetType().GetCustomAttribute(typeof(CoreStruct), false), items)); } else {//update parameters constructors.RemoveAt(index); constructors.Add(Tuple.Create(obj.GetType(), (CoreStruct)obj.GetType().GetCustomAttribute(typeof(CoreStruct), false), items)); } } /*if (!XThread.IsAlive) * XThread.Start();*/ return(obj); }