コード例 #1
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        internal static void Save(DBMS database = Settings.Database)
        {
            Alliances.ForEach(alliance =>
            {
                try
                {
                    Alliances.Save(alliance, database);
                }
                catch (Exception)
                {
                    Debugger.Debug($"Did not succeed in saving alliance [{alliance}].");
                }
            });

            Debugger.Info($"Saved {Alliances.Count} alliances.");
        }
コード例 #2
0
        /// <summary>
        /// Removes the specified alliance.
        /// </summary>
        internal static void Remove(Alliance alliance)
        {
            if (Alliances.Pool.ContainsKey(alliance.Identifier))
            {
                if (!Alliances.Pool.TryRemove(alliance.Identifier, out Alliance tmpAlliance))
                {
                    Debugger.Error("Unsuccessfully removed the specified alliance from the dictionary.");
                }
                else
                {
                    if (!tmpAlliance.Equals(alliance))
                    {
                        Debugger.Error("Successfully removed a alliance from the list but the returned alliance was not equal to our alliance.");
                    }
                }
            }

            Alliances.Save(alliance);
        }
コード例 #3
0
        internal static void Delete(Alliance alliance, DBMS database = Settings.Database)
        {
            Alliances.Remove(alliance);

            switch (database)
            {
            case DBMS.Mongo:
            {
                AllianceDb.Delete(alliance.HighID, alliance.LowID).GetAwaiter().GetResult();
                break;
            }

            case DBMS.File:
            {
                new FileInfo($"{Directory.GetCurrentDirectory()}/Saves/Alliances/{alliance.HighID}-{alliance.LowID}.json").DeleteIfExists();
                break;
            }
            }

            Alliances.Save();
        }