Bladeren bron

Cleanup and configuration layering

Lukas Angerer 5 jaren geleden
bovenliggende
commit
5eb30d2c45

+ 0 - 6
CronAlarm.sln

@@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.30711.63
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CronAlarm", "CronAlarm\CronAlarm.csproj", "{7E64081D-B278-4DA4-8936-9993A53E9C19}"
 EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ninject.Web.AspNetCore", "H:\development\Ninject\Ninject.Web.AspNetCore\src\Ninject.Web.AspNetCore\Ninject.Web.AspNetCore.csproj", "{5B8D8AA8-81ED-4800-9580-0A24B9646368}"
-EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -17,10 +15,6 @@ Global
 		{7E64081D-B278-4DA4-8936-9993A53E9C19}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{7E64081D-B278-4DA4-8936-9993A53E9C19}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{7E64081D-B278-4DA4-8936-9993A53E9C19}.Release|Any CPU.Build.0 = Release|Any CPU
-		{5B8D8AA8-81ED-4800-9580-0A24B9646368}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{5B8D8AA8-81ED-4800-9580-0A24B9646368}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{5B8D8AA8-81ED-4800-9580-0A24B9646368}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{5B8D8AA8-81ED-4800-9580-0A24B9646368}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 7
CronAlarm/CronAlarm.csproj

@@ -7,17 +7,12 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <None Include="wwwroot\cron-fragment.txt">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
+    <None Include="wwwroot\data\cron-fragment.txt" />
   </ItemGroup>
 
   <ItemGroup>
     <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
-  </ItemGroup>
-
-  <ItemGroup>
-    <ProjectReference Include="H:\development\Ninject\Ninject.Web.AspNetCore\src\Ninject.Web.AspNetCore\Ninject.Web.AspNetCore.csproj" />
+    <PackageReference Include="Ninject.Web.AspNetCore" Version="5.1.0-alpha1" />
   </ItemGroup>
 
 </Project>

+ 13 - 1
CronAlarm/Program.cs

@@ -13,6 +13,7 @@ namespace CronAlarm
         public static void Main(string[] args)
         {
             var hostConfiguration = new AspNetCoreHostConfiguration(args)
+                    .UseWebHostBuilder(() => CreateWebHostBuilder(args))
                     .UseStartup<Startup>()
                     .UseKestrel()
                     .BlockOnStart();
@@ -21,7 +22,18 @@ namespace CronAlarm
             host.Start();
         }
 
-        public static IKernel CreateKernel()
+        private static IWebHostBuilder CreateWebHostBuilder(string[] args)
+        {
+            var config = new DefaultWebHostConfiguration(args);
+
+            config.ConfigureAll();
+            return config.GetBuilder().ConfigureAppConfiguration((hostingContext, config) =>
+                {
+                    config.AddJsonFile("wwwroot/data/settings.json", optional: true, reloadOnChange: true);
+                });
+        }
+
+        private static IKernel CreateKernel()
         {
             var settings = new NinjectSettings();
             // Unfortunately, in .NET Core projects, referenced NuGet assemblies are not copied to the output directory

+ 2 - 17
CronAlarm/Properties/launchSettings.json

@@ -1,20 +1,5 @@
 {
-  "iisSettings": {
-    "windowsAuthentication": false,
-    "anonymousAuthentication": true,
-    "iisExpress": {
-      "applicationUrl": "http://localhost:54198",
-      "sslPort": 44334
-    }
-  },
   "profiles": {
-    "IIS Express": {
-      "commandName": "IISExpress",
-      "launchBrowser": true,
-      "environmentVariables": {
-        "ASPNETCORE_ENVIRONMENT": "Development"
-      }
-    },
     "CronAlarm": {
       "commandName": "Project",
       "launchBrowser": true,
@@ -22,14 +7,14 @@
         "ASPNETCORE_ENVIRONMENT": "Development"
       },
       "dotnetRunMessages": "true",
-      "applicationUrl": "https://localhost:5001;http://localhost:5000"
+      "applicationUrl": "http://localhost:5000"
     },
     "Docker": {
       "commandName": "Docker",
       "launchBrowser": true,
       "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
       "publishAllPorts": true,
-      "useSSL": true
+      "useSSL": false
     }
   }
 }

+ 2 - 2
CronAlarm/Startup.cs

@@ -40,10 +40,10 @@ namespace CronAlarm
             {
                 app.UseExceptionHandler("/Error");
                 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
-                app.UseHsts();
+                //app.UseHsts();
             }
 
-            app.UseHttpsRedirection();
+            //app.UseHttpsRedirection();
             app.UseStaticFiles();
 
             app.UseRouting();

+ 1 - 49
CronAlarm/appsettings.json

@@ -8,54 +8,6 @@
   },
   "AllowedHosts": "*",
   "CronFragment": {
-    "FilePath": "./wwwroot/cron-fragment.txt"
-  },
-  "Alerts": {
-    "Command": "/home/pi/mpc-alarm-cron.sh",
-    "Groups": [
-      {
-        "Name": "Weekdays",
-        "Options": [
-          {
-            "Label": "06:20 - Work",
-            "Pattern": "20 06 * * MON-FRI"
-          },
-          {
-            "Label": "08:30 - Holidays",
-            "Pattern": "30 08 * * MON-FRI"
-          },
-          {
-            "Label": "09:00 - Sleeping In",
-            "Pattern": "00 09 * * MON-FRI"
-          }
-        ]
-      },
-      {
-        "Name": "Saturday",
-        "Options": [
-          {
-            "Label": "08:20 - Long-Jog",
-            "Pattern": "20 08 * * SAT"
-          },
-          {
-            "Label": "08:00 - Long-Jog (early)",
-            "Pattern": "00 08 * * SAT"
-          },
-          {
-            "Label": "07:40 - Long-Jog (very early)",
-            "Pattern": "40 07 * * SAT"
-          }
-        ]
-      },
-      {
-        "Name": "Sunday",
-        "Options": [
-          {
-            "Label": "09:00 - Lazy",
-            "Pattern": "00 09 * * SUN"
-          }
-        ]
-      }
-    ]
+    "FilePath": "./wwwroot/data/cron-fragment.txt"
   }
 }

+ 0 - 3
CronAlarm/wwwroot/cron-fragment.txt

@@ -1,3 +0,0 @@
-30 08 * * MON-FRI       /home/pi/mpc-alarm-cron.sh
-20 08 * * SAT           /home/pi/mpc-alarm-cron.sh
-00 09 * * SUN           /home/pi/mpc-alarm-cron.sh

+ 6 - 0
CronAlarm/wwwroot/data/cron-fragment.txt

@@ -0,0 +1,6 @@
+# Weekdays / 06:20 - Work
+20 06 * * MON-FRI        /home/pi/mpc-alarm-cron.sh
+# Saturday / 08:20 - Long-Jog
+20 08 * * SAT            /home/pi/mpc-alarm-cron.sh
+# Sunday / 09:00 - Lazy
+00 09 * * SUN            /home/pi/mpc-alarm-cron.sh

+ 50 - 0
CronAlarm/wwwroot/data/settings.json

@@ -0,0 +1,50 @@
+{
+  "Alerts": {
+    "Command": "/home/pi/mpc-alarm-cron.sh",
+    "Groups": [
+      {
+        "Name": "Weekdays",
+        "Options": [
+          {
+            "Label": "06:20 - Work",
+            "Pattern": "20 06 * * MON-FRI"
+          },
+          {
+            "Label": "08:30 - Holidays",
+            "Pattern": "30 08 * * MON-FRI"
+          },
+          {
+            "Label": "09:00 - Sleeping In",
+            "Pattern": "00 09 * * MON-FRI"
+          }
+        ]
+      },
+      {
+        "Name": "Saturday",
+        "Options": [
+          {
+            "Label": "08:20 - Long-Jog",
+            "Pattern": "20 08 * * SAT"
+          },
+          {
+            "Label": "08:00 - Long-Jog (early)",
+            "Pattern": "00 08 * * SAT"
+          },
+          {
+            "Label": "07:40 - Long-Jog (very early)",
+            "Pattern": "40 07 * * SAT"
+          }
+        ]
+      },
+      {
+        "Name": "Sunday",
+        "Options": [
+          {
+            "Label": "09:00 - Lazy",
+            "Pattern": "00 09 * * SUN"
+          }
+        ]
+      }
+    ]
+  }
+}