Exemplo n.º 1
0
        /// <summary>
        ///     Inserts the records from the supplied data reader using supplied connection
        /// </summary>
        /// <param name="reader">records to insert via data reader</param>
        /// <param name="mappingStrategy">column mapping for bulk insert</param>
        /// <param name="sqlConnection">existing sql connection to use</param>
        private void Insert(IDataReader reader, BulkInsertMappingStrategy mappingStrategy, SqlConnection sqlConnection)
        {
            Arguments.NotNull(reader, nameof(reader));
            Arguments.NotNull(mappingStrategy, nameof(mappingStrategy));
            Arguments.NotNull(sqlConnection, nameof(sqlConnection));

            var transactionId = FormattableString.Invariant($"{this.Configuration.Destination} - {Guid.NewGuid()}");

            if (transactionId.Length > 32)
            {
#if NETSTANDARD2_0
                transactionId = transactionId.Substring(0, 32);
#else
                transactionId = transactionId[..32];
Exemplo n.º 2
0
        /// <summary>
        ///     Inserts the records from the supplied data reader
        /// </summary>
        /// <param name="reader">records to insert via data reader</param>
        /// <param name="mappingStrategy">column mapping for bulk insert</param>
        public void Insert(IDataReader reader, BulkInsertMappingStrategy mappingStrategy)
        {
            Arguments.NotNull(reader, nameof(reader));
            Arguments.NotNull(mappingStrategy, nameof(mappingStrategy));

            this.ThrowIfDisposed();

            using var sqlConnection = new SqlConnection
                  {
                      ConnectionString = this.Configuration.SqlConnection.ConnectionString,
                  };

            sqlConnection.InfoMessage += (sender, args) => { this.Logger.Info("InfoMessage - Sender:{0} Args.Message:{1} Args.Source:{2} Args.Errors:{3}", sender, args.Message, args.Source, args.Errors); };

            sqlConnection.Disposed += (sender, args) => { this.Logger.Info("Disposed - Sender:{0}", sender); };

            sqlConnection.StateChange += (sender, args) => { this.Logger.Info("StateChange - Sender:{0} Args.OriginalState:{1} => Args.CurrentState:{2}", sender, args.OriginalState, args.CurrentState); };

            sqlConnection.Open();

            this.Insert(reader, mappingStrategy, sqlConnection);
        }