-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
115 lines (87 loc) · 3.68 KB
/
Program.cs
File metadata and controls
115 lines (87 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using NetCore2BlocklyNew;
using SoftataWebAPI.Controllers;
using SoftataWebAPI.Data;
using System.Reflection;
using System.Text.Json.Serialization;
namespace SoftataWebAPI
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddDistributedMemoryCache();
builder.Services.AddDbContext<SoftataWebAPI.Data.Db.SoftataDbContext>(options =>
{
options.UseSqlite(
builder.Configuration.GetConnectionString("DefaultConnection"));
});
Console.WriteLine($"Config Directory: {builder.Configuration.GetConnectionString("DefaultConnection")}");
Console.WriteLine($"Current Directory: {Environment.CurrentDirectory}");
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(120);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
// Register the SharedService
builder.Services.AddScoped<ISoftataGenCmds, SharedService>();
//builder.Services.AddScoped<INewsService,NewsService>(); A work in progress
//Swagger Documentation Section
var info = new OpenApiInfo()
{
Title = "SoftataController",
Version = "v6.00",
Description = "An Arduino API LIKE Firmata for RPI Pico W running Arduino. Includes a .NET package so that you can write your own client in C# to remotely control Pico W devices.",
Contact = new OpenApiContact()
{
Name = "David Jones",
Email = "davidjones@sportronics.com.au",
}
};
//builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", info);
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
builder.Services.AddControllers().AddJsonOptions(options =>
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
var app = builder.Build();
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
//app.UseSwagger();
//app.UseSwaggerUI();
//}
app.UseSwagger(u =>
{
u.RouteTemplate = "swagger/{documentName}/swagger.json";
});
app.UseSwaggerUI(c =>
{
c.RoutePrefix = "swagger";
c.SwaggerEndpoint(url: "/swagger/v1/swagger.json", name: "Softata");
c.DocumentTitle="Softata";
});
app.UseHttpsRedirection();
app.UseAuthorization();
app.UseSession();
app.MapControllers();
app.UseBlocklyUI(app.Environment);
app.UseBlocklyAutomation();
app.UseDefaultFiles();
app.UseStaticFiles();
app.Run();
}
}
}