Exemple #1
0
        private async Task <List <Application> > GetAppStoreApplicationsAsync(string keyword)
        {
            using (var db = new AppStoreAppsRepository())
            {
                var apps = db.SearchRequests
                           .Include(s => s.Applications)
                           .ThenInclude(a => a.Screenshots)
                           .FirstOrDefault(s => s.Keyword == keyword)?.Applications.ToList();

                if (apps == null)
                {
                    await Console.Out.WriteLineAsync("Get data from web resourse");

                    List <string> top3AppStoreAppsNames = await _appStoreClient.GetTop3SearchSuggestAsync(keyword);

                    var getAppStoreAppsInfoTask = top3AppStoreAppsNames.Select(async n =>
                    {
                        return(await _appStoreClient.GetApplicationInfo(n));
                    });
                    var applications = await Task.WhenAll(getAppStoreAppsInfoTask);

                    db.SearchRequests.Add(new SearchRequest {
                        Keyword = keyword, Applications = applications
                    });
                    db.SaveChanges();
                    return(applications.ToList());
                }
                await Console.Out.WriteLineAsync("Get data from database");

                return(apps);
            }
        }
Exemple #2
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     using (var appStoreContext = new AppStoreAppsRepository())
     {
         appStoreContext.Database.Migrate();
     }
     using (var googlePlayContext = new GooglePlayAppsRepository())
     {
         googlePlayContext.Database.Migrate();
     }
     app.UseMvc();
 }