From dbaed6094bb533029a397144e58d7c517eacbcaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Fri, 14 Nov 2025 14:42:05 +0100 Subject: [PATCH] Make core library aot compatible. --- .../Processors/GmailChangeProcessor.cs | 2 +- .../Processors/OutlookChangeProcessor.cs | 2 +- Wino.Core/Requests/Bundles/RequestBundle.cs | 8 +++---- Wino.Core/Synchronizers/GmailSynchronizer.cs | 22 ++++++++++------- .../ImapSynchronizationStrategyBase.cs | 1 - Wino.Core/Synchronizers/ImapSynchronizer.cs | 7 +++--- .../Synchronizers/OutlookSynchronizer.cs | 24 +++++++++---------- Wino.Core/Synchronizers/WinoSynchronizer.cs | 8 ------- 8 files changed, 34 insertions(+), 40 deletions(-) diff --git a/Wino.Core/Integration/Processors/GmailChangeProcessor.cs b/Wino.Core/Integration/Processors/GmailChangeProcessor.cs index c478308d..e7d6ab90 100644 --- a/Wino.Core/Integration/Processors/GmailChangeProcessor.cs +++ b/Wino.Core/Integration/Processors/GmailChangeProcessor.cs @@ -253,7 +253,7 @@ public class GmailChangeProcessor : DefaultChangeProcessor, IGmailChangeProcesso } // Upsert the event. - await Connection.InsertOrReplaceAsync(existingCalendarItem); + await Connection.InsertOrReplaceAsync(existingCalendarItem, typeof(CalendarItem)); } private string GetOrganizerName(Event calendarEvent, MailAccount account) diff --git a/Wino.Core/Integration/Processors/OutlookChangeProcessor.cs b/Wino.Core/Integration/Processors/OutlookChangeProcessor.cs index 3b72c33e..b597d788 100644 --- a/Wino.Core/Integration/Processors/OutlookChangeProcessor.cs +++ b/Wino.Core/Integration/Processors/OutlookChangeProcessor.cs @@ -132,7 +132,7 @@ public class OutlookChangeProcessor(IDatabaseService databaseService, } // Upsert the event. - await Connection.InsertOrReplaceAsync(savingItem); + await Connection.InsertOrReplaceAsync(savingItem, typeof(CalendarItem)); // Manage attendees. if (calendarEvent.Attendees != null) diff --git a/Wino.Core/Requests/Bundles/RequestBundle.cs b/Wino.Core/Requests/Bundles/RequestBundle.cs index 75ab6321..8a61727e 100644 --- a/Wino.Core/Requests/Bundles/RequestBundle.cs +++ b/Wino.Core/Requests/Bundles/RequestBundle.cs @@ -1,7 +1,7 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Text.Json; +using System.Text.Json.Serialization.Metadata; using System.Threading; using System.Threading.Tasks; using Wino.Core.Domain.Interfaces; @@ -21,12 +21,10 @@ public record HttpRequestBundle(TRequest NativeRequest, IUIChangeReque /// Batch request that is generated by base synchronizer. public record HttpRequestBundle(TRequest NativeRequest, IRequestBase Request) : HttpRequestBundle(NativeRequest, Request) { - [RequiresDynamicCode("AOT")] - [RequiresUnreferencedCode("AOT")] - public async Task DeserializeBundleAsync(HttpResponseMessage httpResponse, CancellationToken cancellationToken = default) + public async Task DeserializeBundleAsync(HttpResponseMessage httpResponse, JsonTypeInfo typeInfo, CancellationToken cancellationToken = default) { var content = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); - return JsonSerializer.Deserialize(content) ?? throw new InvalidOperationException("Invalid Http Response Deserialization"); + return JsonSerializer.Deserialize(content, typeInfo) ?? throw new InvalidOperationException("Invalid Http Response Deserialization"); } } diff --git a/Wino.Core/Synchronizers/GmailSynchronizer.cs b/Wino.Core/Synchronizers/GmailSynchronizer.cs index e59edfc6..baefed5e 100644 --- a/Wino.Core/Synchronizers/GmailSynchronizer.cs +++ b/Wino.Core/Synchronizers/GmailSynchronizer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; +using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; using System.Web; @@ -42,6 +43,11 @@ using CalendarService = Google.Apis.Calendar.v3.CalendarService; namespace Wino.Core.Synchronizers.Mail; +[JsonSerializable(typeof(Message))] +[JsonSerializable(typeof(Label))] +[JsonSerializable(typeof(Draft))] +public partial class GmailSynchronizerJsonContext : JsonSerializerContext; + /// /// Gmail synchronizer implementation with per-folder history ID synchronization. /// @@ -190,7 +196,7 @@ public class GmailSynchronizer : WinoSynchronizer messageBundle) { - var gmailMessage = await messageBundle.DeserializeBundleAsync(httpResponseMessage, cancellationToken).ConfigureAwait(false); + var gmailMessage = await messageBundle.DeserializeBundleAsync(httpResponseMessage, GmailSynchronizerJsonContext.Default.Message, cancellationToken).ConfigureAwait(false); if (gmailMessage == null) return; @@ -1392,7 +1398,7 @@ public class GmailSynchronizer : WinoSynchronizer, IImapSynchronizer { - [Obsolete("N/A")] + /// + /// N/A for IMAP as it doesn't support batch modifications natively. + /// public override uint BatchModificationSize => 1000; public override uint InitialMessageDownloadCountPerFolder => 500; - public override int InitialSyncMimeDownloadCount => 50; #region Idle Implementation @@ -313,7 +314,7 @@ public class ImapSynchronizer : WinoSynchronizer(String, CancellationToken)")] private async Task DeserializeGraphBatchResponseAsync(BatchResponseContentCollection collection, string requestId, CancellationToken cancellationToken = default) where T : IParsable, new() { // This deserialization may throw generalException in case of failure. @@ -893,12 +891,12 @@ public class OutlookSynchronizer : WinoSynchronizer