Exemplo n.º 1
0
        public async Task <bool> RemoveAlliance(long id)
        {
            try
            {
                if (!ContainsKey(id))
                {
                    return(true);
                }

                var alliance = this[id];

                alliance.Timer.Stop();

                if (Redis.IsConnected)
                {
                    await Redis.CacheAlliance(alliance);
                }

                await AllianceDb.Save(alliance);

                return(TryRemove(id, out var value));
            }
            catch (Exception exception)
            {
                Logger.Log(exception, Enums.LogType.Error);
                return(false);
            }
        }
Exemplo n.º 2
0
        public async void SaveCallback(object state, ElapsedEventArgs args)
        {
            if (Redis.IsConnected)
            {
                await Redis.CacheAlliance(this);
            }

            await AllianceDb.Save(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the specified alliance in the specified database.
        /// </summary>
        internal static void Save(Alliance alliance, DBMS database = Settings.Database)
        {
            if (alliance != null)
            {
                switch (database)
                {
                case DBMS.Mongo:
                {
                    AllianceDb.Save(alliance).GetAwaiter().GetResult();
                    break;
                }

                case DBMS.File:
                {
                    new FileInfo($"{Directory.GetCurrentDirectory()}/Saves/Alliances/{alliance}.json").WriteAllText(JsonConvert.SerializeObject(alliance, AllianceDb.JsonSettings));
                    break;
                }
                }
            }
        }