NetMud.DataAccess.FileSystem.PlayerData.WriteOnePlayer C# (CSharp) Method

WriteOnePlayer() public method

Writes one player out to disk
public WriteOnePlayer ( IPlayer entity ) : bool
entity IPlayer
return bool
        public bool WriteOnePlayer(IPlayer entity)
        {
            var playersDir = BaseDirectory;

            if (!VerifyDirectory(playersDir))
                throw new Exception("Players directory unable to be verified or created during full backup.");

            LoggingUtility.Log("Backing up player character " + entity.DataTemplateId + ".", LogChannels.Backup, true);

            try
            {
                var charData = entity.DataTemplate<ICharacter>();

                var currentDirName = playersDir + charData.AccountHandle + "/" + CurrentDirectoryName + charData.ID + "/";
                var archiveDirName = playersDir + charData.AccountHandle + "/" + ArchiveDirectoryName + charData.ID + "/";

                //Wipe out the existing one so we can create all new files
                if (VerifyDirectory(currentDirName, false))
                {
                    var currentRoot = new DirectoryInfo(currentDirName);

                    if (!VerifyDirectory(archiveDirName))
                        return false;

                    //move is literal move, no need to delete afterwards
                    currentRoot.MoveTo(archiveDirName + DatedBackupDirectory);
                }

                DirectoryInfo entityDirectory = Directory.CreateDirectory(currentDirName);

                WritePlayer(entityDirectory, entity);
                WriteCharacter(charData);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return false;
            }

            return true;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb = new List<string>();

            var player = (Player)Actor;

            sb.Add("You save your life.");

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, null, null, OriginLocation, null);

            var playerDataWrapper = new PlayerData();

            //Save the player out
            playerDataWrapper.WriteOnePlayer(player);
        }
All Usage Examples Of NetMud.DataAccess.FileSystem.PlayerData::WriteOnePlayer