From abf7d16af0ed6842bfc1a6f66323c9d5728b5ec7 Mon Sep 17 00:00:00 2001 From: Maksim Makushchenko Date: Tue, 31 Dec 2019 13:11:02 +0300 Subject: [PATCH] Add project files. --- Excursion360.Desktop.sln | 25 +++++++ .../Excursion360.Desktop.csproj | 17 +++++ Excursion360.Desktop/Extensions.cs | 17 +++++ Excursion360.Desktop/Program.cs | 69 +++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 Excursion360.Desktop.sln create mode 100644 Excursion360.Desktop/Excursion360.Desktop.csproj create mode 100644 Excursion360.Desktop/Extensions.cs create mode 100644 Excursion360.Desktop/Program.cs diff --git a/Excursion360.Desktop.sln b/Excursion360.Desktop.sln new file mode 100644 index 0000000..16bcd2c --- /dev/null +++ b/Excursion360.Desktop.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29521.150 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excursion360.Desktop", "Excursion360.Desktop\Excursion360.Desktop.csproj", "{57AB85E0-518E-4278-846B-50B2A63B6C4C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {57AB85E0-518E-4278-846B-50B2A63B6C4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57AB85E0-518E-4278-846B-50B2A63B6C4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57AB85E0-518E-4278-846B-50B2A63B6C4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57AB85E0-518E-4278-846B-50B2A63B6C4C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A23D4AEF-7BC6-4281-B5BA-CE087ABAD54C} + EndGlobalSection +EndGlobal diff --git a/Excursion360.Desktop/Excursion360.Desktop.csproj b/Excursion360.Desktop/Excursion360.Desktop.csproj new file mode 100644 index 0000000..b61289f --- /dev/null +++ b/Excursion360.Desktop/Excursion360.Desktop.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp3.1 + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Excursion360.Desktop/Extensions.cs b/Excursion360.Desktop/Extensions.cs new file mode 100644 index 0000000..55e404f --- /dev/null +++ b/Excursion360.Desktop/Extensions.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Excursion360.Desktop +{ + static class Extensions + { + public static ILogger CreateLogger(this IWebHost host, string categoryName) + { + return host.Services.GetService().CreateLogger(categoryName); + } + } +} diff --git a/Excursion360.Desktop/Program.cs b/Excursion360.Desktop/Program.cs new file mode 100644 index 0000000..a47947f --- /dev/null +++ b/Excursion360.Desktop/Program.cs @@ -0,0 +1,69 @@ +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using System; +using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting.Server.Features; +using System.Linq; +using System.Threading.Tasks; + +namespace Excursion360.Desktop +{ + class Program + { + static async Task Main(string[] args) + { + var host = WebHost + .CreateDefaultBuilder() + .UseWebRoot("") + .Configure(app => app.UseStaticFiles()) + .ConfigureLogging(logs => + { + logs.SetMinimumLevel(LogLevel.Information); + }) + .Build(); + + var firefoxInstallLogger = host.CreateLogger("FireFox.Installer"); + + if (!IsFirefoxInstalled(firefoxInstallLogger)) + { + if (!TryInstallFirefox(firefoxInstallLogger)) + { + return; + } + } + var hostTask = host.RunAsync().ConfigureAwait(false); + + var url = host.ServerFeatures + .Get() + .Addresses + .Single(a => a.StartsWith("http:", StringComparison.Ordinal)); + + StartFirefox(host.CreateLogger("FireFox.Start"), url); + + await hostTask; + } + + + static bool IsFirefoxInstalled(ILogger logger) + { + logger.LogInformation("Checking for firefox..."); + // TODO + return true; + } + + static bool TryInstallFirefox(ILogger logger) + { + logger.LogInformation("Installing firefox..."); + // TODO + return true; + } + + private static void StartFirefox(ILogger logger, string url) + { + logger.LogInformation($"Starting firefox on {url}"); + } + } +}