public UnitOfWorkManager(ICHCContext context) { // http://stackoverflow.com/questions/3552000/entity-framework-code-only-error-the-model-backing-the-context-has-changed-sinc Database.SetInitializer <CHCContext>(null); _context = context as CHCContext; }
public override void HandleAutoTask() { LogManager.Instance.Write("Start CompanyOrder Handler ******************************************************"); using (var cache = new EntityCache <CompanyOrder, CHCContext>(p => p.Locked == true && p.IsBuildCompleted == false)) { while (true) { LogManager.Instance.Write(cache.Results.Count().ToString()); var importExportService = new ImportExportService(); var companyOrderService = new CompanyOrderService(null, importExportService, null, null); if (cache.Results.Count() > 0) { foreach (var order in cache.Results) { companyOrderService.ExportCompanyOrderForms(ConfigurationManager.AppSettings["CHCWebRootPath"], order); using (var context = new CHCContext()) { var entity = context.CompanyOrder.SingleOrDefault(e => e.Id == order.Id); entity.Locked = true; entity.IsBuildCompleted = true; context.SaveChanges(); } } } Thread.Sleep(5000); } } }
/// <summary> /// Constructor /// </summary> public UnitOfWork(CHCContext context) { _context = context; // In order to make calls that are overidden in the caching ef-wrapper, we need to use // transactions from the connection, rather than TransactionScope. // This results in our call e.g. to commit() being intercepted // by the wrapper so the cache can be adjusted. // This won't work with the dbcontext because it handles the connection itself, so we must use the underlying ObjectContext. // http://blogs.msdn.com/b/diego/archive/2012/01/26/exception-from-dbcontext-api-entityconnection-can-only-be-constructed-with-a-closed-dbconnection.aspx _objectContext = ((IObjectContextAdapter)_context).ObjectContext; if (_objectContext.Connection.State != ConnectionState.Open) { _objectContext.Connection.Open(); _transaction = _objectContext.Connection.BeginTransaction(); } }
public override void HandleAutoTask() { LogManager.Instance.Write("Start Email Handler ******************************************************"); var emailAccount = new EmailAccount() { Email = ConfigurationManager.AppSettings["EmailAccount"], DisplayName = ConfigurationManager.AppSettings["EmailDisplayName"], Host = ConfigurationManager.AppSettings["EmailHost"], Port = int.Parse(ConfigurationManager.AppSettings["EmailPort"]), Username = ConfigurationManager.AppSettings["EmailUsername"], Password = ConfigurationManager.AppSettings["EmailPassword"], EnableSsl = bool.Parse(ConfigurationManager.AppSettings["EmailEnableSsl"]), UseDefaultCredentials = bool.Parse(ConfigurationManager.AppSettings["EmailUseDefaultCredentials"]), }; using (var cache = new EntityCache <Email, CHCContext>(p => !p.SentDate.HasValue)) { while (true) { LogManager.Instance.Write(cache.Results.Count().ToString()); if (cache.Results.Count() > 0) { foreach (var email in cache.Results) { var bcc = String.IsNullOrWhiteSpace(email.Bcc) ? null : email.Bcc.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var cc = String.IsNullOrWhiteSpace(email.CC) ? null : email.CC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); try { EmailHelper.SendEmail(emailAccount, email.Subject, email.Body, emailAccount.Email, emailAccount.DisplayName, email.To, email.ToName, email.ReplyTo, email.ReplyToName, bcc, cc, email.AttachmentFilePath, email.AttachmentFileName); using (var context = new CHCContext()) { var entity = context.Email.SingleOrDefault(e => e.Id == email.Id); entity.SentTries++; entity.SentDate = DateTime.Now; context.SaveChanges(); } } catch (Exception ex) { LogManager.Instance.Write(ex.ToString()); using (var context = new CHCContext()) { var entity = context.Email.SingleOrDefault(e => e.Id == email.Id); entity.SentTries++; context.SaveChanges(); } } } } Thread.Sleep(5000); } } }
public EmailRepository(ICHCContext context) { _context = context as CHCContext; }
public MenuItemRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_CompositionRepository(ICHCContext context) { _context = context as CHCContext; }
public CompanyOrderRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_Substance_ExposureLimitRepository(ICHCContext context) { _context = context as CHCContext; }
public HealthResultRepository(ICHCContext context) { _context = context as CHCContext; }
public EmployeeBaseInfoRepository(ICHCContext context) { _context = context as CHCContext; }
public HospitalCalendarRepository(ICHCContext context) { _context = context as CHCContext; }
public CompanyOrder_Employee_MappingRepository(ICHCContext context) { _context = context as CHCContext; }
public MembershipRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_WorkStationRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_CustomerRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_H_StatementRepository(ICHCContext context) { _context = context as CHCContext; }
public CompanyEmployeeRepository(ICHCContext context) { _context = context as CHCContext; }
public MembershipUser_Company_MappingRepository(ICHCContext context) { _context = context as CHCContext; }
public PermissionRecordRepository(ICHCContext context) { _context = context as CHCContext; }
public CategoryRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_HazardousSubstancesRepository(ICHCContext context) { _context = context as CHCContext; }
public MembershipUser_EmailTaskType_MappingRepository(ICHCContext context) { _context = context as CHCContext; }
public PermissionRecord_MembershipRole_MappingRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_SpecificationRepository(ICHCContext context) { _context = context as CHCContext; }
public FunctionRecordRepository(ICHCContext context) { _context = context as CHCContext; }
public MSDS_WorkShopRepository(ICHCContext context) { _context = context as CHCContext; }
public MembershipUser_MembershipRole_MappingRepository(ICHCContext context) { _context = context as CHCContext; }
public AutoTaskRepository(ICHCContext context) { this._context = context as CHCContext; }
public EmployeeWorkHistoryRepository(ICHCContext context) { _context = context as CHCContext; }