コード例 #1
0
        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));
        }
コード例 #2
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration, IWebHostEnvironment env,
                                    ILogger logger)
        {
            var sapServerSettings = new SapServerSettings();

            configuration.Bind(nameof(SapServerSettings), sapServerSettings);
            var sapContextOptions = new SapContextOptions
            {
                DiApiServerConnection = sapServerSettings.SapServerDiAPi,
                SapSqlServerOptions   = new DbContextOptionsBuilder <SapSqlDbContext>()
                                        .UseSqlServer(sapServerSettings.SapServerSql)
                                        // .EnableSensitiveDataLogging()
                                        .Options,
                ExtrasServerOptions = new DbContextOptionsBuilder <RalDbContext>()
                                      .UseSqlServer(sapServerSettings.IamServerSql)
                                      //  .EnableSensitiveDataLogging()
                                      .Options
            };

            services.AddSingleton(sapContextOptions);

            services.AddSingleton <IUnitOfWork, SapUnitOfWork>();
            SapUnitOfWork.CurrentProvider = services.BuildServiceProvider();
            services.AddSingleton <IDalService, DalService>();

            //for migration and identity
            services.AddDbContext <RalDbContext>(builder => builder
                                                 .UseSqlServer(sapServerSettings.IamServerSql)
                                                 .EnableSensitiveDataLogging());

            services.AddIdentityCore <IdentityUser>()
            .AddEntityFrameworkStores <RalDbContext>()
            .AddDefaultTokenProviders();
        }
コード例 #3
0
        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();
                }
            });
        }
コード例 #4
0
        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
            }
        }