Exemple #1
0
        /// <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);
        }
Exemple #2
0
 /// <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();
     }
 }
Exemple #3
0
 public static void EnsureInitialized()
 {
     if (ContentMgr.s_mappersByType != null)
     {
         return;
     }
     ContentMgr.InitializeDefault();
 }
Exemple #4
0
 public static void InitializeAndLoad(Assembly asm)
 {
     if (ContentMgr.inited)
     {
         return;
     }
     Converters.Provider = (IConverterProvider) new NHibernateConverterProvider();
     ContentMgr.Initialize(asm);
     ContentMgr.Load();
     ContentMgr.inited = true;
 }
Exemple #5
0
        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);
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
 /// <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);
 }
Exemple #9
0
 public static LightDBMapper GetMapper <T>() where T : IDataHolder
 {
     return(ContentMgr.GetMapper(typeof(T)));
 }
Exemple #10
0
 public static void SaveStubs(Assembly asm)
 {
     ContentMgr.EnsureInitialized();
     LightDBMgr.SaveAllStubs(Path.Combine(ContentMgr.s_implementationRoot, ".stubs"),
                             (IEnumerable <DataHolderDefinition>)DataHolderMgr.CreateDataHolderDefinitionArray(asm));
 }
Exemple #11
0
 public static void SaveDefaultStubs()
 {
     ContentMgr.SaveStubs(typeof(ContentMgr).Assembly);
 }
Exemple #12
0
        /// <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()));
        }
Exemple #13
0
        /// <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()));
        }
Exemple #14
0
 /// <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();
 }
Exemple #15
0
 /// <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());
 }
Exemple #16
0
 public static void Initialize()
 {
     ContentMgr.InitializeAndLoad(typeof(ContentMgr).Assembly);
     ServerApp <WCell.RealmServer.RealmServer> .InitMgr.SignalGlobalMgrReady(typeof(ContentMgr));
 }
Exemple #17
0
 public static Dictionary <object, IDataHolder> GetObjectMap <T>() where T : IDataHolder
 {
     return(ContentMgr.GetMapper <T>().GetObjectMap <T>());
 }
Exemple #18
0
 public static void InitializeDefault()
 {
     RealmDBMgr.Initialize();
     ContentMgr.InitializeAndLoad(typeof(ContentMgr).Assembly);
 }
Exemple #19
0
 public static void Load(LightDBMapper mapper)
 {
     ContentMgr.Load(mapper, true);
 }
Exemple #20
0
 /// <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));
 }
Exemple #21
0
 /// <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));
 }
Exemple #22
0
 /// <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);
 }