当前位置: 首页>>代码示例>>C#>>正文


C# CommittableTransaction.Commit方法代码示例

本文整理汇总了C#中System.Transactions.CommittableTransaction.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# CommittableTransaction.Commit方法的具体用法?C# CommittableTransaction.Commit怎么用?C# CommittableTransaction.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Transactions.CommittableTransaction的用法示例。


在下文中一共展示了CommittableTransaction.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessData

        public void ProcessData(int employeeId)
        {
            // There is not much processing logic here...
            // We are assuming that the organization has 50 employees with sequential Employee Ids
            // If the employeeId  > 50, we are sending an Http Status code of 500 (Internal Server Error) back to the client
            // else, we assume that the processing is successful and send an Http Status code of 200 (Successfull)
            ReceiveContext receiveContext;
            if (!ReceiveContext.TryGet(OperationContext.Current.IncomingMessageProperties, out receiveContext))
            {
                Console.WriteLine("ReceiveContext property was not found in the message...");
                return;
            }

            if (employeeId > 50)
            {
                // Abandon
                receiveContext.Abandon(TimeSpan.MaxValue);
            }
            else
            {
                // Complete in Transaction block.
                CommittableTransaction committableTransaction = new CommittableTransaction();
                Transaction.Current = committableTransaction;
                try
                {
                    receiveContext.Complete(TimeSpan.MaxValue);
                    committableTransaction.Commit();
                }
                catch
                {
                    committableTransaction.Rollback();
                    // If the transaction was not completed we call Abandon explicitly which sends an Http 500 to the client
                    receiveContext.Abandon(TimeSpan.MaxValue);
                }
            }
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:36,代码来源:ProcessEmployeeDataService.cs

示例2: ExplicitTransaction6

		public void ExplicitTransaction6 ()
		{
		    ExceptionAssert.Throws<InvalidOperationException>(
		        delegate
		            {
		                CommittableTransaction ct = new CommittableTransaction();

		                IntResourceManager irm = new IntResourceManager(1);
		                irm.Value = 2;
		                ct.Commit();

		                ct.Commit();
		            });
		}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:14,代码来源:TransactionScopeTest.cs

示例3: EnlistmentCounts_CommittableTransaction

		public void EnlistmentCounts_CommittableTransaction()
		{
			var newGuid = Guid.NewGuid();
			for (int i = 0; i < 5; i++)
			{
				using (var tx = new CommittableTransaction(new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted }))
				using (new TxScope(tx, NullLogger.Instance)) // set ambient also!
				{
					System.Transactions.Transaction.Current.EnlistDurable(newGuid, new EnlistmentTracking(), EnlistmentOptions.None);
					System.Transactions.Transaction.Current.EnlistDurable(newGuid, new EnlistmentTracking(), EnlistmentOptions.None);

					tx.Commit();
				}

				Assert.That(EnlistmentTracking.EnlistmentCounts, Is.EqualTo(0).Or.EqualTo(1).Or.EqualTo(2));
			}
		}
开发者ID:hammett,项目名称:Castle.Transactions,代码行数:17,代码来源:WhoStoleMyTransaction_TestCase.cs

示例4: Vol2_Dur1_Fail5

		public void Vol2_Dur1_Fail5 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager [] irm = new IntResourceManager [2];
			irm [0] = new IntResourceManager ( 1 );
			irm [1] = new IntResourceManager ( 3 );

			Transaction.Current = ct;
			irm [0].Type = ResourceManagerType.Durable;
			irm [0].FailSPC = true;
			irm [0].FailWithException = true;

			for ( int i = 0; i < 2; i++ )
				irm [i].UseSingle = true;

			/* Durable RM irm[2] does on SPC, so
			 * all volatile RMs get Rollback */
			
			using ( TransactionScope scope = new TransactionScope () ) {
				irm [0].Value = 2;
				irm [1].Value = 6;

				scope.Complete ();
			}

			try {
				ct.Commit ();
			}
			catch ( TransactionAbortedException e ) {
				Assert.IsNotNull ( e.InnerException, "Expected e.InnerException == NotSupportedException, but got None" );
				Assert.AreEqual ( typeof ( NotSupportedException ), e.InnerException.GetType (), "Expected e.InnerException == NotSupportedException, but got " + e.GetType () );

				irm [0].Check ( 1, 0, 0, 0, 0, 0, 0, "irm [0]" );
				irm [1].Check ( 0, 1, 0, 1, 0, 0, 0, "irm [1]" );
				try {
					ct.Commit ();
				}
				catch (InvalidOperationException x ) {
					Assert.IsNull ( x.InnerException);
					Transaction.Current = null;
					return;
				}
				Assert.Fail ( "Should not be reached" );
			}

			Assert.Fail ( "Expected TransactionAbortedException" );
		}
开发者ID:HarrievG,项目名称:mono,代码行数:47,代码来源:EnlistTest.cs

示例5: RetryOnFailure

		public void RetryOnFailure()
		{
			using (var t = new CommittableTransaction())
			using (new TxScope(t, NullLogger.Instance))
			{
				t.EnlistVolatile(new ThrowingResource(true), EnlistmentOptions.EnlistDuringPrepareRequired);

				using (var c = GetConnection())
				using (var cmd = c.CreateCommand())
				{
					cmd.CommandText = "SELECT TOP 1 Val FROM Thing";
					var scalar = (double)cmd.ExecuteScalar();
					Console.WriteLine("got val {0}", scalar);
				}

				try
				{
					t.Commit();
					Assert.Fail("first commit should fail");
				}
				catch (ApplicationException)
				{
					Assert.That(t.TransactionInformation.Status, Is.EqualTo(TransactionStatus.Committed));
				}
			}
		}
开发者ID:ols,项目名称:Castle.Facilities.NHibernate,代码行数:26,代码来源:ScratchBoard_LTM.cs

示例6: button84_Click

        private void button84_Click(object sender, EventArgs e)
        {
            CommittableTransaction tx = null;
            try
            {

                using (tx = new CommittableTransaction())
                {
                    using (SqlConnection conn1 = new SqlConnection(Properties.Settings.Default.NorthwindConnectionString))
                    {

                        using (SqlCommand myCommand = new SqlCommand())
                        {

                            myCommand.Connection = conn1;

                            conn1.Open();
                            conn1.EnlistTransaction(tx);


                            //Restore database to near it's original condition so sample will work correctly.
                            myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)";
                            myCommand.ExecuteNonQuery();

                            //Insert the first record.
                            myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')";
                            myCommand.ExecuteNonQuery();


                            //測試交易失敗用
                            //Insert the first record.
                            myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')";
                            myCommand.ExecuteNonQuery();


                            //Insert the second record.
                            myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')";
                            myCommand.ExecuteNonQuery();


                            tx.Commit();

                            MessageBox.Show("trans. Successfully");
                        }
                    }
                }

            }


            catch (TransactionException ex)
            {
                MessageBox.Show(ex.Message);
                tx.Rollback();
            }
            catch (Exception ex)
            {

                MessageBox.Show("trans. roll back " + ex.Message);
            }
        }
开发者ID:YiYingChuang,项目名称:ADO.NET,代码行数:61,代码来源:FrmConnected.cs

示例7: Delete

		public override int Delete(DataTable dt, string fname, DataColumnCollection colinfo)
		{
			int rlt = 0;
			string sqlmain = "delete from {0} ";
			string sqlwhere = " where {0} in ({1}) ";
			string sql, where, ids = "";
			LastException = null;
			foreach (DataRow row in dt.Rows)
			{
				if (dt.Columns.Contains(fname))
				{
					ids += "," + SqlHelper.MakeSafeFieldSql(row[fname].ToString(), colinfo[fname].ToString(), true);
				}
			}
			ids = ids.Substring(1);
			where = string.Format(sqlwhere, SqlHelper.MakeSafeFieldNameSql(fname), ids);
			sql = string.Format(sqlmain, SqlHelper.MakeSafeFieldNameSql(dt.TableName)) + where;
			Logger.Log(sql);
			CommittableTransaction ts = new CommittableTransaction();
			DbConnection conn = db.GetConnection();
			conn.Open();
			conn.EnlistTransaction(ts);
			ExecuteResult er = db.Execute(sql, conn, ts);
			rlt = er.IntRlt;
			if (er.Exception != null)
			{
				LastException = er.Exception;
				rlt = 0;
			}
			else
			{
				ts.Commit();
			}
			if (conn.State != ConnectionState.Closed)
			{
				conn.Close();
			}
			ts.Dispose();
			return rlt;
		}
开发者ID:mind0n,项目名称:hive,代码行数:40,代码来源:BulkOperation.cs

示例8: ExplicitTransaction2

		public void ExplicitTransaction2 ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");
			CommittableTransaction ct = new CommittableTransaction ();
			Transaction oldTransaction = Transaction.Current;

			Transaction.Current = ct;

			IntResourceManager irm = new IntResourceManager (1);

			irm.Value = 2;
			using (TransactionScope scope = new TransactionScope ()) {
				Assert.AreEqual (ct, Transaction.Current, "#44");

				/* Not calling scope.Complete
				scope.Complete ();*/
			}

			Assert.AreEqual (TransactionStatus.Aborted, ct.TransactionInformation.Status, "#45");
			Assert.AreEqual (ct, Transaction.Current, "#46");
			Assert.AreEqual (1, irm.Actual, "#47");
			Assert.AreEqual (1, irm.NumRollback, "#48");
			irm.Check ( 0, 0, 1, 0, "irm" );
			Transaction.Current = oldTransaction;

			try {
				ct.Commit ();
			} catch (TransactionAbortedException) {
				return;
			}
			Assert.Fail ("Commit on an aborted transaction should fail");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:32,代码来源:TransactionScopeTest.cs

示例9: ExplicitTransaction3

		public void ExplicitTransaction3 ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");
			CommittableTransaction ct = new CommittableTransaction ();
			Transaction oldTransaction = Transaction.Current;

			Transaction.Current = ct;

			IntResourceManager irm = new IntResourceManager (1);

			using (TransactionScope scope = new TransactionScope (TransactionScopeOption.RequiresNew)) {
				Assert.IsTrue (ct != Transaction.Current, "Scope with RequiresNew should have a new ambient transaction");

				irm.Value = 3;
				scope.Complete ();
			}

			irm.Value = 2;

			Assert.AreEqual (3, irm.Actual, "#50");

			Assert.AreEqual (ct, Transaction.Current, "#51");
			ct.Commit ();
			Assert.AreEqual (2, irm.Actual, "#52");
			Transaction.Current = oldTransaction;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:26,代码来源:TransactionScopeTest.cs

示例10: ExplicitTransactionCommit

		public void ExplicitTransactionCommit ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");

			CommittableTransaction ct = new CommittableTransaction ();
			Transaction oldTransaction = Transaction.Current;
			Transaction.Current = ct;

			IntResourceManager irm = new IntResourceManager (1);
			irm.Value = 2;
			ct.Commit ();

			Assert.AreEqual (2, irm.Value, "#33");
			Assert.AreEqual (TransactionStatus.Committed, ct.TransactionInformation.Status, "#34");
			Transaction.Current = oldTransaction;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:16,代码来源:TransactionScopeTest.cs

示例11: ExplicitTransaction1

		public void ExplicitTransaction1 ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");
			CommittableTransaction ct = new CommittableTransaction ();
			Transaction oldTransaction = Transaction.Current;

			Transaction.Current = ct;

			IntResourceManager irm = new IntResourceManager (1);

			irm.Value = 2;

			using (TransactionScope scope = new TransactionScope ()) {
				Assert.AreEqual (ct, Transaction.Current, "#38");
				irm.Value = 4;
				scope.Complete ();
			}

			Assert.AreEqual (ct, Transaction.Current, "#39");
			Assert.AreEqual (TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "#40");
			Assert.AreEqual (1, irm.Actual, "#41"); /* Actual value */

			ct.Commit ();
			Assert.AreEqual (4, irm.Actual, "#42"); /* New committed actual value */
			Assert.AreEqual (TransactionStatus.Committed, Transaction.Current.TransactionInformation.Status, "#43");
			Transaction.Current = oldTransaction;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:27,代码来源:TransactionScopeTest.cs

示例12: ExplicitTransaction16

		public void ExplicitTransaction16 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager irm0 = new IntResourceManager ( 3 );
			IntResourceManager irm = new IntResourceManager ( 1 );

			Assert.IsNull ( Transaction.Current );

			Transaction.Current = ct;

			irm.FailPrepare = true;
			irm.FailWithException = true;
			irm.Value = 2;
			irm0.Value = 6;

			try {
				ct.Commit ();
			} catch (TransactionAbortedException e) {
				Assert.IsNotNull ( e.InnerException, "Expected an InnerException of type NotSupportedException" );
				Assert.AreEqual ( typeof (NotSupportedException), e.InnerException.GetType (), "Inner exception should be NotSupportedException" );
				irm.Check ( 1, 0, 0, 0, "irm" );
				irm0.Check ( 0, 0, 1, 0, "irm0" );
				Transaction.Current = null;
				return;
			}
			 
			Assert.Fail ( "Should not be reached" );
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:28,代码来源:TransactionScopeTest.cs

示例13: Learn

        public void Learn(Stream words)
        {
            var wordStream = new WordStream(words);
            LinkedList<string> wordHistory = new LinkedList<string>();
            for (int i = 0; i < 4; i++)
            {
                wordHistory.AddLast(String.Empty);
            }
            foreach (var word in wordStream)
            {
                using (var transaction = new CommittableTransaction())
                {
                    wordHistory.RemoveFirst();
                    wordHistory.AddLast(word);

                    HandleWord(word);
                    HandleTwoGram(wordHistory.AsEnumerable().Skip(2).Take(2).ToList());
                    var gram = HandleThreeGram(wordHistory.AsEnumerable().Skip(1).Take(3).ToList());
                    HandleFourGram(wordHistory.AsEnumerable().ToList(), gram);

                    context.SaveChanges();
                    transaction.Commit();
                }
            }
        }
开发者ID:bladespinner,项目名称:AI-Course-Project,代码行数:25,代码来源:EntityLearner.cs

示例14: ExplicitTransaction6a

		public void ExplicitTransaction6a ()
		{
		    ExceptionAssert.Throws<InvalidOperationException>(
		        delegate
		            {
		                CommittableTransaction ct = new CommittableTransaction();

		                IntResourceManager irm = new IntResourceManager(1);
		                irm.Value = 2;
		                ct.Commit();

		                /* Using a already committed transaction in a new 
                         * TransactionScope
                         */
		                TransactionScope scope = new TransactionScope(ct);
		            });
		}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:17,代码来源:TransactionScopeTest.cs

示例15: ExplicitTransaction13

		public void ExplicitTransaction13 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager irm = new IntResourceManager ( 1 );

			Assert.IsNull ( Transaction.Current );
			Transaction.Current = ct;
			irm.Value = 2;
			irm.FailPrepare = true;

			try {
				ct.Commit ();
			} catch ( TransactionAbortedException ) {
				Assert.AreEqual ( TransactionStatus.Aborted, ct.TransactionInformation.Status );
				try {
					ct.BeginCommit ( null, null );
				} catch (Exception) {
					Transaction.Current = null;
					return;
				}
				Assert.Fail ( "Should not be reached(2)" );
			}
			Assert.Fail ("Should not be reached");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:24,代码来源:TransactionScopeTest.cs


注:本文中的System.Transactions.CommittableTransaction.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。