Example #1
0
 public static void Load(LightDBMapper mapper, bool failException)
 {
     try
     {
         if (EnableCaching && mapper.SupportsCaching && mapper.LoadCache())
         {
             return;
         }
         mapper.Fetch();
         if (!EnableCaching || !mapper.SupportsCaching)
         {
             return;
         }
         log.Info("Saving cache for: " +
                  mapper.Mapping.DataHolderDefinitions
                  .ToString(", "));
         mapper.SaveCache();
     }
     catch (Exception ex)
     {
         if (failException)
         {
             throw new ContentException(ex, "Unable to load entries using \"{0}\"", (object)mapper);
         }
     }
 }
Example #2
0
        private static bool LoadCache(this LightDBMapper mapper)
        {
            var file = GetCacheFilename(mapper);

            if (mapper.IsCached())
            {
                try
                {
                    // Utility.Measure("Loading contnt from Cache - " + mapper, 1, () => {
                    if (mapper.LoadCache(file))
                    {
                        // loaded cache successfully
                        return(true);
                    }
                    log.Warn("Cache signature in file \"{0}\" is out of date.", file);
                    log.Warn("Reloading content from Database...");
                    //});
                    //return;
                }
                catch (Exception ex)
                {
                    if (ex is EndOfStreamException)
                    {
                        log.Warn("Cache signature in file \"{0}\" is out of date.", file);
                    }
                    else
                    {
                        LogUtil.ErrorException(ex, "Unable to load cache from \"" + file + "\".");
                    }
                    log.Warn("Reloading content from Database...");
                }
            }
            return(false);
        }
Example #3
0
 public static void Load(LightDBMapper mapper, bool failException)
 {
     try
     {
         if (ContentMgr.EnableCaching && mapper.SupportsCaching && mapper.LoadCache())
         {
             return;
         }
         mapper.Fetch();
         if (!ContentMgr.EnableCaching || !mapper.SupportsCaching)
         {
             return;
         }
         ContentMgr.log.Info("Saving cache for: " +
                             ((IEnumerable <DataHolderDefinition>)mapper.Mapping.DataHolderDefinitions)
                             .ToString <DataHolderDefinition>(", "));
         mapper.SaveCache();
     }
     catch (Exception ex)
     {
         if (failException)
         {
             throw new ContentException(ex, "Unable to load entries using \"{0}\"", new object[1]
             {
                 (object)mapper
             });
         }
     }
 }
Example #4
0
        private static bool LoadCache(this LightDBMapper mapper)
        {
            string cacheFilename = mapper.GetCacheFilename();

            if (mapper.IsCached())
            {
                try
                {
                    if (mapper.LoadCache(cacheFilename))
                    {
                        return(true);
                    }
                    ContentMgr.log.Warn("Cache signature in file \"{0}\" is out of date.", cacheFilename);
                    ContentMgr.log.Warn("Reloading content from Database...");
                }
                catch (Exception ex)
                {
                    if (ex is EndOfStreamException)
                    {
                        ContentMgr.log.Warn("Cache signature in file \"{0}\" is out of date.", cacheFilename);
                    }
                    else
                    {
                        LogUtil.ErrorException(ex, "Unable to load cache from \"" + cacheFilename + "\".",
                                               new object[0]);
                    }
                    ContentMgr.log.Warn("Reloading content from Database...");
                }
            }

            return(false);
        }
Example #5
0
        public static void Load(LightDBMapper mapper, bool failException)
        {
            try
            {
                if (EnableCaching && mapper.SupportsCaching)
                {
                    if (mapper.LoadCache())
                    {
                        // loaded cache successfully
                        return;
                    }
                }

                //Utility.Measure("Loading content from DB - " + mapper + "", 1, () => {
                mapper.Fetch();
                //});

                if (EnableCaching && mapper.SupportsCaching)
                {
                    log.Info("Saving cache for: " + mapper.Mapping.DataHolderDefinitions.ToString(", "));
                    mapper.SaveCache();
                }
            }
            catch (Exception e)
            {
                if (failException)
                {
                    throw new ContentException(e, "Unable to load entries using \"{0}\"", mapper);
                }
                // LogUtil.ErrorException(e, "Unable to load entries using \"{0}\"", mapper);
            }
        }
Example #6
0
        public static void FlushCache(this LightDBMapper mapper)
        {
            var file = GetCacheFilename(mapper);

            if (File.Exists(file))
            {
                File.Delete(file);
            }
        }
Example #7
0
        public static void FlushCache(this LightDBMapper mapper)
        {
            string cacheFilename = mapper.GetCacheFilename();

            if (!File.Exists(cacheFilename))
            {
                return;
            }
            File.Delete(cacheFilename);
        }
Example #8
0
        public static string GetCacheFilename(this LightDBMapper mapper)
        {
            var str = new StringBuilder(mapper.Mapping.DataHolderDefinitions.Length * 12);

            foreach (var def in mapper.Mapping.DataHolderDefinitions)
            {
                str.Append(def.Name);
            }
            str.Append(CacheFileSuffix);
            return(RealmServerConfiguration.Instance.GetCacheFile(str.ToString()));
        }
Example #9
0
        public static string GetCacheFilename(this LightDBMapper mapper)
        {
            StringBuilder stringBuilder = new StringBuilder(mapper.Mapping.DataHolderDefinitions.Length * 12);

            foreach (DataHolderDefinition holderDefinition in mapper.Mapping.DataHolderDefinitions)
            {
                stringBuilder.Append(holderDefinition.Name);
            }
            stringBuilder.Append(".cache");
            return(RealmServerConfiguration.Instance.GetCacheFile(stringBuilder.ToString()));
        }
Example #10
0
 public void Prepare(LightDBMapper mapper)
 {
     TableDefinition[] tableDefinitions = mapper.Mapping.TableDefinitions;
     m_selectCommands = new IDbCommand[tableDefinitions.Length];
     for (int index = 0; index < tableDefinitions.Length; ++index)
     {
         TableDefinition tableDefinition = tableDefinitions[index];
         IDbCommand      command         =
             CreateCommand(SqlUtil.BuildSelect(tableDefinition.AllColumns, tableDefinition.Name));
         m_selectCommands[index] = command;
     }
 }
Example #11
0
        public static Dictionary <Type, LightDBMapper> CreateMappersByType()
        {
            var map = new Dictionary <Type, LightDBMapper>();

            foreach (var mapping in s_definitions.Mappings)
            {
                var mapper = new LightDBMapper(mapping, new NHibernateDbWrapper());
                foreach (var def in mapping.DataHolderDefinitions)
                {
                    map.Add(def.Type, mapper);
                }
            }
            return(map);
        }
Example #12
0
 public void Prepare(LightDBMapper mapper)
 {
     var tables = mapper.Mapping.TableDefinitions;
     m_selectCommands = new IDbCommand[tables.Length];
     for (var i = 0; i < tables.Length; i++)
     {
         var table = tables[i];
         var cmd = CreateCommand(SqlUtil.BuildSelect(table.AllColumns, table.Name)
             //+ " ORDER BY " + table.PrimaryColumns[0].Name
                 );
         //tables[i].QueryString, emptySqlTypeArr);
         m_selectCommands[i] = cmd;
     }
 }
Example #13
0
		public void Prepare(LightDBMapper mapper)
		{
			var tables = mapper.Mapping.TableDefinitions;
			m_selectCommands = new IDbCommand[tables.Length];
			for (var i = 0; i < tables.Length; i++)
			{
				var table = tables[i];
				var cmd = CreateCommand(string.Format("select {0} from {1}",string.Join(",",table.AllColumns), table.Name) //TODO: Check this generates the query as intended
						//+ " ORDER BY " + table.PrimaryColumns[0].Name
						);
				//tables[i].QueryString, emptySqlTypeArr);
				m_selectCommands[i] = cmd;
			}
		}
Example #14
0
        public static void SaveCache(this LightDBMapper mapper)
        {
            string cacheFilename = mapper.GetCacheFilename();

            try
            {
                mapper.SaveCache(cacheFilename);
            }
            catch (Exception ex)
            {
                File.Delete(cacheFilename);
                LogUtil.ErrorException(ex, "Failed to save cache to file: " + cacheFilename, new object[0]);
            }
        }
Example #15
0
        public static void SaveCache(this LightDBMapper mapper)
        {
            // save cache after loading
            var file = GetCacheFilename(mapper);

            try
            {
                mapper.SaveCache(file);
            }
            catch (Exception e)
            {
                File.Delete(file);
                LogUtil.ErrorException(e, "Failed to save cache to file: " + file);
            }
        }
Example #16
0
        public static Dictionary <Type, LightDBMapper> CreateMappersByType()
        {
            Dictionary <Type, LightDBMapper> dictionary = new Dictionary <Type, LightDBMapper>();

            foreach (DataHolderTableMapping mapping in ContentMgr.s_definitions.Mappings)
            {
                LightDBMapper lightDbMapper = new LightDBMapper(mapping, (IDbWrapper) new NHibernateDbWrapper());
                foreach (DataHolderDefinition holderDefinition in mapping.DataHolderDefinitions)
                {
                    dictionary.Add(holderDefinition.Type, lightDbMapper);
                }
            }

            return(dictionary);
        }
Example #17
0
        public void Prepare(LightDBMapper mapper)
        {
            var tables = mapper.Mapping.TableDefinitions;

            m_selectCommands = new IDbCommand[tables.Length];
            for (var i = 0; i < tables.Length; i++)
            {
                var table = tables[i];
                var cmd   = CreateCommand(SqlUtil.BuildSelect(table.AllColumns, table.Name)
                                          //+ " ORDER BY " + table.PrimaryColumns[0].Name
                                          );
                //tables[i].QueryString, emptySqlTypeArr);
                m_selectCommands[i] = cmd;
            }
        }
Example #18
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);
        }
Example #19
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 = GetMapper(t);

            ServerApp <RealmServer> .IOQueue.ExecuteInContext(() => mapper.Flush());
        }
Example #20
0
        public static bool IsCached(this LightDBMapper mapper)
        {
            var file = GetCacheFilename(mapper);

            return(File.Exists(file));
        }
Example #21
0
 public static bool IsCached(this LightDBMapper mapper)
 {
     return(File.Exists(mapper.GetCacheFilename()));
 }
Example #22
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()));
        }
Example #23
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()));
        }
Example #24
0
 public static void Load(LightDBMapper mapper)
 {
     Load(mapper, true);
 }
Example #25
0
 public static void Load(LightDBMapper mapper)
 {
     ContentMgr.Load(mapper, true);
 }