From 06ed54b2c6c2e1f49d6975a34ea36f685d7f7c49 Mon Sep 17 00:00:00 2001 From: James Stine Date: Sun, 13 Aug 2017 17:44:00 -0400 Subject: First commit. --- Dewdrop/Controllers/CheckController.cs | 60 ++++++++++++++++++++++++++++++++++ Dewdrop/Dewdrop.csproj | 27 +++++++++++++++ Dewdrop/Models/IModModel.cs | 16 +++++++++ Dewdrop/Models/ModGenericModel.cs | 40 +++++++++++++++++++++++ Dewdrop/Models/NexusResponseModel.cs | 48 +++++++++++++++++++++++++++ Dewdrop/Program.cs | 27 +++++++++++++++ Dewdrop/Properties/launchSettings.json | 29 ++++++++++++++++ Dewdrop/Startup.cs | 43 ++++++++++++++++++++++++ Dewdrop/appsettings.Development.json | 10 ++++++ Dewdrop/appsettings.json | 8 +++++ 10 files changed, 308 insertions(+) create mode 100644 Dewdrop/Controllers/CheckController.cs create mode 100644 Dewdrop/Dewdrop.csproj create mode 100644 Dewdrop/Models/IModModel.cs create mode 100644 Dewdrop/Models/ModGenericModel.cs create mode 100644 Dewdrop/Models/NexusResponseModel.cs create mode 100644 Dewdrop/Program.cs create mode 100644 Dewdrop/Properties/launchSettings.json create mode 100644 Dewdrop/Startup.cs create mode 100644 Dewdrop/appsettings.Development.json create mode 100644 Dewdrop/appsettings.json (limited to 'Dewdrop') diff --git a/Dewdrop/Controllers/CheckController.cs b/Dewdrop/Controllers/CheckController.cs new file mode 100644 index 00000000..f3cdd364 --- /dev/null +++ b/Dewdrop/Controllers/CheckController.cs @@ -0,0 +1,60 @@ +using System; +using System.Net.Http; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.Collections.Generic; +using Dewdrop.Models; + +namespace Dewdrop.Controllers +{ + [Produces("application/json")] + [Route("api/check")] + public class CheckController : Controller + { + [HttpPost] + public async Task Post([FromBody] NexusResponseModel[] mods) + { + using (var client = new HttpClient()) + { + // the return array of mods + var modList = new List(); + + foreach (var mod in mods) + { + try + { + // create request with HttpRequestMessage + var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.Id}")); + + // add the Nexus Client useragent to get JSON response from the site + request.Headers.UserAgent.ParseAdd("Nexus Client v0.63.15"); + + // send the request out + var response = await client.SendAsync(request); + // ensure the response is valid (throws exception) + response.EnsureSuccessStatusCode(); + + // get the JSON string of the response + var stringResponse = await response.Content.ReadAsStringAsync(); + + // create the mod data from the JSON string + var modData = JsonConvert.DeserializeObject(stringResponse); + + // add to the list of mods + modList.Add(modData.ModInfo()); + } + catch (Exception ex) + { + var modData = mod.ModInfo(); + modData.Valid = false; + + modList.Add(modData); + } + } + + return JsonConvert.SerializeObject(modList, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + } + } + } +} \ No newline at end of file diff --git a/Dewdrop/Dewdrop.csproj b/Dewdrop/Dewdrop.csproj new file mode 100644 index 00000000..fa1d88eb --- /dev/null +++ b/Dewdrop/Dewdrop.csproj @@ -0,0 +1,27 @@ + + + + netcoreapp1.1 + portable-net45+win8 + + + + + + + + + + + + + + + + + + + + + + diff --git a/Dewdrop/Models/IModModel.cs b/Dewdrop/Models/IModModel.cs new file mode 100644 index 00000000..aa6583d4 --- /dev/null +++ b/Dewdrop/Models/IModModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Dewdrop.Models +{ + interface IModModel + { + /// + /// Basic information in the form of + /// + /// + ModGenericModel ModInfo(); + } +} diff --git a/Dewdrop/Models/ModGenericModel.cs b/Dewdrop/Models/ModGenericModel.cs new file mode 100644 index 00000000..829c396a --- /dev/null +++ b/Dewdrop/Models/ModGenericModel.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Dewdrop.Models +{ + public class ModGenericModel + { + /// + /// An identifier for the mod. + /// + public int Id { get; set; } + + /// + /// The mod's name. + /// + public string Name { get; set; } + + /// + /// The vendor identifier for the mod. + /// + public string Vendor { get; set; } + + /// + /// The mod's version number. + /// + public string Version { get; set; } + + /// + /// The mod's URL + /// + public string Url { get; set; } + + /// + /// Is the mod a valid mod. + /// + public bool Valid { get; set; } = true; + } +} diff --git a/Dewdrop/Models/NexusResponseModel.cs b/Dewdrop/Models/NexusResponseModel.cs new file mode 100644 index 00000000..e954a8bc --- /dev/null +++ b/Dewdrop/Models/NexusResponseModel.cs @@ -0,0 +1,48 @@ +using System; +using Newtonsoft.Json; + +namespace Dewdrop.Models +{ + public class NexusResponseModel : IModModel + { + /// + /// The name of the mod. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// The version of the mod. + /// + [JsonProperty("version")] + public string Version { get; set; } + + /// + /// The NexusMod ID for the mod. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// The URL of the mod. + /// + [JsonProperty("mod_page_uri")] + public string Url { get; set; } + + /// + /// Return mod information about a Nexus mod + /// + /// + public ModGenericModel ModInfo() + { + return new ModGenericModel + { + Id = Id, + Version = Version, + Name = Name, + Url = Url, + Vendor = "Nexus" + }; + } + } +} diff --git a/Dewdrop/Program.cs b/Dewdrop/Program.cs new file mode 100644 index 00000000..c6a5a642 --- /dev/null +++ b/Dewdrop/Program.cs @@ -0,0 +1,27 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Dewdrop +{ + public class Program + { + public static void Main(string[] args) + { + var host = new WebHostBuilder() + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .UseApplicationInsights() + .Build(); + + host.Run(); + } + } +} diff --git a/Dewdrop/Properties/launchSettings.json b/Dewdrop/Properties/launchSettings.json new file mode 100644 index 00000000..c15134dc --- /dev/null +++ b/Dewdrop/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:59482/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/check", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Dewdrop": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/check", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:59483" + } + } +} diff --git a/Dewdrop/Startup.cs b/Dewdrop/Startup.cs new file mode 100644 index 00000000..00c18bab --- /dev/null +++ b/Dewdrop/Startup.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Dewdrop +{ + public class Startup + { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + // Add framework services. + services.AddMvc(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + + app.UseMvc(); + } + } +} diff --git a/Dewdrop/appsettings.Development.json b/Dewdrop/appsettings.Development.json new file mode 100644 index 00000000..fa8ce71a --- /dev/null +++ b/Dewdrop/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/Dewdrop/appsettings.json b/Dewdrop/appsettings.json new file mode 100644 index 00000000..5fff67ba --- /dev/null +++ b/Dewdrop/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Warning" + } + } +} -- cgit