Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var fsql = new FreeSql.FreeSqlBuilder()
                       .UseConnectionString(FreeSql.DataType.Sqlite, "data source=task.db;max pool size=5")
                       .UseAutoSyncStructure(true)
                       .UseNoneCommandParameter(true)
                       .UseMonitorCommand(cmd => Console.WriteLine($"=========sql: {cmd.CommandText}\r\n"))
                       .Build();

            Scheduler scheduler = new Scheduler(new MyTaskHandler(fsql));

            var dt = DateTime.Now;

            for (var a = 0; a < 2; a++)
            {
                //临时任务
                scheduler.AddTempTask(TimeSpan.FromSeconds(20), () =>
                {
                    Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] 20秒后被执行,还剩 {scheduler.QuantityTempTask} 个临时任务");
                });

                //循环任务,执行10次,每次间隔10秒
                scheduler.AddTask(topic: "test001", body: "data1", round: 10, seconds: 10);
            }
            var dtts = DateTime.Now.Subtract(dt).TotalMilliseconds;

            Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] 注册耗时 {dtts}ms,共计 {scheduler.QuantityTempTask} 个临时任务,{scheduler.QuantityTask} 个循环任务");

            Console.ReadKey();

            dtts = DateTime.Now.Subtract(dt).TotalMilliseconds;
            Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] 耗时 {dtts}ms,还剩 {scheduler.QuantityTempTask} 个任务,{scheduler.QuantityTask} 个循环任务");
            scheduler.Dispose();
            fsql.Dispose();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取服务器数据库
        /// </summary>
        /// <param name="sqlconnect"></param>
        /// <returns></returns>
        private ActionResult ServerDbList(SqlConnect sqlconnect)
        {
            PageResponse reponse = new PageResponse();

            try
            {
                IFreeSql fsql = new FreeSql.FreeSqlBuilder()
                                .UseConnectionString(sqlconnect.SqlType, sqlconnect.Address)
                                .Build();
                var dbs = fsql.DbFirst.GetDatabases();
                fsql.Dispose();
                if (!string.IsNullOrEmpty(sqlconnect.DbName))
                {
                    dbs = dbs.Where(p => p == sqlconnect.DbName).ToList();
                }
                List <TableConfig> list_table = new List <TableConfig>();
                foreach (var name in dbs)
                {
                    TableConfig tableConfig = new TableConfig()
                    {
                        Id        = Guid.NewGuid().ToString(),
                        TableName = name
                    };
                    list_table.Add(tableConfig);
                }
                return(Response(list_table, list_table.Count()));
            }
            catch (Exception ex)
            {
                return(Response(ex));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 生成种子数据
        /// </summary>
        public void GenerateSeedData()
        {
            IFreeSql fsql = new FreeSql.FreeSqlBuilder()
                            .UseConnectionString(FreeSql.DataType.MySql, "Server=localhost; Port=3306; Database=Tenant1db; Uid=root; Pwd=000000; Charset=utf8mb4;")
                            .Build();

            var sysApiEntities                  = fsql.GetRepository <SysApiEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysConditionEntities            = fsql.GetRepository <SysConditionEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysDictionaryDetailEntities     = fsql.GetRepository <SysDictionaryDetailEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysDictionaryEntities           = fsql.GetRepository <SysDictionaryEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysGroupEntities                = fsql.GetRepository <SysGroupEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysPermissionEntities           = fsql.GetRepository <SysPermissionEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysResourceEntities             = fsql.GetRepository <SysResourceEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysRoleEntities                 = fsql.GetRepository <SysRoleEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysRPermissionConditionEntities = fsql.GetRepository <SysRPermissionConditionEntity>().Select.ToList();
            var SysRPermissionGroupEntities     = fsql.GetRepository <SysRPermissionGroupEntity>().Select.ToList();
            var SysRPermissionRoleEntities      = fsql.GetRepository <SysRPermissionRoleEntity>().Select.ToList();
            var SysRResourceApiEntities         = fsql.GetRepository <SysRResourceApiEntity>().Select.ToList();
            var SysRRoleResourceEntities        = fsql.GetRepository <SysRRoleResourceEntity>().Select.ToList();
            var SysSettingEntities              = fsql.GetRepository <SysSettingEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysUserEntities                 = fsql.GetRepository <SysUserEntity>().Select.Where(x => x.IsDeleted == false).ToList();

            SeedDataEntity seedDataEntity = new SeedDataEntity()
            {
                SysApiEntities                  = sysApiEntities,
                SysConditionEntities            = SysConditionEntities,
                SysDictionaryDetailEntities     = SysDictionaryDetailEntities,
                SysDictionaryEntities           = SysDictionaryEntities,
                SysGroupEntities                = SysGroupEntities,
                SysPermissionEntities           = SysPermissionEntities,
                SysResourceEntities             = SysResourceEntities,
                SysRoleEntities                 = SysRoleEntities,
                SysRPermissionConditionEntities = SysRPermissionConditionEntities,
                SysRPermissionGroupEntities     = SysRPermissionGroupEntities,
                SysRPermissionRoleEntities      = SysRPermissionRoleEntities,
                SysRResourceApiEntities         = SysRResourceApiEntities,
                SysRRoleResourceEntities        = SysRRoleResourceEntities,
                SysSettingEntities              = SysSettingEntities,
                SysUserEntities                 = SysUserEntities
            };


            WriteSeedData(seedDataEntity);


            fsql.Dispose();
        }
Exemplo n.º 4
0
        public async Task <JsonResult> GetDbTable(string id, string dbName)
        {
            PageResponse reponse    = new PageResponse();
            var          sqlconnect = _sqliteFreeSql.Select <SqlConnect>().Where(p => p.Id == id).ToOne();

            IFreeSql fsql = new FreeSql.FreeSqlBuilder()
                            .UseConnectionString(sqlconnect.SqlType, sqlconnect.Address)
                            .Build();
            var db = fsql.DbFirst.GetTablesByDatabase(dbName);

            fsql.Dispose();
            List <TableConfig> list_table = new List <TableConfig>();

            foreach (var table in db)
            {
                TableConfig tableConfig = new TableConfig()
                {
                    Id           = Guid.NewGuid().ToString(),
                    TableName    = table.Name,
                    ColumnConfig = new List <ColumnConfig>()
                };
                foreach (var column in table.Columns)
                {
                    tableConfig.ColumnConfig.Add(new ColumnConfig()
                    {
                        ColumnName = column.Name,
                        CsType     = column.CsType.ToString(),
                        Remark     = column.Coment
                    });
                }
                list_table.Add(tableConfig);
            }
            reponse.code   = "200";
            reponse.data   = list_table;
            reponse.status = 0;
            reponse.total  = list_table.Count();
            return(Json(reponse));
        }