From 92e5978cf1cf54ff587ee93dcbcb5f5dc05ea55c Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 18 Feb 2019 16:44:35 +0000 Subject: Deleted main console program, and moved server to main --- Main/.vscode/launch.json | 28 +++++++++++++++++---- Main/.vscode/tasks.json | 2 +- Main/Main.csproj | 23 +++++++++--------- Main/Program.cs | 58 +++++++++++--------------------------------- Main/Startup.cs | 47 +++++++++++++++++++++++++++++++++++ Main/wwwroot/css/main.css | 0 Main/wwwroot/index.html | 18 ++++++++++++++ Main/wwwroot/scripts/main.ts | 8 ++++++ Main/wwwroot/tsconfig.json | 8 ++++++ 9 files changed, 131 insertions(+), 61 deletions(-) create mode 100644 Main/Startup.cs create mode 100644 Main/wwwroot/css/main.css create mode 100644 Main/wwwroot/index.html create mode 100644 Main/wwwroot/scripts/main.ts create mode 100644 Main/wwwroot/tsconfig.json (limited to 'Main') diff --git a/Main/.vscode/launch.json b/Main/.vscode/launch.json index 618a536..7a4e712 100644 --- a/Main/.vscode/launch.json +++ b/Main/.vscode/launch.json @@ -5,18 +5,36 @@ "version": "0.2.0", "configurations": [ { - "name": ".NET Core Launch (console)", + "name": ".NET Core Launch (web)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/Main.dll", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/Server.dll", "args": [], "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window - "console": "externalTerminal", "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart" + "internalConsoleOptions": "openOnSessionStart", + "launchBrowser": { + "enabled": true, + "args": "${auto-detect-url}", + "windows": { + "command": "cmd.exe", + "args": "/C start ${auto-detect-url}" + }, + "osx": { + "command": "open" + }, + "linux": { + "command": "xdg-open" + } + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } }, { "name": ".NET Core Attach", diff --git a/Main/.vscode/tasks.json b/Main/.vscode/tasks.json index 9f2ef21..93c8951 100644 --- a/Main/.vscode/tasks.json +++ b/Main/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/Main.csproj" + "${workspaceFolder}/Server.csproj" ], "problemMatcher": "$msCompile" } diff --git a/Main/Main.csproj b/Main/Main.csproj index d132460..fb94fca 100644 --- a/Main/Main.csproj +++ b/Main/Main.csproj @@ -1,4 +1,15 @@ - + + + + netcoreapp2.1 + + + + + + + + @@ -6,14 +17,4 @@ - - - - - - Exe - netcoreapp2.1 - Latest - - diff --git a/Main/Program.cs b/Main/Program.cs index 3d56b36..9db50bb 100644 --- a/Main/Program.cs +++ b/Main/Program.cs @@ -1,51 +1,21 @@ using System; +using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; -using System.Collections.Generic; - -using Database; -using Classes; -using Aggregator.Parser; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; -namespace Main { - internal static class Program { - private static async Task Main(string[] args) { - List configs = new List() { - new Config() { //BBC - Source = "BBC", - Title = 0, - Description = 1, - ArticleLink = 2, - ImageLink = 5, - PublishDate = 4 - }, - new Config(){ //Sky - Source = "Sky", - Title = 0, - Description = 2, - ArticleLink = 1, - ImageLink = 7, - PublishDate = 3 - }, - new Config(){ //ABC - Source = "ABC", - Title = 7, - Description = 11, - ArticleLink = 8, - ImageLink = 0, - PublishDate = 10 - } - }; - string[] xmls = new[] { - await Download.DownloadXML("http://feeds.bbci.co.uk/news/rss.xml"), - await Download.DownloadXML("http://feeds.skynews.com/feeds/rss/world.xml"), - await Download.DownloadXML("https://abcnews.go.com/abcnews/topstories") - }; - List
articles = ParserService.ParseMultiple(xmls, configs).ToList(); - - using (var db = new DatabaseContext()) { - await db.InsertArticles(articles); - } +namespace Server { + public class Program { + public static void Main(string[] args) { + CreateWebHostBuilder(args).Build().Run(); } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); } } diff --git a/Main/Startup.cs b/Main/Startup.cs new file mode 100644 index 0000000..7314290 --- /dev/null +++ b/Main/Startup.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +using Classes; +using Database; +using Aggregator.Parser; + +namespace Server { + public class Startup { + public Startup(IConfiguration configuration) { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + public void ConfigureServices(IServiceCollection services) { + services.Configure(options => { + options.CheckConsentNeeded = context => true; + options.MinimumSameSitePolicy = SameSiteMode.None; + }); + + services.AddDbContext(options => { + options.UseMySQL(Configuration.GetConnectionString("connectionString")); + }); + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env) { + if (env.IsDevelopment()) { + app.UseDeveloperExceptionPage(); + } + else { + app.UseExceptionHandler("/Error"); + app.UseHsts(); + } + + app.UseDefaultFiles(); + } + } +} diff --git a/Main/wwwroot/css/main.css b/Main/wwwroot/css/main.css new file mode 100644 index 0000000..e69de29 diff --git a/Main/wwwroot/index.html b/Main/wwwroot/index.html new file mode 100644 index 0000000..cd392d4 --- /dev/null +++ b/Main/wwwroot/index.html @@ -0,0 +1,18 @@ + + + + + + + Page Title + + + + + + +
+
+ + + \ No newline at end of file diff --git a/Main/wwwroot/scripts/main.ts b/Main/wwwroot/scripts/main.ts new file mode 100644 index 0000000..77a80d3 --- /dev/null +++ b/Main/wwwroot/scripts/main.ts @@ -0,0 +1,8 @@ +var root = document.getElementsByClassName('app'); + +class Article { + Title: HTMLElement; + Description: string; + ArticleLink: string; + Image: HTMLElement; +} \ No newline at end of file diff --git a/Main/wwwroot/tsconfig.json b/Main/wwwroot/tsconfig.json new file mode 100644 index 0000000..89d01c4 --- /dev/null +++ b/Main/wwwroot/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "esnext", + "sourceMap": true, + "outDir": "js/" + } +} \ No newline at end of file -- cgit v1.2.3-13-gbd6f