コード例 #1
0
        private static Task RunInsertOption(InsertToTableOption insertOption)
        {
            var connectionString = insertOption.SqlConnectionString;
            var table            = insertOption.TableName;
            var csvFileName      = insertOption.StatFilePath;
            var sqlClient        = new SqlClient(connectionString);

            sqlClient.Open();
            try
            {
                sqlClient.CreateTableIfNotExist(table);
                int insertSucc = 0;
                foreach (var stat in LoadReportRecords.GetReportRecords(csvFileName))
                {
                    var ts = stat.Timestamp;
                    var id = Convert.ToInt64(ts);
                    var dt = Utils.ConvertFromTimestamp(ts);
                    insertSucc += sqlClient.InsertRecord(
                        table,
                        $"{id}{stat.Scenario}",
                        dt,
                        stat.Scenario,
                        stat.Unit(),
                        stat.Connections,
                        stat.Sends,
                        stat.SendTPuts,
                        stat.RecvTPuts,
                        stat.Reference);
                }
                Console.WriteLine($"Finally successfully insert {insertSucc}");
            }
            finally
            {
                sqlClient.Close();
            }
            return(Task.CompletedTask);
        }
コード例 #2
0
        private static Task CreateTableOption(CreateTableOption createTableOption)
        {
            var connectionString = createTableOption.SqlConnectionString;
            var table            = createTableOption.TableName;
            var sqlClient        = new SqlClient(connectionString);

            sqlClient.Open();
            try
            {
                if (createTableOption.TableType == 1)
                {
                    sqlClient.CreateTableIfNotExist(table, SqlClient.CommandsToCreateTable);
                }
                else if (createTableOption.TableType == 2)
                {
                    sqlClient.CreateTableIfNotExist(table, SqlClient.CommandsToCreateConnStatTable);
                }
            }
            finally
            {
                sqlClient.Close();
            }
            return(Task.CompletedTask);
        }