< 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_22190969454
Line coverage
88%
Covered lines: 78
Uncovered lines: 10
Coverable lines: 88
Total lines: 218
Line coverage: 88.6%
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%1189.28%

File(s)

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

#LineLine coverage
 1using Microsoft.AspNetCore.HttpLogging;
 2using NLog;
 3using NLog.Extensions.Logging;
 4using NLog.Web;
 5using pva.SuperV.Api.Routes.Classes;
 6using pva.SuperV.Api.Routes.FieldDefinitions;
 7using pva.SuperV.Api.Routes.FieldFormatters;
 8using pva.SuperV.Api.Routes.FieldProcessings;
 9using pva.SuperV.Api.Routes.HistoryRepositories;
 10using pva.SuperV.Api.Routes.HistoryValues;
 11using pva.SuperV.Api.Routes.Instances;
 12using pva.SuperV.Api.Routes.Projects;
 13using pva.SuperV.Api.Routes.Scripts;
 14using pva.SuperV.Api.Services.Classes;
 15using pva.SuperV.Api.Services.FieldDefinitions;
 16using pva.SuperV.Api.Services.FieldFormatters;
 17using pva.SuperV.Api.Services.FieldProcessings;
 18using pva.SuperV.Api.Services.History;
 19using pva.SuperV.Api.Services.HistoryRepositories;
 20using pva.SuperV.Api.Services.Instances;
 21using pva.SuperV.Api.Services.Projects;
 22using pva.SuperV.Api.Services.Scripts;
 23using pva.SuperV.Model;
 24using pva.SuperV.Model.Classes;
 25using pva.SuperV.Model.FieldDefinitions;
 26using pva.SuperV.Model.FieldFormatters;
 27using pva.SuperV.Model.FieldProcessings;
 28using pva.SuperV.Model.HistoryRepositories;
 29using pva.SuperV.Model.HistoryRetrieval;
 30using pva.SuperV.Model.Instances;
 31using pva.SuperV.Model.Projects;
 32using pva.SuperV.Model.Services;
 33using Scalar.AspNetCore;
 34using System.Text.Json.Serialization;
 35
 36namespace pva.SuperV.Api
 37{
 38    public class WebApiProgram
 39    {
 40        public static void Main(string[] args)
 14541        {
 14542            new WebApiProgram()
 14543                .Run(args);
 044        }
 45
 46        private void Run(string[] args)
 14547        {
 14548            var builder = WebApplication.CreateSlimBuilder(args);
 14549            builder.Logging.ClearProviders();
 14550            builder.Host.UseNLog();
 14551            var config = new ConfigurationBuilder()
 14552                .SetBasePath(Directory.GetCurrentDirectory())
 14553                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
 14554                .AddEnvironmentVariables().Build();
 14555            Logger logger = LogManager.Setup()
 14556                                   .LoadConfigurationFromSection(config)
 14557                                   .GetCurrentClassLogger();
 58
 14559            builder.Services
 14560                .ConfigureHttpJsonOptions(options => options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSe
 14561                .AddHttpLogging(logging => logging.LoggingFields = HttpLoggingFields.All)
 14562                .AddProblemDetails()
 14563                .AddSingleton<IProjectService, ProjectService>()
 14564                .AddSingleton<IClassService, ClassService>()
 14565                .AddSingleton<IFieldFormatterService, FieldFormatterService>()
 14566                .AddSingleton<IHistoryRepositoryService, HistoryRepositoryService>()
 14567                .AddSingleton<IFieldDefinitionService, FieldDefinitionService>()
 14568                .AddSingleton<IFieldProcessingService, FieldProcessingService>()
 14569                .AddSingleton<IInstanceService, InstanceService>()
 14570                .AddSingleton<IFieldValueService, FieldValueService>()
 14571                .AddSingleton<IHistoryValuesService, HistoryValuesService>()
 14572                .AddSingleton<IScriptService, ScriptService>();
 14573            builder.Services.AddOpenApi(options =>
 174            {
 175                options.AddDocumentTransformer((document, _, __) =>
 176                {
 177                    document.Info = new()
 178                    {
 179                        Title = "SuperV API",
 180                        Version = "v1",
 181                        Description = "API for accessing SuperV projects."
 182                    };
 183                    return Task.CompletedTask;
 284                });
 14685            });
 43586            builder.Services.AddHttpLogging(_ => { });
 14587            builder.Logging.AddConsole();
 14588            builder.Logging.AddJsonConsole();
 89            const string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
 14590            builder.Services.AddCors(options =>
 14591            {
 14592                options.AddPolicy(name: MyAllowSpecificOrigins,
 14593                                  policy =>
 14594                                      policy
 14595                                      .AllowAnyMethod()
 14596                                      .AllowAnyHeader()
 097                                      .SetIsOriginAllowed(_ => true)
 14598                                      .AllowCredentials()
 14599                                  );
 290100            });
 101
 145102            var app = builder.Build();
 103
 145104            app.UseHttpLogging();
 145105            app.UseExceptionHandler(exceptionHandlerApp =>
 145106            {
 145107                exceptionHandlerApp.Run(async httpContext =>
 0108                {
 0109                    var pds = httpContext.RequestServices.GetService<IProblemDetailsService>();
 0110                    if (pds == null
 0111                        || !await pds.TryWriteAsync(new() { HttpContext = httpContext }))
 0112                    {
 145113                        // Fallback behavior
 0114                        await httpContext.Response.WriteAsync("Fallback: An error occurred.");
 0115                    }
 145116                });
 290117            });
 145118            app.UseStatusCodePages();
 145119            app.UseDeveloperExceptionPage();
 120
 145121            app.MapOpenApi();
 145122            app.MapScalarApiReference();
 123
 145124            app.MapProjectEndpoints()
 145125               .MapClassEndpoints()
 145126               .MapFieldFormatterEndpoints()
 145127               .MapHistoryRepositoryEndpoints()
 145128               .MapFieldDefinitionEndpoints()
 145129               .MapFieldProcessingEndpoints()
 145130               .MapInstancesEndpoints()
 145131               .MapHistoryValuesEndpoints()
 145132               .MapScriptEndpoints();
 145133            app.UseCors(MyAllowSpecificOrigins);
 134
 145135            logger.Info("Starting SuperV web API");
 145136            app.Run();
 0137        }
 138    }
 139
 140    [JsonSerializable(typeof(IFormFile))]
 141    [JsonSerializable(typeof(FormFile))]
 142
 143    [JsonSerializable(typeof(List<ProjectModel>))]
 144    [JsonSerializable(typeof(ProjectModel))]
 145    [JsonSerializable(typeof(CreateProjectRequest))]
 146    [JsonSerializable(typeof(UpdateProjectRequest))]
 147    [JsonSerializable(typeof(ProjectPagedSearchRequest))]
 148    [JsonSerializable(typeof(PagedSearchResult<ProjectModel>))]
 149
 150    [JsonSerializable(typeof(List<FieldFormatterModel>))]
 151    [JsonSerializable(typeof(FieldFormatterModel))]
 152    [JsonSerializable(typeof(EnumFormatterModel))]
 153    [JsonSerializable(typeof(CreateFieldFormatterRequest))]
 154    [JsonSerializable(typeof(PagedSearchResult<FieldFormatterModel>))]
 155    [JsonSerializable(typeof(FieldFormatterPagedSearchRequest))]
 156
 157    [JsonSerializable(typeof(List<ClassModel>))]
 158    [JsonSerializable(typeof(ClassModel))]
 159    [JsonSerializable(typeof(PagedSearchResult<ClassModel>))]
 160    [JsonSerializable(typeof(ClassPagedSearchRequest))]
 161
 162    [JsonSerializable(typeof(List<HistoryRepositoryModel>))]
 163    [JsonSerializable(typeof(HistoryRepositoryModel))]
 164
 165    [JsonSerializable(typeof(List<FieldDefinitionModel>))]
 166    [JsonSerializable(typeof(FieldDefinitionModel))]
 167    [JsonSerializable(typeof(BoolFieldDefinitionModel))]
 168    [JsonSerializable(typeof(DateTimeFieldDefinitionModel))]
 169    [JsonSerializable(typeof(DoubleFieldDefinitionModel))]
 170    [JsonSerializable(typeof(FloatFieldDefinitionModel))]
 171    [JsonSerializable(typeof(IntFieldDefinitionModel))]
 172    [JsonSerializable(typeof(LongFieldDefinitionModel))]
 173    [JsonSerializable(typeof(ShortFieldDefinitionModel))]
 174    [JsonSerializable(typeof(StringFieldDefinitionModel))]
 175    [JsonSerializable(typeof(TimeSpanFieldDefinitionModel))]
 176    [JsonSerializable(typeof(UintFieldDefinitionModel))]
 177    [JsonSerializable(typeof(UlongFieldDefinitionModel))]
 178    [JsonSerializable(typeof(UshortFieldDefinitionModel))]
 179    [JsonSerializable(typeof(PagedSearchResult<FieldDefinitionModel>))]
 180    [JsonSerializable(typeof(FieldDefinitionPagedSearchRequest))]
 181
 182    [JsonSerializable(typeof(List<FieldValueProcessingModel>))]
 183    [JsonSerializable(typeof(FieldValueProcessingModel))]
 184    [JsonSerializable(typeof(AlarmStateProcessingModel))]
 185    [JsonSerializable(typeof(HistorizationProcessingModel))]
 186
 187    [JsonSerializable(typeof(List<InstanceModel>))]
 188    [JsonSerializable(typeof(InstanceModel))]
 189    [JsonSerializable(typeof(BoolFieldValueModel))]
 190    [JsonSerializable(typeof(DateTimeFieldValueModel))]
 191    [JsonSerializable(typeof(DoubleFieldValueModel))]
 192    [JsonSerializable(typeof(FloatFieldValueModel))]
 193    [JsonSerializable(typeof(IntFieldValueModel))]
 194    [JsonSerializable(typeof(LongFieldValueModel))]
 195    [JsonSerializable(typeof(ShortFieldValueModel))]
 196    [JsonSerializable(typeof(StringFieldValueModel))]
 197    [JsonSerializable(typeof(TimeSpanFieldValueModel))]
 198    [JsonSerializable(typeof(UintFieldValueModel))]
 199    [JsonSerializable(typeof(UlongFieldValueModel))]
 200    [JsonSerializable(typeof(UshortFieldValueModel))]
 201    [JsonSerializable(typeof(PagedSearchResult<InstanceModel>))]
 202    [JsonSerializable(typeof(InstancePagedSearchRequest))]
 203
 204    [JsonSerializable(typeof(HistoryRequestModel))]
 205    [JsonSerializable(typeof(HistoryRawResultModel))]
 206    [JsonSerializable(typeof(List<HistoryRawRowModel>))]
 207    [JsonSerializable(typeof(HistoryResultModel))]
 208    [JsonSerializable(typeof(List<HistoryFieldModel>))]
 209    [JsonSerializable(typeof(HistoryStatisticsRequestModel))]
 210    [JsonSerializable(typeof(HistoryStatisticsRawResultModel))]
 211    [JsonSerializable(typeof(List<HistoryStatisticsRawRowModel>))]
 212    [JsonSerializable(typeof(HistoryStatisticsResultModel))]
 213    [JsonSerializable(typeof(List<HistoryStatisticsRowModel>))]
 214
 215    [JsonSerializable(typeof(ScriptDefinitionModel))]
 216    [JsonSerializable(typeof(List<ScriptDefinitionModel>))]
 217    internal partial class AppJsonSerializerContext : JsonSerializerContext;
 218}