From 7313bbebb66aa568004e5a1379b18eb3e3236643 Mon Sep 17 00:00:00 2001 From: Berend Wouters Date: Wed, 9 Jul 2025 20:27:58 +0200 Subject: [PATCH] feat: use system.text.json --- BrixelAPI.SpaceAPI/Bootstrapper.cs | 3 +- .../BrixelAPI.SpaceState.csproj | 1 - .../Domain/SpaceStateAggregate/SpaceState.cs | 4 +- .../SpaceStateChangedLog.cs | 2 +- .../GetFullStatus/GetFullStatusController.cs | 4 +- .../GetFullStatus/GetFullStatusHandler.cs | 13 +- .../GetFullStatus/GetFullStatusResponse.cs | 7 +- .../GetStateChangedLogController.cs | 4 +- .../GetStateChangedLogHandler.cs | 8 +- .../GetStateChangedLogResponse.cs | 2 +- .../ToggleIsOpenStateController.cs | 4 +- .../UpdateState/ToggleIsOpenStateHandler.cs | 11 +- .../Infrastructure/ISpaceStateRepository.cs | 2 +- .../Migrations/MigrationsController.cs | 6 +- .../Infrastructure/SpaceStateRepository.cs | 6 +- .../Infrastructure/SpaceStateUnitOfWork.cs | 4 +- .../20200807202527_Initial_Migration.cs | 4 +- BrixelAPI.SpaceAPI/Schema/Schema.cs | 951 ++++++++++-------- .../AdditionalParametersDocumentFilter.cs | 2 +- SpaceAPI.Host/Properties/launchSettings.json | 4 +- .../Services/ServerLessRequestService.cs | 10 +- SpaceAPI.Host/SpaceAPI.Host.csproj | 1 - SpaceAPI.Host/WebApplicationBuilder.cs | 7 +- 23 files changed, 608 insertions(+), 452 deletions(-) diff --git a/BrixelAPI.SpaceAPI/Bootstrapper.cs b/BrixelAPI.SpaceAPI/Bootstrapper.cs index bda7f57..2d60d6e 100644 --- a/BrixelAPI.SpaceAPI/Bootstrapper.cs +++ b/BrixelAPI.SpaceAPI/Bootstrapper.cs @@ -1,7 +1,6 @@ using BrixelAPI.SpaceState.Features.UpdateState; using BrixelAPI.SpaceState.Infrastructure; using FluentValidation; -using MediatR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -13,7 +12,7 @@ public static class Bootstrapper public static void Configure(IServiceCollection serviceCollection, IConfiguration configuration) { serviceCollection.AddMediatR(x => x.RegisterServicesFromAssembly(typeof(Bootstrapper).Assembly)); - + serviceCollection.AddScoped(); serviceCollection.AddScoped(); diff --git a/BrixelAPI.SpaceAPI/BrixelAPI.SpaceState.csproj b/BrixelAPI.SpaceAPI/BrixelAPI.SpaceState.csproj index 50c1a70..bcda633 100644 --- a/BrixelAPI.SpaceAPI/BrixelAPI.SpaceState.csproj +++ b/BrixelAPI.SpaceAPI/BrixelAPI.SpaceState.csproj @@ -18,7 +18,6 @@ - diff --git a/BrixelAPI.SpaceAPI/Domain/SpaceStateAggregate/SpaceState.cs b/BrixelAPI.SpaceAPI/Domain/SpaceStateAggregate/SpaceState.cs index 5ec4799..ece8b7f 100644 --- a/BrixelAPI.SpaceAPI/Domain/SpaceStateAggregate/SpaceState.cs +++ b/BrixelAPI.SpaceAPI/Domain/SpaceStateAggregate/SpaceState.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using BrixelAPI.SpaceState.Schema; + namespace BrixelAPI.SpaceState.Domain.SpaceStateAggregate; @@ -18,7 +18,7 @@ public static SpaceState GetConfiguredSpaceAPI() { return new SpaceState() { - ApiCompatibility = new[] { "0.14" }, + ApiCompatibility = ["0.14"], Space = "Brixel", Logo = "https://www.brixel.be/wp-content/uploads/2015/09/Logo_small_transparant.png", Url = "http://brixel.be", diff --git a/BrixelAPI.SpaceAPI/Domain/SpaceStateChangedAggregate/SpaceStateChangedLog.cs b/BrixelAPI.SpaceAPI/Domain/SpaceStateChangedAggregate/SpaceStateChangedLog.cs index d66e3c8..e0ceec0 100644 --- a/BrixelAPI.SpaceAPI/Domain/SpaceStateChangedAggregate/SpaceStateChangedLog.cs +++ b/BrixelAPI.SpaceAPI/Domain/SpaceStateChangedAggregate/SpaceStateChangedLog.cs @@ -10,7 +10,7 @@ public class SpaceStateChangedLog public DateTime ChangedAtDateTime { get; set; } private SpaceStateChangedLog() { - + } public static SpaceStateChangedLog Create(bool isOpen, string user) diff --git a/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusController.cs b/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusController.cs index 0e1d0a4..f90f04d 100644 --- a/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusController.cs +++ b/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusController.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; -using MediatR; +using MediatR; using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Features.GetFullStatus { diff --git a/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusHandler.cs b/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusHandler.cs index 4594eac..be4eabf 100644 --- a/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusHandler.cs +++ b/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusHandler.cs @@ -1,10 +1,8 @@ -using System; -using System.IO; +using BrixelAPI.SpaceState.Infrastructure; +using MediatR; +using System; using System.Threading; using System.Threading.Tasks; -using BrixelAPI.SpaceState.Domain.SpaceStateAggregate; -using BrixelAPI.SpaceState.Infrastructure; -using MediatR; namespace BrixelAPI.SpaceState.Features.GetFullStatus { @@ -22,14 +20,15 @@ public async Task Handle(GetFullStatusRequest request, Ca var state = Domain.SpaceStateAggregate.SpaceState.GetConfiguredSpaceAPI(); var lastState = await _spaceStateRepository.GetLastLogAsync(); - if (lastState != null) { + if (lastState != null) + { state.State.Open = lastState.IsOpen; state.State.Lastchange = lastState.ChangedAtDateTime .ToUniversalTime() .Subtract(new DateTime(1970, 1, 1)).TotalSeconds; } - + var response = new GetFullStatusResponse(state); return response; } diff --git a/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusResponse.cs b/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusResponse.cs index c0e649b..354eb4f 100644 --- a/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusResponse.cs +++ b/BrixelAPI.SpaceAPI/Features/GetFullStatus/GetFullStatusResponse.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text.Json.Serialization; -using BrixelAPI.SpaceState.Schema; +using System.Linq; namespace BrixelAPI.SpaceState.Features.GetFullStatus { @@ -42,5 +39,5 @@ public GetFullStatusResponse(Domain.SpaceStateAggregate.SpaceState spaceState) } } - + } \ No newline at end of file diff --git a/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogController.cs b/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogController.cs index 7211855..c1dd95f 100644 --- a/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogController.cs +++ b/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogController.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; -using MediatR; +using MediatR; using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Features.GetStateChangedLogs { diff --git a/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogHandler.cs b/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogHandler.cs index 50fea8c..74bc5b9 100644 --- a/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogHandler.cs +++ b/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogHandler.cs @@ -1,10 +1,10 @@ -using System.ComponentModel; +using BrixelAPI.SpaceState.Infrastructure; +using MediatR; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; -using BrixelAPI.SpaceState.Infrastructure; -using MediatR; -using Microsoft.EntityFrameworkCore; namespace BrixelAPI.SpaceState.Features.GetStateChangedLogs { diff --git a/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogResponse.cs b/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogResponse.cs index 19ea984..a5cce66 100644 --- a/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogResponse.cs +++ b/BrixelAPI.SpaceAPI/Features/GetStateChangedLogs/GetStateChangedLogResponse.cs @@ -3,7 +3,7 @@ namespace BrixelAPI.SpaceState.Features.GetStateChangedLogs { - public class GetStateChangedLogResponse + public class GetStateChangedLogResponse { public List Logs { get; } diff --git a/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateController.cs b/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateController.cs index 6cea9ab..5f5d799 100644 --- a/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateController.cs +++ b/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateController.cs @@ -1,7 +1,7 @@ -using System.Threading.Tasks; -using MediatR; +using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Features.UpdateState { diff --git a/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateHandler.cs b/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateHandler.cs index 2265ef2..d0a04ff 100644 --- a/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateHandler.cs +++ b/BrixelAPI.SpaceAPI/Features/UpdateState/ToggleIsOpenStateHandler.cs @@ -1,10 +1,9 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using BrixelAPI.SpaceState.Domain.SpaceStateAggregate; -using BrixelAPI.SpaceState.Domain.SpaceStateChangedAggregate; +using BrixelAPI.SpaceState.Domain.SpaceStateChangedAggregate; using BrixelAPI.SpaceState.Infrastructure; using MediatR; +using System; +using System.Threading; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Features.UpdateState { @@ -28,7 +27,7 @@ public async Task Handle(ToggleIsOpenStateRequest req var state = Domain.SpaceStateAggregate.SpaceState.GetConfiguredSpaceAPI(); state.ChangeState(request.IsOpen); - + await _spaceStateRepository.AddAsync(SpaceStateChangedLog.Create(request.IsOpen, "User")); await _unitOfWork.CommitAsync(); diff --git a/BrixelAPI.SpaceAPI/Infrastructure/ISpaceStateRepository.cs b/BrixelAPI.SpaceAPI/Infrastructure/ISpaceStateRepository.cs index 0ffe574..36872eb 100644 --- a/BrixelAPI.SpaceAPI/Infrastructure/ISpaceStateRepository.cs +++ b/BrixelAPI.SpaceAPI/Infrastructure/ISpaceStateRepository.cs @@ -1,5 +1,5 @@ -using System.Threading.Tasks; using BrixelAPI.SpaceState.Domain.SpaceStateChangedAggregate; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Infrastructure; diff --git a/BrixelAPI.SpaceAPI/Infrastructure/Migrations/MigrationsController.cs b/BrixelAPI.SpaceAPI/Infrastructure/Migrations/MigrationsController.cs index 8b461ed..b44f16a 100644 --- a/BrixelAPI.SpaceAPI/Infrastructure/Migrations/MigrationsController.cs +++ b/BrixelAPI.SpaceAPI/Infrastructure/Migrations/MigrationsController.cs @@ -1,7 +1,7 @@ -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using System.Threading; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Infrastructure.Migrations { diff --git a/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateRepository.cs b/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateRepository.cs index 6601ebe..eb41444 100644 --- a/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateRepository.cs +++ b/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateRepository.cs @@ -1,7 +1,7 @@ -using System.Linq; -using System.Threading.Tasks; using BrixelAPI.SpaceState.Domain.SpaceStateChangedAggregate; using Microsoft.EntityFrameworkCore; +using System.Linq; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Infrastructure; @@ -20,7 +20,7 @@ public async Task AddAsync(SpaceStateChangedLog spaceStateChangedLog) public Task GetLastLogAsync() { - return + return _context.SpaceStateChangedLog .OrderByDescending(x => x.ChangedAtDateTime) .FirstOrDefaultAsync(); diff --git a/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateUnitOfWork.cs b/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateUnitOfWork.cs index d81c63a..95b7f9a 100644 --- a/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateUnitOfWork.cs +++ b/BrixelAPI.SpaceAPI/Infrastructure/SpaceStateUnitOfWork.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; -using BrixelAPI.SpaceState.Domain.SpaceStateChangedAggregate; +using BrixelAPI.SpaceState.Domain.SpaceStateChangedAggregate; using Microsoft.EntityFrameworkCore; +using System.Threading.Tasks; namespace BrixelAPI.SpaceState.Infrastructure { diff --git a/BrixelAPI.SpaceAPI/Migrations/20200807202527_Initial_Migration.cs b/BrixelAPI.SpaceAPI/Migrations/20200807202527_Initial_Migration.cs index 2963743..00132af 100644 --- a/BrixelAPI.SpaceAPI/Migrations/20200807202527_Initial_Migration.cs +++ b/BrixelAPI.SpaceAPI/Migrations/20200807202527_Initial_Migration.cs @@ -1,5 +1,5 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; +using System; namespace BrixelAPI.SpaceState.Migrations { diff --git a/BrixelAPI.SpaceAPI/Schema/Schema.cs b/BrixelAPI.SpaceAPI/Schema/Schema.cs index 6a897e5..7aa070f 100644 --- a/BrixelAPI.SpaceAPI/Schema/Schema.cs +++ b/BrixelAPI.SpaceAPI/Schema/Schema.cs @@ -1,59 +1,74 @@ -using System; +// +// +// To parse this JSON data, add NuGet 'System.Text.Json' then do: +// +// using SpaceApi; +// +// var coordinate = Coordinate.FromJson(jsonString); + +using System; +using System.Collections.Generic; + +using System.Text.Json; +using System.Text.Json.Serialization; using System.Globalization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace BrixelAPI.SpaceState.Schema; +/// +/// SpaceAPI v14 +/// public partial class SpaceApi { /// /// The versions your SpaceAPI endpoint supports /// - [JsonProperty("api_compatibility")] + [JsonPropertyName("api_compatibility")] public string[] ApiCompatibility { get; set; } /// /// URL(s) of webcams in your space /// - [JsonProperty("cam", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("cam")] public string[] Cam { get; set; } /// /// Contact information about your space /// - [JsonProperty("contact")] + [JsonPropertyName("contact")] public Contact Contact { get; set; } /// /// Events which happened recently in your space and which could be interesting to the /// public, like 'User X has entered/triggered/did something at timestamp Z' /// - [JsonProperty("events", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("events")] public Event[] Events { get; set; } /// /// Feeds where users can get updates of your space /// - [JsonProperty("feeds", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("feeds")] public Feeds Feeds { get; set; } /// /// Arbitrary links that you'd like to share /// - [JsonProperty("links", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("links")] public Link[] Links { get; set; } /// /// Position data such as a postal address or geographic coordinates /// - [JsonProperty("location")] + [JsonPropertyName("location")] public Location Location { get; set; } /// /// URL to your space logo /// - [JsonProperty("logo")] + [JsonPropertyName("logo")] public string Logo { get; set; } /// @@ -62,13 +77,15 @@ public partial class SpaceApi /// but you bill it yearly (aka. the member pays the fee once per year), set the amount to /// 120 an the billing_interval to yearly. /// - [JsonProperty("membership_plans", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("membership_plans")] public MembershipPlan[] MembershipPlans { get; set; } /// /// Your project sites (links to GitHub, wikis or wherever your projects are hosted) /// - [JsonProperty("projects", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("projects")] public string[] Projects { get; set; } /// @@ -77,140 +94,158 @@ public partial class SpaceApi /// types may be defined by you. In this case, you are requested to share your definition for /// inclusion in this specification. /// - [JsonProperty("sensors", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("sensors")] public Sensors Sensors { get; set; } /// /// The name of your space /// - [JsonProperty("space")] + [JsonPropertyName("space")] public string Space { get; set; } /// /// A flag indicating if the hackerspace uses SpaceFED, a federated login scheme so that /// visiting hackers can use the space WiFi with their home space credentials. /// - [JsonProperty("spacefed", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("spacefed")] public Spacefed Spacefed { get; set; } /// /// A collection of status-related data: actual open/closed status, icons, last change /// timestamp etc. /// - [JsonProperty("state", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("state")] public State State { get; set; } /// /// URL to your space website /// - [JsonProperty("url")] + [JsonPropertyName("url")] public string Url { get; set; } - } /// /// Contact information about your space /// -public class Contact +public partial class Contact { /// /// E-mail address for contacting your space. If this is a mailing list consider to use the /// contact/ml field. /// - [JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("email")] public string Email { get; set; } /// /// Facebook account URL /// - [JsonProperty("facebook", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("facebook")] public string Facebook { get; set; } /// /// Foursquare ID, in the form 4d8a9114d85f3704eab301dc /// - [JsonProperty("foursquare", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("foursquare")] public string Foursquare { get; set; } /// /// A URL to find information about the Space in the Gopherspace /// - [JsonProperty("gopher", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("gopher")] public string Gopher { get; set; } /// /// Identi.ca or StatusNet account, in the form yourspace@example.org /// - [JsonProperty("identica", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("identica")] public string Identica { get; set; } /// /// URL of the IRC channel /// - [JsonProperty("irc", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("irc")] public string Irc { get; set; } /// /// A separate email address for issue reports. This value can be Base64-encoded. /// - [JsonProperty("issue_mail", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("issue_mail")] public string IssueMail { get; set; } /// /// Persons who carry a key and are able to open the space upon request. One of the fields /// irc_nick, phone, email or twitter must be specified. /// - [JsonProperty("keymasters", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("keymasters")] public Keymaster[] Keymasters { get; set; } /// /// Mastodon username /// - [JsonProperty("mastodon", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("mastodon")] public string Mastodon { get; set; } /// /// Matrix channel/community for the Hackerspace /// - [JsonProperty("matrix", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("matrix")] public string Matrix { get; set; } /// /// The e-mail address of your mailing list. If you use Google Groups then the e-mail looks /// like your-group@googlegroups.com. /// - [JsonProperty("ml", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("ml")] public string Ml { get; set; } /// /// URL to a Mumble server/channel, as specified in https://wiki.mumble.info/wiki/Mumble_URL /// - [JsonProperty("mumble", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("mumble")] public string Mumble { get; set; } /// /// Phone number, including country code with a leading plus sign /// - [JsonProperty("phone", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("phone")] public string Phone { get; set; } /// /// URI for Voice-over-IP via SIP /// - [JsonProperty("sip", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("sip")] public string Sip { get; set; } /// /// Twitter username with leading @ /// - [JsonProperty("twitter", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("twitter")] public string Twitter { get; set; } /// /// A public Jabber/XMPP multi-user chatroom in the form /// chatroom@conference.example.net /// - [JsonProperty("xmpp", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("xmpp")] public string Xmpp { get; set; } } @@ -219,50 +254,58 @@ public partial class Keymaster /// /// Email address which can be base64 encoded /// - [JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("email")] public string Email { get; set; } /// /// Contact the person with this nickname directly in irc if available. The irc channel to be /// used is defined in the contact/irc field. /// - [JsonProperty("irc_nick", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("irc_nick")] public string IrcNick { get; set; } /// /// Mastodon username /// - [JsonProperty("mastodon", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("mastodon")] public string Mastodon { get; set; } /// /// Matrix username (including domain) /// - [JsonProperty("matrix", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("matrix")] public string Matrix { get; set; } /// /// Real name /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// Phone number, including country code with a leading plus sign /// - [JsonProperty("phone", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("phone")] public string Phone { get; set; } /// /// Twitter username with leading @ /// - [JsonProperty("twitter", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("twitter")] public string Twitter { get; set; } /// /// XMPP (Jabber) ID /// - [JsonProperty("xmpp", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("xmpp")] public string Xmpp { get; set; } } @@ -271,20 +314,21 @@ public partial class Event /// /// A custom text field to give more information about the event /// - [JsonProperty("extra", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("extra")] public string Extra { get; set; } /// /// Name or other identity of the subject (e.g. J. Random Hacker, /// fridge, 3D printer, …) /// - [JsonProperty("name")] + [JsonPropertyName("name")] public string Name { get; set; } /// /// Unix timestamp when the event occurred /// - [JsonProperty("timestamp")] + [JsonPropertyName("timestamp")] public double Timestamp { get; set; } /// @@ -292,7 +336,7 @@ public partial class Event /// …). Define your own actions and use them consistently, canonical actions are not (yet) /// specified /// - [JsonProperty("type")] + [JsonPropertyName("type")] public string Type { get; set; } } @@ -301,16 +345,20 @@ public partial class Event /// public partial class Feeds { - [JsonProperty("blog", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("blog")] public Blog Blog { get; set; } - [JsonProperty("calendar", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("calendar")] public Calendar Calendar { get; set; } - [JsonProperty("flickr", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("flickr")] public Flickr Flickr { get; set; } - [JsonProperty("wiki", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("wiki")] public Wiki Wiki { get; set; } } @@ -319,13 +367,14 @@ public partial class Blog /// /// Type of the feed /// - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("type")] public string Type { get; set; } /// /// Feed URL /// - [JsonProperty("url")] + [JsonPropertyName("url")] public string Url { get; set; } } @@ -334,13 +383,14 @@ public partial class Calendar /// /// Type of the feed /// - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("type")] public string Type { get; set; } /// /// Feed URL /// - [JsonProperty("url")] + [JsonPropertyName("url")] public string Url { get; set; } } @@ -349,13 +399,14 @@ public partial class Flickr /// /// Type of the feed /// - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("type")] public string Type { get; set; } /// /// Feed URL /// - [JsonProperty("url")] + [JsonPropertyName("url")] public string Url { get; set; } } @@ -364,13 +415,14 @@ public partial class Wiki /// /// Type of the feed /// - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("type")] public string Type { get; set; } /// /// Feed URL /// - [JsonProperty("url")] + [JsonPropertyName("url")] public string Url { get; set; } } @@ -379,19 +431,20 @@ public partial class Link /// /// An extra field for a more detailed description of the link /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The link name /// - [JsonProperty("name")] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The URL /// - [JsonProperty("url")] + [JsonPropertyName("url")] public string Url { get; set; } } @@ -405,21 +458,22 @@ public partial class Location /// you usually need in your country, and the country itself).
Examples:
  • Netzladen /// e.V., Breite Straße 74, 53111 Bonn, Germany
/// - [JsonProperty("address", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("address")] public string Address { get; set; } /// /// Latitude of your space location, in degree with decimal places. Use positive values for /// locations north of the equator, negative values for locations south of equator. /// - [JsonProperty("lat")] + [JsonPropertyName("lat")] public double Lat { get; set; } /// /// Longitude of your space location, in degree with decimal places. Use positive values for /// locations east of Greenwich, and negative values for locations west of Greenwich. /// - [JsonProperty("lon")] + [JsonPropertyName("lon")] public double Lon { get; set; } /// @@ -427,7 +481,8 @@ public partial class Location /// target="_blank" href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">TZ /// database location names. /// - [JsonProperty("timezone", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("timezone")] public string Timezone { get; set; } } @@ -437,7 +492,7 @@ public partial class MembershipPlan /// How often is the membership billed? If you select other, please specify in the /// description what your billing interval is. /// - [JsonProperty("billing_interval")] + [JsonPropertyName("billing_interval")] public BillingInterval BillingInterval { get; set; } /// @@ -445,25 +500,26 @@ public partial class MembershipPlan /// href="https://en.wikipedia.org/wiki/ISO_4217" target="_blank">ISO 4217 short-code /// format. /// - [JsonProperty("currency")] + [JsonPropertyName("currency")] public string Currency { get; set; } /// /// A free form string /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The name of the membership plan /// - [JsonProperty("name")] + [JsonPropertyName("name")] public string Name { get; set; } /// /// How much does this plan cost? /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -478,65 +534,75 @@ public partial class Sensors /// /// How rich is your hackerspace? /// - [JsonProperty("account_balance", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("account_balance")] public AccountBalance[] AccountBalance { get; set; } /// /// Barometer sensor /// - [JsonProperty("barometer", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("barometer")] public Barometer[] Barometer { get; set; } /// /// How much Mate and beer is in your fridge? /// - [JsonProperty("beverage_supply", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("beverage_supply")] public BeverageSupply[] BeverageSupply { get; set; } /// /// Sensor type to indicate if a certain door is locked /// - [JsonProperty("door_locked", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("door_locked")] public DoorLocked[] DoorLocked { get; set; } /// /// Humidity sensor /// - [JsonProperty("humidity", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("humidity")] public Humidity[] Humidity { get; set; } /// /// This sensor type is to specify the currently active ethernet or wireless network devices. /// You can create different instances for each network type. /// - [JsonProperty("network_connections", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("network_connections")] public NetworkConnection[] NetworkConnections { get; set; } /// /// The current network traffic, in bits/second or packets/second (or both) /// - [JsonProperty("network_traffic", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("network_traffic")] public NetworkTraffic[] NetworkTraffic { get; set; } /// /// Specify the number of people that are currently in your space. Optionally you can define /// a list of names. /// - [JsonProperty("people_now_present", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("people_now_present")] public PeopleNowPresent[] PeopleNowPresent { get; set; } /// /// The power consumption of a specific device or of your whole space /// - [JsonProperty("power_consumption", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("power_consumption")] public PowerConsumption[] PowerConsumption { get; set; } /// /// Compound radiation sensor. Check this resource. /// - [JsonProperty("radiation", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("radiation")] public Radiation Radiation { get; set; } /// @@ -544,19 +610,22 @@ public partial class Sensors /// href="http://en.wikipedia.org/wiki/Temperature_conversion_formulas" /// target="_blank">Wikipedia. /// - [JsonProperty("temperature", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("temperature")] public Temperature[] Temperature { get; set; } /// /// Specify the number of space members. /// - [JsonProperty("total_member_count", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("total_member_count")] public TotalMemberCount[] TotalMemberCount { get; set; } /// /// Your wind sensor /// - [JsonProperty("wind", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("wind")] public Wind[] Wind { get; set; } } @@ -566,19 +635,22 @@ public partial class AccountBalance /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// If you have more than one account you can use this field to specify where it is. /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// Give your sensor instance a name. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// @@ -586,13 +658,13 @@ public partial class AccountBalance /// href="https://en.wikipedia.org/wiki/ISO_4217" target="_blank">ISO 4217 short-code /// format. /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public string Unit { get; set; } /// /// How much? /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -602,33 +674,35 @@ public partial class Barometer /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location")] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The unit of pressure used by your sensor
Note: The hPA unit is deprecated /// and should not be used anymore. Use the correct hPa unit instead. ///
- [JsonProperty("unit")] + [JsonPropertyName("unit")] public BarometerUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -638,32 +712,35 @@ public partial class BeverageSupply /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The unit, either btl for bottles or crt for crates /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public BeverageSupplyUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -673,26 +750,28 @@ public partial class DoorLocked /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location")] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public bool Value { get; set; } } @@ -702,33 +781,35 @@ public partial class Humidity /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location")] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The unit of the sensor value. You should always define the unit though if the sensor is a /// flag of a boolean type then you can of course omit it. /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public HumidityUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -738,26 +819,30 @@ public partial class NetworkConnection /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// The machines that are currently connected with the network. /// - [JsonProperty("machines", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("machines")] public Machine[] Machines { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// @@ -766,13 +851,14 @@ public partial class NetworkConnection /// href="https://spacefed.net/wiki/index.php/Spacenet" /// target="_blank">spacenet-authenticated connections. /// - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("type")] public TypeEnum? Type { get; set; } /// /// The amount of network connections. /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -781,13 +867,14 @@ public partial class Machine /// /// The machine's MAC address of the format D3:3A:DB:EE:FF:00. /// - [JsonProperty("mac")] + [JsonPropertyName("mac")] public string Mac { get; set; } /// /// The machine name. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } } @@ -797,31 +884,36 @@ public partial class NetworkTraffic /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// Location the measurement relates to, e.g. WiFi or Uplink /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// Name of the measurement, e.g. to distinguish between upstream and downstream traffic /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("properties")] + [JsonPropertyName("properties")] public NetworkTrafficProperties Properties { get; set; } } public partial class NetworkTrafficProperties { - [JsonProperty("bits_per_second", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("bits_per_second")] public BitsPerSecond BitsPerSecond { get; set; } - [JsonProperty("packets_per_second", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("packets_per_second")] public PacketsPerSecond PacketsPerSecond { get; set; } } @@ -830,14 +922,15 @@ public partial class BitsPerSecond /// /// The maximum available throughput in bits/second, e.g. as sold by your ISP /// - [JsonProperty("maximum", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("maximum")] [JsonConverter(typeof(MinMaxValueCheckConverter))] public double? Maximum { get; set; } /// /// The measurement value, in bits/second /// - [JsonProperty("value")] + [JsonPropertyName("value")] [JsonConverter(typeof(MinMaxValueCheckConverter))] public double Value { get; set; } } @@ -847,7 +940,7 @@ public partial class PacketsPerSecond /// /// The measurement value, in packets/second /// - [JsonProperty("value")] + [JsonPropertyName("value")] [JsonConverter(typeof(MinMaxValueCheckConverter))] public double Value { get; set; } } @@ -858,14 +951,16 @@ public partial class PeopleNowPresent /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// If you use multiple sensor instances for different rooms, use this field to indicate the /// location. /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// @@ -873,19 +968,21 @@ public partial class PeopleNowPresent /// field is not intended to be used for names of hackerspace members. Use the field 'names' /// instead. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// List of hackerspace members that are currently occupying the space. /// - [JsonProperty("names", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("names")] public string[] Names { get; set; } /// /// The amount of present people. /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -895,39 +992,41 @@ public partial class PowerConsumption /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location")] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The unit of the sensor value. You should always define the unit though if the sensor is a /// flag of a boolean type then you can of course omit it. /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public PowerConsumptionUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } /// /// Compound radiation sensor. Check this resource. /// public partial class Radiation @@ -935,25 +1034,29 @@ public partial class Radiation /// /// An alpha sensor /// - [JsonProperty("alpha", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("alpha")] public Alpha[] Alpha { get; set; } /// /// A beta sensor /// - [JsonProperty("beta", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("beta")] public Beta[] Beta { get; set; } /// /// A sensor which cannot filter beta and gamma radiation separately. /// - [JsonProperty("beta_gamma", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("beta_gamma")] public BetaGamma[] BetaGamma { get; set; } /// /// A gamma sensor /// - [JsonProperty("gamma", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("gamma")] public Gamma[] Gamma { get; set; } } @@ -968,40 +1071,45 @@ public partial class Alpha /// target="_blank">full of wrong copy & pastes, don't even trust your neighbour /// hackerspace. If in doubt ask the tube manufacturer. /// - [JsonProperty("conversion_factor", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversion_factor")] public double? ConversionFactor { get; set; } /// /// The dead time in µs. See the description of the value field to see how to use the dead /// time. /// - [JsonProperty("dead_time", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("dead_time")] public double? DeadTime { get; set; } /// /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// Choose the appropriate unit for your radiation sensor instance /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public AlphaUnit Unit { get; set; } /// @@ -1010,7 +1118,7 @@ public partial class Alpha /// CPM formula:
cpm = ocpm ( 1 + 1 / (1 - ocpm x dead_time) )
Conversion formula: ///
µSv/h = cpm x conversion_factor
///
- [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1025,40 +1133,45 @@ public partial class Beta /// target="_blank">full of wrong copy & pastes, don't even trust your neighbour /// hackerspace. If in doubt ask the tube manufacturer. /// - [JsonProperty("conversion_factor", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversion_factor")] public double? ConversionFactor { get; set; } /// /// The dead time in µs. See the description of the value field to see how to use the dead /// time. /// - [JsonProperty("dead_time", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("dead_time")] public double? DeadTime { get; set; } /// /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// Choose the appropriate unit for your radiation sensor instance /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public AlphaUnit Unit { get; set; } /// @@ -1067,7 +1180,7 @@ public partial class Beta /// CPM formula:
cpm = ocpm ( 1 + 1 / (1 - ocpm x dead_time) )
Conversion formula: ///
µSv/h = cpm x conversion_factor
///
- [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1082,40 +1195,45 @@ public partial class BetaGamma /// target="_blank">full of wrong copy & pastes, don't even trust your neighbour /// hackerspace. If in doubt ask the tube manufacturer. /// - [JsonProperty("conversion_factor", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversion_factor")] public double? ConversionFactor { get; set; } /// /// The dead time in µs. See the description of the value field to see how to use the dead /// time. /// - [JsonProperty("dead_time", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("dead_time")] public double? DeadTime { get; set; } /// /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// Choose the appropriate unit for your radiation sensor instance /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public AlphaUnit Unit { get; set; } /// @@ -1124,7 +1242,7 @@ public partial class BetaGamma /// CPM formula:
cpm = ocpm ( 1 + 1 / (1 - ocpm x dead_time) )
Conversion formula: ///
µSv/h = cpm x conversion_factor
///
- [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1139,40 +1257,45 @@ public partial class Gamma /// target="_blank">full of wrong copy & pastes, don't even trust your neighbour /// hackerspace. If in doubt ask the tube manufacturer. /// - [JsonProperty("conversion_factor", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversion_factor")] public double? ConversionFactor { get; set; } /// /// The dead time in µs. See the description of the value field to see how to use the dead /// time. /// - [JsonProperty("dead_time", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("dead_time")] public double? DeadTime { get; set; } /// /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// Choose the appropriate unit for your radiation sensor instance /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public AlphaUnit Unit { get; set; } /// @@ -1181,7 +1304,7 @@ public partial class Gamma /// CPM formula:
cpm = ocpm ( 1 + 1 / (1 - ocpm x dead_time) )
Conversion formula: ///
µSv/h = cpm x conversion_factor
///
- [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1191,32 +1314,34 @@ public partial class Temperature /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location")] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The unit of the sensor value /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public TemperatureUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1226,27 +1351,30 @@ public partial class TotalMemberCount /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// Specify the location if your hackerspace has different departments (for whatever reason). /// This field is for one department. Every department should have its own sensor instance. /// - [JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("location")] public string Location { get; set; } /// /// You can use this field to specify if this sensor instance counts active or inactive /// members. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } /// /// The amount of your space members. /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1256,23 +1384,25 @@ public partial class Wind /// An extra field that you can use to attach some additional information to this sensor /// instance /// - [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] public string Description { get; set; } /// /// The location of your sensor /// - [JsonProperty("location")] + [JsonPropertyName("location")] public string Location { get; set; } /// /// This field is an additional field to give your sensor a name. This can be useful if you /// have multiple sensors in the same location. /// - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("properties")] + [JsonPropertyName("properties")] public WindProperties Properties { get; set; } } @@ -1281,19 +1411,19 @@ public partial class WindProperties /// /// The wind direction in degrees /// - [JsonProperty("direction")] + [JsonPropertyName("direction")] public Direction Direction { get; set; } /// /// Height above mean sea level /// - [JsonProperty("elevation")] + [JsonPropertyName("elevation")] public Elevation Elevation { get; set; } - [JsonProperty("gust")] + [JsonPropertyName("gust")] public Gust Gust { get; set; } - [JsonProperty("speed")] + [JsonPropertyName("speed")] public Speed Speed { get; set; } } @@ -1306,13 +1436,13 @@ public partial class Direction /// The unit of the sensor value. You should always define the unit though if the sensor is a /// flag of a boolean type then you can of course omit it. /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public DirectionUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1325,13 +1455,13 @@ public partial class Elevation /// The unit of the sensor value. You should always define the unit though if the sensor is a /// flag of a boolean type then you can of course omit it. /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public ElevationUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1341,13 +1471,13 @@ public partial class Gust /// The unit of the sensor value. You should always define the unit though if the sensor is a /// flag of a boolean type then you can of course omit it. /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public GustUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1357,13 +1487,13 @@ public partial class Speed /// The unit of the sensor value. You should always define the unit though if the sensor is a /// flag of a boolean type then you can of course omit it. /// - [JsonProperty("unit")] + [JsonPropertyName("unit")] public GustUnit Unit { get; set; } /// /// The sensor value /// - [JsonProperty("value")] + [JsonPropertyName("value")] public double Value { get; set; } } @@ -1377,13 +1507,13 @@ public partial class Spacefed /// See the wiki. /// - [JsonProperty("spacenet")] + [JsonPropertyName("spacenet")] public bool Spacenet { get; set; } /// /// See the wiki. /// - [JsonProperty("spacesaml")] + [JsonPropertyName("spacesaml")] public bool Spacesaml { get; set; } } @@ -1396,20 +1526,23 @@ public partial class State /// /// Icons that show the status graphically /// - [JsonProperty("icon", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("icon")] public Icon Icon { get; set; } /// /// The Unix timestamp when the space status changed most recently /// - [JsonProperty("lastchange", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("lastchange")] public double? Lastchange { get; set; } /// /// An additional free-form string, could be something like 'open for public', /// 'members only' or whatever you want it to be /// - [JsonProperty("message", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("message")] public string Message { get; set; } /// @@ -1420,13 +1553,14 @@ public partial class State /// is also allowed to explicitly have the value null for backwards compatibility with older /// schema versions, but this is deprecated and will be removed in a future version. /// - [JsonProperty("open")] + [JsonPropertyName("open")] public bool? Open { get; set; } /// /// The person who lastly changed the state e.g. opened or closed the space /// - [JsonProperty("trigger_person", NullValueHandling = NullValueHandling.Ignore)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("trigger_person")] public string TriggerPerson { get; set; } } @@ -1438,13 +1572,13 @@ public partial class Icon /// /// The URL to your customized space logo showing a closed space /// - [JsonProperty("closed")] + [JsonPropertyName("closed")] public string Closed { get; set; } /// /// The URL to your customized space logo showing an open space /// - [JsonProperty("open")] + [JsonPropertyName("open")] public string Open { get; set; } } @@ -1513,22 +1647,20 @@ public enum ElevationUnit { M }; /// public enum GustUnit { KmH, Kn, MS }; -public partial class SpaceApi +public partial class Coordinate { - public static BrixelAPI.SpaceState.Domain.SpaceStateAggregate.SpaceState FromJson(string json) => JsonConvert.DeserializeObject(json, Converter.Settings); + public static Coordinate FromJson(string json) => JsonSerializer.Deserialize(json, Converter.Settings); } public static class Serialize { - public static string ToJson(this BrixelAPI.SpaceState.Domain.SpaceStateAggregate.SpaceState self) => JsonConvert.SerializeObject(self, Converter.Settings); + public static string ToJson(this Coordinate self) => JsonSerializer.Serialize(self, Converter.Settings); } internal static class Converter { - public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings + public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General) { - MetadataPropertyHandling = MetadataPropertyHandling.Ignore, - DateParseHandling = DateParseHandling.None, Converters = { BillingIntervalConverter.Singleton, @@ -1542,19 +1674,20 @@ internal static class Converter DirectionUnitConverter.Singleton, ElevationUnitConverter.Singleton, GustUnitConverter.Singleton, - new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } + new DateOnlyConverter(), + new TimeOnlyConverter(), + IsoDateTimeOffsetConverter.Singleton }, }; } -internal class BillingIntervalConverter : JsonConverter +internal class BillingIntervalConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(BillingInterval) || t == typeof(BillingInterval?); + public override bool CanConvert(Type t) => t == typeof(BillingInterval); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override BillingInterval Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "daily": @@ -1573,33 +1706,27 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type BillingInterval"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, BillingInterval value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (BillingInterval)untypedValue; switch (value) { case BillingInterval.Daily: - serializer.Serialize(writer, "daily"); + JsonSerializer.Serialize(writer, "daily", options); return; case BillingInterval.Hourly: - serializer.Serialize(writer, "hourly"); + JsonSerializer.Serialize(writer, "hourly", options); return; case BillingInterval.Monthly: - serializer.Serialize(writer, "monthly"); + JsonSerializer.Serialize(writer, "monthly", options); return; case BillingInterval.Other: - serializer.Serialize(writer, "other"); + JsonSerializer.Serialize(writer, "other", options); return; case BillingInterval.Weekly: - serializer.Serialize(writer, "weekly"); + JsonSerializer.Serialize(writer, "weekly", options); return; case BillingInterval.Yearly: - serializer.Serialize(writer, "yearly"); + JsonSerializer.Serialize(writer, "yearly", options); return; } throw new Exception("Cannot marshal type BillingInterval"); @@ -1608,14 +1735,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly BillingIntervalConverter Singleton = new BillingIntervalConverter(); } -internal class BarometerUnitConverter : JsonConverter +internal class BarometerUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(BarometerUnit) || t == typeof(BarometerUnit?); + public override bool CanConvert(Type t) => t == typeof(BarometerUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override BarometerUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "hPA": @@ -1626,21 +1752,15 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type BarometerUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, BarometerUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (BarometerUnit)untypedValue; switch (value) { case BarometerUnit.UnitHPa: - serializer.Serialize(writer, "hPA"); + JsonSerializer.Serialize(writer, "hPA", options); return; case BarometerUnit.HPa: - serializer.Serialize(writer, "hPa"); + JsonSerializer.Serialize(writer, "hPa", options); return; } throw new Exception("Cannot marshal type BarometerUnit"); @@ -1649,14 +1769,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly BarometerUnitConverter Singleton = new BarometerUnitConverter(); } -internal class BeverageSupplyUnitConverter : JsonConverter +internal class BeverageSupplyUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(BeverageSupplyUnit) || t == typeof(BeverageSupplyUnit?); + public override bool CanConvert(Type t) => t == typeof(BeverageSupplyUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override BeverageSupplyUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "btl": @@ -1667,21 +1786,15 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type BeverageSupplyUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, BeverageSupplyUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (BeverageSupplyUnit)untypedValue; switch (value) { case BeverageSupplyUnit.Btl: - serializer.Serialize(writer, "btl"); + JsonSerializer.Serialize(writer, "btl", options); return; case BeverageSupplyUnit.Crt: - serializer.Serialize(writer, "crt"); + JsonSerializer.Serialize(writer, "crt", options); return; } throw new Exception("Cannot marshal type BeverageSupplyUnit"); @@ -1690,14 +1803,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly BeverageSupplyUnitConverter Singleton = new BeverageSupplyUnitConverter(); } -internal class HumidityUnitConverter : JsonConverter +internal class HumidityUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(HumidityUnit) || t == typeof(HumidityUnit?); + public override bool CanConvert(Type t) => t == typeof(HumidityUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override HumidityUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); if (value == "%") { return HumidityUnit.Empty; @@ -1705,17 +1817,11 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type HumidityUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, HumidityUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (HumidityUnit)untypedValue; if (value == HumidityUnit.Empty) { - serializer.Serialize(writer, "%"); + JsonSerializer.Serialize(writer, "%", options); return; } throw new Exception("Cannot marshal type HumidityUnit"); @@ -1724,14 +1830,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly HumidityUnitConverter Singleton = new HumidityUnitConverter(); } -internal class TypeEnumConverter : JsonConverter +internal class TypeEnumConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(TypeEnum) || t == typeof(TypeEnum?); + public override bool CanConvert(Type t) => t == typeof(TypeEnum); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override TypeEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "cable": @@ -1744,24 +1849,18 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type TypeEnum"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, TypeEnum value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (TypeEnum)untypedValue; switch (value) { case TypeEnum.Cable: - serializer.Serialize(writer, "cable"); + JsonSerializer.Serialize(writer, "cable", options); return; case TypeEnum.Spacenet: - serializer.Serialize(writer, "spacenet"); + JsonSerializer.Serialize(writer, "spacenet", options); return; case TypeEnum.Wifi: - serializer.Serialize(writer, "wifi"); + JsonSerializer.Serialize(writer, "wifi", options); return; } throw new Exception("Cannot marshal type TypeEnum"); @@ -1770,14 +1869,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly TypeEnumConverter Singleton = new TypeEnumConverter(); } -internal class MinMaxValueCheckConverter : JsonConverter +internal class MinMaxValueCheckConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?); + public override bool CanConvert(Type t) => t == typeof(double); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetDouble(); if (value >= 0) { return value; @@ -1785,17 +1883,11 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type double"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (double)untypedValue; if (value >= 0) { - serializer.Serialize(writer, value); + JsonSerializer.Serialize(writer, value, options); return; } throw new Exception("Cannot marshal type double"); @@ -1804,14 +1896,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly MinMaxValueCheckConverter Singleton = new MinMaxValueCheckConverter(); } -internal class PowerConsumptionUnitConverter : JsonConverter +internal class PowerConsumptionUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(PowerConsumptionUnit) || t == typeof(PowerConsumptionUnit?); + public override bool CanConvert(Type t) => t == typeof(PowerConsumptionUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override PowerConsumptionUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "VA": @@ -1824,24 +1915,18 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type PowerConsumptionUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, PowerConsumptionUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (PowerConsumptionUnit)untypedValue; switch (value) { case PowerConsumptionUnit.Va: - serializer.Serialize(writer, "VA"); + JsonSerializer.Serialize(writer, "VA", options); return; case PowerConsumptionUnit.W: - serializer.Serialize(writer, "W"); + JsonSerializer.Serialize(writer, "W", options); return; case PowerConsumptionUnit.MW: - serializer.Serialize(writer, "mW"); + JsonSerializer.Serialize(writer, "mW", options); return; } throw new Exception("Cannot marshal type PowerConsumptionUnit"); @@ -1850,14 +1935,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly PowerConsumptionUnitConverter Singleton = new PowerConsumptionUnitConverter(); } -internal class AlphaUnitConverter : JsonConverter +internal class AlphaUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(AlphaUnit) || t == typeof(AlphaUnit?); + public override bool CanConvert(Type t) => t == typeof(AlphaUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override AlphaUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "cpm": @@ -1874,30 +1958,24 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type AlphaUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, AlphaUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (AlphaUnit)untypedValue; switch (value) { case AlphaUnit.Cpm: - serializer.Serialize(writer, "cpm"); + JsonSerializer.Serialize(writer, "cpm", options); return; case AlphaUnit.MSvA: - serializer.Serialize(writer, "mSv/a"); + JsonSerializer.Serialize(writer, "mSv/a", options); return; case AlphaUnit.RH: - serializer.Serialize(writer, "r/h"); + JsonSerializer.Serialize(writer, "r/h", options); return; case AlphaUnit.ΜSvA: - serializer.Serialize(writer, "µSv/a"); + JsonSerializer.Serialize(writer, "µSv/a", options); return; case AlphaUnit.ΜSvH: - serializer.Serialize(writer, "µSv/h"); + JsonSerializer.Serialize(writer, "µSv/h", options); return; } throw new Exception("Cannot marshal type AlphaUnit"); @@ -1906,14 +1984,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly AlphaUnitConverter Singleton = new AlphaUnitConverter(); } -internal class TemperatureUnitConverter : JsonConverter +internal class TemperatureUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(TemperatureUnit) || t == typeof(TemperatureUnit?); + public override bool CanConvert(Type t) => t == typeof(TemperatureUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override TemperatureUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "K": @@ -1936,39 +2013,33 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type TemperatureUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, TemperatureUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (TemperatureUnit)untypedValue; switch (value) { case TemperatureUnit.K: - serializer.Serialize(writer, "K"); + JsonSerializer.Serialize(writer, "K", options); return; case TemperatureUnit.C: - serializer.Serialize(writer, "°C"); + JsonSerializer.Serialize(writer, "°C", options); return; case TemperatureUnit.De: - serializer.Serialize(writer, "°De"); + JsonSerializer.Serialize(writer, "°De", options); return; case TemperatureUnit.F: - serializer.Serialize(writer, "°F"); + JsonSerializer.Serialize(writer, "°F", options); return; case TemperatureUnit.N: - serializer.Serialize(writer, "°N"); + JsonSerializer.Serialize(writer, "°N", options); return; case TemperatureUnit.R: - serializer.Serialize(writer, "°R"); + JsonSerializer.Serialize(writer, "°R", options); return; case TemperatureUnit.Ré: - serializer.Serialize(writer, "°Ré"); + JsonSerializer.Serialize(writer, "°Ré", options); return; case TemperatureUnit.Rø: - serializer.Serialize(writer, "°Rø"); + JsonSerializer.Serialize(writer, "°Rø", options); return; } throw new Exception("Cannot marshal type TemperatureUnit"); @@ -1977,14 +2048,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly TemperatureUnitConverter Singleton = new TemperatureUnitConverter(); } -internal class DirectionUnitConverter : JsonConverter +internal class DirectionUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(DirectionUnit) || t == typeof(DirectionUnit?); + public override bool CanConvert(Type t) => t == typeof(DirectionUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override DirectionUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); if (value == "°") { return DirectionUnit.Empty; @@ -1992,17 +2062,11 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type DirectionUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, DirectionUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (DirectionUnit)untypedValue; if (value == DirectionUnit.Empty) { - serializer.Serialize(writer, "°"); + JsonSerializer.Serialize(writer, "°", options); return; } throw new Exception("Cannot marshal type DirectionUnit"); @@ -2011,14 +2075,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly DirectionUnitConverter Singleton = new DirectionUnitConverter(); } -internal class ElevationUnitConverter : JsonConverter +internal class ElevationUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(ElevationUnit) || t == typeof(ElevationUnit?); + public override bool CanConvert(Type t) => t == typeof(ElevationUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override ElevationUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); if (value == "m") { return ElevationUnit.M; @@ -2026,17 +2089,11 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type ElevationUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, ElevationUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (ElevationUnit)untypedValue; if (value == ElevationUnit.M) { - serializer.Serialize(writer, "m"); + JsonSerializer.Serialize(writer, "m", options); return; } throw new Exception("Cannot marshal type ElevationUnit"); @@ -2045,14 +2102,13 @@ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSeria public static readonly ElevationUnitConverter Singleton = new ElevationUnitConverter(); } -internal class GustUnitConverter : JsonConverter +internal class GustUnitConverter : JsonConverter { - public override bool CanConvert(Type t) => t == typeof(GustUnit) || t == typeof(GustUnit?); + public override bool CanConvert(Type t) => t == typeof(GustUnit); - public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) + public override GustUnit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonToken.Null) return null; - var value = serializer.Deserialize(reader); + var value = reader.GetString(); switch (value) { case "km/h": @@ -2065,28 +2121,135 @@ public override object ReadJson(JsonReader reader, Type t, object existingValue, throw new Exception("Cannot unmarshal type GustUnit"); } - public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) + public override void Write(Utf8JsonWriter writer, GustUnit value, JsonSerializerOptions options) { - if (untypedValue == null) - { - serializer.Serialize(writer, null); - return; - } - var value = (GustUnit)untypedValue; switch (value) { case GustUnit.KmH: - serializer.Serialize(writer, "km/h"); + JsonSerializer.Serialize(writer, "km/h", options); return; case GustUnit.Kn: - serializer.Serialize(writer, "kn"); + JsonSerializer.Serialize(writer, "kn", options); return; case GustUnit.MS: - serializer.Serialize(writer, "m/s"); + JsonSerializer.Serialize(writer, "m/s", options); return; } throw new Exception("Cannot marshal type GustUnit"); } public static readonly GustUnitConverter Singleton = new GustUnitConverter(); -} \ No newline at end of file +} + +public class DateOnlyConverter : JsonConverter +{ + private readonly string serializationFormat; + public DateOnlyConverter() : this(null) { } + + public DateOnlyConverter(string? serializationFormat) + { + this.serializationFormat = serializationFormat ?? "yyyy-MM-dd"; + } + + public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var value = reader.GetString(); + return DateOnly.Parse(value!); + } + + public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(serializationFormat)); +} + +public class TimeOnlyConverter : JsonConverter +{ + private readonly string serializationFormat; + + public TimeOnlyConverter() : this(null) { } + + public TimeOnlyConverter(string? serializationFormat) + { + this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff"; + } + + public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var value = reader.GetString(); + return TimeOnly.Parse(value!); + } + + public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(serializationFormat)); +} + +internal class IsoDateTimeOffsetConverter : JsonConverter +{ + public override bool CanConvert(Type t) => t == typeof(DateTimeOffset); + + private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; + + private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind; + private string? _dateTimeFormat; + private CultureInfo? _culture; + + public DateTimeStyles DateTimeStyles + { + get => _dateTimeStyles; + set => _dateTimeStyles = value; + } + + public string? DateTimeFormat + { + get => _dateTimeFormat ?? string.Empty; + set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; + } + + public CultureInfo Culture + { + get => _culture ?? CultureInfo.CurrentCulture; + set => _culture = value; + } + + public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) + { + string text; + + + if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal + || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal) + { + value = value.ToUniversalTime(); + } + + text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture); + + writer.WriteStringValue(text); + } + + public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string? dateText = reader.GetString(); + + if (string.IsNullOrEmpty(dateText) == false) + { + if (!string.IsNullOrEmpty(_dateTimeFormat)) + { + return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles); + } + else + { + return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles); + } + } + else + { + return default(DateTimeOffset); + } + } + + + public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter(); +} +#pragma warning restore CS8618 +#pragma warning restore CS8601 +#pragma warning restore CS8603 diff --git a/SpaceAPI.Host/AdditionalParametersDocumentFilter.cs b/SpaceAPI.Host/AdditionalParametersDocumentFilter.cs index 2928c50..160a6eb 100644 --- a/SpaceAPI.Host/AdditionalParametersDocumentFilter.cs +++ b/SpaceAPI.Host/AdditionalParametersDocumentFilter.cs @@ -1,6 +1,6 @@ -using System.Linq; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; +using System.Linq; namespace SpaceAPI.Host { diff --git a/SpaceAPI.Host/Properties/launchSettings.json b/SpaceAPI.Host/Properties/launchSettings.json index a5d7624..c060d04 100644 --- a/SpaceAPI.Host/Properties/launchSettings.json +++ b/SpaceAPI.Host/Properties/launchSettings.json @@ -11,7 +11,7 @@ "profiles": { "IIS Express": { "commandName": "IISExpress", - "launchBrowser": true, + "launchBrowser": false, "launchUrl": "api/status", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" @@ -19,7 +19,7 @@ }, "SpaceAPI.Host": { "commandName": "Project", - "launchBrowser": true, + "launchBrowser": false, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/SpaceAPI.Host/Services/ServerLessRequestService.cs b/SpaceAPI.Host/Services/ServerLessRequestService.cs index 38730a5..6fdd1b6 100644 --- a/SpaceAPI.Host/Services/ServerLessRequestService.cs +++ b/SpaceAPI.Host/Services/ServerLessRequestService.cs @@ -1,11 +1,11 @@ -using System; +using Microsoft.Extensions.Options; +using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; +using System.Text.Json; using System.Threading.Tasks; -using Microsoft.Extensions.Options; -using Newtonsoft.Json; namespace SpaceAPI.Host.Services { @@ -20,7 +20,7 @@ public ServerLessRequestService(IOptions options) _serverLessOptions = options.Value ?? throw new ArgumentNullException(nameof(ServerLessOptions)); var baseAddress = _serverLessOptions.FunctionBaseUri; - _httpClient = new HttpClient {BaseAddress = new Uri(baseAddress)}; + _httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; //ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; @@ -34,7 +34,7 @@ public async Task SpaceStateChanged(bool isOpen) { IsOpen = isOpen }; - string textMessage = JsonConvert.SerializeObject(spaceStateChanged); + string textMessage = JsonSerializer.Serialize(spaceStateChanged); var httpContent = new StringContent(textMessage, Encoding.UTF8, "application/json"); await _httpClient.PostAsync(spaceStateChangedUri, httpContent); } diff --git a/SpaceAPI.Host/SpaceAPI.Host.csproj b/SpaceAPI.Host/SpaceAPI.Host.csproj index 782ef59..4037a5b 100644 --- a/SpaceAPI.Host/SpaceAPI.Host.csproj +++ b/SpaceAPI.Host/SpaceAPI.Host.csproj @@ -17,7 +17,6 @@ - diff --git a/SpaceAPI.Host/WebApplicationBuilder.cs b/SpaceAPI.Host/WebApplicationBuilder.cs index 6ff8c68..07c5194 100644 --- a/SpaceAPI.Host/WebApplicationBuilder.cs +++ b/SpaceAPI.Host/WebApplicationBuilder.cs @@ -1,4 +1,3 @@ -using System.Reflection; using BrixelAPI.SpaceState; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; @@ -11,6 +10,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; +using System.Reflection; namespace SpaceAPI.Host { @@ -33,6 +33,7 @@ public static void ConfigureServices(IServiceCollection services, IConfiguration }).AddJsonOptions(o => { o.JsonSerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull; + }); @@ -138,9 +139,9 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseHttpsRedirection(); app.UseRouting(); - + app.UseCors(); - + app.UseAuthentication(); app.UseAuthorization();