< Summary - pva.SuperV

Information
Class: pva.SuperV.Api.WebApiProgram
Assembly: pva.SuperV.Api
File(s): /home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Api/WebApiProgram.cs
Tag: dotnet-ubuntu_18869653307
Line coverage
88%
Covered lines: 74
Uncovered lines: 10
Coverable lines: 84
Total lines: 206
Line coverage: 88%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Main(...)100%1175%
Run(...)100%1188.75%

File(s)

/home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Api/WebApiProgram.cs

#LineLine coverage
 1using Microsoft.AspNetCore.HttpLogging;
 2using pva.SuperV.Api.Routes.Classes;
 3using pva.SuperV.Api.Routes.FieldDefinitions;
 4using pva.SuperV.Api.Routes.FieldFormatters;
 5using pva.SuperV.Api.Routes.FieldProcessings;
 6using pva.SuperV.Api.Routes.HistoryRepositories;
 7using pva.SuperV.Api.Routes.HistoryValues;
 8using pva.SuperV.Api.Routes.Instances;
 9using pva.SuperV.Api.Routes.Projects;
 10using pva.SuperV.Api.Services.Classes;
 11using pva.SuperV.Api.Services.FieldDefinitions;
 12using pva.SuperV.Api.Services.FieldFormatters;
 13using pva.SuperV.Api.Services.FieldProcessings;
 14using pva.SuperV.Api.Services.History;
 15using pva.SuperV.Api.Services.HistoryRepositories;
 16using pva.SuperV.Api.Services.Instances;
 17using pva.SuperV.Api.Services.Projects;
 18using pva.SuperV.Model;
 19using pva.SuperV.Model.Classes;
 20using pva.SuperV.Model.FieldDefinitions;
 21using pva.SuperV.Model.FieldFormatters;
 22using pva.SuperV.Model.FieldProcessings;
 23using pva.SuperV.Model.HistoryRepositories;
 24using pva.SuperV.Model.HistoryRetrieval;
 25using pva.SuperV.Model.Instances;
 26using pva.SuperV.Model.Projects;
 27using pva.SuperV.Model.Services;
 28using Scalar.AspNetCore;
 29using System.Text.Json.Serialization;
 30
 31namespace pva.SuperV.Api
 32{
 33    public class WebApiProgram
 34    {
 35        public static void Main(string[] args)
 13136        {
 13137            new WebApiProgram()
 13138                .Run(args);
 039        }
 40
 41        private void Run(string[] args)
 13142        {
 13143            var builder = WebApplication.CreateSlimBuilder(args);
 44
 13145            builder.Services
 13146                .ConfigureHttpJsonOptions(options =>
 13147                {
 13148                    options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
 13149
 13150                })
 13151                .AddHttpLogging(logging =>
 13152                {
 13153                    logging.LoggingFields = HttpLoggingFields.All;
 13154                })
 13155                .AddProblemDetails()
 13156                .AddSingleton<IProjectService, ProjectService>()
 13157                .AddSingleton<IClassService, ClassService>()
 13158                .AddSingleton<IFieldFormatterService, FieldFormatterService>()
 13159                .AddSingleton<IHistoryRepositoryService, HistoryRepositoryService>()
 13160                .AddSingleton<IFieldDefinitionService, FieldDefinitionService>()
 13161                .AddSingleton<IFieldProcessingService, FieldProcessingService>()
 13162                .AddSingleton<IInstanceService, InstanceService>()
 13163                .AddSingleton<IFieldValueService, FieldValueService>()
 13164                .AddSingleton<IHistoryValuesService, HistoryValuesService>();
 13165            builder.Services.AddOpenApi(options =>
 166            {
 167                options.AddDocumentTransformer((document, context, cancellationToken) =>
 168                {
 169                    document.Info = new()
 170                    {
 171                        Title = "SuperV API",
 172                        Version = "v1",
 173                        Description = "API for accessing SuperV projects."
 174                    };
 175                    return Task.CompletedTask;
 276                });
 13277            });
 39378            builder.Services.AddHttpLogging(o => { });
 13179            builder.Logging.AddConsole();
 13180            builder.Logging.AddJsonConsole();
 13181            var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
 13182            builder.Services.AddCors(options =>
 13183            {
 13184                options.AddPolicy(name: MyAllowSpecificOrigins,
 13185                                  policy =>
 13186                                      policy
 13187                                      .AllowAnyMethod()
 13188                                      .AllowAnyHeader()
 089                                      .SetIsOriginAllowed(origin => true)
 13190                                      .AllowCredentials()
 13191                                  );
 26292            });
 93
 13194            var app = builder.Build();
 95
 13196            app.UseHttpLogging();
 13197            app.UseExceptionHandler(exceptionHandlerApp =>
 13198            {
 13199                exceptionHandlerApp.Run(async httpContext =>
 0100                {
 0101                    var pds = httpContext.RequestServices.GetService<IProblemDetailsService>();
 0102                    if (pds == null
 0103                        || !await pds.TryWriteAsync(new() { HttpContext = httpContext }))
 0104                    {
 131105                        // Fallback behavior
 0106                        await httpContext.Response.WriteAsync("Fallback: An error occurred.");
 0107                    }
 131108                });
 262109            });
 131110            app.UseStatusCodePages();
 131111            app.UseDeveloperExceptionPage();
 112
 131113            app.MapOpenApi();
 131114            app.MapScalarApiReference();
 115
 131116            app.MapProjectEndpoints()
 131117               .MapClassEndpoints()
 131118               .MapFieldFormatterEndpoints()
 131119               .MapHistoryRepositoryEndpoints()
 131120               .MapFieldDefinitionEndpoints()
 131121               .MapFieldProcessingEndpoints()
 131122               .MapInstancesEndpoints()
 131123               .MapHistoryValuesEndpoints();
 131124            app.UseCors(MyAllowSpecificOrigins);
 131125            app.Run();
 0126        }
 127    }
 128
 129    [JsonSerializable(typeof(IFormFile))]
 130    [JsonSerializable(typeof(FormFile))]
 131
 132    [JsonSerializable(typeof(List<ProjectModel>))]
 133    [JsonSerializable(typeof(ProjectModel))]
 134    [JsonSerializable(typeof(CreateProjectRequest))]
 135    [JsonSerializable(typeof(UpdateProjectRequest))]
 136    [JsonSerializable(typeof(ProjectPagedSearchRequest))]
 137    [JsonSerializable(typeof(PagedSearchResult<ProjectModel>))]
 138
 139    [JsonSerializable(typeof(List<FieldFormatterModel>))]
 140    [JsonSerializable(typeof(FieldFormatterModel))]
 141    [JsonSerializable(typeof(EnumFormatterModel))]
 142    [JsonSerializable(typeof(CreateFieldFormatterRequest))]
 143    [JsonSerializable(typeof(PagedSearchResult<FieldFormatterModel>))]
 144    [JsonSerializable(typeof(FieldFormatterPagedSearchRequest))]
 145
 146    [JsonSerializable(typeof(List<ClassModel>))]
 147    [JsonSerializable(typeof(ClassModel))]
 148    [JsonSerializable(typeof(PagedSearchResult<ClassModel>))]
 149    [JsonSerializable(typeof(ClassPagedSearchRequest))]
 150
 151    [JsonSerializable(typeof(List<HistoryRepositoryModel>))]
 152    [JsonSerializable(typeof(HistoryRepositoryModel))]
 153
 154    [JsonSerializable(typeof(List<FieldDefinitionModel>))]
 155    [JsonSerializable(typeof(FieldDefinitionModel))]
 156    [JsonSerializable(typeof(BoolFieldDefinitionModel))]
 157    [JsonSerializable(typeof(DateTimeFieldDefinitionModel))]
 158    [JsonSerializable(typeof(DoubleFieldDefinitionModel))]
 159    [JsonSerializable(typeof(FloatFieldDefinitionModel))]
 160    [JsonSerializable(typeof(IntFieldDefinitionModel))]
 161    [JsonSerializable(typeof(LongFieldDefinitionModel))]
 162    [JsonSerializable(typeof(ShortFieldDefinitionModel))]
 163    [JsonSerializable(typeof(StringFieldDefinitionModel))]
 164    [JsonSerializable(typeof(TimeSpanFieldDefinitionModel))]
 165    [JsonSerializable(typeof(UintFieldDefinitionModel))]
 166    [JsonSerializable(typeof(UlongFieldDefinitionModel))]
 167    [JsonSerializable(typeof(UshortFieldDefinitionModel))]
 168    [JsonSerializable(typeof(PagedSearchResult<FieldDefinitionModel>))]
 169    [JsonSerializable(typeof(FieldDefinitionPagedSearchRequest))]
 170
 171    [JsonSerializable(typeof(List<FieldValueProcessingModel>))]
 172    [JsonSerializable(typeof(FieldValueProcessingModel))]
 173    [JsonSerializable(typeof(AlarmStateProcessingModel))]
 174    [JsonSerializable(typeof(HistorizationProcessingModel))]
 175
 176    [JsonSerializable(typeof(List<InstanceModel>))]
 177    [JsonSerializable(typeof(InstanceModel))]
 178    [JsonSerializable(typeof(BoolFieldValueModel))]
 179    [JsonSerializable(typeof(DateTimeFieldValueModel))]
 180    [JsonSerializable(typeof(DoubleFieldValueModel))]
 181    [JsonSerializable(typeof(FloatFieldValueModel))]
 182    [JsonSerializable(typeof(IntFieldValueModel))]
 183    [JsonSerializable(typeof(LongFieldValueModel))]
 184    [JsonSerializable(typeof(ShortFieldValueModel))]
 185    [JsonSerializable(typeof(StringFieldValueModel))]
 186    [JsonSerializable(typeof(TimeSpanFieldValueModel))]
 187    [JsonSerializable(typeof(UintFieldValueModel))]
 188    [JsonSerializable(typeof(UlongFieldValueModel))]
 189    [JsonSerializable(typeof(UshortFieldValueModel))]
 190    [JsonSerializable(typeof(PagedSearchResult<InstanceModel>))]
 191    [JsonSerializable(typeof(InstancePagedSearchRequest))]
 192
 193    [JsonSerializable(typeof(HistoryRequestModel))]
 194    [JsonSerializable(typeof(HistoryRawResultModel))]
 195    [JsonSerializable(typeof(List<HistoryRawRowModel>))]
 196    [JsonSerializable(typeof(HistoryResultModel))]
 197    [JsonSerializable(typeof(List<HistoryFieldModel>))]
 198    [JsonSerializable(typeof(HistoryStatisticsRequestModel))]
 199    [JsonSerializable(typeof(HistoryStatisticsRawResultModel))]
 200    [JsonSerializable(typeof(List<HistoryStatisticsRawRowModel>))]
 201    [JsonSerializable(typeof(HistoryStatisticsResultModel))]
 202    [JsonSerializable(typeof(List<HistoryStatisticsRowModel>))]
 203    internal partial class AppJsonSerializerContext : JsonSerializerContext
 204    {
 205    }
 206}