コード例 #1
0
        /// <summary>
        /// Writes everything in the cache back to the file system
        /// </summary>
        /// <returns>full or partial success</returns>
        public static bool WriteFullBackup(string backupName = "")
        {
            DataAccess.FileSystem.ConfigData fileAccessor = new DataAccess.FileSystem.ConfigData();

            try
            {
                LoggingUtility.Log("World BackingData backup to current INITIATED.", LogChannels.Backup, true);

                if (!string.IsNullOrWhiteSpace(backupName))
                {
                    fileAccessor.ArchiveFull(ConfigDataType.Dictionary, backupName);
                }

                fileAccessor.ArchiveFull(ConfigDataType.Language, backupName);

                LoggingUtility.Log("Entire backing data set archived.", LogChannels.Backup, true);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
コード例 #2
0
        private void GetNotifications(DataAccess.FileSystem.ConfigData dataAccessor, DirectoryInfo charDirectory)
        {
            try
            {
                IEnumerable <FileInfo> files = charDirectory.EnumerateFiles("*.PlayerMessage", SearchOption.TopDirectoryOnly);

                List <IPlayerMessage> dataList = new List <IPlayerMessage>();
                foreach (FileInfo file in files)
                {
                    if (file == null)
                    {
                        continue;
                    }

                    IPlayerMessage newMessage = (IPlayerMessage)dataAccessor.ReadEntity(file, typeof(IPlayerMessage));

                    if (newMessage != null)
                    {
                        ConfigDataCache.Add(newMessage);
                        dataList.Add(newMessage);
                    }
                }

                Notifications = dataList;
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                //Let it keep going
            }
        }
コード例 #3
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 static bool LoadAllToCache(Type objectType)
        {
            if (!objectType.GetInterfaces().Contains(typeof(IConfigData)))
            {
                return(false);
            }

            DataAccess.FileSystem.ConfigData fileAccessor = new DataAccess.FileSystem.ConfigData();
            string typeDirectory = fileAccessor.GetCurrentDirectoryForType(objectType);

            if (!fileAccessor.VerifyDirectory(typeDirectory, false))
            {
                return(false);
            }

            DirectoryInfo filesDirectory = new DirectoryInfo(typeDirectory);

            foreach (FileInfo file in filesDirectory.EnumerateFiles("*." + objectType.Name))
            {
                try
                {
                    ConfigDataCache.Add(fileAccessor.ReadEntity(file, objectType));
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                    //Let it keep going
                }
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Update the field data for this object to the db
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool SystemSave()
        {
            DataAccess.FileSystem.ConfigData accessor = new DataAccess.FileSystem.ConfigData();

            try
            {
                if (string.IsNullOrWhiteSpace(CreatorHandle))
                {
                    CreatorHandle = DataHelpers.SystemUserHandle;
                }

                //only able to edit its own crap
                if (CreatorHandle != DataHelpers.SystemUserHandle)
                {
                    return(false);
                }

                State          = ApprovalState.Approved;
                ApproverHandle = DataHelpers.SystemUserHandle;
                ApprovedOn     = DateTime.Now;
                ApproverRank   = StaffRank.Builder;

                PersistToCache();
                accessor.WriteEntity(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Remove this object from the db permenantly
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool Remove(IAccount remover, StaffRank rank)
        {
            DataAccess.FileSystem.ConfigData accessor = new DataAccess.FileSystem.ConfigData();

            try
            {
                //Not allowed to remove stuff you didn't make unless you're an admin, TODO: Make this more nuanced for guilds
                if (rank < StaffRank.Admin && !remover.Equals(Creator))
                {
                    return(false);
                }

                //Remove from cache first
                ConfigDataCache.Remove(new ConfigDataCacheKey(this));

                //Remove it from the file system.
                accessor.RemoveEntity(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Update the field data for this object to the db
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool Save(IAccount editor, StaffRank rank)
        {
            DataAccess.FileSystem.ConfigData accessor = new DataAccess.FileSystem.ConfigData();

            try
            {
                //Not allowed to edit stuff you didn't make unless you're an admin, TODO: Make this more nuanced for guilds
                if (ApprovalType != ContentApprovalType.None && rank < StaffRank.Admin && !editor.Equals(Creator))
                {
                    return(false);
                }

                //Disapprove of things first
                State      = ApprovalState.Pending;
                ApprovedBy = null;
                ApprovedOn = DateTime.MinValue;

                //Figure out automated approvals, always throw reviewonly in there
                if (rank < StaffRank.Admin && ApprovalType != ContentApprovalType.ReviewOnly)
                {
                    switch (ApprovalType)
                    {
                    case ContentApprovalType.None:
                        ApproveMe(editor, rank);
                        break;

                    case ContentApprovalType.Leader:
                        if (rank == StaffRank.Builder)
                        {
                            ApproveMe(editor, rank);
                        }

                        break;
                    }
                }
                else
                {
                    //Staff Admin always get approved
                    ApproveMe(editor, rank);
                }

                if (Creator == null)
                {
                    Creator     = editor;
                    CreatorRank = rank;
                }

                PersistToCache();
                accessor.WriteEntity(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
コード例 #7
0
        /// <summary>
        /// Change the approval status of this thing
        /// </summary>
        /// <returns>success</returns>
        public bool ChangeApprovalStatus(IAccount approver, StaffRank rank, ApprovalState newState)
        {
            //Can't approve/deny your own stuff
            if (rank < StaffRank.Admin && Creator.Equals(approver))
            {
                return(false);
            }

            DataAccess.FileSystem.ConfigData accessor = new DataAccess.FileSystem.ConfigData();
            ApproveMe(approver, rank, newState);

            PersistToCache();
            accessor.WriteEntity(this);

            return(true);
        }
コード例 #8
0
        /// <summary>
        /// Remove this object from the db permenantly
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool SystemRemove()
        {
            DataAccess.FileSystem.ConfigData accessor = new DataAccess.FileSystem.ConfigData();

            try
            {
                //Remove from cache first
                ConfigDataCache.Remove(new ConfigDataCacheKey(this));

                //Remove it from the file system.
                accessor.RemoveEntity(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
コード例 #9
0
        public bool RestoreConfig(IAccount account)
        {
            if (account == null)
            {
                return(false);
            }

            if (_account == null)
            {
                _account = account;
            }

            DataAccess.FileSystem.ConfigData configData = new DataAccess.FileSystem.ConfigData();

            string directory = configData.GetCurrentDirectoryForEntity(this);

            DirectoryInfo  charDirectory = new DirectoryInfo(directory);
            IAccountConfig newConfig     = null;

            try
            {
                FileInfo file = charDirectory.EnumerateFiles("*.AccountConfig", SearchOption.TopDirectoryOnly).FirstOrDefault();

                if (file == null)
                {
                    return(false);
                }

                newConfig = (IAccountConfig)configData.ReadEntity(file, GetType());
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                //Let it keep going
            }

            if (newConfig != null)
            {
                UITutorialMode   = newConfig.UITutorialMode;
                GossipSubscriber = newConfig.GossipSubscriber;
                SoundMuted       = newConfig.SoundMuted;
                MusicMuted       = newConfig.MusicMuted;
                UILanguage       = newConfig.UILanguage;

                GetNotifications(configData, charDirectory);

                if (newConfig.Playlists == null)
                {
                    Playlists = new HashSet <IPlaylist>();
                }
                else
                {
                    Playlists = newConfig.Playlists;
                }

                if (newConfig.Acquaintences == null)
                {
                    Acquaintences = Enumerable.Empty <IAcquaintence>();
                }
                else
                {
                    Acquaintences = newConfig.Acquaintences;
                }

                if (newConfig.Combos == null)
                {
                    Combos = Enumerable.Empty <IFightingArtCombination>();
                }
                else
                {
                    Combos = newConfig.Combos;
                }

                if (newConfig.UIModules == null)
                {
                    UIModules = Enumerable.Empty <Tuple <IUIModule, int> >();
                }
                else
                {
                    UIModules = newConfig.UIModules;
                }

                ConfigDataCache.Add(this);

                return(true);
            }

            return(false);
        }