コード例 #1
0
        public async Task <ActionResult <Department> > Add(
            [FromServices] IRepository <Models.Department, int> departmentRepository,
            [FromServices] IEntityScraper <Models.Department> departmentScraper,
            [FromBody] Uri uri)
        {
            var absoluteUrl      = uri.AbsoluteUri;
            var storedDepartment =
                departmentRepository.Find(department => department.Url == absoluteUrl).FirstOrDefault();

            if (storedDepartment == null)
            {
                var dateTime   = DateTime.Now;
                var department = new Models.Department
                {
                    Name      = "Unknown Department",
                    IsEnabled = true,
                    Url       = UriHelper.EnsureDepartmentUrl(absoluteUrl),
                    Added     = dateTime,
                    Updated   = dateTime,
                    Read      = dateTime
                };

                var transaction = PolicyHelper.WaitAndRetry().Execute(
                    () => departmentRepository.BeginTransaction(IsolationLevel.Serializable));
                departmentRepository.Add(department);
                await departmentRepository.SaveChangesAsync();

                await transaction.CommitAsync();

                return(department.ToDataTransferObject(true));
            }


            return(storedDepartment?.ToDataTransferObject());
        }
コード例 #2
0
 public StoreService(
     IRepository <Store, int> storesRepository,
     IEntityScraper <Store> entityScraper,
     ICookiesAwareHttpClientFactory cookiesAwareHttpClientFactory)
 {
     this.storesRepository = storesRepository;
     _entityScraper        = entityScraper;
     this.cookiesAwareHttpClientFactory = cookiesAwareHttpClientFactory;
 }
コード例 #3
0
 public InspectDepartmentProductsScraper(
     IBrowsingContext browsingContext,
     IEntityScraper <Product> productScraper,
     HttpClient httpClient)
 {
     this.browsingContext = browsingContext;
     this._productScraper = productScraper;
     this.httpClient      = httpClient;
 }
コード例 #4
0
 public InspectStoreDepartmentsScraper(
     IBrowsingContext browsingContext,
     IEntityScraper <Department> entityScraper,
     HttpClient httpClient)
 {
     this.browsingContext = browsingContext;
     this._entityScraper  = entityScraper;
     this.httpClient      = httpClient;
 }
コード例 #5
0
 public DepartmentScraper(
     IBrowsingContext browsingContext,
     IEntityScraper <Store> storeScraper,
     ICacheStorage <string, Department> cacheStorage,
     ICookiesAwareHttpClientFactory cookiesAwareHttpClientFactory)
 {
     this.browsingContext = browsingContext;
     this.storeScraper    = storeScraper;
     this.cacheStorage    = cacheStorage;
     this.cookiesAwareHttpClientFactory = cookiesAwareHttpClientFactory;
 }