private void tsb_deleteLink_Click(object sender, EventArgs e)
        {
            if (dgv_dbLink.SelectedRows.Count == 0)
            {
                MessageBox.Show("请选择要修改的记录!");

                return;
            }

            if (MessageBox.Show("确认要删除这条记录吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            string[] array = { _linkDt.Rows[dgv_dbLink.SelectedRows[0].Index]["数据源代码"].ToString() };

            DBConfigHelper helper = new DBConfigHelper();

            if (helper.DeleteSourceDatabaseConfig(array) > 0)
            {
                MessageBox.Show("删除成功!");
            }
            else
            {
                MessageBox.Show("删除失败!");
            }
        }
示例#2
0
        public static IWebHostBuilder CreateHostBuilder(string[] args)
        {
            var environment    = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var appSettingJson = environment == Environments.Development ? $"appsettings.json" : "appsettings.json";

            var config = new ConfigurationBuilder().AddJsonFile(appSettingJson).Build();

            var webSettings = new WebHostSettingHelper();

            config.GetSection("WebHostSettings").Bind(webSettings);

            var appConfig = new AppConfigHelper();

            config.GetSection("AppConfig").Bind(appConfig);

            var dbConfig = new DBConfigHelper();

            config.GetSection("DBConfig").Bind(dbConfig);

            ServicePointManager.Expect100Continue      = false;
            ServicePointManager.DefaultConnectionLimit = int.MaxValue;
            ServicePointManager.UseNagleAlgorithm      = false;
            ServicePointManager.DnsRefreshTimeout      = 60 * 10 * 1000;

            AppConfigHelper.ApiUrl = webSettings.Urls;

            var host = new WebHostBuilder()
                       .UseKestrel(
                o =>
            {
                o.Limits.KeepAliveTimeout         = TimeSpan.FromMinutes(1);
                o.Limits.RequestHeadersTimeout    = TimeSpan.FromSeconds(30);
                o.Limits.MaxConcurrentConnections = webSettings.MaxConcurrentConnections;
                o.AllowSynchronousIO = true;
            })
                       .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath);

                config.AddJsonFile(appSettingJson);
                config.AddEnvironmentVariables(prefix: "ASPNETCORE_");
            })
                       .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddConsole(c =>
                {
                    c.TimestampFormat = "[HH:mm:ss.fff] ";
                });
            })
                       .UseStartup <Startup>()
                       .UseIIS()
                       .UseIISIntegration()
                       .UseUrls(webSettings.Urls);

            return(host);
        }
示例#3
0
        public void ConfigureServices(IServiceCollection services)
        {
            var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: false).Build();

            var webSettings = new DBConfigHelper();

            config.GetSection("DBConfig").Bind(webSettings);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddDbContext <BaseDbContext>(options => options.UseSqlServer(GetConnectionString(), b => b.MigrationsAssembly("MigrationToolTest")));
        }
示例#4
0
        private void tsb_save_Click(object sender, EventArgs e)
        {
            if (!ValidateValue())
            {
                return;
            }

            DBConfigHelper helper = new DBConfigHelper();

            if (SettingDr == null)
            {
                string[] array = { cbb_conn.SelectedValue.ToString(), cbb_view.Text, txt_pollinginterval.Text, txt_pollingrecordcount.Text, txt_retrycount.Text, txt_retryinterval.Text, "0", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), cbb_column.Text, txt_initvalue.Text, cbb_type.SelectedIndex.ToString() };
                if (helper.InsertFlatViewPollConfig(array) > 0)
                {
                    MessageBox.Show("保存成功!");
                }
                else
                {
                    MessageBox.Show("保存失败!");
                }
            }
            else
            {
                string[] array = { cbb_conn.SelectedValue.ToString(), cbb_view.Text, txt_pollinginterval.Text, txt_pollingrecordcount.Text, txt_retrycount.Text, txt_retryinterval.Text, cbb_column.Text, txt_initvalue.Text, cbb_type.SelectedIndex.ToString(), SettingDr["编号"].ToString() };
                if (helper.UpdateFlatViewPollConfig(array) > 0)
                {
                    MessageBox.Show("保存成功!");
                }
                else
                {
                    MessageBox.Show("保存失败!");
                }
            }

            _main.BindSetting();
            Close();
        }
        private void tsb_save_Click(object sender, EventArgs e)
        {
            if (!ValidateData())
            {
                return;
            }

            if (!dbConnect.CheckValue())
            {
                return;
            }
            DataBaseClass dataBaseClass = (DataBaseClass)cbb_dbClass.SelectedIndex;
            string        conn          = string.Empty;

            switch (dataBaseClass)
            {
            case DataBaseClass.SqlServer:
                conn = $"data source={dbConnect._host};initial catalog={dbConnect._dbName};user id={dbConnect._userName};password={dbConnect._password};";
                break;

            case DataBaseClass.Oracle:
                conn = $"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={dbConnect._host})(PORT={dbConnect._port}))(CONNECT_DATA=(SERVICE_NAME={dbConnect._dbName})));Persist Security Info=True;user id={dbConnect._userName};password={dbConnect._password};";
                break;

            case DataBaseClass.Mysql:
                break;

            case DataBaseClass.MongoDB:
                break;

            case DataBaseClass.DB2:
                break;

            default:
                break;
            }

            //添加
            if (_linkDr == null)
            {
                string[] array = { txt_dbName.Text.Trim(), cbb_dbClass.SelectedIndex.ToString(), dbConnect._host, dbConnect._port, dbConnect._dbName, dbConnect._userName, dbConnect._password, "0", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), conn };

                DBConfigHelper helper = new DBConfigHelper();
                if (helper.InsertSourceDatabaseConfig(array) > 0)
                {
                    MessageBox.Show("保存成功!");
                }
                else
                {
                    MessageBox.Show("保存失败!");
                }
            }//修改
            else
            {
                string[] array = { txt_dbName.Text.Trim(), cbb_dbClass.SelectedIndex.ToString(), dbConnect._host, dbConnect._port, dbConnect._dbName, dbConnect._userName, dbConnect._password, "0", _linkDr["数据源添加时间"].ToString(), _linkDr["数据源代码"].ToString(), conn };

                DBConfigHelper helper = new DBConfigHelper();
                if (helper.UpdateSourceDatabaseConfig(array) > 0)
                {
                    MessageBox.Show("保存成功!");
                }
                else
                {
                    MessageBox.Show("保存失败!");
                }
            }


            _master.BindDGV();
            Close();
        }
示例#6
0
        /// <summary>
        /// 判断任务有无执行完成
        /// </summary>
        /// <param name="dr"></param>
        public void RunSingleTask(DataRow dr)
        {
            if (dr == null)
            {
                return;
            }
            string constraintValue = new DBConfigHelper().GetLastSyncNo(dr["TaskID"].ToString()); //最新的时间或者序号
            object obj             = GetMaxConstraintValue(dr, constraintValue);                  //当前要取数据的最大值

            int seqNo = 0;

            if (obj == null || string.IsNullOrEmpty(obj.ToString()) || (int.TryParse(constraintValue, out seqNo) && Convert.ToInt32(obj) <= Convert.ToInt32(constraintValue)))
            {
                Console.WriteLine($"{_jobName}暂时没有需要同步的记录!当前时间{DateTime.Now}");
                dr["Status"] = 0;
                return;
            }
            Console.WriteLine($"{_jobName}开始执行,当前时间{DateTime.Now}");
            ConstraintColumnType constrainType = (ConstraintColumnType)Convert.ToInt32(dr["ConstraintType"]);
            string        viewName             = dr["ViewName"].ToString();             //源数据库视图名称
            string        constraintColumnName = dr["ConstraintColumnName"].ToString(); //约束列名称
            string        conn          = dr["SourceConnString"].ToString();            //源数据库连接字符串
            string        batchCount    = dr["BatchCount"].ToString();                  //批量处理记录数或者间隔
            int           reTryCount    = Convert.ToInt32(dr["ReTryCount"]);            //重试次数
            int           reTryInterval = Convert.ToInt32(dr["ReTryInterval"]);         //重试间隔
            DataBaseClass databaseClass = (DataBaseClass)Convert.ToInt32(dr["SourceType"]);

            StringBuilder builder = new StringBuilder();

            builder.Append("select * from ");
            builder.Append(viewName);

            switch (constrainType)
            {
            case ConstraintColumnType.日期时间列:
                builder.Append(" where ");
                builder.Append(constraintColumnName);
                builder.Append(">");
                builder.Append(FillStringBuilder(databaseClass, constraintValue));
                builder.Append(" and ");
                builder.Append(constraintColumnName);
                builder.Append("<=");
                _endSyncNo = Convert.ToDateTime(obj).ToString("yyyy-MM-dd HH:mm:ss:fff");
                builder.Append(FillStringBuilder(databaseClass, _endSyncNo));
                break;

            case ConstraintColumnType.自增长列:
                builder.Append(" where ");
                builder.Append(constraintColumnName);
                builder.Append(">");
                builder.Append(constraintValue);
                builder.Append(" and ");
                builder.Append(constraintColumnName);
                builder.Append("<=");
                int count = Convert.ToInt32(constraintValue) + Convert.ToInt32(batchCount);
                if (count > Convert.ToInt32(obj))
                {
                    count = Convert.ToInt32(obj);
                }
                _endSyncNo = count.ToString();
                builder.Append(count);
                break;

            default:
                break;
            }

            string sql = builder.ToString();

            SqlHelper helper = new SqlHelper(conn, databaseClass);

            DataTable dt = null;

            for (int i = 0; i < reTryCount; i++)
            {
                if (dt == null)
                {
                    try
                    {
                        dt = helper.GetData(sql);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Thread.Sleep(reTryInterval);
                    }
                }
            }

            BulkCopy(dt);

            UpdateConfig(dr);

            //修改为未执行状态
            dr["Status"] = 0;


            Console.WriteLine($"{_jobName}执行结束,当前时间{DateTime.Now}");
        }