Beispiel #1
0
        private ILog log = null;         // Initialise this somewhere...

        /// <summary>
        ///
        /// </summary>
        /// <param name="dataSet"></param>
        public void UpdateCustomDetails(CustomDataSet dataSet)
        {
            IDbConnection connection = new System.Data.SqlClient.SqlConnection(/* Connection string goes here*/);

            Library.TransactionWrapper transactionWrapper = new Library.TransactionWrapper(connection);

            // Hook the data onto the operation parameters
            CustomDataUpdate             customDataUpdate = new CustomDataUpdate(this.log);
            CustomTransactionedOperation operation        = new CustomTransactionedOperation(dataSet);

            operation.Execute += new Library.TransactionedOperationDelegate(customDataUpdate.UpdateData);

            transactionWrapper.MakeAtomic(operation);
        }
Beispiel #2
0
        public override void UpdateData(Library.TransactionWrapper sender, Library.TransactionArgs args)
        {
            CustomTransactionedOperation operation = args.Operation as CustomTransactionedOperation;

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.Transaction = args.Transaction as System.Data.SqlClient.SqlTransaction;
            sqlCommand.Connection  = args.Connection as System.Data.SqlClient.SqlConnection;

            sqlCommand.CommandText = operation.Example; /* Some suitable text here */

            sqlCommand.ExecuteNonQuery();               // TODO: note the number of rows affected and publish via an event

            base.UpdateData(sender, args);
        }
Beispiel #3
0
        /// <summary>
        /// Performs multiple updates in a single transaction, with disparate (but presumably related) data.
        /// </summary>
        /// <param name="dataSet1">first data set</param>
        /// <param name="dataSet2">second data set</param>
        public void UpdateMultipleDetails(CustomDataSet dataSet1, SpecialDataSet dataSet2)
        {
            // Prepare the connection
            IDbConnection connection = new System.Data.SqlClient.SqlConnection(/* Connection string goes here*/);

            Library.TransactionWrapper transactionWrapper = new Library.TransactionWrapper(connection);

            // Hook data for first operation
            CustomDataUpdate             customDataUpdate = new CustomDataUpdate(this.log);
            CustomTransactionedOperation operation1       = new CustomTransactionedOperation(dataSet1);

            operation1.Execute += new Library.TransactionedOperationDelegate(customDataUpdate.UpdateData);

            // Hook data for second operation
            AggregateTransactionedOperation operation2 = new AggregateTransactionedOperation(dataSet2);

            operation2.Execute += new Library.TransactionedOperationDelegate(AggregateTransactionedOperation.SelfContainedUpdateData);

            // Collect together the operations and make them atomic
            Library.TransactionedOperation[] operations = new Library.TransactionedOperation[] { operation1, operation2 };
            transactionWrapper.MakeAtomic(operations);
        }