public IActionResult UserAnalysis(string userHandle, [FromServices] ITwitAPI twitService, [FromServices] ISpellCheck spellService) { UserAnalysis u = new UserAnalysis(userHandle, twitService, spellService); if (u.IsValid()) { return(View(u)); } else { return(View("BadEntry")); } }
//Constructor public UserAnalysis(string userHandle, ITwitAPI twitService, ISpellCheck spellService) { //Forcing user to enter @ to make clear what name is needed, but we don't actually want it if (userHandle[0] == '@') { userHandle = userHandle.Substring(1); } userHandle = userHandle.ToLower(); this.spellService = spellService; this.twitService = twitService; var waitTweets = this.twitService.GetUserTweets(userHandle); waitTweets.Wait(); this.twitterUser = waitTweets.Result; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ITwitAPI twitService, ISpellCheck spellService) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); //Get auth keys string keyFile = File.ReadAllText(env.ContentRootPath + "\\APIKeys.json"); JsonDocument keys = JsonDocument.Parse(keyFile); JsonElement root = keys.RootElement; string APIKey = root.GetProperty("APIKey").ToString(); string APISecret = root.GetProperty("APISecret").ToString(); string bearer = root.GetProperty("Bearer").ToString(); twitService.Authenticate(APIKey, APISecret, bearer); spellService.loadWords(Path.Combine(env.ContentRootPath, "English.dic")); }