public async Task <DropshipAccount> GetAccount(string username)
        {
            //Check cache for account info
            var accountInfo = new DropshipAccount()
            {
                Username = username
            };

            if (await cache.Exists(RedisKeyConvert.Serialize(accountInfo)))
            {
                return(JsonConvert.DeserializeObject <DropshipAccount>(await cache.GetString(RedisKeyConvert.Serialize(accountInfo))));
            }

            //Couldn't find it in the cache, look in db
            accountInfo = await dbAccounts.GetOneByUsername(username);

            if (accountInfo != null)
            {
                return(accountInfo);
            }

            //Couldn't find it in db, must be a new account
            accountInfo = new DropshipAccount()
            {
                Username = username,
                Status   = AccountStatus.New
            };

            return(accountInfo);
        }
示例#2
0
        async Task <bool> existItemSearch(SearchCriteria criteria, int page)
        {
            var crit = JsonConvert.DeserializeObject <SearchCriteria>(JsonConvert.SerializeObject(criteria));

            crit.Page = page;

            var key = RedisKeyConvert.Serialize(crit);

            return(await cache.Exists(key));
        }
        public static async Task RetrieveSearchServices(WebSearchService[] services, IApplicationCache cache, SearchCriteria criteria, bool allNew = false)
        {
            foreach (var webService in services)
            {
                var type = webService.ServiceType;

                var service = new SearchServiceModel()
                {
                    Criteria = criteria,
                    Type     = type
                };

                var key = service.GetRedisKey();

                try
                {
                    if (!allNew && await cache.Exists(key))
                    {
                        webService.ServiceModel = (JsonConvert.DeserializeObject <SearchServiceModel>(await cache.GetString(key)));
                        continue;
                    }
                }
                catch
                {
                    //Something wrong with the service so we'll have to return a new one
                }

                webService.ServiceModel = new SearchServiceModel()
                {
                    Criteria = criteria,
                    MaxPage  = 0,
                    Page     = 0,
                    PageKey  = "",
                    Type     = type,
                    Pages    = new int[] { 0 },
                    Searched = false
                };
            }
        }
示例#4
0
        public async Task <SearchResultOverview> SearchItems(SearchCriteria search)
        {
            //Check for cached item list
            string key = RedisKeyConvert.Serialize(search);

            SearchResultOverview result = null;

            try
            {
                storeSearchHistory(search);

                if (await cache.Exists(key))
                {
                    var cachedResult = JsonConvert.DeserializeObject <SearchResultOverview>(await cache.GetString(key));

                    result = cachedResult;
                }
                else
                {
                    await SearchServiceProvider.RetrieveSearchServices(services, cache, search, allNew : true);

                    var results = await SearchDispatcher.Search(services, new int[] { search.Page });

                    var formattedResults = SearchFormatter.FormatResults(0, results);

                    await searchCache.CacheSearch(search, services, formattedResults.Results);

                    result = formattedResults.Results;
                }

                searchCache.StartCacheJob(search, null);
            }
            catch (Exception e)
            {
                await raven.CaptureNetCoreEventAsync(e);
            }

            return(result);
        }
示例#5
0
        async Task <OAuthShopifyModel> GetCredentials(string username)
        {
            var key = $"OAuth:Shopify:{username}";

            if (await cache.Exists(key))
            {
                return(JsonConvert.DeserializeObject <OAuthShopifyModel>(await cache.GetString(key)));
            }

            var integrations = await oauthDb.GetMultipleByUsername(username);

            var shopifyIntegration = integrations.FirstOrDefault(x => x.Service == "Shopify");

            if (shopifyIntegration != null)
            {
                await cache.StoreString(key, JsonConvert.SerializeObject(shopifyIntegration));

                return(JsonConvert.DeserializeObject <OAuthShopifyModel>(JsonConvert.SerializeObject(shopifyIntegration)));
            }
            else
            {
                return(null);
            }
        }