Merge pull request #1 from jtom38/features/rebuild-again

Rebuilding in dotnet for practice
This commit is contained in:
James Tombleson 2023-02-14 17:51:44 -08:00 committed by GitHub
commit 0b624eb49a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 483 additions and 0 deletions

3
.gitignore vendored
View File

@ -10,6 +10,9 @@
*.userosscache
*.sln.docstates
appsettings.Development.json
appsettings.json
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

35
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"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}/Newsbot.Collector.Api/bin/Debug/net7.0/Newsbot.Collector.Api.dll",
"args": [],
"cwd": "${workspaceFolder}/Newsbot.Collector.Api",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"files.exclude": {
"**/obj": true,
"**/bin": true
}
}

41
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.33" />
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Newsbot.Collector.Domain\Newsbot.Collector.Domain.csproj" />
<ProjectReference Include="..\Newsbot.Collector.Services\Newsbot.Collector.Services.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,44 @@
using Hangfire;
using Hangfire.MemoryStorage;
using Newsbot.Collector.Services;
using Newsbot.Collector.Domain.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Build the conifg
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
var cfg = config.GetRequiredSection("Config").Get<ConfigModel>();
builder.Configuration.AddConfiguration(config);
builder.Services.AddHangfire(f => f.UseMemoryStorage());
builder.Services.AddHangfireServer();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseHangfireDashboard();
//RecurringJob.AddOrUpdate()
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:12777",
"sslPort": 44387
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5011",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7155;http://localhost:5011",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,12 @@
namespace Newsbot.Collector.Api;
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}

View File

@ -0,0 +1,31 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Config": {
"ServerAddress": "",
"SqlConnectionString": "",
"Reddit": {
"IsEnabled": false,
"PullHot": false,
"PullNsfw": false,
"PullTop": false
},
"Youtube": {
"IsEnabled": false,
"Debug": false
},
"Twitch": {
"IsEnabled": false,
"ClientID": "",
"ClientSecret": ""
},
"FFXIV": {
"IsEnabled": false
}
},
"AllowedHosts": "*"
}

View File

@ -0,0 +1,5 @@
namespace Newsbot.Collector.Domain;
public class Class1
{
}

View File

@ -0,0 +1,16 @@
namespace Newsbot.Collector.Domain.Models;
public class ConfigModel
{
public string? ServerAddress { get; set; }
public string? SqlConnectionString { get; set; }
public RedditConfigModel? Reddit { get; set; }
}
public class RedditConfigModel
{
public bool IsEnabled { get; set; }
public bool PullHot { get; set; }
public bool PullNsfw { get; set; }
public bool PullTop { get; set; }
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,77 @@
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Services;
public static class EnvLoader
{
public static ConfigModel Load()
{
var reddit = new RedditConfigModel
{
IsEnabled = Bool("FEATURE_ENABLE_REDDIT_BACKEND"),
PullHot = Bool("REDDIT_PULL_HOT"),
PullNsfw = Bool("REDDIT_PULL_NSFW"),
PullTop = Bool("REDDIT_PULL_TOP")
};
return new ConfigModel
{
ServerAddress = String("SERVER_ADDRESS"),
SqlConnectionString = String("SQL_CONNECTION_STRING"),
Reddit = reddit,
};
}
public static void LoadEnvFile()
{
var curDir = Directory.GetCurrentDirectory();
var filePath = Path.Combine(curDir, ".env");
if (!File.Exists(filePath))
return;
foreach (var line in File.ReadAllLines(filePath))
{
var parts = line.Split('=', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 2)
continue;
if (parts[1].Contains("'") == true ){
parts[1] = parts[1].Replace("'", "");
}
Environment.SetEnvironmentVariable(parts[0], parts[1]);
}
}
private static string String(string Key)
{
var result = Environment.GetEnvironmentVariable(Key);
if (result is null)
{
return "";
}
return result;
}
private static bool Bool(string Key)
{
var result = String(Key);
if (result == "")
{
return false;
}
if (result.ToLower() == "true")
{
return true;
}
else
{
return false;
}
}
}

View File

@ -0,0 +1,18 @@
namespace Newsbot.Collector.Services.Jobs;
public class HelloWorldJob
{
public readonly string _message;
public HelloWorldJob(string message)
{
_message = message;
}
public void Execute()
{
Console.WriteLine(_message);
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Newsbot.Collector.Domain\Newsbot.Collector.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="7.0.1" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
namespace Newsbot.Collector.Tests;
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}

View File

@ -0,0 +1 @@
global using Xunit;

40
Newsbot.Collector.sln Normal file
View File

@ -0,0 +1,40 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newsbot.Collector.Api", "Newsbot.Collector.Api\Newsbot.Collector.Api.csproj", "{BDAA344D-0C78-40E5-9C7D-BFAAA8F3FCEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newsbot.Collector.Domain", "Newsbot.Collector.Domain\Newsbot.Collector.Domain.csproj", "{BAEF51D8-DB35-4A67-A13A-9DB77525C769}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newsbot.Collector.Services", "Newsbot.Collector.Services\Newsbot.Collector.Services.csproj", "{58D012BB-DAC0-4BF6-AB03-A10F5AE6A1D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newsbot.Collector.Tests", "Newsbot.Collector.Tests\Newsbot.Collector.Tests.csproj", "{B677151F-5E71-4AA9-968A-D2AAB6375DE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BDAA344D-0C78-40E5-9C7D-BFAAA8F3FCEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDAA344D-0C78-40E5-9C7D-BFAAA8F3FCEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDAA344D-0C78-40E5-9C7D-BFAAA8F3FCEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDAA344D-0C78-40E5-9C7D-BFAAA8F3FCEB}.Release|Any CPU.Build.0 = Release|Any CPU
{BAEF51D8-DB35-4A67-A13A-9DB77525C769}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAEF51D8-DB35-4A67-A13A-9DB77525C769}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAEF51D8-DB35-4A67-A13A-9DB77525C769}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAEF51D8-DB35-4A67-A13A-9DB77525C769}.Release|Any CPU.Build.0 = Release|Any CPU
{58D012BB-DAC0-4BF6-AB03-A10F5AE6A1D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58D012BB-DAC0-4BF6-AB03-A10F5AE6A1D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58D012BB-DAC0-4BF6-AB03-A10F5AE6A1D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58D012BB-DAC0-4BF6-AB03-A10F5AE6A1D7}.Release|Any CPU.Build.0 = Release|Any CPU
{B677151F-5E71-4AA9-968A-D2AAB6375DE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B677151F-5E71-4AA9-968A-D2AAB6375DE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B677151F-5E71-4AA9-968A-D2AAB6375DE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B677151F-5E71-4AA9-968A-D2AAB6375DE4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal