From 06ed54b2c6c2e1f49d6975a34ea36f685d7f7c49 Mon Sep 17 00:00:00 2001 From: James Stine Date: Sun, 13 Aug 2017 17:44:00 -0400 Subject: First commit. --- .gitignore | 235 +++++++++++++++++++++++++++++++++ Dewdrop.sln | 22 +++ 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 ++ 12 files changed, 565 insertions(+) create mode 100644 .gitignore create mode 100644 Dewdrop.sln 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..500c9423 --- /dev/null +++ b/.gitignore @@ -0,0 +1,235 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ +Dewdrop/ScaffoldingReadMe.txt diff --git a/Dewdrop.sln b/Dewdrop.sln new file mode 100644 index 00000000..761e6ccc --- /dev/null +++ b/Dewdrop.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dewdrop", "Dewdrop\Dewdrop.csproj", "{0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal 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 From 9791de306c22c744732219dadfd97b7dd556a5b2 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Sep 2017 23:35:18 -0400 Subject: minor cleanup, formatting, documentation (#336) --- Dewdrop.sln | 22 ---------------- Dewdrop/Controllers/CheckController.cs | 8 +++++- Dewdrop/Models/IModModel.cs | 18 +++++-------- Dewdrop/Models/ModGenericModel.cs | 37 +++++++++----------------- Dewdrop/Models/NexusResponseModel.cs | 47 +++++++++++++++------------------- Dewdrop/Program.cs | 22 ++++++++-------- Dewdrop/Startup.cs | 39 +++++++++++++++++----------- src/StardewModdingAPI.sln | 17 ++++++++++++ 8 files changed, 98 insertions(+), 112 deletions(-) delete mode 100644 Dewdrop.sln diff --git a/Dewdrop.sln b/Dewdrop.sln deleted file mode 100644 index 761e6ccc..00000000 --- a/Dewdrop.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.16 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dewdrop", "Dewdrop\Dewdrop.csproj", "{0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0DEC7A86-4D43-43B0-A5F8-7686DDB6EC97}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Dewdrop/Controllers/CheckController.cs b/Dewdrop/Controllers/CheckController.cs index f3cdd364..def2edbc 100644 --- a/Dewdrop/Controllers/CheckController.cs +++ b/Dewdrop/Controllers/CheckController.cs @@ -8,10 +8,16 @@ 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) { @@ -25,7 +31,7 @@ namespace Dewdrop.Controllers try { // create request with HttpRequestMessage - var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.Id}")); + 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"); diff --git a/Dewdrop/Models/IModModel.cs b/Dewdrop/Models/IModModel.cs index aa6583d4..f1b09f8a 100644 --- a/Dewdrop/Models/IModModel.cs +++ b/Dewdrop/Models/IModModel.cs @@ -1,16 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Dewdrop.Models +namespace Dewdrop.Models { - interface IModModel + /// A mod metadata response which provides a method to extract generic info. + internal interface IModModel { - /// - /// Basic information in the form of - /// - /// + /********* + ** Public methods + *********/ + /// Get basic mod metadata. ModGenericModel ModInfo(); } } diff --git a/Dewdrop/Models/ModGenericModel.cs b/Dewdrop/Models/ModGenericModel.cs index 829c396a..0da04295 100644 --- a/Dewdrop/Models/ModGenericModel.cs +++ b/Dewdrop/Models/ModGenericModel.cs @@ -1,40 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Dewdrop.Models +namespace Dewdrop.Models { + /// Generic metadata about a mod. public class ModGenericModel { - /// - /// An identifier for the mod. - /// - public int Id { get; set; } + /********* + ** Accessors + *********/ + /// The unique mod ID. + public int ID { get; set; } - /// - /// The mod's name. - /// + /// The mod name. public string Name { get; set; } - /// - /// The vendor identifier for the mod. - /// + /// The mod's vendor ID. public string Vendor { get; set; } - /// - /// The mod's version number. - /// + /// The mod's semantic version number. public string Version { get; set; } - /// - /// The mod's URL - /// + /// The mod's web URL. public string Url { get; set; } - /// - /// Is the mod a valid mod. - /// + /// Whether the mod is valid. public bool Valid { get; set; } = true; } } diff --git a/Dewdrop/Models/NexusResponseModel.cs b/Dewdrop/Models/NexusResponseModel.cs index e954a8bc..fa663910 100644 --- a/Dewdrop/Models/NexusResponseModel.cs +++ b/Dewdrop/Models/NexusResponseModel.cs @@ -1,46 +1,39 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Dewdrop.Models { + /// A mod metadata response from Nexus Mods. public class NexusResponseModel : IModModel { - /// - /// The name of the mod. - /// - [JsonProperty("name")] + /********* + ** Accessors + *********/ + /// The unique mod ID. + public int ID { get; set; } + + /// The mod name. public string Name { get; set; } - /// - /// The version of the mod. - /// - [JsonProperty("version")] + /// The mod's semantic version number. public string Version { get; set; } - /// - /// The NexusMod ID for the mod. - /// - [JsonProperty("id")] - public int Id { get; set; } - - /// - /// The URL of the mod. - /// + /// The mod's web URL. [JsonProperty("mod_page_uri")] public string Url { get; set; } - /// - /// Return mod information about a Nexus mod - /// - /// + + /********* + ** Public methods + *********/ + /// Get basic mod metadata. public ModGenericModel ModInfo() { return new ModGenericModel { - Id = Id, - Version = Version, - Name = Name, - Url = Url, + ID = this.ID, + Version = this.Version, + Name = this.Name, + Url = this.Url, Vendor = "Nexus" }; } diff --git a/Dewdrop/Program.cs b/Dewdrop/Program.cs index c6a5a642..0e831a23 100644 --- a/Dewdrop/Program.cs +++ b/Dewdrop/Program.cs @@ -1,27 +1,27 @@ -using System; -using System.IO; -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using System.IO; using Microsoft.AspNetCore.Hosting; -using Newtonsoft.Json; -using System.Collections.Generic; 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) { - var host = new WebHostBuilder() + // configure web server + new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() .UseApplicationInsights() - .Build(); - - host.Run(); + .Build() + .Run(); } } } diff --git a/Dewdrop/Startup.cs b/Dewdrop/Startup.cs index 00c18bab..d1618037 100644 --- a/Dewdrop/Startup.cs +++ b/Dewdrop/Startup.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -10,33 +6,46 @@ 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) { - var builder = new ConfigurationBuilder() + this.Configuration = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); + .AddEnvironmentVariables() + .Build(); } - public IConfigurationRoot Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. + /// The method called by the runtime to add services to the container. + /// The service injection 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. + /// 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(Configuration.GetSection("Logging")); + loggerFactory.AddConsole(this.Configuration.GetSection("Logging")); loggerFactory.AddDebug(); - app.UseMvc(); } } diff --git a/src/StardewModdingAPI.sln b/src/StardewModdingAPI.sln index a2e0ec44..3cf129c0 100644 --- a/src/StardewModdingAPI.sln +++ b/src/StardewModdingAPI.sln @@ -29,6 +29,8 @@ 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}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,8 +81,23 @@ Global {36CCB19E-92EB-48C7-9615-98EEFD45109B}.Release|Mixed Platforms.Build.0 = Release|x86 {36CCB19E-92EB-48C7-9615-98EEFD45109B}.Release|x86.ActiveCfg = Release|x86 {36CCB19E-92EB-48C7-9615-98EEFD45109B}.Release|x86.Build.0 = Release|x86 + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|x86.ActiveCfg = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|x86.Build.0 = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Any CPU.Build.0 = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|x86.ActiveCfg = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {70143042-A862-47A8-A677-7C819DDC90DC} + EndGlobalSection EndGlobal -- cgit 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 From 1f32d72099b16a554c4c79f499f678ebd6a904a9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Sep 2017 23:39:20 -0400 Subject: simplify .gitignore --- .gitignore | 249 ++----------------------------------------------------------- 1 file changed, 5 insertions(+), 244 deletions(-) diff --git a/.gitignore b/.gitignore index 91b9bce3..f2d50778 100644 --- a/.gitignore +++ b/.gitignore @@ -1,264 +1,25 @@ -# SMAPI Specific Ignores -StardewModdingAPI/bin/ -StardewModdingAPI/obj/ -TrainerMod/bin/ -TrainerMod/obj/ -StardewInjector/bin/ -StardewInjector/obj/ -packages/ -steamapps/ - -*.symlink -*.lnk -!*.exe -!*.dll - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files +# user-specific files *.suo *.user *.userosscache *.sln.docstates -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results +# build results [Dd]ebug/ -[Dd]ebugPublic/ [Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ [Bb]in/ [Oo]bj/ -[Ll]og/ -# Visual Studio 2015 cache/options directory +# Visual Studio cache/options .vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in +# ReSharper _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# NuGet Packages +# NuGet packages *.nupkg -# The packages folder can be ignored because of Package Restore **/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files *.nuget.props *.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Microsoft Azure ApplicationInsights config file -ApplicationInsights.config - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntv