/// <summary>Checks the validity of all Table definitions</summary> /// <returns>The amount of invalid columns.</returns> public static int Check(Action <string> feedbackCallback) { ContentMgr.EnsureInitialized(); int num = 0; foreach (LightDBMapper lightDbMapper in ContentMgr.s_mappersByType.Values) { foreach (TableDefinition tableDefinition in lightDbMapper.Mapping.TableDefinitions) { foreach (SimpleDataColumn columnDefinition in tableDefinition.ColumnDefinitions) { if (!columnDefinition.IsEmpty) { try { using (lightDbMapper.Wrapper.Query(SqlUtil.BuildSelect(new string[1] { columnDefinition.ColumnName }, tableDefinition.Name, "LIMIT 1"))) ; } catch (Exception ex) { feedbackCallback(string.Format("Invalid column \"{0}\" in table \"{1}\": {2}", (object)columnDefinition, (object)tableDefinition.Name, (object)ex.GetAllMessages().ToString <string>("\n\t"))); ++num; } } } } } return(num); }
/// <summary>Fetches all content of all registered DataHolders.</summary> public static void FetchAll() { ContentMgr.EnsureInitialized(); foreach (LightDBMapper lightDbMapper in ContentMgr.s_mappersByType.Values) { lightDbMapper.Fetch(); } }
public static void EnsureInitialized() { if (ContentMgr.s_mappersByType != null) { return; } ContentMgr.InitializeDefault(); }
public static void InitializeAndLoad(Assembly asm) { if (ContentMgr.inited) { return; } Converters.Provider = (IConverterProvider) new NHibernateConverterProvider(); ContentMgr.Initialize(asm); ContentMgr.Load(); ContentMgr.inited = true; }
public static LightDBMapper GetMapper(Type t) { ContentMgr.EnsureInitialized(); LightDBMapper lightDbMapper; if (!ContentMgr.s_mappersByType.TryGetValue(t, out lightDbMapper)) { throw new Exception(string.Format( "DataHolder Type \"{0}\" was not registered - Make sure that it's XML definition was defined and associated correctly. If the Type is not in the Core, call ContentHandler.Initialize(Assembly) on its Assembly first.", (object)t.FullName)); } return(lightDbMapper); }
public static void Load() { ContentMgr.s_definitions.Clear(); string file = Path.Combine(ContentMgr.s_implementationFolder, "Tables.xml"); string dir = Path.Combine(ContentMgr.s_implementationFolder, "Data"); ContentMgr.s_definitions.LoadTableDefinitions(file); ContentMgr.CheckVersion(); ContentMgr.s_definitions.LoadDataHolderDefinitions(dir); if (!ActiveRecordStarter.IsInitialized) { throw new InvalidOperationException("ActiveRecord must be initialized."); } ContentMgr.s_mappersByType = ContentMgr.CreateMappersByType(); }
/// <summary> /// Ensures that the DataHolder of the given type and those that are connected with it, are loaded. /// /// </summary> /// <param name="force">Whether to re-load if already loaded.</param> public static bool Load <T>(bool force) where T : IDataHolder { ContentMgr.EnsureInitialized(); LightDBMapper mapper = ContentMgr.GetMapper <T>(); if (!force && mapper.Fetched) { return(false); } if (force && mapper.IsCached()) { mapper.FlushCache(); } ContentMgr.Load(mapper); return(true); }
/// <summary> /// Inserts the Object into the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// </summary> public static void CommitInsert(this IDataHolder obj) { ContentMgr.GetMapper(obj.GetType()).Insert(obj); }
public static LightDBMapper GetMapper <T>() where T : IDataHolder { return(ContentMgr.GetMapper(typeof(T))); }
public static void SaveStubs(Assembly asm) { ContentMgr.EnsureInitialized(); LightDBMgr.SaveAllStubs(Path.Combine(ContentMgr.s_implementationRoot, ".stubs"), (IEnumerable <DataHolderDefinition>)DataHolderMgr.CreateDataHolderDefinitionArray(asm)); }
public static void SaveDefaultStubs() { ContentMgr.SaveStubs(typeof(ContentMgr).Assembly); }
/// <summary> /// Flush all commited changes to the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// Will be executed in the global IO context. /// </summary> public static void FlushCommit(Type t) { LightDBMapper mapper = ContentMgr.GetMapper(t); ServerApp <WCell.RealmServer.RealmServer> .IOQueue.ExecuteInContext((Action)(() => mapper.Flush())); }
/// <summary> /// Flush all commited changes to the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// Will be executed in the global IO context. /// </summary> public static void FlushCommit <T>() where T : IDataHolder { LightDBMapper mapper = ContentMgr.GetMapper(typeof(T)); ServerApp <WCell.RealmServer.RealmServer> .IOQueue.ExecuteInContext((Action)(() => mapper.Flush())); }
/// <summary> /// Ignore all changes before last FlushCommit() (will not change the Object's state). /// </summary> public static void IgnoreUnflushedChanges <T>() where T : IDataHolder { ContentMgr.GetMapper(typeof(T)).IgnoreUnflushedChanges(); }
/// <summary> /// Deletes the Object from the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// </summary> public static void CommitDeleteAndFlush(this IDataHolder obj) { obj.CommitDelete(); ContentMgr.FlushCommit(obj.GetType()); }
public static void Initialize() { ContentMgr.InitializeAndLoad(typeof(ContentMgr).Assembly); ServerApp <WCell.RealmServer.RealmServer> .InitMgr.SignalGlobalMgrReady(typeof(ContentMgr)); }
public static Dictionary <object, IDataHolder> GetObjectMap <T>() where T : IDataHolder { return(ContentMgr.GetMapper <T>().GetObjectMap <T>()); }
public static void InitializeDefault() { RealmDBMgr.Initialize(); ContentMgr.InitializeAndLoad(typeof(ContentMgr).Assembly); }
public static void Load(LightDBMapper mapper) { ContentMgr.Load(mapper, true); }
/// <summary> /// Ensures that the DataHolder of the given type and those that are connected with it, are loaded. /// /// </summary> public static bool Load <T>() where T : IDataHolder { return(ContentMgr.Load <T>(false)); }
/// <summary> /// Reports incorrect data, that is not Database-provider dependent. /// </summary> /// <param name="msg"></param> /// <param name="args"></param> public static void OnInvalidClientData(string msg, params object[] args) { ContentMgr.OnInvalidClientData(string.Format(msg, args)); }
/// <summary> /// Deletes the Object from the underlying Database. /// FlushCommit() needs to be called to persist the operation. /// </summary> public static void CommitDelete(this IDataHolder obj) { ContentMgr.GetMapper(obj.GetType()).Delete(obj); }