| | | 1 | | using Microsoft.AspNetCore.HttpLogging; |
| | | 2 | | using pva.SuperV.Api.Routes.Classes; |
| | | 3 | | using pva.SuperV.Api.Routes.FieldDefinitions; |
| | | 4 | | using pva.SuperV.Api.Routes.FieldFormatters; |
| | | 5 | | using pva.SuperV.Api.Routes.FieldProcessings; |
| | | 6 | | using pva.SuperV.Api.Routes.HistoryRepositories; |
| | | 7 | | using pva.SuperV.Api.Routes.HistoryValues; |
| | | 8 | | using pva.SuperV.Api.Routes.Instances; |
| | | 9 | | using pva.SuperV.Api.Routes.Projects; |
| | | 10 | | using pva.SuperV.Api.Services.Classes; |
| | | 11 | | using pva.SuperV.Api.Services.FieldDefinitions; |
| | | 12 | | using pva.SuperV.Api.Services.FieldFormatters; |
| | | 13 | | using pva.SuperV.Api.Services.FieldProcessings; |
| | | 14 | | using pva.SuperV.Api.Services.History; |
| | | 15 | | using pva.SuperV.Api.Services.HistoryRepositories; |
| | | 16 | | using pva.SuperV.Api.Services.Instances; |
| | | 17 | | using pva.SuperV.Api.Services.Projects; |
| | | 18 | | using pva.SuperV.Model; |
| | | 19 | | using pva.SuperV.Model.Classes; |
| | | 20 | | using pva.SuperV.Model.FieldDefinitions; |
| | | 21 | | using pva.SuperV.Model.FieldFormatters; |
| | | 22 | | using pva.SuperV.Model.FieldProcessings; |
| | | 23 | | using pva.SuperV.Model.HistoryRepositories; |
| | | 24 | | using pva.SuperV.Model.HistoryRetrieval; |
| | | 25 | | using pva.SuperV.Model.Instances; |
| | | 26 | | using pva.SuperV.Model.Projects; |
| | | 27 | | using pva.SuperV.Model.Services; |
| | | 28 | | using Scalar.AspNetCore; |
| | | 29 | | using System.Text.Json.Serialization; |
| | | 30 | | |
| | | 31 | | namespace pva.SuperV.Api |
| | | 32 | | { |
| | | 33 | | public class WebApiProgram |
| | | 34 | | { |
| | | 35 | | public static void Main(string[] args) |
| | 131 | 36 | | { |
| | 131 | 37 | | new WebApiProgram() |
| | 131 | 38 | | .Run(args); |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | private void Run(string[] args) |
| | 131 | 42 | | { |
| | 131 | 43 | | var builder = WebApplication.CreateSlimBuilder(args); |
| | | 44 | | |
| | 131 | 45 | | builder.Services |
| | 131 | 46 | | .ConfigureHttpJsonOptions(options => |
| | 131 | 47 | | { |
| | 131 | 48 | | options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); |
| | 131 | 49 | | |
| | 131 | 50 | | }) |
| | 131 | 51 | | .AddHttpLogging(logging => |
| | 131 | 52 | | { |
| | 131 | 53 | | logging.LoggingFields = HttpLoggingFields.All; |
| | 131 | 54 | | }) |
| | 131 | 55 | | .AddProblemDetails() |
| | 131 | 56 | | .AddSingleton<IProjectService, ProjectService>() |
| | 131 | 57 | | .AddSingleton<IClassService, ClassService>() |
| | 131 | 58 | | .AddSingleton<IFieldFormatterService, FieldFormatterService>() |
| | 131 | 59 | | .AddSingleton<IHistoryRepositoryService, HistoryRepositoryService>() |
| | 131 | 60 | | .AddSingleton<IFieldDefinitionService, FieldDefinitionService>() |
| | 131 | 61 | | .AddSingleton<IFieldProcessingService, FieldProcessingService>() |
| | 131 | 62 | | .AddSingleton<IInstanceService, InstanceService>() |
| | 131 | 63 | | .AddSingleton<IFieldValueService, FieldValueService>() |
| | 131 | 64 | | .AddSingleton<IHistoryValuesService, HistoryValuesService>(); |
| | 131 | 65 | | builder.Services.AddOpenApi(options => |
| | 1 | 66 | | { |
| | 1 | 67 | | options.AddDocumentTransformer((document, context, cancellationToken) => |
| | 1 | 68 | | { |
| | 1 | 69 | | document.Info = new() |
| | 1 | 70 | | { |
| | 1 | 71 | | Title = "SuperV API", |
| | 1 | 72 | | Version = "v1", |
| | 1 | 73 | | Description = "API for accessing SuperV projects." |
| | 1 | 74 | | }; |
| | 1 | 75 | | return Task.CompletedTask; |
| | 2 | 76 | | }); |
| | 132 | 77 | | }); |
| | 393 | 78 | | builder.Services.AddHttpLogging(o => { }); |
| | 131 | 79 | | builder.Logging.AddConsole(); |
| | 131 | 80 | | builder.Logging.AddJsonConsole(); |
| | 131 | 81 | | var MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; |
| | 131 | 82 | | builder.Services.AddCors(options => |
| | 131 | 83 | | { |
| | 131 | 84 | | options.AddPolicy(name: MyAllowSpecificOrigins, |
| | 131 | 85 | | policy => |
| | 131 | 86 | | policy |
| | 131 | 87 | | .AllowAnyMethod() |
| | 131 | 88 | | .AllowAnyHeader() |
| | 0 | 89 | | .SetIsOriginAllowed(origin => true) |
| | 131 | 90 | | .AllowCredentials() |
| | 131 | 91 | | ); |
| | 262 | 92 | | }); |
| | | 93 | | |
| | 131 | 94 | | var app = builder.Build(); |
| | | 95 | | |
| | 131 | 96 | | app.UseHttpLogging(); |
| | 131 | 97 | | app.UseExceptionHandler(exceptionHandlerApp => |
| | 131 | 98 | | { |
| | 131 | 99 | | exceptionHandlerApp.Run(async httpContext => |
| | 0 | 100 | | { |
| | 0 | 101 | | var pds = httpContext.RequestServices.GetService<IProblemDetailsService>(); |
| | 0 | 102 | | if (pds == null |
| | 0 | 103 | | || !await pds.TryWriteAsync(new() { HttpContext = httpContext })) |
| | 0 | 104 | | { |
| | 131 | 105 | | // Fallback behavior |
| | 0 | 106 | | await httpContext.Response.WriteAsync("Fallback: An error occurred."); |
| | 0 | 107 | | } |
| | 131 | 108 | | }); |
| | 262 | 109 | | }); |
| | 131 | 110 | | app.UseStatusCodePages(); |
| | 131 | 111 | | app.UseDeveloperExceptionPage(); |
| | | 112 | | |
| | 131 | 113 | | app.MapOpenApi(); |
| | 131 | 114 | | app.MapScalarApiReference(); |
| | | 115 | | |
| | 131 | 116 | | app.MapProjectEndpoints() |
| | 131 | 117 | | .MapClassEndpoints() |
| | 131 | 118 | | .MapFieldFormatterEndpoints() |
| | 131 | 119 | | .MapHistoryRepositoryEndpoints() |
| | 131 | 120 | | .MapFieldDefinitionEndpoints() |
| | 131 | 121 | | .MapFieldProcessingEndpoints() |
| | 131 | 122 | | .MapInstancesEndpoints() |
| | 131 | 123 | | .MapHistoryValuesEndpoints(); |
| | 131 | 124 | | app.UseCors(MyAllowSpecificOrigins); |
| | 131 | 125 | | app.Run(); |
| | 0 | 126 | | } |
| | | 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 | | } |