本文整理汇总了C#中System.Transactions.TransactionScope.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# TransactionScope.Complete方法的具体用法?C# TransactionScope.Complete怎么用?C# TransactionScope.Complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Transactions.TransactionScope
的用法示例。
在下文中一共展示了TransactionScope.Complete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GuardarAsignaciones
public void GuardarAsignaciones(IList<int> ordenesVenta, IList<Usuario> asistentes)
{
try
{
var transactionOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted };
using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
foreach (var idOrdenVenta in ordenesVenta)
{
var ordenVenta = _orderVentaDA.ObtenerPorID(idOrdenVenta);
var asistenteConMenorCarga = asistentes.OrderBy(p => p.CantidadOV).FirstOrDefault();
if (asistenteConMenorCarga != null)
{
asistenteConMenorCarga.CantidadOV++;
ordenVenta.Estado = Constantes.EstadoOrdenVenta.Asignado;
ordenVenta.AsistentePlaneamiento = asistenteConMenorCarga;
_orderVentaDA.AsignarAsistentePlaneamiento(ordenVenta);
}
}
transactionScope.Complete();
}
}
catch (Exception ex)
{
throw ThrowException(ex, MethodBase.GetCurrentMethod().Name);
}
}
示例2: TransactionScopeCompleted3
public void TransactionScopeCompleted3 ()
{
using (TransactionScope scope = new TransactionScope ()) {
scope.Complete ();
scope.Complete ();
}
}
示例3: SetCost
/// <summary>
/// ���Ŀ����ǰ��ɣ�����ǰ������Ͳ����ˡ�
/// </summary>
/// <param name="productSysNo">��Ʒ���</param>
/// <param name="hereQty">��������</param>
/// <param name="hereCost">���γɱ�</param>
public void SetCost(int productSysNo, int hereQty, decimal hereCost)
{
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = TransactionManager.DefaultTimeout;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
{
//��ȡ����Ʒ�ĵ�ǰ�ɱ�
InventoryManager.GetInstance().InitInventory(productSysNo);
InventoryInfo oInv = InventoryManager.GetInstance().LoadInventory(productSysNo);
ProductPriceInfo oPrice = ProductManager.GetInstance().LoadPrice(productSysNo);
int curQty = oInv.AccountQty;
decimal curCost = oPrice.UnitCost;
//�����ǰ�ɱ����ڱ��γɱ����ø�����
if (curCost == hereCost)
{
scope.Complete();
return;
}
decimal newCost = AppConst.DecimalNull;
//�������Ϊ�����������ijɱ�Ϊ�����ñ��γɱ�����
if ( curQty + hereQty == 0 )
newCost = hereCost;
else
{
newCost = Decimal.Round( (curQty*curCost + hereQty*hereCost) / ( curQty+hereQty)*1.0M, 2);
if ( newCost < 0 )
newCost = hereCost;
}
//�������������Ҳ���ø���
if (newCost == curCost)
{
scope.Complete();
return;
}
if ( newCost == AppConst.DecimalNull )
throw new BizException("calc cost error");
//���³ɱ������ݿ�
if ( 1!=new ProductPriceDac().UpdateCost(productSysNo, newCost))
throw new BizException("expected one-row update failed, cancel verify failed ");
scope.Complete();
}
}
示例4: HandleError
public static void HandleError(MsmqPoisonMessageException error)
{
ProcessorQueue processorQueue = (ProcessorQueue)error.Data["processorQueue"];
MessageQueue poisonQueue = new System.Messaging.MessageQueue(processorQueue.PoisonQueue);
MessageQueue errorQueue = new System.Messaging.MessageQueue(processorQueue.ErrorQueue);
using (TransactionScope txScope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
try
{
// Send the message to the poison and error message queues.
poisonQueue.Send((IWorkflowMessage)error.Data["message"], MessageQueueTransactionType.Automatic);
errorQueue.Send((WorkflowErrorMessage)error.Data["errorMessage"], MessageQueueTransactionType.Automatic);
txScope.Complete();
}
catch (InvalidOperationException)
{
}
finally
{
poisonQueue.Dispose();
errorQueue.Dispose();
}
}
}
开发者ID:invertedsoftware,项目名称:Inverted-Software-Workflow-Engine,代码行数:26,代码来源:QueueOperationsHandler.cs
示例5: Raven_dtc_bug
public void Raven_dtc_bug()
{
new MessageQueue(QueueAddress, QueueAccessMode.ReceiveAndAdmin)
.Purge();
using (var tx = new TransactionScope())
{
using (var session = store.OpenSession())
{
session.Store(new GatewayMessage());
session.SaveChanges();
}
using (var q = new MessageQueue(QueueAddress, QueueAccessMode.Send))
{
var toSend = new Message { BodyStream = new MemoryStream(new byte[8]) };
//sending a message to a msmq queue causes raven to promote the tx
q.Send(toSend, MessageQueueTransactionType.Automatic);
}
//when we complete raven commits it tx but the DTC tx is never commited and eventually times out
tx.Complete();
}
Thread.Sleep(1000);
Assert.AreEqual(1,new MessageQueue(QueueAddress, QueueAccessMode.ReceiveAndAdmin)
.GetAllMessages().Length);
}
示例6: MessageQueuedForReceive_EventIsRaised
public void MessageQueuedForReceive_EventIsRaised()
{
using (var sender = SetupSender())
using (var receiver = SetupReciever())
{
receiver.MessageQueuedForReceive += RecordMessageEvent;
using (var tx = new TransactionScope())
{
sender.Send(
new Uri("file://localhost/h"),
new MessagePayload
{
Data = new byte[] { 1, 2, 4, 5 }
});
tx.Complete();
}
while (_messageEventCount == 0)
Thread.Sleep(100);
receiver.MessageQueuedForReceive -= RecordMessageEvent;
}
Assert.NotNull(_messageEventArgs);
Assert.Equal("h", _messageEventArgs.Message.Queue);
}
示例7: add
/// <summary>
/// add number
/// </summary>
/// <param name="_code"></param>
/// <param name="_newVal"></param>
public void add(string _code, string _newVal)
{
LTDHDataContext DB = new LTDHDataContext(@strPathDB);
try
{
using (TransactionScope ts = new TransactionScope())
{
var r = DB.tblStatistics.Single(p => p.Code == _code);
long oldVal = long.Parse(r.Value);
long newVal = long.Parse(_newVal);
if (oldVal > 0 || newVal > 0)
{
oldVal += newVal;
}
r.Value = oldVal.ToString();
DB.SubmitChanges();
ts.Complete();
}
}
catch (Exception e)
{
log.writeLog(DBHelper.strPathLogFile, e.Message
+ CommonConstants.NEWLINE
+ e.Source
+ CommonConstants.NEWLINE
+ e.StackTrace
+ CommonConstants.NEWLINE
+ e.HelpLink);
}
}
示例8: list_video
private static void list_video()
{
using (TransactionScope transactionScope = new TransactionScope())
{
SqlConnection sqlConnection = connect_database();
using (SqlCommand command = new SqlCommand())
{
command.Connection = sqlConnection;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = String.Format("SELECT PkId,Id,Description FROM {0}", table_name);
try
{
SqlDataReader reader = command.ExecuteReader();
Console.WriteLine("\n List Video in Database");
Console.WriteLine("==============================");
while (reader.Read())
{
Console.WriteLine("ID: {0}, Name : {1}, Identifier : {2}", reader.GetValue(0), reader.GetValue(2), reader.GetValue(1));
}
Console.WriteLine("============================== \n");
}
catch (Exception e)
{
Console.WriteLine("{0}", e);
}
}
disconnect_database(sqlConnection);
transactionScope.Complete();
}
}
示例9: AddUserToGroup
static bool AddUserToGroup(string userName, string groupName)
{
using (UsersGroupsEntities context = new UsersGroupsEntities())
{
using (TransactionScope scope = new TransactionScope())
{
if (!context.Groups.Where(g => g.Name == groupName).Any())
{
context.Groups.Add(new Group() { Name = groupName });
context.SaveChanges();
}
Group groupToAddIn = context.Groups.Where(g => g.Name == groupName).First();
if (groupToAddIn.Users.Where(u => u.Name == userName).Any())
{
scope.Dispose();
return false;
}
else
{
User newUser = new User() { Name = userName };
groupToAddIn.Users.Add(newUser);
context.SaveChanges();
scope.Complete();
return true;
}
}
}
}
示例10: CambiarVersionActualRubrica
public ActionResult CambiarVersionActualRubrica(String RubricaId, String Version, String TipoArtefacto)
{
try
{
using (TransactionScope scope = new TransactionScope())
{
var Actuales = RubricOnRepositoryFactory.GetVersionesRubricasRepository().GetWhere(x => x.RubricaId == RubricaId && x.TipoArtefacto == TipoArtefacto && x.EsActual == true);
foreach (var actual in Actuales)
actual.EsActual = false;
RubricOnRepositoryFactory.GetVersionesRubricasRepository().Update(Actuales);
RubricOnRepositoryFactory.SubmitChanges(true);
var VersionActual = RubricOnRepositoryFactory.GetVersionesRubricasRepository().GetOne(RubricaId, TipoArtefacto, Version);
VersionActual.EsActual = true;
RubricOnRepositoryFactory.GetVersionesRubricasRepository().Update(VersionActual);
RubricOnRepositoryFactory.SubmitChanges(true);
scope.Complete();
PostMessage("La version actual ha sido cambiada exitosamente.", MessageType.Success);
}
}
catch (Exception ex)
{
PostMessage("Ha ocurrido un error.", MessageType.Error);
}
return RedirectToAction("ListarVersionesRubrica", new { RubricaId = RubricaId, TipoArtefacto = TipoArtefacto });
}
示例11: DtcCommitWillGiveOldResult
public void DtcCommitWillGiveOldResult()
{
using(var documentStore = NewDocumentStore())
{
using(var s = documentStore.OpenSession())
{
s.Store(new AccurateCount.User{ Name = "Ayende"});
s.SaveChanges();
}
using (var s = documentStore.OpenSession())
using (var scope = new TransactionScope())
{
var user = s.Load<AccurateCount.User>("users/1");
user.Name = "Rahien";
s.SaveChanges();
scope.Complete();
}
using (var s = documentStore.OpenSession())
{
var user = s.Load<AccurateCount.User>("users/1");
Assert.Equal("Ayende", user.Name);
}
}
}
示例12: MakeSureThatWeDoNotHaveTimeoutExceptionDueToStaleIndexes
public void MakeSureThatWeDoNotHaveTimeoutExceptionDueToStaleIndexes()
{
// This must run on ESENT to expose the failure
using (var store = NewRemoteDocumentStore(databaseName: "Test", requestedStorage: "esent"))
{
for (var i = 1; i < 10; i++)
{
try
{
using (var scope = new TransactionScope())
using (var session = store.OpenSession())
{
session.Store(new Foo {Bar = "aaa"});
session.SaveChanges();
scope.Complete();
}
using (var session = store.OpenSession())
{
var count = session.Query<Foo>()
.Customize(customization => customization.WaitForNonStaleResultsAsOfNow(TimeSpan.FromSeconds(5)))
.Count();
Assert.Equal(i, count);
}
}
catch (Exception)
{
Console.WriteLine(i);
throw;
}
}
}
}
开发者ID:925coder,项目名称:ravendb,代码行数:34,代码来源:WhenUsingDtcWeMustMakeSureToUpdateTheIndexingAboutNewWorkSoWeWontHaveInfiniteStaleIndexes.cs
示例13: SendsMessageOnlyWhenTransactionScopeIsCompleted
public async Task SendsMessageOnlyWhenTransactionScopeIsCompleted(bool completeTheScope, bool throwException, bool expectToReceiveMessage)
{
var gotMessage = false;
_activator.Handle<string>(async str => gotMessage = true);
try
{
using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
scope.EnlistRebus();
await _bus.SendLocal("hallå i stuen!1");
if (throwException)
{
throw new ApplicationException("omg what is this?????");
}
if (completeTheScope)
{
scope.Complete();
}
}
}
catch(ApplicationException exception) when (exception.Message == "omg what is this?????")
{
Console.WriteLine("An exception occurred... quite expected though");
}
await Task.Delay(1000);
Assert.That(gotMessage, Is.EqualTo(expectToReceiveMessage), "Must receive message IFF the tx scope is completed");
}
示例14: CreateCustomer
public void CreateCustomer(Customer customer)
{
using (TransactionScope scope = new TransactionScope())
{
try
{
Log.Info($"Criando um novo usuário com o CPF {customer.CPF}");
if (this.ExistsCustomer(customer))
throw new Exception($"CPF {customer.CPF} já cadastrado");
var userId = Guid.NewGuid();
customer.Id = userId;
customer.Password = Infra.Utils.SecurityUtils.HashSHA1(customer.Password);
this.customerRepository.Save(customer);
if (!this.Login(customer.Email, customer.Password, true, false))
throw new Exception("Usuário não cadastrado, por favor tente mais tarde");
}
catch (Exception ex)
{
Log.Error(ex.Message, ex);
this.LogOut();
throw;
}
finally
{
Log.Info($"Finalizando a criação de um novo usuário com o CPF {customer.CPF}");
scope.Complete();
}
}
}
示例15: GermanString
public void GermanString()
{
UInt64 id = 0;
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = new VelocityDbSchema.Person();
person.LastName = "Med vänliga hälsningar";
id = session.Persist(person);
trans.Complete();
}
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
person.LastName = "Mit freundlichen Grüßen";
trans.Complete();
}
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
person.LastName = "Med vänliga hälsningar";
trans.Complete();
}
}
}