예제 #1
0
        private async Task InternalClientProcess(MonitorReport report, int clientNumber, CancellationToken token)
        {
            string agentName = $"Client_{clientNumber}";

            using (var monitor = new MonitorRate(report, agentName))
            {
                while (!token.IsCancellationRequested)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add("Id", typeof(int));
                    dt.Columns.Add("Variable", typeof(int));
                    dt.Columns.Add("Description", typeof(string));

                    foreach (int index in Enumerable.Range(0, _options.BatchSize))
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        int id  = Interlocked.Increment(ref _idCounter);
                        var row = new Row2(id);
                        dt.Rows.Add(row.Id, row.Variable, row.Description);
                    }

                    using (var conn = new SqlConnection(_configuration.SqlConnectionString))
                    {
                        conn.Open();

                        using (var bulkCopy = new SqlBulkCopy(_configuration.SqlConnectionString))
                        {
                            bulkCopy.DestinationTableName = "[App].[Import2]";
                            await bulkCopy.WriteToServerAsync(dt, token);
                        }
                    }

                    monitor.IncrementBatch();
                    monitor.IncrementNew(dt.Rows.Count);
                }
            }
        }
        private async Task InternalClientProcess(MonitorReport report, int clientNumber, CancellationToken token)
        {
            string agentName = $"Client_{clientNumber}";

            var itemList = new List <Row>();

            using (var monitor = new MonitorRate(report, agentName))
            {
                while (!token.IsCancellationRequested)
                {
                    foreach (int index in Enumerable.Range(0, _options.BatchSize))
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        int id = Interlocked.Increment(ref _idCounter);
                        itemList.Add(new Row(id));
                    }

                    using (var conn = new SqlConnection(_configuration.SqlConnectionString))
                    {
                        conn.Open();

                        using (var bulkCopy = new SqlBulkCopy(_configuration.SqlConnectionString))
                        {
                            bulkCopy.DestinationTableName = "[App].[Import]";
                            var dataReader = new DataReader(itemList);
                            await bulkCopy.WriteToServerAsync(dataReader, token);
                        }
                    }

                    monitor.IncrementBatch();
                    monitor.IncrementNew(itemList.Count);

                    itemList.Clear();
                }
            }
        }
예제 #3
0
        private async Task InternalClientProcess(MonitorReport report, int clientNumber, CancellationToken token)
        {
            string agentName = $"Client_{clientNumber}";
            var    table     = new SqlTableParameter <Row>("items", "[dbo].[ImportList]");

            table.ColumnDefinitions.Add(new SqlColumnDefintion <Row>(nameof(Row.Id), SqlDbType.Int, x => x.Id));
            table.ColumnDefinitions.Add(new SqlColumnDefintion <Row>(nameof(Row.Variable), SqlDbType.Variant, x => x.Variable));
            table.ColumnDefinitions.Add(new SqlColumnDefintion <Row>(nameof(Row.Description), SqlDbType.NVarChar, x => x.Description, 50));

            using (var monitor = new MonitorRate(report, agentName))
            {
                while (!token.IsCancellationRequested)
                {
                    foreach (int index in Enumerable.Range(0, _options.BatchSize))
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        int id = Interlocked.Increment(ref _idCounter);
                        table.Items.Add(new Row(id));
                    }

                    await new SqlExec(_configuration)
                    .SetCommand("[App].[InsertIntoImport]", CommandType.StoredProcedure)
                    .AddParameter(table)
                    .ExecuteNonQuery();

                    monitor.IncrementBatch();
                    monitor.IncrementNew(table.Items.Count);

                    table.Items.Clear();
                }
            }
        }