Ejemplo n.º 1
0
        /// <summary>
        /// Dumps everything of a single type into the cache from the filesystem for BackingData
        /// </summary>
        /// <typeparam name="T">the type to get and store</typeparam>
        /// <returns>full or partial success</returns>
        public bool LoadAllCharactersForAccountToCache(string accountHandle)
        {
            string currentBackupDirectory = BaseDirectory + accountHandle + "/" + CurrentDirectoryName;

            //No current directory? WTF
            if (!VerifyDirectory(currentBackupDirectory, false))
            {
                return(false);
            }

            DirectoryInfo charDirectory = new DirectoryInfo(currentBackupDirectory);

            foreach (FileInfo file in charDirectory.EnumerateFiles("*.playertemplate", SearchOption.AllDirectories))
            {
                try
                {
                    byte[] fileData = ReadFile(file);
                    System.Runtime.Remoting.ObjectHandle blankEntity = Activator.CreateInstance("NetMud.Data", "NetMud.Data.Players.PlayerTemplate");

                    IPlayerTemplate objRef = blankEntity.Unwrap() as IPlayerTemplate;

                    IPlayerTemplate newChar = objRef.FromBytes(fileData) as IPlayerTemplate;

                    PlayerDataCache.Add(newChar);
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                    //Let it keep going
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Put it in the cache
        /// </summary>
        /// <returns>success status</returns>
        public override bool PersistToCache()
        {
            try
            {
                PlayerDataCache.Add(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex, LogChannels.SystemWarnings);
                return(false);
            }

            return(true);
        }