From bc33295bc4490da7230b200b8bbaf7c7c6491300 Mon Sep 17 00:00:00 2001
From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com>
Date: Sun, 26 Nov 2023 14:17:57 +0700
Subject: [PATCH] Disable AOT, refactor Program.cs
---
BotNet/BotNet.csproj | 1 -
BotNet/Program.cs | 142 ++++++++++--------
.../local/appInsights.arm.json | 66 --------
BotNet/Properties/launchSettings.json | 2 +-
BotNet/Properties/serviceDependencies.json | 11 --
.../Properties/serviceDependencies.local.json | 13 --
BotNet/Startup.cs | 43 ------
7 files changed, 81 insertions(+), 197 deletions(-)
delete mode 100644 BotNet/Properties/ServiceDependencies/local/appInsights.arm.json
delete mode 100644 BotNet/Properties/serviceDependencies.json
delete mode 100644 BotNet/Properties/serviceDependencies.local.json
delete mode 100644 BotNet/Startup.cs
diff --git a/BotNet/BotNet.csproj b/BotNet/BotNet.csproj
index 7e20125..7f2802b 100644
--- a/BotNet/BotNet.csproj
+++ b/BotNet/BotNet.csproj
@@ -6,7 +6,6 @@
Linux
true
true
- true
diff --git a/BotNet/Program.cs b/BotNet/Program.cs
index 8cee582..46a21a7 100644
--- a/BotNet/Program.cs
+++ b/BotNet/Program.cs
@@ -1,5 +1,4 @@
-using BotNet;
-using BotNet.Bot;
+using BotNet.Bot;
using BotNet.Services.BMKG;
using BotNet.Services.Brainfuck;
using BotNet.Services.ClearScript;
@@ -9,10 +8,11 @@
using BotNet.Services.GoogleMap;
using BotNet.Services.Hosting;
using BotNet.Services.ImageConverter;
+using BotNet.Services.Meme;
using BotNet.Services.OpenAI;
using BotNet.Services.OpenGraph;
-using BotNet.Services.Piston;
using BotNet.Services.Pesto;
+using BotNet.Services.Piston;
using BotNet.Services.Preview;
using BotNet.Services.ProgrammerHumor;
using BotNet.Services.Stability;
@@ -22,71 +22,89 @@
using BotNet.Services.Tokopedia;
using BotNet.Services.Typography;
using BotNet.Services.Weather;
+using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans.Hosting;
-using BotNet.Services.Meme;
-Host.CreateDefaultBuilder(args)
- .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup())
- .ConfigureAppConfiguration((hostBuilderContext, configurationBuilder) => {
- configurationBuilder
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .AddJsonFile($"appsettings.{hostBuilderContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
- .AddKeyPerFile("/run/secrets", optional: true, reloadOnChange: true)
- .AddEnvironmentVariables("ASPNETCORE_")
- .AddUserSecrets(optional: true, reloadOnChange: true);
- })
- .ConfigureServices((hostBuilderContext, services) => {
- IConfiguration configuration = hostBuilderContext.Configuration;
+WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
+
+// HTTPS
+builder.WebHost.UseKestrelHttpsConfiguration();
+
+// Configuration sources
+builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
+ .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
+ .AddKeyPerFile("/run/secrets", optional: true, reloadOnChange: true)
+ .AddEnvironmentVariables("ASPNETCORE_")
+ .AddUserSecrets(optional: true, reloadOnChange: true);
+
+// DI Services
+builder.Services.Configure(builder.Configuration.GetSection("HostingOptions"));
+builder.Services.Configure(builder.Configuration.GetSection("TenorOptions"));
+builder.Services.Configure(builder.Configuration.GetSection("V8Options"));
+builder.Services.Configure(builder.Configuration.GetSection("PistonOptions"));
+builder.Services.Configure(builder.Configuration.GetSection("PestoOptions"));
+builder.Services.Configure(builder.Configuration.GetSection("OpenAIOptions"));
+builder.Services.Configure(builder.Configuration.GetSection("StabilityOptions"));
+builder.Services.Configure(builder.Configuration.GetSection("GoogleMapOptions"));
+builder.Services.Configure(builder.Configuration.GetSection("WeatherOptions"));
+builder.Services.AddHttpClient();
+builder.Services.AddTenorClient();
+builder.Services.AddFontService();
+builder.Services.AddColorCardRenderer();
+builder.Services.AddOpenGraph();
+builder.Services.AddImageConverter();
+builder.Services.AddBrainfuckTranspiler();
+builder.Services.AddV8Evaluator();
+builder.Services.AddPistonClient();
+builder.Services.AddPestoClient();
+builder.Services.AddOpenAIClient();
+builder.Services.AddProgrammerHumorScraper();
+builder.Services.AddTiktokServices();
+builder.Services.AddCSharpEvaluator();
+builder.Services.AddThisXDoesNotExist();
+builder.Services.AddCraiyonClient();
+builder.Services.AddStabilityClient();
+builder.Services.AddTokopediaServices();
+builder.Services.AddGoogleMaps();
+builder.Services.AddWeatherService();
+builder.Services.AddBMKG();
+builder.Services.AddPreviewServices();
+builder.Services.AddMemeGenerator();
+
+// Hosted Services
+builder.Services.Configure(builder.Configuration.GetSection("BotOptions"));
+builder.Services.AddSingleton();
+builder.Services.AddHostedService();
+
+// Telegram Bot
+builder.Services.AddTelegramBot(botToken: builder.Configuration["BotOptions:AccessToken"]!);
+
+// Localhost Orleans
+builder.Host.UseOrleans((hostBuilderContext, siloBuilder) => {
+ siloBuilder.UseLocalhostClustering();
+});
+
+// Web
+builder.Services.AddControllersWithViews().AddNewtonsoftJson();
+builder.Services.AddResponseCaching();
+builder.Services.AddResponseCompression();
+
+WebApplication app = builder.Build();
- // DI Services
- services.Configure(configuration.GetSection("HostingOptions"));
- services.Configure(configuration.GetSection("TenorOptions"));
- services.Configure(configuration.GetSection("V8Options"));
- services.Configure(configuration.GetSection("PistonOptions"));
- services.Configure(configuration.GetSection("PestoOptions"));
- services.Configure(configuration.GetSection("OpenAIOptions"));
- services.Configure(configuration.GetSection("StabilityOptions"));
- services.Configure(configuration.GetSection("GoogleMapOptions"));
- services.Configure(configuration.GetSection("WeatherOptions"));
- services.AddHttpClient();
- services.AddTenorClient();
- services.AddFontService();
- services.AddColorCardRenderer();
- services.AddOpenGraph();
- services.AddImageConverter();
- services.AddBrainfuckTranspiler();
- services.AddV8Evaluator();
- services.AddPistonClient();
- services.AddPestoClient();
- services.AddOpenAIClient();
- services.AddProgrammerHumorScraper();
- services.AddTiktokServices();
- services.AddCSharpEvaluator();
- services.AddThisXDoesNotExist();
- services.AddCraiyonClient();
- services.AddStabilityClient();
- services.AddTokopediaServices();
- services.AddGoogleMaps();
- services.AddWeatherService();
- services.AddBMKG();
- services.AddPreviewServices();
- services.AddMemeGenerator();
+if (app.Environment.IsDevelopment()) {
+ app.UseDeveloperExceptionPage();
+} else {
+ app.UseHsts();
+}
- // Hosted Services
- services.Configure(configuration.GetSection("BotOptions"));
- services.AddSingleton();
- services.AddHostedService();
+app.UseHttpsRedirection();
+app.UseRouting();
+app.UseResponseCaching();
+app.UseResponseCompression();
+app.MapControllers();
- // Telegram Bot
- services.AddTelegramBot(botToken: configuration["BotOptions:AccessToken"]!);
- })
- .UseOrleans((hostBuilderContext, siloBuilder) => {
- siloBuilder
- .UseLocalhostClustering();
- })
- .Build()
- .Run();
+app.Run();
diff --git a/BotNet/Properties/ServiceDependencies/local/appInsights.arm.json b/BotNet/Properties/ServiceDependencies/local/appInsights.arm.json
deleted file mode 100644
index 2db6c09..0000000
--- a/BotNet/Properties/ServiceDependencies/local/appInsights.arm.json
+++ /dev/null
@@ -1,66 +0,0 @@
-{
- "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
- "contentVersion": "1.0.0.0",
- "parameters": {
- "resourceGroupName": {
- "type": "string",
- "defaultValue": "BotNet",
- "metadata": {
- "_parameterType": "resourceGroup",
- "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
- }
- },
- "resourceGroupLocation": {
- "type": "string",
- "defaultValue": "westeurope",
- "metadata": {
- "_parameterType": "location",
- "description": "Location of the resource group. Resource groups could have different location than resources."
- }
- },
- "resourceLocation": {
- "type": "string",
- "defaultValue": "[parameters('resourceGroupLocation')]",
- "metadata": {
- "_parameterType": "location",
- "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
- }
- }
- },
- "resources": [
- {
- "type": "Microsoft.Resources/resourceGroups",
- "name": "[parameters('resourceGroupName')]",
- "location": "[parameters('resourceGroupLocation')]",
- "apiVersion": "2019-10-01"
- },
- {
- "type": "Microsoft.Resources/deployments",
- "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('BotNet', subscription().subscriptionId)))]",
- "resourceGroup": "[parameters('resourceGroupName')]",
- "apiVersion": "2019-10-01",
- "dependsOn": [
- "[parameters('resourceGroupName')]"
- ],
- "properties": {
- "mode": "Incremental",
- "template": {
- "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
- "contentVersion": "1.0.0.0",
- "resources": [
- {
- "name": "BotNet",
- "type": "microsoft.insights/components",
- "location": "[parameters('resourceLocation')]",
- "kind": "web",
- "properties": {
- "Application_Type": "web"
- },
- "apiVersion": "2015-05-01"
- }
- ]
- }
- }
- }
- ]
-}
\ No newline at end of file
diff --git a/BotNet/Properties/launchSettings.json b/BotNet/Properties/launchSettings.json
index bfe122a..8c3285a 100644
--- a/BotNet/Properties/launchSettings.json
+++ b/BotNet/Properties/launchSettings.json
@@ -7,7 +7,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000",
- "dotnetRunMessages": "true"
+ "dotnetRunMessages": true
},
"Docker": {
"commandName": "Docker",
diff --git a/BotNet/Properties/serviceDependencies.json b/BotNet/Properties/serviceDependencies.json
deleted file mode 100644
index 919af22..0000000
--- a/BotNet/Properties/serviceDependencies.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "dependencies": {
- "secrets": {
- "type": "secrets"
- },
- "appInsights": {
- "type": "appInsights",
- "connectionId": "ConnectionStrings:AppInsights"
- }
- }
-}
\ No newline at end of file
diff --git a/BotNet/Properties/serviceDependencies.local.json b/BotNet/Properties/serviceDependencies.local.json
deleted file mode 100644
index 66fc274..0000000
--- a/BotNet/Properties/serviceDependencies.local.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "dependencies": {
- "secrets": {
- "type": "secrets.user"
- },
- "appInsights": {
- "secretStore": "LocalSecretsFile",
- "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/microsoft.insights/components/BotNet",
- "type": "appInsights.azure",
- "connectionId": "ConnectionStrings:AppInsights"
- }
- }
-}
\ No newline at end of file
diff --git a/BotNet/Startup.cs b/BotNet/Startup.cs
deleted file mode 100644
index dd56b28..0000000
--- a/BotNet/Startup.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Hosting;
-
-namespace BotNet {
- [ExcludeFromCodeCoverage]
- public class Startup(IConfiguration configuration, IWebHostEnvironment environment) {
- public IConfiguration Configuration { get; } = configuration;
- public IWebHostEnvironment Environment { get; } = environment;
-
- public void ConfigureServices(IServiceCollection services) {
- IMvcBuilder mvcBuilder = services.AddControllersWithViews();
- if (Environment.IsDevelopment()) {
- mvcBuilder.AddRazorRuntimeCompilation();
- }
-
- // Yes. Those f***ers still use NewtonsoftJson
- services.AddControllers()
- .AddNewtonsoftJson();
-
- services.AddResponseCaching();
- services.AddResponseCompression();
- }
-
- public void Configure(IApplicationBuilder app) {
- if (Environment.IsDevelopment()) {
- app.UseDeveloperExceptionPage();
- } else {
- app.UseHsts();
- }
-
- app.UseHttpsRedirection();
- app.UseRouting();
- app.UseResponseCaching();
- app.UseResponseCompression();
-
- app.UseEndpoints(endpoints => endpoints.MapControllers());
- }
- }
-}