Skip to content

Commit 6d22671

Browse files
author
0phios
committed
Add sample application
1 parent 78a2fe7 commit 6d22671

File tree

11 files changed

+213
-5
lines changed

11 files changed

+213
-5
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
99
<RepositoryType>git</RepositoryType>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11-
<Version>0.1.0</Version>
11+
<Version>1.0.0</Version>
1212

1313
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1414
<EmbedUntrackedSources>true</EmbedUntrackedSources>

Ragnarok.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F5FD3F8F-4C1
1616
EndProject
1717
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{54FE648F-488E-4079-81FA-5278EF4BB596}"
1818
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeatherAPI", "samples\WeatherAPI\WeatherAPI.csproj", "{BDEB3408-B82A-4D14-823A-43C0F28C0EAF}"
20+
EndProject
1921
Global
2022
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2123
Debug|Any CPU = Debug|Any CPU
@@ -34,6 +36,10 @@ Global
3436
{96014DF0-2881-432F-9EA2-55EC3B60B585}.Debug|Any CPU.Build.0 = Debug|Any CPU
3537
{96014DF0-2881-432F-9EA2-55EC3B60B585}.Release|Any CPU.ActiveCfg = Release|Any CPU
3638
{96014DF0-2881-432F-9EA2-55EC3B60B585}.Release|Any CPU.Build.0 = Release|Any CPU
39+
{BDEB3408-B82A-4D14-823A-43C0F28C0EAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{BDEB3408-B82A-4D14-823A-43C0F28C0EAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{BDEB3408-B82A-4D14-823A-43C0F28C0EAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{BDEB3408-B82A-4D14-823A-43C0F28C0EAF}.Release|Any CPU.Build.0 = Release|Any CPU
3743
EndGlobalSection
3844
GlobalSection(SolutionProperties) = preSolution
3945
HideSolutionNode = FALSE
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Logging;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
7+
namespace WeatherAPI.Controllers
8+
{
9+
[ApiController]
10+
[Route("[controller]")]
11+
public class WeatherForecastController : ControllerBase
12+
{
13+
private static readonly string[] Summaries = new[]
14+
{
15+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
16+
};
17+
18+
private readonly ILogger<WeatherForecastController> _logger;
19+
20+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
21+
{
22+
_logger = logger;
23+
}
24+
25+
[HttpGet]
26+
public IEnumerable<WeatherForecast> Get()
27+
{
28+
var rng = new Random();
29+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
30+
{
31+
Date = DateTime.Now.AddDays(index),
32+
TemperatureC = rng.Next(-20, 55),
33+
Summary = Summaries[rng.Next(Summaries.Length)]
34+
})
35+
.ToArray();
36+
}
37+
}
38+
}

samples/WeatherAPI/Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
using Ragnarok.HostedService.Extensions;
4+
5+
namespace WeatherAPI
6+
{
7+
public class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
CreateHostBuilder(args).Build().Run();
12+
}
13+
14+
public static IHostBuilder CreateHostBuilder(string[] args) =>
15+
Host.CreateDefaultBuilder(args)
16+
.ConfigureWebHostDefaults(webBuilder =>
17+
{
18+
webBuilder.UseStartup<Startup>();
19+
webBuilder.UseNgrok(options => options.DownloadNgrok = true); //use the extension method to configure the hostedservice
20+
});
21+
}
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:64341",
8+
"sslPort": 44397
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "swagger",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"WeatherAPI": {
21+
"commandName": "Project",
22+
"dotnetRunMessages": "true",
23+
"launchBrowser": true,
24+
"launchUrl": "swagger",
25+
"applicationUrl": "https://localhost:5001",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

samples/WeatherAPI/Startup.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
using Microsoft.OpenApi.Models;
7+
8+
namespace WeatherAPI
9+
{
10+
public class Startup
11+
{
12+
public Startup(IConfiguration configuration)
13+
{
14+
Configuration = configuration;
15+
}
16+
17+
public IConfiguration Configuration { get; }
18+
19+
// This method gets called by the runtime. Use this method to add services to the container.
20+
public void ConfigureServices(IServiceCollection services)
21+
{
22+
23+
services.AddControllers();
24+
services.AddSwaggerGen(c =>
25+
{
26+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "WeatherAPI", Version = "v1" });
27+
});
28+
}
29+
30+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
31+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
32+
{
33+
if (env.IsDevelopment())
34+
{
35+
app.UseDeveloperExceptionPage();
36+
app.UseSwagger();
37+
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WeatherAPI v1"));
38+
}
39+
40+
app.UseHttpsRedirection();
41+
42+
app.UseRouting();
43+
44+
app.UseAuthorization();
45+
46+
app.UseEndpoints(endpoints =>
47+
{
48+
endpoints.MapControllers();
49+
});
50+
}
51+
}
52+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
8+
<NoWarn>1701;1702;1591</NoWarn>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\src\Ragnarok.HostedService\Ragnarok.HostedService.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace WeatherAPI
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}

0 commit comments

Comments
 (0)