diff --git a/README.md b/README.md index 7365c59d04..f9314c5e7c 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,13 @@ ### Run the application: 1. Run build.cmd to restore all the necessary packages and generate project files 2. Open a command prompt and cd \src\MusicStore\ -3. Execute CopyAspNetLoader.cmd to copy the AspNet.Loader.dll to the bin directory -4. Execute Run.cmd to launch the app on IISExpress. +3. [Helios]: + 4. Execute CopyAspNetLoader.cmd to copy the AspNet.Loader.dll to the bin directory + 5. Helios.cmd to launch the app on IISExpress. +4. [SelfHost]: + 5. Run Selfhost.cmd (This runs k web) (Note: If your changes to C# files are not picked up in successive builds - try deleting the bin and obj folder) +5. [CustomHost]: + 6. Run CustomHost.cmd (This hosts the app in a console application) (Note: If your changes to C# files are not picked up in successive builds - try deleting the bin and obj folder) ### Adding a new package: 1. Edit the project.json to include the package you want to install @@ -20,4 +25,4 @@ ### Note: 1. By default this script starts the application at http://localhost:5001/. Modify Run.cmd if you would like to change the url -2. Use Visual studio only for editing & intellisense. Don't try to build or run the app from Visual studio. \ No newline at end of file +2. Use Visual studio only for editing & intellisense. Don't try to build or run the app from Visual studio. diff --git a/src/MusicStore/Controllers/CheckoutController.cs b/src/MusicStore/Controllers/CheckoutController.cs index 485bc00dc1..1b7f37840b 100644 --- a/src/MusicStore/Controllers/CheckoutController.cs +++ b/src/MusicStore/Controllers/CheckoutController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Mvc; using MusicStore.Models; using System; using System.Linq; +using System.Threading.Tasks; namespace MusicStore.Controllers { @@ -28,9 +29,9 @@ namespace MusicStore.Controllers //Bug: Http verbs not available. Also binding to FormCollection is not available. //[HttpPost] //public IActionResult AddressAndPayment(FormCollection values) - public IActionResult AddressAndPayment(int workaroundId) + public async Task AddressAndPayment(int workaroundId) { - var coll = this.Context.Request.GetFormAsync().Result; + var formCollection = await Context.Request.GetFormAsync(); var order = new Order(); //TryUpdateModel(order); @@ -39,7 +40,7 @@ namespace MusicStore.Controllers { //if (string.Equals(values["PromoCode"], PromoCode, // StringComparison.OrdinalIgnoreCase) == false) - if (string.Equals(coll.GetValues("PromoCode").FirstOrDefault(), PromoCode, + if (string.Equals(formCollection.GetValues("PromoCode").FirstOrDefault(), PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return View(order); diff --git a/src/MusicStore/Controllers/StoreManagerController.cs b/src/MusicStore/Controllers/StoreManagerController.cs index 76a9a4d073..5496caf9b7 100644 --- a/src/MusicStore/Controllers/StoreManagerController.cs +++ b/src/MusicStore/Controllers/StoreManagerController.cs @@ -40,7 +40,7 @@ namespace MusicStore.Controllers { //Bug: Need method HttpNotFound() on Controller //return HttpNotFound(); - return this.HttpNotFound(); + return new HttpStatusCodeResult(404); } return View(album); } @@ -87,7 +87,7 @@ namespace MusicStore.Controllers { //Bug: Need method HttpNotFound() on Controller //return HttpNotFound(); - return this.HttpNotFound(); + return new HttpStatusCodeResult(404); } //ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId); //ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId); @@ -122,7 +122,7 @@ namespace MusicStore.Controllers if (album == null) { //Bug: Missing Helper - return this.HttpNotFound(); + return new HttpStatusCodeResult(404); } return View(album); } @@ -151,27 +151,4 @@ namespace MusicStore.Controllers // base.Dispose(disposing); //} } - - /// - /// Bug: HttpNotFoundResult not available in Controllers. Work around. - /// - public class HttpNotFoundResult : HttpStatusCodeResult - { - public HttpNotFoundResult() - : base(404) - { - - } - } - - /// - /// Bug: HttpNotFoundResult not available in Controllers. Work around. - /// - public static class Extensions - { - public static IActionResult HttpNotFound(this Controller controller) - { - return new HttpNotFoundResult(); - } - } } \ No newline at end of file diff --git a/src/MusicStore/CustomHost.cmd b/src/MusicStore/CustomHost.cmd new file mode 100644 index 0000000000..dc89e0482a --- /dev/null +++ b/src/MusicStore/CustomHost.cmd @@ -0,0 +1,8 @@ +REM Selfhost does not need this bin folder +rmdir /S /Q bin + +REM Figure out path to K.cmd + +FOR /F %%j IN ('dir /b /o:-d ..\..\packages\ProjectK*') do (SET K_CMD_PATH=..\..\packages\%%j\tools\k.cmd) +echo Found k.cmd at %K_CMD_PATH%. Starting the self host application +%K_CMD_PATH% run server.urls=http://localhost:5001 \ No newline at end of file diff --git a/src/MusicStore/Helios.cmd b/src/MusicStore/Helios.cmd new file mode 100644 index 0000000000..9fa1a25ea7 --- /dev/null +++ b/src/MusicStore/Helios.cmd @@ -0,0 +1 @@ +"%ProgramFiles(x86)%\iis Express\iisexpress.exe" /port:5001 /path:"%cd%" \ No newline at end of file diff --git a/src/MusicStore/LKG.json b/src/MusicStore/LKG.json index 8107f88f10..36efaf1a2c 100644 --- a/src/MusicStore/LKG.json +++ b/src/MusicStore/LKG.json @@ -1,30 +1,38 @@ { "version": "0.1-alpha-*", "dependencies": { - "Helios": "0.1-alpha-098", - "Microsoft.AspNet.Abstractions": "0.1-alpha-152", - "Microsoft.AspNet.Mvc": "0.1-alpha-296", - "Microsoft.AspNet.Razor": "0.1-alpha-136", - "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-108", - "Microsoft.AspNet.DependencyInjection": "0.1-alpha-159", - "Microsoft.AspNet.RequestContainer": "0.1-alpha-124", - "Microsoft.AspNet.Routing": "0.1-alpha-100", - "Microsoft.AspNet.Mvc.ModelBinding": "0.1-alpha-296", - "Microsoft.AspNet.Mvc.Core": "0.1-alpha-296", - "Microsoft.AspNet.Mvc.Razor": "0.1-alpha-296", - "Microsoft.AspNet.Mvc.Rendering": "0.1-alpha-296", - "Microsoft.AspNet.StaticFiles": "0.1-alpha-081", - "System.Security.Claims": "0.1-alpha-045", - "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-092", - "Microsoft.AspNet.Identity": "0.1-alpha-155", - "Microsoft.AspNet.Identity.Entity": "0.1-alpha-155", - "Microsoft.AspNet.Identity.InMemory": "0.1-alpha-155" + "Helios": "0.1-alpha-107", + "Microsoft.AspNet.Abstractions": "0.1-alpha-162", + "Microsoft.AspNet.Mvc": "0.1-alpha-324", + "Microsoft.AspNet.Razor": "0.1-alpha-144", + "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-117", + "Microsoft.AspNet.DependencyInjection": "0.1-alpha-169", + "Microsoft.AspNet.RequestContainer": "0.1-alpha-133", + "Microsoft.AspNet.Routing": "0.1-alpha-115", + "Microsoft.AspNet.Mvc.ModelBinding": "0.1-alpha-324", + "Microsoft.AspNet.Mvc.Core": "0.1-alpha-324", + "Microsoft.AspNet.Mvc.Razor": "0.1-alpha-324", + "Microsoft.AspNet.Mvc.Rendering": "0.1-alpha-324", + "Microsoft.AspNet.StaticFiles": "0.1-alpha-090", + "System.Security.Claims": "0.1-alpha-052", + "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-100", + "Microsoft.AspNet.Identity": "0.1-alpha-164", + "Microsoft.AspNet.Identity.Entity": "0.1-alpha-164", + "Microsoft.AspNet.Identity.InMemory": "0.1-alpha-164", + "Microsoft.Data.Entity": "0.1-alpha-284", + "Microsoft.Data.Relational": "0.1-alpha-284", + "Microsoft.Data.SqlServer": "0.1-pre-284", + "Microsoft.Data.InMemory": "0.1-alpha-284", + "Microsoft.AspNet.Diagnostics": "0.1-alpha-025", + "Microsoft.AspNet.Hosting": "0.1-alpha-133", + "Microsoft.AspNet.Server.WebListener": "0.1-alpha-039" }, "configurations": { "net45": { "dependencies": { "System.Runtime": "", - "System.ComponentModel.DataAnnotations": "" + "System.ComponentModel.DataAnnotations": "", + "System.Data": "" } }, "k10": { @@ -38,7 +46,7 @@ "System.Console": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.Diagnostics.Tools": "4.0.0.0", - "Microsoft.ComponentModel.DataAnnotations": "0.1-alpha-032" + "Microsoft.ComponentModel.DataAnnotations": "4.0.10.0" } } } diff --git a/src/MusicStore/Program.cs b/src/MusicStore/Program.cs new file mode 100644 index 0000000000..d37c349dbe --- /dev/null +++ b/src/MusicStore/Program.cs @@ -0,0 +1,53 @@ +using Microsoft.AspNet.ConfigurationModel; +using Microsoft.AspNet.ConfigurationModel.Sources; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.AspNet.Hosting; +using System; +using System.Threading.Tasks; + +namespace MusicStore +{ + public class Program + { + private readonly IServiceProvider _hostServiceProvider; + + public Program(IServiceProvider hostServiceProvider) + { + _hostServiceProvider = hostServiceProvider; + } + + public Task Main(string[] args) + { + //Add command line to the configuration source to read command line parameters. + var config = new Configuration(); + config.AddCommandLine(args); + + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices(config)); + var services = serviceCollection.BuildServiceProvider(_hostServiceProvider); + + var context = new HostingContext() + { + Services = services, + Configuration = config, + ServerName = "Microsoft.AspNet.Server.WebListener", + ApplicationName = "BugTracker" + }; + + var engine = services.GetService(); + if (engine == null) + { + throw new Exception("TODO: IHostingEngine service not available exception"); + } + + using (engine.Start(context)) + { + Console.WriteLine("Started the server.."); + Console.WriteLine("Press any key to stop the server"); + Console.ReadLine(); + } + return Task.FromResult(0); + } + } +} \ No newline at end of file diff --git a/src/MusicStore/SelfHost.cmd b/src/MusicStore/SelfHost.cmd new file mode 100644 index 0000000000..d79b405b6c --- /dev/null +++ b/src/MusicStore/SelfHost.cmd @@ -0,0 +1,8 @@ +REM Selfhost does not need this bin folder +rmdir /S /Q bin + +REM Figure out path to K.cmd + +FOR /F %%j IN ('dir /b /o:-d ..\..\packages\ProjectK*') do (SET K_CMD_PATH=..\..\packages\%%j\tools\k.cmd) +echo Found k.cmd at %K_CMD_PATH%. Starting the self host application +%K_CMD_PATH% web \ No newline at end of file diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index a98e501d75..d67d4cc171 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -6,6 +6,7 @@ using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.DependencyInjection.NestedProviders; +using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.InMemory; using Microsoft.AspNet.Mvc; @@ -21,6 +22,16 @@ public class Startup { CreateAdminUser(); + app.UseErrorPage(new ErrorPageOptions() + { + ShowCookies = true, + ShowEnvironment = true, + ShowExceptionDetails = true, + ShowHeaders = true, + ShowQuery = true, + ShowSourceCode = true + }); + app.UseFileServer(); var serviceProvider = MvcServices.GetDefaultServices().BuildServiceProvider(app.ServiceProvider); diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index 06605a32a4..18e6da6e8d 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -22,7 +22,13 @@ "Microsoft.Data.Entity": "0.1-alpha-*", "Microsoft.Data.Relational": "0.1-alpha-*", "Microsoft.Data.SqlServer": "0.1-pre-*", - "Microsoft.Data.InMemory": "0.1-alpha-*" + "Microsoft.Data.InMemory": "0.1-alpha-*", + "Microsoft.AspNet.Diagnostics": "0.1-alpha-*", + "Microsoft.AspNet.Hosting": "0.1-alpha-*", + "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" + }, + "commands": { + "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "configurations": { "net45": { @@ -34,8 +40,8 @@ }, "k10": { "dependencies": { - "System.Collections": "4.0.0.0", - "System.Linq": "4.0.0.0", + "System.Collections": "4.0.0.0", + "System.Linq": "4.0.0.0", "System.Runtime": "4.0.20.0", "System.Dynamic.Runtime": "4.0.0.0", "System.Threading.Tasks": "4.0.0.0", @@ -43,7 +49,7 @@ "System.Console": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.Diagnostics.Tools": "4.0.0.0", - "Microsoft.ComponentModel.DataAnnotations": "0.1-alpha-*" + "Microsoft.ComponentModel.DataAnnotations": "4.0.10.0" } } } diff --git a/src/MusicStore/web.config b/src/MusicStore/web.config index 3db5091cf0..eeb4f5b40a 100644 --- a/src/MusicStore/web.config +++ b/src/MusicStore/web.config @@ -7,7 +7,8 @@ - + +