private void PushServiceDomain(Transaction newCurrent) { if (((newCurrent == null) || !newCurrent.Equals(ContextUtil.SystemTransaction)) && ((newCurrent != null) || (ContextUtil.SystemTransaction != null))) { ServiceConfig cfg = new ServiceConfig(); try { if (newCurrent != null) { cfg.Synchronization = SynchronizationOption.RequiresNew; ServiceDomain.Enter(cfg); this.createdDoubleServiceDomain = true; cfg.Synchronization = SynchronizationOption.Required; cfg.BringYourOwnSystemTransaction = newCurrent; } ServiceDomain.Enter(cfg); this.createdServiceDomain = true; } catch (COMException exception) { if (System.Transactions.Oletx.NativeMethods.XACT_E_NOTRANSACTION == exception.ErrorCode) { throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceBase"), System.Transactions.SR.GetString("TransactionAlreadyOver"), exception); } throw TransactionException.Create(System.Transactions.SR.GetString("TraceSourceBase"), exception.Message, exception); } finally { if (!this.createdServiceDomain && this.createdDoubleServiceDomain) { ServiceDomain.Leave(); } } } }
public void Scheduling_Appointment_After_Clinic_Hours_Should_Fail() { //Arrange Setup(); var providerDomain = new ProviderDomain(new ProvidersRepository()); var patientDomain = new PatientDomain(new PatientsRepository()); var serviceDomain = new ServiceDomain(new ServicesRepository()); var appointmentDomain = new AppointmentsDomain(new AppointmentsRepository()); var savedProvider = providerDomain.GetProvider(1); var savedPatient = patientDomain.GetPatient(1); var savedService = serviceDomain.GetService(1); var appointment = new Appointment { Patient = savedPatient, Provider = savedProvider, Service = savedService, ReasonForVisit = "There's no place like home", RequestedAppointmentDate = DateTime.Parse("2000/01/01 16:00:01.000"), }; //Act var savedAppointment = appointmentDomain.SetAppointment(appointment); }
private void EnterTransactionContext() { if (++this.TransactionScopeCount == 1) { if (_logger.IsDebugEnabled) { _logger.Debug("Create a new ServiceConfig in ServiceDomain."); } ServiceConfig cfg = new ServiceConfig { TrackingEnabled = true, TrackingAppName = "iBATIS.NET", TrackingComponentName = "TransactionScope", TransactionDescription = "iBATIS.NET Distributed Transaction", Transaction = this.TransactionScopeOptions2TransactionOption(this._txScopeOptions), TransactionTimeout = this._txOptions.TimeOut.Seconds, IsolationLevel = this.IsolationLevel2TransactionIsolationLevel(this._txOptions.IsolationLevel) }; ServiceDomain.Enter(cfg); } this._closed = false; if (_logger.IsDebugEnabled) { _logger.Debug("Open TransactionScope :" + ContextUtil.ContextId); } }
public void Scheduling_Appointment_For_Underage_Patients_Should_Fail() { //Arrange Setup(); var providerDomain = new ProviderDomain(new ProvidersRepository()); var patientDomain = new PatientDomain(new PatientsRepository()); var serviceDomain = new ServiceDomain(new ServicesRepository()); var appointmentDomain = new AppointmentsDomain(new AppointmentsRepository()); var savedProvider = providerDomain.GetProvider(1); var savedService = serviceDomain.GetService(1); var underagePatient = new Patient { Age = 15, Name = "Lion" }; underagePatient = patientDomain.CreatePatient(underagePatient); var appointment = new Appointment { Patient = underagePatient, Provider = savedProvider, Service = savedService, ReasonForVisit = "There's no place like home", RequestedAppointmentDate = DateTime.Parse("2000/01/01 09:00:00.000"), }; //Act var savedAppointment = appointmentDomain.SetAppointment(appointment); }
public void Scheduling_Appointment_For_Unqualified_Provider_Should_Fail() { //Arrange Setup(); var providerDomain = new ProviderDomain(new ProvidersRepository()); var patientDomain = new PatientDomain(new PatientsRepository()); var serviceDomain = new ServiceDomain(new ServicesRepository()); var appointmentDomain = new AppointmentsDomain(new AppointmentsRepository()); var savedService = serviceDomain.GetService(1); var savedPatient = patientDomain.GetPatient(1); var unqualifiedProvider = new Provider { Name = "Dr Quack.", CertificationLevel = 1 }; unqualifiedProvider = providerDomain.CreateProvider(unqualifiedProvider); var appointment = new Appointment { Patient = savedPatient, Provider = unqualifiedProvider, Service = savedService, ReasonForVisit = "There's no place like home", RequestedAppointmentDate = DateTime.Parse("2000/01/01 09:00:00.000"), }; //Act var savedAppointment = appointmentDomain.SetAppointment(appointment); }
public void Close() { if (!this._closed) { if (_logger.IsDebugEnabled) { _logger.Debug("Close TransactionScope"); } if (ContextUtil.IsInTransaction) { if (this._consistent && this.IsVoteCommit) { ContextUtil.EnableCommit(); } else { ContextUtil.DisableCommit(); } } if (--this.TransactionScopeCount == 0) { if (_logger.IsDebugEnabled) { _logger.Debug("Leave in ServiceDomain "); } ServiceDomain.Leave(); } this._closed = true; } }
private void TransformServiceFunction(ServiceDomain serviceDomain, TemplateRow templateRow) { var serviceFunction = serviceDomain.ServiceFunctions.FirstOrDefault(d => d.FunctionType.FunctionName.Trim() == templateRow.ServiceFunction.Trim()); if (serviceFunction == null) { var dateTimeNow = DateTime.Now; serviceFunction = new ServiceFunction { ServiceDomain = serviceDomain, FunctionType = _functionTypeRefDataService.InsertorUpdate(templateRow.ServiceFunction), ServiceComponents = new List <ServiceComponent>(), DiagramOrder = 5, InsertedBy = _userIdentity.Name, InsertedDate = dateTimeNow, UpdatedBy = _userIdentity.Name, UpdatedDate = dateTimeNow }; serviceDomain.ServiceFunctions.Add(serviceFunction); _serviceDomainService.Update(serviceDomain); } if (!string.IsNullOrEmpty(templateRow.ServiceComponentLevel1)) { TransformComponentLevelOne(serviceFunction, templateRow); } }
private void TransformServiceDomain(ServiceDesk serviceDesk, TemplateRow templateRow) { var serviceDomain = serviceDesk.ServiceDomains.FirstOrDefault(d => d.DomainType.DomainName.Trim() == templateRow.ServiceDomain.Trim()); if (serviceDomain == null) { var dateTimeNow = DateTime.Now; serviceDomain = new ServiceDomain { DomainType = _domainTypeRefDataService.InsertorUpdate(templateRow.ServiceDomain), ServiceFunctions = new List <ServiceFunction>(), DiagramOrder = 5, InsertedBy = _userIdentity.Name, InsertedDate = dateTimeNow, UpdatedBy = _userIdentity.Name, UpdatedDate = dateTimeNow }; serviceDesk.ServiceDomains.Add(serviceDomain); _serviceDeskService.Update(serviceDesk); } if (!string.IsNullOrEmpty(templateRow.ServiceFunction)) { TransformServiceFunction(serviceDomain, templateRow); } }
/// <summary> /// /// </summary> private void EnterTransactionContext() { if (++TransactionScopeCount == 1) { if (_logger.IsDebugEnabled) { _logger.Debug("Create a new ServiceConfig in ServiceDomain."); } ServiceConfig config = new ServiceConfig(); config.TrackingEnabled = true; config.TrackingAppName = "iBATIS.NET"; config.TrackingComponentName = "TransactionScope"; config.TransactionDescription = "iBATIS.NET Distributed Transaction"; config.Transaction = TransactionScopeOptions2TransactionOption(_txScopeOptions); config.TransactionTimeout = _txOptions.TimeOut.Seconds; config.IsolationLevel = IsolationLevel2TransactionIsolationLevel(_txOptions.IsolationLevel); // every call to ServiceDomain.Enter() creates a new COM+ Context //(verified by calls to ContextUtil.ContextId), // and every call to ServiceDomain.Leave() terminates that context ServiceDomain.Enter(config); } _closed = false; if (_logger.IsDebugEnabled) { _logger.Debug("Open TransactionScope :" + ContextUtil.ContextId); } }
public void Scheduling_Appointment_HappyPath() { //Arrange Setup(); var providerDomain = new ProviderDomain(new ProvidersRepository()); var patientDomain = new PatientDomain(new PatientsRepository()); var serviceDomain = new ServiceDomain(new ServicesRepository()); var appointmentDomain = new AppointmentsDomain(new AppointmentsRepository()); var savedProvider = providerDomain.GetProvider(1); var savedPatient = patientDomain.GetPatient(1); var savedService = serviceDomain.GetService(1); var appointment = new Appointment { Patient = savedPatient, Provider = savedProvider, Service = savedService, ReasonForVisit = "There's no place like home", RequestedAppointmentDate = DateTime.Parse("2000/01/01 09:00:00.000"), }; //Act var savedAppointment = appointmentDomain.SetAppointment(appointment); //Assert Assert.IsTrue(savedAppointment.Id != 0); }
/// <summary> /// Close the TransactionScope /// </summary> public void Close() { if (_closed == false) { if (_logger.IsDebugEnabled) { _logger.Debug("Close TransactionScope"); } if (ContextUtil.IsInTransaction) { if (_consistent == true && (this.IsVoteCommit)) { ContextUtil.EnableCommit(); } else { ContextUtil.DisableCommit(); } } if (0 == --TransactionScopeCount) { if (_logger.IsDebugEnabled) { _logger.Debug("Leave in ServiceDomain "); } ServiceDomain.Leave(); } _closed = true; } }
private static void ClickEnroll() // This simulates input from a web form for enrollment { try { // Setup context ServiceConfig context = new ServiceConfig { Transaction = TransactionOption.Required }; ServiceDomain.Enter(context); // enter the transactional context (not using MTS) // Business Logic var courseReg = new CourseRegistrationR(); courseReg.RegisterStudent(); // Check success TransactionStatus status = ServiceDomain.Leave(); Console.WriteLine("Transaction result {0}. Enrollments: {1}, Open Seats: {2}", status, Helper.GetTotalEnrollments(), Helper.GetOpenSeats()); // TODO: Handle result accordingly } catch (Exception ex) { Console.WriteLine("Caught Exception: {0}", ex.Message); ContextUtil.SetAbort(); TransactionStatus status = ServiceDomain.Leave(); Console.WriteLine("Transaction result {0}", status); } }
public void ServiceDomainService_Update_CallUpdateDomainAndCallsSaveChanges() { #region Arrange var dateTimeNow = DateTime.Now; var serviceDomain = new ServiceDomain() { Id = 3, DomainType = _serviceDomainTypes.FirstOrDefault(x => x.Id == 1), ServiceDesk = new ServiceDesk() { Id = 1, DeskName = "Service Desk" }, InsertedBy = UserNameOne, InsertedDate = dateTimeNow, UpdatedBy = UserNameOne, UpdatedDate = dateTimeNow, }; #endregion #region Act _serviceDomainService.Update(serviceDomain); #endregion #region Assert _mockServiceDomainRepository.Verify(x => x.Update(It.IsAny <ServiceDomain>()), Times.Once()); _mockUnitOfWork.Verify(x => x.Save(), Times.Exactly(1)); #endregion }
//进入事务上下文 private void EnterTxContext(TransactionOption txOption) { ServiceConfig config = new ServiceConfig(); config.Transaction = txOption; ServiceDomain.Enter(config); }
/// <summary> Start a new database transaction.</summary> public static void BeginTransaction() { log.Debug("Starting new COM+ transaction."); ServiceConfig sc = new ServiceConfig(); sc.Transaction = TransactionOption.RequiresNew; ServiceDomain.Enter(sc); }
private void JitSafeLeaveServiceDomain() { if (this.createdDoubleServiceDomain) { ServiceDomain.Leave(); } ServiceDomain.Leave(); }
public void Update(ServiceDomain entity) { RetryableOperation.Invoke(ExceptionPolicies.General, () => { _serviceDomainRepository.Update(entity); _unitOfWork.Save(); }); }
public int Create(ServiceDomain entity) { RetryableOperation.Invoke(ExceptionPolicies.General, () => { _serviceDomainRepository.Insert(entity); _unitOfWork.Save(); }); return(entity.Id); }
public void Dispose() { if (!this.consistent) { //取消事务 ContextUtil.SetAbort(); } ServiceDomain.Leave(); }
public static void TransactionStart() { // Enter a new transaction without inheriting from ServicedComponent Console.WriteLine("Attempting to enter a transactional context..."); ServiceConfig config = new ServiceConfig(); config.Transaction = TransactionOption.RequiresNew; ServiceDomain.Enter(config); Console.WriteLine("Attempt suceeded!"); }
public ServiceFunctionProcessor(ServiceDomain serviceDomain, IEnumerable <ServiceFunction> serviceFunctions, ISLMDataContext dataContext, IUnitOfWork unitOfWork) { _serviceDomain = serviceDomain; _serviceFunctions = serviceFunctions; _dataContext = dataContext; _unitOfWork = unitOfWork; }
public static void TransactionLeave() { Console.WriteLine("Attempting to Leave transactional context..."); if (ContextUtil.IsInTransaction) { // Abort the running transaction ContextUtil.SetAbort(); } ServiceDomain.Leave(); Console.WriteLine("Left context!"); }
public void TestMethod1() { ServiceDomain.Enter(new ServiceConfig()); MockRepository mocks = new MockRepository(); ISomething something = (ISomething)mocks.StrictMock(typeof(ISomething)); mocks.ReplayAll(); mocks.VerifyAll(); ContextUtil.SetAbort(); ServiceDomain.Leave(); }
public ServiceDomain GetByCustomerAndId(int customerId, int id) { ServiceDomain result = null; RetryableOperation.Invoke(ExceptionPolicies.General, () => { result = _serviceDomainRepository .SingleOrDefault(x => x.ServiceDesk.CustomerId == customerId && x.Id == id); }); return(result); }
public ServiceDomain GetById(int id) { ServiceDomain result = null; RetryableOperation.Invoke(ExceptionPolicies.General, () => { result = _serviceDomainRepository.GetById(id); }); return(result); }
public void TestMethod1() { ServiceDomain.Enter(new ServiceConfig()); ISomething something = MockRepository.Mock <ISomething>(); something.VerifyAllExpectations(); ContextUtil.SetAbort(); ServiceDomain.Leave(); }
public static void ProcessServiceFunctions(this ChartDataListItem chartData, bool svcComponents, bool resolverGroups, bool svcActivities, bool opProcs, string customerName, ServiceDomain deskDomain, List <List <DotMatrixListItem> > dotMatrix) { if (deskDomain.ServiceFunctions == null) { return; } foreach (var domainFunction in deskDomain.ServiceFunctions.OrderBy(x => x.DiagramOrder).ThenBy(x => x.FunctionType.FunctionName)) { var function = new ChartDataListItem { Id = domainFunction.Id, Title = domainFunction.AlternativeName ?? domainFunction.FunctionType.FunctionName, Type = DecompositionType.Function.ToString(), CenteredTitle = string.Empty, Units = new List <ChartDataListItem>(), }; if (svcComponents) { function.ProcessServiceComponents(resolverGroups, svcActivities, opProcs, customerName, domainFunction, dotMatrix); } else if (resolverGroups) { if (domainFunction.ServiceComponents != null) { foreach (var component in domainFunction.ServiceComponents.Where(x => x.ComponentLevel == 1)) { function.ProcessResolvers(svcActivities, opProcs, customerName, component, dotMatrix); } } } else if (svcActivities) { if (domainFunction.ServiceComponents != null) { foreach (var component in domainFunction.ServiceComponents.Where(x => x.ComponentLevel == 1)) { function.ProcessServiceActivities(opProcs, component, dotMatrix); } } } chartData.Units.Add(function); } }
public void Setup() { var providerDomain = new ProviderDomain(new ProvidersRepository()); var patientDomain = new PatientDomain(new PatientsRepository()); var serviceDomain = new ServiceDomain(new ServicesRepository()); var provider = new Provider { Name = "Dr. Oz", CertificationLevel = 10 }; var differentProvider = new Provider { Name = "Dr. Jekyll", CertificationLevel = 10 }; var patient = new Patient { Name = "Dorothy", Age = 16 }; var differentPatient = new Patient { Name = "Glenda", Age = 99 }; var service = new Service { Name = "A New Heart", Duration = TimeSpan.FromHours(5), MinimumRequiredAge = 16, RequiredCertificationLevel = 10 }; var shortService = new Service { Name = "Consultation", Duration = TimeSpan.FromMinutes(30), MinimumRequiredAge = 16, RequiredCertificationLevel = 10 }; providerDomain.CreateProvider(provider); providerDomain.CreateProvider(differentProvider); patientDomain.CreatePatient(patient); patientDomain.CreatePatient(differentPatient); serviceDomain.CreateService(service); serviceDomain.CreateService(shortService); }
public async Task <VerifyServiceStatusResponse> VerifyServiceStatus(ServiceDomain domain) { var request = CreateRequest(); request.URI = string.Format("{0}/servicestatus", CommonManager.ToXmlEnumString <ServiceDomain>(domain)); var response = await client.GetAsync(request); var result = await ProcessResponse <VerifyServiceStatusResponse>(response); return(result); }
public void TestMethod1() { ServiceDomain.Enter(new ServiceConfig()); ISomething something = MockRepository.Mock <ISomething>(); something.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); something.VerifyAllExpectations(); ContextUtil.SetAbort(); ServiceDomain.Leave(); }