Tiraggo.Interfaces.tgTransactionScope.Complete C# (CSharp) Method

Complete() public method

You must call Complete to commit the transaction. Calls and transactions can be nested, only the final outer call to Complete will commit the transaction.
public Complete ( ) : void
return void
        public void Complete()
        {
            this.root.count--;

            if (this.root == this && this.root.count == 0 && this.option != tgTransactionScopeOption.Suppress)
            {
                foreach (Transaction tx in this.root.transactions.Values)
                {
                    IDbConnection cn = tx.sqlTx.Connection;

                    tx.sqlTx.Commit();

                    tx.sqlTx.Dispose();
                    tx.sqlTx = null;

                    if (cn != null && cn.State == ConnectionState.Open)
                    {
                        cn.Close();
                    }

                    tx.sqlCn = null;
                }

                this.root.transactions.Clear();

                if (this.commitList != null)
                {
                    foreach (ICommittable commit in this.commitList)
                    {
                        commit.Commit();
                    }

                    commitList.Clear();
                }
            }
        }

Usage Example

Exemplo n.º 1
0
        private static DataTable SaveDynamicCollection(tgDataRequest request)
        {
            if (request.CollectionSavePacket == null) return null;

            using (tgTransactionScope scope = new tgTransactionScope())
            {
                NpgsqlCommand cmd = null;
                bool exception = false;

                foreach (tgEntitySavePacket packet in request.CollectionSavePacket)
                {
                    exception = false;
                    cmd = null;

                    switch (packet.RowState)
                    {
                        case tgDataRowState.Added:
                            cmd = Shared.BuildDynamicInsertCommand(request, packet);
                            break;

                        case tgDataRowState.Modified:
                            cmd = Shared.BuildDynamicUpdateCommand(request, packet);
                            break;

                        case tgDataRowState.Deleted:
                            cmd = Shared.BuildDynamicDeleteCommand(request, packet);
                            break;

                        case tgDataRowState.Unchanged:
                            continue;
                    }

                    try
                    {
                        tgTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);
                        int count;

                        #region Profiling

                        if (sTraceHandler != null)
                        {
                            using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "SaveCollectionDynamic", System.Environment.StackTrace))
                            {
                                try
                                {
                                    count = cmd.ExecuteNonQuery(); ;
                                }
                                catch (Exception ex)
                                {
                                    esTrace.Exception = ex.Message;
                                    throw;
                                }
                            }
                        }
                        else

                        #endregion Profiling

                        {
                            count = cmd.ExecuteNonQuery();
                        }

                        if (count < 1)
                        {
                            throw new tgConcurrencyException("Update failed to update any records");
                        }
                    }
                    catch (Exception ex)
                    {
                        exception = true;

                        request.FireOnError(packet, ex.Message);

                        if (!request.ContinueUpdateOnError)
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        tgTransactionScope.DeEnlist(cmd);
                        cmd.Dispose();
                    }

                    if (!exception && packet.RowState != tgDataRowState.Deleted && cmd.Parameters != null)
                    {
                        foreach (NpgsqlParameter param in cmd.Parameters)
                        {
                            switch (param.Direction)
                            {
                                case ParameterDirection.Output:
                                case ParameterDirection.InputOutput:

                                    packet.CurrentValues[param.SourceColumn] = param.Value;
                                    break;
                            }
                        }
                    }
                }

                scope.Complete();
            }

            return null;
        }
All Usage Examples Of Tiraggo.Interfaces.tgTransactionScope::Complete