public SapUnitOfWork(SapContextOptions options) { //this.InjectInstanceOf(typeof(IRepository), sapSqlDbContext, diApiContext); //this.InjectInstanceOf(typeof(IRepository), sapSqlDbContext, diApiContext, options.SqlServerConnection, new DemoItemPropertiesRepository()); var productPropertiesRepository = new DemoProductPropertiesRepository(); _options = options; _extrasDbContext = new RalDbContext(options.ExtrasServerOptions); _diApiContext = new SapDiApiContext(options.DiApiServerConnection, CurrentProvider.GetService <ILogger <SapDiApiContext> >()); _sapSqlDbContext = new SapSqlDbContext(options.SapSqlServerOptions); BusinessPartners = new SapBusinessPartnerRepository(_sapSqlDbContext, _diApiContext); Salesmen = new SapSalesmanRepository(_sapSqlDbContext, _diApiContext); Employees = new SapEmployeeRepository(_sapSqlDbContext, _diApiContext); Company = new SapCompanyRepository(_sapSqlDbContext, _diApiContext); Quotations = new SapDocumentRepository <QuotationEntity, QuotationHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository); Orders = new SapDocumentRepository <OrderEntity, OrderHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository); DeliveryNotes = new SapDocumentRepository <DeliveryNoteEntity, DeliveryNoteHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository); Invoices = new SapDocumentRepository <InvoiceEntity, InvoiceHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository); CreditNotes = new SapDocumentRepository <CreditNoteEntity, CreditNoteHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository); DownPaymentRequests = new SapDocumentRepository <DownPaymentRequest, DownPaymentRequestHeader>(_sapSqlDbContext, _diApiContext, productPropertiesRepository); ProductGroups = new SapProductGroupRepository(_sapSqlDbContext, _diApiContext); Products = new SapProductRepository(_sapSqlDbContext, _diApiContext); RefreshTokens = new AuthenticationRepository(_extrasDbContext); UserLocations = new UserLocationRepository(_extrasDbContext); LeadUsersData = new LeadUserDataRepository(_extrasDbContext); EmployeeTimeClocks = new EmployeeTimeClockRepository(_extrasDbContext); _activities = new Lazy <IActivityRepository>(new SapActivityRepository(_sapSqlDbContext, _diApiContext, _extrasDbContext, options)); _attachments = new Lazy <IAttachmentRepository>(new SapAttachmentRepository(_sapSqlDbContext, _diApiContext)); _identityUsers = new Lazy <IIdentityRepository>(new IdentityUserRepository(_extrasDbContext)); }
public MockDbAllocatorStartup(RalDbContext dbContext, UserManager <IdentityUser> userManager, ILogger <MockDbAllocatorStartup> logger) { _dbContext = dbContext; _userManager = userManager; _logger = logger; }
public void InstallConfiguration(IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration, ILogger logger) { using var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope(); var connOpts = serviceScope.ServiceProvider.GetService <SapContextOptions>(); var dbContext = new RalDbContext(connOpts.ExtrasServerOptions); // dbContext.Database.OpenConnection(); // dbContext.Database.EnsureDeleted(); // dbContext.Database.Migrate(); // dbContext.Database.EnsureCreated(); }
public BaseServicesTest() { TestServer = new TestServer( WebHost .CreateDefaultBuilder() .UseEnvironment("InMemoryTesting") .UseStartup <Startup>()); var configuration = (IConfiguration)TestServer.Host.Services.GetService(typeof(IConfiguration)); DbContext = (RalDbContext)TestServer.Host.Services.GetService(typeof(RalDbContext)); DalService = (IDalService)TestServer.Host.Services.GetService(typeof(IDalService)); Mapper = (IMapper)TestServer.Host.Services.GetService(typeof(IMapper)); }
private static void SyncActivitiesCache(SapContextOptions options) { Task.Run(() => { if (_lastSync.HasValue && _lastSync.Value.AddMinutes(10) >= DateTime.Now) { return; } _lastSync = DateTime.Now; var extraDbContext = new RalDbContext(options.ExtrasServerOptions); var dbActivities = extraDbContext.Activities.ToList(); var unchanged = 0; var cachedActivitiesValues = _cachedActivities.Values; foreach (var cachedActivity in cachedActivitiesValues) { var dbActivity = dbActivities.SingleOrDefault(x => x.Code == cachedActivity.Code); if (cachedActivity.Code == 8) { Console.WriteLine("e"); } if (dbActivity == null) { extraDbContext.Activities.Add(cachedActivity); } else if (dbActivity.Equals(cachedActivity) == false) { extraDbContext.Entry(dbActivity).CurrentValues.SetValues(cachedActivity); // temp = extraDbContext.Activities.Update(cachedActivity); } else { unchanged++; } } if (unchanged != cachedActivitiesValues.Count) { extraDbContext.SaveChanges(); } }); }
public SapActivityRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext, RalDbContext extraDbContext, SapContextOptions options) : base(SelectActivitiesFromDb(dbContext), x => x.Code.Value, diApiContext.Activities) { _context = dbContext; if (_cachedActivities == null) { _cachedActivities = new Dictionary <int, Activity>(); extraDbContext.Activities.ForEachAsync(a => { if (a.Code != null) { _cachedActivities[a.Code.Value] = a; } }).Wait(); } else { #pragma warning disable 4014 SyncActivitiesCache(options); #pragma warning restore 4014 } }
// private DbContextOptions<RalDbContext> _options; public RalUnitOfWork(RalDbContext dbContext) { _dbContext = dbContext; BusinessPartners = new BusinessPartnerRepository(dbContext); Company = new CompanyRepository(dbContext); Employees = new EmployeesRepository(dbContext); Quotations = new DocumentRepository <QuotationEntity, QuotationHeaderEntity>(dbContext); Orders = new DocumentRepository <OrderEntity, OrderHeaderEntity>(dbContext); DeliveryNotes = new DocumentRepository <DeliveryNoteEntity, DeliveryNoteHeaderEntity>(dbContext); Invoices = new DocumentRepository <InvoiceEntity, InvoiceHeaderEntity>(dbContext); CreditNotes = new DocumentRepository <CreditNoteEntity, CreditNoteHeaderEntity>(dbContext); DownPaymentRequests = new DocumentRepository <DownPaymentRequest, DownPaymentRequestHeader>(dbContext); Salesmen = new SalesmanRepository(dbContext); ProductGroups = new ProductGroupRepository(dbContext); Products = new ProductRepository(dbContext); RefreshTokens = new AuthenticationRepository(dbContext); IdentityUsers = new IdentityUserRepository(dbContext); UserLocations = new UserLocationRepository(dbContext); LeadUsersData = new LeadUserDataRepository(dbContext); EmployeeTimeClocks = new EmployeeTimeClockRepository(dbContext); Activities = new ActivityRepository(dbContext); Attachments = new AttachmentRepository(dbContext); }