From cddcd9a8cfde182e843f8b2224d00ba742596c76 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Sep 2017 23:39:12 -0400 Subject: standardise project name (#336) --- Dewdrop/Controllers/CheckController.cs | 66 ---------------------- Dewdrop/Dewdrop.csproj | 27 --------- Dewdrop/Models/IModModel.cs | 12 ---- Dewdrop/Models/ModGenericModel.cs | 27 --------- Dewdrop/Models/NexusResponseModel.cs | 41 -------------- Dewdrop/Program.cs | 27 --------- Dewdrop/Properties/launchSettings.json | 29 ---------- Dewdrop/Startup.cs | 52 ----------------- Dewdrop/appsettings.Development.json | 10 ---- Dewdrop/appsettings.json | 8 --- .../Controllers/CheckController.cs | 66 ++++++++++++++++++++++ src/StardewModdingAPI.Web/Models/IModModel.cs | 12 ++++ .../Models/ModGenericModel.cs | 27 +++++++++ .../Models/NexusResponseModel.cs | 41 ++++++++++++++ src/StardewModdingAPI.Web/Program.cs | 27 +++++++++ .../Properties/launchSettings.json | 29 ++++++++++ .../StardewModdingAPI.Web.csproj | 27 +++++++++ src/StardewModdingAPI.Web/Startup.cs | 52 +++++++++++++++++ .../appsettings.Development.json | 10 ++++ src/StardewModdingAPI.Web/appsettings.json | 8 +++ src/StardewModdingAPI.sln | 2 +- 21 files changed, 300 insertions(+), 300 deletions(-) delete mode 100644 Dewdrop/Controllers/CheckController.cs delete mode 100644 Dewdrop/Dewdrop.csproj delete mode 100644 Dewdrop/Models/IModModel.cs delete mode 100644 Dewdrop/Models/ModGenericModel.cs delete mode 100644 Dewdrop/Models/NexusResponseModel.cs delete mode 100644 Dewdrop/Program.cs delete mode 100644 Dewdrop/Properties/launchSettings.json delete mode 100644 Dewdrop/Startup.cs delete mode 100644 Dewdrop/appsettings.Development.json delete mode 100644 Dewdrop/appsettings.json create mode 100644 src/StardewModdingAPI.Web/Controllers/CheckController.cs create mode 100644 src/StardewModdingAPI.Web/Models/IModModel.cs create mode 100644 src/StardewModdingAPI.Web/Models/ModGenericModel.cs create mode 100644 src/StardewModdingAPI.Web/Models/NexusResponseModel.cs create mode 100644 src/StardewModdingAPI.Web/Program.cs create mode 100644 src/StardewModdingAPI.Web/Properties/launchSettings.json create mode 100644 src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj create mode 100644 src/StardewModdingAPI.Web/Startup.cs create mode 100644 src/StardewModdingAPI.Web/appsettings.Development.json create mode 100644 src/StardewModdingAPI.Web/appsettings.json diff --git a/Dewdrop/Controllers/CheckController.cs b/Dewdrop/Controllers/CheckController.cs deleted file mode 100644 index def2edbc..00000000 --- a/Dewdrop/Controllers/CheckController.cs +++ /dev/null @@ -1,66 +0,0 @@ -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 -{ - /// Provides an API to perform mod update checks. - [Produces("application/json")] - [Route("api/check")] - public class CheckController : Controller - { - /********* - ** Public methods - *********/ - /// Fetch version metadata for the given mods. - /// The mods for which to fetch update metadata. - [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 deleted file mode 100644 index fa1d88eb..00000000 --- a/Dewdrop/Dewdrop.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - netcoreapp1.1 - portable-net45+win8 - - - - - - - - - - - - - - - - - - - - - - diff --git a/Dewdrop/Models/IModModel.cs b/Dewdrop/Models/IModModel.cs deleted file mode 100644 index f1b09f8a..00000000 --- a/Dewdrop/Models/IModModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Dewdrop.Models -{ - /// A mod metadata response which provides a method to extract generic info. - internal interface IModModel - { - /********* - ** Public methods - *********/ - /// Get basic mod metadata. - ModGenericModel ModInfo(); - } -} diff --git a/Dewdrop/Models/ModGenericModel.cs b/Dewdrop/Models/ModGenericModel.cs deleted file mode 100644 index 0da04295..00000000 --- a/Dewdrop/Models/ModGenericModel.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Dewdrop.Models -{ - /// Generic metadata about a mod. - public class ModGenericModel - { - /********* - ** Accessors - *********/ - /// The unique mod ID. - public int ID { get; set; } - - /// The mod name. - public string Name { get; set; } - - /// The mod's vendor ID. - public string Vendor { get; set; } - - /// The mod's semantic version number. - public string Version { get; set; } - - /// The mod's web URL. - public string Url { get; set; } - - /// Whether the mod is valid. - public bool Valid { get; set; } = true; - } -} diff --git a/Dewdrop/Models/NexusResponseModel.cs b/Dewdrop/Models/NexusResponseModel.cs deleted file mode 100644 index fa663910..00000000 --- a/Dewdrop/Models/NexusResponseModel.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Newtonsoft.Json; - -namespace Dewdrop.Models -{ - /// A mod metadata response from Nexus Mods. - public class NexusResponseModel : IModModel - { - /********* - ** Accessors - *********/ - /// The unique mod ID. - public int ID { get; set; } - - /// The mod name. - public string Name { get; set; } - - /// The mod's semantic version number. - public string Version { get; set; } - - /// The mod's web URL. - [JsonProperty("mod_page_uri")] - public string Url { get; set; } - - - /********* - ** Public methods - *********/ - /// Get basic mod metadata. - public ModGenericModel ModInfo() - { - return new ModGenericModel - { - ID = this.ID, - Version = this.Version, - Name = this.Name, - Url = this.Url, - Vendor = "Nexus" - }; - } - } -} diff --git a/Dewdrop/Program.cs b/Dewdrop/Program.cs deleted file mode 100644 index 0e831a23..00000000 --- a/Dewdrop/Program.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.IO; -using Microsoft.AspNetCore.Hosting; - -namespace Dewdrop -{ - /// The main app entry point. - public class Program - { - /********* - ** Public methods - *********/ - /// The main app entry point. - /// The command-line arguments. - public static void Main(string[] args) - { - // configure web server - new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseStartup() - .UseApplicationInsights() - .Build() - .Run(); - } - } -} diff --git a/Dewdrop/Properties/launchSettings.json b/Dewdrop/Properties/launchSettings.json deleted file mode 100644 index c15134dc..00000000 --- a/Dewdrop/Properties/launchSettings.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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 deleted file mode 100644 index d1618037..00000000 --- a/Dewdrop/Startup.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Dewdrop -{ - /// The web app startup configuration. - public class Startup - { - /********* - ** Accessors - *********/ - /// The web app configuration. - public IConfigurationRoot Configuration { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The hosting environment. - public Startup(IHostingEnvironment env) - { - this.Configuration = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables() - .Build(); - } - - /// The method called by the runtime to add services to the container. - /// The service injection container. - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - /// The method called by the runtime to configure the HTTP request pipeline. - /// The application builder. - /// The hosting environment. - /// The logger factory. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) - { - loggerFactory.AddConsole(this.Configuration.GetSection("Logging")); - loggerFactory.AddDebug(); - app.UseMvc(); - } - } -} diff --git a/Dewdrop/appsettings.Development.json b/Dewdrop/appsettings.Development.json deleted file mode 100644 index fa8ce71a..00000000 --- a/Dewdrop/appsettings.Development.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - } -} diff --git a/Dewdrop/appsettings.json b/Dewdrop/appsettings.json deleted file mode 100644 index 5fff67ba..00000000 --- a/Dewdrop/appsettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Warning" - } - } -} diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs new file mode 100644 index 00000000..8ab4611b --- /dev/null +++ b/src/StardewModdingAPI.Web/Controllers/CheckController.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using StardewModdingAPI.Web.Models; + +namespace StardewModdingAPI.Web.Controllers +{ + /// Provides an API to perform mod update checks. + [Produces("application/json")] + [Route("api/check")] + public class CheckController : Controller + { + /********* + ** Public methods + *********/ + /// Fetch version metadata for the given mods. + /// The mods for which to fetch update metadata. + [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 }); + } + } + } +} diff --git a/src/StardewModdingAPI.Web/Models/IModModel.cs b/src/StardewModdingAPI.Web/Models/IModModel.cs new file mode 100644 index 00000000..2eadcaec --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/IModModel.cs @@ -0,0 +1,12 @@ +namespace StardewModdingAPI.Web.Models +{ + /// A mod metadata response which provides a method to extract generic info. + internal interface IModModel + { + /********* + ** Public methods + *********/ + /// Get basic mod metadata. + ModGenericModel ModInfo(); + } +} diff --git a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs new file mode 100644 index 00000000..208af416 --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs @@ -0,0 +1,27 @@ +namespace StardewModdingAPI.Web.Models +{ + /// Generic metadata about a mod. + public class ModGenericModel + { + /********* + ** Accessors + *********/ + /// The unique mod ID. + public int ID { get; set; } + + /// The mod name. + public string Name { get; set; } + + /// The mod's vendor ID. + public string Vendor { get; set; } + + /// The mod's semantic version number. + public string Version { get; set; } + + /// The mod's web URL. + public string Url { get; set; } + + /// Whether the mod is valid. + public bool Valid { get; set; } = true; + } +} diff --git a/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs b/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs new file mode 100644 index 00000000..ae5c691c --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs @@ -0,0 +1,41 @@ +using Newtonsoft.Json; + +namespace StardewModdingAPI.Web.Models +{ + /// A mod metadata response from Nexus Mods. + public class NexusResponseModel : IModModel + { + /********* + ** Accessors + *********/ + /// The unique mod ID. + public int ID { get; set; } + + /// The mod name. + public string Name { get; set; } + + /// The mod's semantic version number. + public string Version { get; set; } + + /// The mod's web URL. + [JsonProperty("mod_page_uri")] + public string Url { get; set; } + + + /********* + ** Public methods + *********/ + /// Get basic mod metadata. + public ModGenericModel ModInfo() + { + return new ModGenericModel + { + ID = this.ID, + Version = this.Version, + Name = this.Name, + Url = this.Url, + Vendor = "Nexus" + }; + } + } +} diff --git a/src/StardewModdingAPI.Web/Program.cs b/src/StardewModdingAPI.Web/Program.cs new file mode 100644 index 00000000..5e258acc --- /dev/null +++ b/src/StardewModdingAPI.Web/Program.cs @@ -0,0 +1,27 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; + +namespace StardewModdingAPI.Web +{ + /// The main app entry point. + public class Program + { + /********* + ** Public methods + *********/ + /// The main app entry point. + /// The command-line arguments. + public static void Main(string[] args) + { + // configure web server + new WebHostBuilder() + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .UseApplicationInsights() + .Build() + .Run(); + } + } +} diff --git a/src/StardewModdingAPI.Web/Properties/launchSettings.json b/src/StardewModdingAPI.Web/Properties/launchSettings.json new file mode 100644 index 00000000..c15134dc --- /dev/null +++ b/src/StardewModdingAPI.Web/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/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj b/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj new file mode 100644 index 00000000..fa1d88eb --- /dev/null +++ b/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj @@ -0,0 +1,27 @@ + + + + netcoreapp1.1 + portable-net45+win8 + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/StardewModdingAPI.Web/Startup.cs b/src/StardewModdingAPI.Web/Startup.cs new file mode 100644 index 00000000..c7a5e8fe --- /dev/null +++ b/src/StardewModdingAPI.Web/Startup.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace StardewModdingAPI.Web +{ + /// The web app startup configuration. + public class Startup + { + /********* + ** Accessors + *********/ + /// The web app configuration. + public IConfigurationRoot Configuration { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The hosting environment. + public Startup(IHostingEnvironment env) + { + this.Configuration = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables() + .Build(); + } + + /// The method called by the runtime to add services to the container. + /// The service injection container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + + /// The method called by the runtime to configure the HTTP request pipeline. + /// The application builder. + /// The hosting environment. + /// The logger factory. + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(this.Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + app.UseMvc(); + } + } +} diff --git a/src/StardewModdingAPI.Web/appsettings.Development.json b/src/StardewModdingAPI.Web/appsettings.Development.json new file mode 100644 index 00000000..fa8ce71a --- /dev/null +++ b/src/StardewModdingAPI.Web/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/src/StardewModdingAPI.Web/appsettings.json b/src/StardewModdingAPI.Web/appsettings.json new file mode 100644 index 00000000..5fff67ba --- /dev/null +++ b/src/StardewModdingAPI.Web/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Warning" + } + } +} diff --git a/src/StardewModdingAPI.sln b/src/StardewModdingAPI.sln index 3cf129c0..031e2d5f 100644 --- a/src/StardewModdingAPI.sln +++ b/src/StardewModdingAPI.sln @@ -29,7 +29,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardewModdingAPI.Installer EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardewModdingAPI.Tests", "StardewModdingAPI.Tests\StardewModdingAPI.Tests.csproj", "{36CCB19E-92EB-48C7-9615-98EEFD45109B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dewdrop", "..\Dewdrop\Dewdrop.csproj", "{A308F679-51A3-4006-92D5-BAEC7EBD01A1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StardewModdingAPI.Web", "StardewModdingAPI.Web\StardewModdingAPI.Web.csproj", "{A308F679-51A3-4006-92D5-BAEC7EBD01A1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution -- cgit