Ejemplo n.º 1
0
        public static void GlobalDataInit()
        {
            //获取数据库路径
            string DBPath = SugarUtils.GetDataDBPath(SugarUtils.GlobalResDBName);

            Log.Debug("IO", $"获取数据路径{DBPath}");
            //检擦文件是否存在
            IOUtils.CheckFileExists(DBPath);
            //创建数据库链接
            SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);

            try
            {
                if (!SugarUtils.TableExists <RediveDBVersion>(dbClient))
                {
                    Log.Warning("数据库初始化", "未找到版本记录表 - 创建一个新表");
                    SugarUtils.CreateTable <RediveDBVersion>(dbClient);
                }

                if (!SugarUtils.TableExists <PCRChara>(dbClient))
                {
                    Log.Warning("数据库初始化", "未找到角色资源表 - 创建一个新表");
                    SugarUtils.CreateTable <PCRChara>(dbClient);
                }
            }
            catch (Exception e)
            {
                Log.Fatal("数据库初始化错误", Log.ErrorLogBuilder(e));
                Thread.Sleep(5000);
                Environment.Exit(-1);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <param name="eventArgs">CQAppEnableEventArgs</param>
        public static void Init(ConnectEventArgs eventArgs)
        {
            string DBPath = SugarUtils.GetDBPath(eventArgs.LoginUid.ToString());

            ConsoleLog.Debug("IO", $"获取数据路径{DBPath}");
            if (!File.Exists(DBPath))//查找数据文件
            {
                //数据库文件不存在,新建数据库
                ConsoleLog.Warning("数据库初始化", "未找到数据库文件,创建新的数据库");
                Directory.CreateDirectory(Path.GetPathRoot(DBPath) ?? String.Empty);
                File.Create(DBPath).Close();
            }
            SqlSugarClient dbClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString      = $"DATA SOURCE={DBPath}",
                DbType                = DbType.Sqlite,
                IsAutoCloseConnection = true,
                InitKeyType           = InitKeyType.Attribute
            });

            try
            {
                if (!SugarUtils.TableExists <SuiseiData>(dbClient)) //彗酱数据库初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到慧酱数据表 - 创建一个新表");
                    SugarUtils.CreateTable <SuiseiData>(dbClient);
                }
                if (!SugarUtils.TableExists <MemberInfo>(dbClient)) //成员状态表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到成员状态表 - 创建一个新表");
                    SugarUtils.CreateTable <MemberInfo>(dbClient);
                }
                if (!SugarUtils.TableExists <BiliSubscription>(dbClient)) //动态记录表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到动态记录表 - 创建一个新表");
                    SugarUtils.CreateTable <BiliSubscription>(dbClient);
                }
                if (!SugarUtils.TableExists <GuildBattleBoss>(dbClient)) //会战数据表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到会战数据表 - 创建一个新表");
                    SugarUtils.CreateTable <GuildBattleBoss>(dbClient);
                    //写入初始化数据
                    dbClient.Insertable(GuildBattleBoss.GetInitBossInfos()).ExecuteCommand();
                }
                if (!SugarUtils.TableExists <GuildInfo>(dbClient)) //会战状态表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到会战状态表 - 创建一个新表");
                    SugarUtils.CreateTable <GuildInfo>(dbClient);
                }
            }
            catch (Exception exception)
            {
                ConsoleLog.Fatal("数据库初始化错误", ConsoleLog.ErrorLogBuilder(exception));
                Thread.Sleep(5000);
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <param name="e">CQAppEnableEventArgs</param>
        public static void Init(CQAppEnableEventArgs e)
        {
            string DBPath = SugarUtils.GetDBPath(e.CQApi.GetLoginQQ().Id.ToString());

            ConsoleLog.Info("IO", $"获取数据路径{DBPath}");
            if (!File.Exists(DBPath))//查找数据文件
            {
                //数据库文件不存在,新建数据库
                ConsoleLog.Warning("数据库初始化", "未找到数据库文件,创建新的数据库");
                Directory.CreateDirectory(Path.GetPathRoot(DBPath));
                File.Create(DBPath).Close();
            }
            SqlSugarClient dbClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString      = $"DATA SOURCE={DBPath}",
                DbType                = DbType.Sqlite,
                IsAutoCloseConnection = true,
                InitKeyType           = InitKeyType.Attribute
            });

            if (!SugarUtils.TableExists <SuiseiData>(dbClient)) //彗酱数据库初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到慧酱数据表 - 创建一个新表");
                SugarUtils.CreateTable <SuiseiData>(dbClient);
            }
            if (!SugarUtils.TableExists <GuildData>(dbClient)) //公会数据库初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到公会表数据表 - 创建一个新表");
                SugarUtils.CreateTable <GuildData>(dbClient);
            }
            if (!SugarUtils.TableExists <MemberData>(dbClient)) //公会成员数据库初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到成员表数据表 - 创建一个新表");
                SugarUtils.CreateTable <MemberData>(dbClient);
            }
            if (!SugarUtils.TableExists <MemberStatus>(dbClient))//成员状态表的初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到成员状态表 - 创建一个新表");
                SugarUtils.CreateTable <MemberStatus>(dbClient);
            }
            if (!SugarUtils.TableExists <BossInfo>(dbClient))//Boss信息表的初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到Boss信息表 - 创建一个新表");
                SugarUtils.CreateTable <BossInfo>(dbClient);
            }
            if (!SugarUtils.TableExists <BiliSubscription>(dbClient)) //动态记录表的初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到动态记录表 - 创建一个新表");
                SugarUtils.CreateTable <BiliSubscription>(dbClient);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 开始会战
 /// </summary>
 /// <returns>
 /// <para><see langword="1"/> 成功开始统计</para>
 /// <para><see langword="0"/> 未结束会战</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int StartBattle(GuildInfo guildInfo)
 {
     try
     {
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (SugarUtils.TableExists <GuildBattle>(dbClient, BattleTableName))
         {
             ConsoleLog.Error("会战管理数据库", "会战表已经存在,请检查是否未结束上次会战统计");
             return(0);
         }
         else
         {
             SugarUtils.CreateTable <GuildBattle>(dbClient, BattleTableName);
             ConsoleLog.Info("会战管理数据库", "开始新的一期会战统计");
             dbClient.Updateable(new GuildInfo {
                 InBattle = true
             })
             .Where(guild => guild.Gid == GuildEventArgs.SourceGroup.Id)
             .UpdateColumns(i => new { i.InBattle })
             .ExecuteCommandHasChange();
             //获取初始周目boss的信息
             GuildBattleBoss initBossData = dbClient.Queryable <GuildBattleBoss>()
                                            .Where(i => i.ServerId == guildInfo.ServerId &&
                                                   i.Phase == 1 &&
                                                   i.Order == 1)
                                            .First();
             GuildInfo updateBossData =
                 new GuildInfo()
             {
                 BossPhase = initBossData.Phase,
                 Order     = 1,
                 Round     = 1,
                 HP        = initBossData.HP,
                 TotalHP   = initBossData.HP
             };
             return(dbClient.Updateable(updateBossData)
                    .UpdateColumns(i => new { i.Order, i.HP, i.BossPhase, i.Round, i.TotalHP })
                    .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id)
                    .ExecuteCommandHasChange()
                 ? 1
                 : -1);
         }
     }
     catch (Exception e)
     {
         ConsoleLog.Error("Database error", ConsoleLog.ErrorLogBuilder(e));
         return(-1);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <param name="eventArgs">CQAppEnableEventArgs</param>
        public static void UserDataInit(ConnectEventArgs eventArgs)
        {
            string DBPath = SugarUtils.GetDBPath(eventArgs.LoginUid.ToString());

            Log.Debug("IO", $"获取用户数据路径{DBPath}");
            //检查文件是否存在
            IOUtils.CheckFileExists(DBPath);
            //创建数据库链接
            SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);

            try
            {
                if (!SugarUtils.TableExists <MemberInfo>(dbClient)) //成员状态表的初始化
                {
                    Log.Warning("数据库初始化", "未找到成员状态表 - 创建一个新表");
                    SugarUtils.CreateTable <MemberInfo>(dbClient);
                }

                if (!SugarUtils.TableExists <BiliDynamicSubscription>(dbClient)) //动态记录表的初始化
                {
                    Log.Warning("数据库初始化", "未找到动态订阅表 - 创建一个新表");
                    SugarUtils.CreateTable <BiliDynamicSubscription>(dbClient);
                }

                if (!SugarUtils.TableExists <GuildBattleBoss>(dbClient)) //会战数据表的初始化
                {
                    Log.Warning("数据库初始化", "未找到会战数据表 - 创建一个新表");
                    SugarUtils.CreateTable <GuildBattleBoss>(dbClient);
                }

                if (!SugarUtils.TableExists <BiliLiveSubscription>(dbClient))
                {
                    Log.Warning("数据库初始化", "未找到直播订阅表 - 创建一个新表");
                    SugarUtils.CreateTable <BiliLiveSubscription>(dbClient);
                }

                if (!SugarUtils.TableExists <GuildInfo>(dbClient)) //会战状态表的初始化
                {
                    Log.Warning("数据库初始化", "未找到会战状态表 - 创建一个新表");
                    SugarUtils.CreateTable <GuildInfo>(dbClient);
                }
            }
            catch (Exception exception)
            {
                Log.Fatal("数据库初始化错误", Log.ErrorLogBuilder(exception));
                Thread.Sleep(5000);
                Environment.Exit(-1);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 开始会战
        /// </summary>
        /// <returns>
        /// <para><see langword="1"/> 成功开始统计</para>
        /// <para><see langword="0"/> 未结束会战</para>
        /// <para><see langword="-1"/> 数据库错误</para>
        /// </returns>
        public int StartBattle(GuildInfo guildInfo)
        {
            try
            {
                using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
                if (SugarUtils.TableExists <GuildBattle>(dbClient, BattleTableName))
                {
                    Log.Error("会战管理数据库", "会战表已经存在,请检查是否未结束上次会战统计");
                    return(0);
                }

                SugarUtils.CreateTable <GuildBattle>(dbClient, BattleTableName);
                Log.Info("会战管理数据库", "开始新的一期会战统计");
                dbClient.Updateable <GuildInfo>()
                .SetColumns(i => new GuildInfo {
                    InBattle = true
                })
                .Where(guild => guild.Gid == guildInfo.Gid)
                .ExecuteCommandHasChange();
                //获取初始周目boss的信息
                var initBossData = dbClient.Queryable <GuildBattleBoss>()
                                   .Where(i => i.ServerId == guildInfo.ServerId &&
                                          i.Phase == 1 &&
                                          i.Order == 1)
                                   .First();
                return(dbClient.Updateable <GuildInfo>()
                       .SetColumns(i => new GuildInfo()
                {
                    BossPhase = initBossData.Phase,
                    Order = 1,
                    Round = 1,
                    HP = initBossData.HP,
                    TotalHP = initBossData.HP
                })
                       .Where(i => i.Gid == guildInfo.Gid)
                       .ExecuteCommandHasChange()
                    ? 1
                    : -1);
            }
            catch (Exception e)
            {
                Log.Error("Database error", Log.ErrorLogBuilder(e));
                return(-1);
            }
        }
Ejemplo n.º 7
0
 public int StartBattle()
 {
     using (SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath))
     {
         if (SugarUtils.TableExists <GuildBattle>(dbClient,
                                                  $"{SugarTableUtils.GetTableName<GuildBattle>()}_{GroupId}"))
         {
             ConsoleLog.Error("会战管理数据库", "会战表已经存在检查是否未结束上次会战统计");
             return(-1);
         }
         else
         {
             SugarUtils.CreateTable <GuildBattle>(dbClient,
                                                  $"{SugarTableUtils.GetTableName<GuildBattle>()}_{GroupId}");
             ConsoleLog.Info("会战管理数据库", "开始新的一期会战统计");
             return(0);
         }
     }
 }