public T GetSingleObject <T>(string id) where T : UnifiedIMObject <T> { string col = UnifiedCollectionAttribute.GetCollection <T>(); EnsureExistence(col, id); return(JsonConvert.DeserializeObject <T>(File.ReadAllText(GetObjectPath(col, id)))); }
public bool DeleteObject <T>(string id) where T : UnifiedIMObject <T> { string col = UnifiedCollectionAttribute.GetCollection <T>(); EnsureExistence(col, id); File.Delete(GetObjectPath(col, id)); return(true); }
public bool UpdateProperties <T>(string id, T obj, string[] properties) where T : UnifiedIMObject <T> { string col = UnifiedCollectionAttribute.GetCollection <T>(); EnsureExistence(col, id); File.WriteAllText(GetObjectPath(col, obj.ObjectID), JsonConvert.SerializeObject(obj)); return(true); }
public bool LoadCollection <C>() where C : UnifiedIMObject <C> { string col = UnifiedCollectionAttribute.GetCollection <C>(); col = GetCollectionPath(col); Directory.CreateDirectory(col); return(true); }
public bool InsertObject <T>(T obj) where T : UnifiedIMObject <T> { string col = UnifiedCollectionAttribute.GetCollection <T>(); if (string.IsNullOrEmpty(obj.ObjectID)) { string id = BuildID(); obj.ObjectID = id; } File.WriteAllText(GetObjectPath(col, obj.ObjectID), JsonConvert.SerializeObject(obj)); return(true); }
public bool LoadCollection <C>() where C : UnifiedIMObject <C> { string collection = UnifiedCollectionAttribute.GetCollection <C>(); if (string.IsNullOrEmpty(collection)) { throw new Exception($"Missing UnifiedCollectionAttribute on type {typeof(C).Name}"); } TableCache.Add(typeof(C), collection); ColumnCache.Add(typeof(C), ColumnProperty.GetCollumns <C>(MSSQLHelper.Instance, true, "ObjectID").Values.ToList()); return(true); }
public List <T> GetAllObjects <T>() where T : UnifiedIMObject <T> { string col = UnifiedCollectionAttribute.GetCollection <T>(); List <T> objs = new List <T>(); foreach (FileInfo f in new DirectoryInfo(GetCollectionPath(col)).GetFiles()) { T obj = JsonConvert.DeserializeObject <T>(File.ReadAllText(f.FullName)); if (obj != null) { objs.Add(obj); } } return(objs); }
public bool LoadCollection <T>() where T : UnifiedIMObject <T> { if (!Collections.ContainsKey(typeof(T))) { string col = UnifiedCollectionAttribute.GetCollection <T>(); if (string.IsNullOrEmpty(col)) { throw new Exception($"Missing UnifiedCollectionAttribute on type {typeof(T).Name}"); } RegisterClass <T>(); UnifiedIMDerivesAttribute derived = UnifiedIMDerivesAttribute.GetAttribute <T>(); if (derived != null) { foreach (Type type in derived.Derived) { Method.CallGeneric(typeof(BsonClassMap).GetMethod("RegisterClassMap", new Type[] { }), null, new Type[] { type }); } } Collections.Add(typeof(T), mongo.GetCollection <T>(col)); } return(true); }
public bool LoadCollection <C>() where C : UnifiedIMObject <C> { string collection = UnifiedCollectionAttribute.GetCollection <C>(); if (string.IsNullOrEmpty(collection)) { throw new Exception($"Missing UnifiedCollectionAttribute on type {typeof(C).Name}"); } TableCache.Add(typeof(C), collection); ColumnCache.Add(typeof(C), ColumnProperty.GetCollumns <C>(MySQLHelper.Instance, true, "ObjectID").Values.ToList()); ColumnProperty objidcol = GetColumns <C>().FirstOrDefault(X => X.Name == "ObjectID"); foreach (ColumnProperty prop in GetColumns <C>()) { if (prop.Name == "ObjectID") { prop.OverrideSqlType("char(32)"); } else { prop.OverrideSqlType(MySQLHelper.Instance.GetSqlType(prop.Type, prop.Column)); } } if (!MySQLTable.GetTables(SQL).Contains(collection)) { try { MySQLTable.CreateTable(SQL, collection, GetColumns <C>()); } catch (Exception ex) { throw new Exception($"Failed to create table {collection}"); } } else { MySQLTable table = MySQLTable.GetTable(SQL, collection); List <ColumnProperty> todo = table.Columns.ToList(); foreach (ColumnProperty col in GetColumns <C>()) { ColumnProperty existing = table.Columns.FirstOrDefault(X => X.Name == col.Name); if (existing == null) { System.Console.WriteLine($"SQL missing Column {col.Name}... Adding"); try { MySQLTable.AddColumn(SQL, collection, col.Name, col.SqlType); } catch (Exception ex) { throw new Exception($"Failed to add collumn {col.Name}\n{ex.Message}"); } } else if (!existing.SqlType.StartsWith(col.SqlType)) { System.Console.WriteLine($"SQL incorrect Column Type for {col.Name}... Converting"); try { MySQLTable.ConvertColumn(SQL, collection, col.Name, col.SqlType); } catch (Exception ex) { throw new Exception($"Failed to convert collumn {col.Name}\n{ex.Message}"); } } if (existing != null) { todo.Remove(existing); } } foreach (ColumnProperty prop in todo) { System.Console.WriteLine($"Excess collumn {prop.Name}... Removing"); try { MySQLTable.RemoveColumn(SQL, collection, prop.Name); } catch (Exception ex) { throw new Exception($"Failed to remove collumn {prop.Name}\n{ex.Message}"); } } } return(true); }