From 8cb8f27e00895fd5ee7cc34dba62f55a4f86498a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Fri, 14 Nov 2025 14:28:10 +0100 Subject: [PATCH] Make services aot compatible. --- Wino.Services/AccountService.cs | 42 ++++++++++++------------ Wino.Services/CalendarService.cs | 12 +++---- Wino.Services/ContactService.cs | 10 +++--- Wino.Services/DatabaseService.cs | 25 +++++++------- Wino.Services/FolderService.cs | 6 ++-- Wino.Services/KeyboardShortcutService.cs | 4 +-- Wino.Services/MailService.cs | 8 ++--- Wino.Services/SignatureService.cs | 8 ++--- 8 files changed, 58 insertions(+), 57 deletions(-) diff --git a/Wino.Services/AccountService.cs b/Wino.Services/AccountService.cs index 3d852403..2a3c7696 100644 --- a/Wino.Services/AccountService.cs +++ b/Wino.Services/AccountService.cs @@ -92,7 +92,7 @@ public class AccountService : BaseDatabaseService, IAccountService }); await Connection.ExecuteAsync(query.GetRawQuery()).ConfigureAwait(false); - await Connection.DeleteAsync(mergedInbox).ConfigureAwait(false); + await Connection.DeleteAsync(mergedInbox).ConfigureAwait(false); // Change the startup entity id if it was the merged inbox. // Take the first account as startup account. @@ -135,7 +135,7 @@ public class AccountService : BaseDatabaseService, IAccountService accountFolderList.Add(folder); folder.IsSticky = false; - await Connection.UpdateAsync(folder); + await Connection.UpdateAsync(folder, typeof(MailItemFolder)); } accountFolderDictionary.Add(account, accountFolderList); @@ -170,20 +170,20 @@ public class AccountService : BaseDatabaseService, IAccountService { folder.IsSticky = true; - await Connection.UpdateAsync(folder); + await Connection.UpdateAsync(folder, typeof(MailItemFolder)); } } } } // 3. Insert merged inbox and assign accounts. - await Connection.InsertAsync(mergedInbox); + await Connection.InsertAsync(mergedInbox, typeof(MergedInbox)); foreach (var account in accountsToMerge) { account.MergedInboxId = mergedInbox.Id; - await Connection.UpdateAsync(account); + await Connection.UpdateAsync(account, typeof(MailAccount)); } WeakReferenceMessenger.Default.Send(new AccountsMenuRefreshRequested()); @@ -254,7 +254,7 @@ public class AccountService : BaseDatabaseService, IAccountService Id = Guid.NewGuid() }; - await Connection.InsertAsync(rootAlias).ConfigureAwait(false); + await Connection.InsertAsync(rootAlias, typeof(MailAccountAlias)).ConfigureAwait(false); Log.Information("Created root alias for the account {AccountId}", accountId); } @@ -321,9 +321,9 @@ public class AccountService : BaseDatabaseService, IAccountService await Connection.Table().DeleteAsync(a => a.AccountId == account.Id); if (account.Preferences != null) - await Connection.DeleteAsync(account.Preferences); + await Connection.DeleteAsync(account.Preferences); - await Connection.DeleteAsync(account); + await Connection.DeleteAsync(account); await _mimeFileService.DeleteUserMimeCacheAsync(account.Id).ConfigureAwait(false); @@ -370,7 +370,7 @@ public class AccountService : BaseDatabaseService, IAccountService IsRootContact = true }; - await Connection.InsertOrReplaceAsync(accountContact).ConfigureAwait(false); + await Connection.InsertOrReplaceAsync(accountContact, typeof(AccountContact)).ConfigureAwait(false); await UpdateAccountAsync(account).ConfigureAwait(false); } @@ -402,15 +402,15 @@ public class AccountService : BaseDatabaseService, IAccountService public async Task UpdateAccountAsync(MailAccount account) { - await Connection.UpdateAsync(account.Preferences).ConfigureAwait(false); - await Connection.UpdateAsync(account).ConfigureAwait(false); + await Connection.UpdateAsync(account.Preferences, typeof(MailAccountPreferences)).ConfigureAwait(false); + await Connection.UpdateAsync(account, typeof(MailAccount)).ConfigureAwait(false); ReportUIChange(new AccountUpdatedMessage(account)); } public async Task UpdateAccountCustomServerInformationAsync(CustomServerInformation customServerInformation) { - await Connection.UpdateAsync(customServerInformation).ConfigureAwait(false); + await Connection.UpdateAsync(customServerInformation, typeof(CustomServerInformation)).ConfigureAwait(false); } public async Task UpdateAccountAliasesAsync(Guid accountId, List aliases) @@ -421,7 +421,7 @@ public class AccountService : BaseDatabaseService, IAccountService // Insert new ones. foreach (var alias in aliases) { - await Connection.InsertAsync(alias).ConfigureAwait(false); + await Connection.InsertAsync(alias, typeof(MailAccountAlias)).ConfigureAwait(false); } } @@ -449,7 +449,7 @@ public class AccountService : BaseDatabaseService, IAccountService AliasSenderName = remoteAlias.AliasSenderName }; - await Connection.InsertAsync(newAlias); + await Connection.InsertAsync(newAlias, typeof(MailAccountAlias)); localAliases.Add(newAlias); } else @@ -460,7 +460,7 @@ public class AccountService : BaseDatabaseService, IAccountService existingAlias.ReplyToAddress = remoteAlias.ReplyToAddress; existingAlias.AliasSenderName = remoteAlias.AliasSenderName; - await Connection.UpdateAsync(existingAlias); + await Connection.UpdateAsync(existingAlias, typeof(MailAccountAlias)); } } @@ -476,7 +476,7 @@ public class AccountService : BaseDatabaseService, IAccountService var idealPrimaryAlias = localAliases.Find(a => a.AliasAddress == account.Address) ?? localAliases.First(); idealPrimaryAlias.IsPrimary = true; - await Connection.UpdateAsync(idealPrimaryAlias).ConfigureAwait(false); + await Connection.UpdateAsync(idealPrimaryAlias, typeof(MailAccountAlias)).ConfigureAwait(false); } if (shouldUpdateRoot) @@ -486,7 +486,7 @@ public class AccountService : BaseDatabaseService, IAccountService var idealRootAlias = localAliases.Find(a => a.AliasAddress == account.Address) ?? localAliases.First(); idealRootAlias.IsRootAlias = true; - await Connection.UpdateAsync(idealRootAlias).ConfigureAwait(false); + await Connection.UpdateAsync(idealRootAlias, typeof(MailAccountAlias)).ConfigureAwait(false); } } @@ -519,7 +519,7 @@ public class AccountService : BaseDatabaseService, IAccountService account.Order = accountCount; } - await Connection.InsertAsync(account); + await Connection.InsertAsync(account, typeof(MailAccount)); var preferences = new MailAccountPreferences() { @@ -552,10 +552,10 @@ public class AccountService : BaseDatabaseService, IAccountService account.Preferences.SignatureIdForFollowingMessages = defaultSignature.Id; account.Preferences.IsSignatureEnabled = true; - await Connection.InsertAsync(preferences); + await Connection.InsertAsync(preferences, typeof(MailAccountPreferences)); if (customServerInformation != null) - await Connection.InsertAsync(customServerInformation); + await Connection.InsertAsync(customServerInformation, typeof(CustomServerInformation)); } //public async Task UpdateSynchronizationIdentifierAsync(Guid accountId, string newIdentifier) @@ -600,7 +600,7 @@ public class AccountService : BaseDatabaseService, IAccountService account.Order = pair.Value; - await Connection.UpdateAsync(account); + await Connection.UpdateAsync(account, typeof(MailAccount)); } Messenger.Send(new AccountMenuItemsReordered(accountIdOrderPair)); diff --git a/Wino.Services/CalendarService.cs b/Wino.Services/CalendarService.cs index 3f31175c..b48f7280 100644 --- a/Wino.Services/CalendarService.cs +++ b/Wino.Services/CalendarService.cs @@ -29,14 +29,14 @@ public class CalendarService : BaseDatabaseService, ICalendarService public async Task InsertAccountCalendarAsync(AccountCalendar accountCalendar) { - await Connection.InsertAsync(accountCalendar); + await Connection.InsertAsync(accountCalendar, typeof(AccountCalendar)); WeakReferenceMessenger.Default.Send(new CalendarListAdded(accountCalendar)); } public async Task UpdateAccountCalendarAsync(AccountCalendar accountCalendar) { - await Connection.UpdateAsync(accountCalendar); + await Connection.UpdateAsync(accountCalendar, typeof(AccountCalendar)); WeakReferenceMessenger.Default.Send(new CalendarListUpdated(accountCalendar)); } @@ -51,7 +51,7 @@ public class CalendarService : BaseDatabaseService, ICalendarService var rawQuery = deleteCalendarItemsQuery.GetRawQuery(); await Connection.ExecuteAsync(rawQuery); - await Connection.DeleteAsync(accountCalendar); + await Connection.DeleteAsync(accountCalendar); WeakReferenceMessenger.Default.Send(new CalendarListDeleted(accountCalendar)); } @@ -85,11 +85,11 @@ public class CalendarService : BaseDatabaseService, ICalendarService { await Connection.RunInTransactionAsync((conn) => { - conn.Insert(calendarItem); + conn.Insert(calendarItem, typeof(CalendarItem)); if (attendees != null) { - conn.InsertAll(attendees); + conn.InsertAll(attendees, typeof(CalendarEventAttendee)); } }); @@ -236,7 +236,7 @@ public class CalendarService : BaseDatabaseService, ICalendarService connection.Execute(query.GetRawQuery()); // Insert new attendees. - connection.InsertAll(allAttendees); + connection.InsertAll(allAttendees, typeof(CalendarEventAttendee)); }); return await Connection.Table().Where(a => a.CalendarItemId == calendarItemId).ToListAsync(); diff --git a/Wino.Services/ContactService.cs b/Wino.Services/ContactService.cs index 1fa6b446..9a83ae73 100644 --- a/Wino.Services/ContactService.cs +++ b/Wino.Services/ContactService.cs @@ -19,7 +19,7 @@ public class ContactService : BaseDatabaseService, IContactService { var contact = new AccountContact() { Address = address, Name = displayName }; - await Connection.InsertAsync(contact).ConfigureAwait(false); + await Connection.InsertAsync(contact, typeof(AccountContact)).ConfigureAwait(false); return contact; } @@ -57,11 +57,11 @@ public class ContactService : BaseDatabaseService, IContactService { if (currentContact == null) { - await Connection.InsertAsync(info).ConfigureAwait(false); + await Connection.InsertAsync(info, typeof(AccountContact)).ConfigureAwait(false); } else if (!currentContact.IsRootContact && !currentContact.IsOverridden) // Don't update root contacts or overridden contacts. { - await Connection.InsertOrReplaceAsync(info).ConfigureAwait(false); + await Connection.InsertOrReplaceAsync(info, typeof(AccountContact)).ConfigureAwait(false); } } catch (Exception ex) @@ -95,7 +95,7 @@ public class ContactService : BaseDatabaseService, IContactService // Mark the contact as overridden when manually updated contact.IsOverridden = true; - await Connection.UpdateAsync(contact).ConfigureAwait(false); + await Connection.UpdateAsync(contact, typeof(AccountContact)).ConfigureAwait(false); return contact; } @@ -106,7 +106,7 @@ public class ContactService : BaseDatabaseService, IContactService if (contact != null && !contact.IsRootContact) { - await Connection.DeleteAsync(contact).ConfigureAwait(false); + await Connection.DeleteAsync(contact).ConfigureAwait(false); } } diff --git a/Wino.Services/DatabaseService.cs b/Wino.Services/DatabaseService.cs index 49d2fa2e..e9233852 100644 --- a/Wino.Services/DatabaseService.cs +++ b/Wino.Services/DatabaseService.cs @@ -47,18 +47,19 @@ public class DatabaseService : IDatabaseService // typeof(CalendarEventAttendee), // typeof(CalendarItem), // typeof(Reminder), - await Connection.CreateTablesAsync(CreateFlags.None, - typeof(MailCopy), - typeof(MailItemFolder), - typeof(MailAccount), - typeof(AccountContact), - typeof(CustomServerInformation), - typeof(AccountSignature), - typeof(MergedInbox), - typeof(MailAccountPreferences), - typeof(MailAccountAlias), - typeof(Thumbnail), - typeof(KeyboardShortcut) + + await Task.WhenAll( + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync(), + Connection.CreateTableAsync() ); } } diff --git a/Wino.Services/FolderService.cs b/Wino.Services/FolderService.cs index e2d55101..217c4d40 100644 --- a/Wino.Services/FolderService.cs +++ b/Wino.Services/FolderService.cs @@ -452,7 +452,7 @@ public class FolderService : BaseDatabaseService, IFolderService { _logger.Debug("Inserting folder {Id} - {FolderName}", folder.Id, folder.FolderName, folder.MailAccountId); - await Connection.InsertAsync(folder).ConfigureAwait(false); + await Connection.InsertAsync(folder, typeof(MailItemFolder)).ConfigureAwait(false); } else { @@ -483,7 +483,7 @@ public class FolderService : BaseDatabaseService, IFolderService _logger.Debug("Updating folder {FolderName}", folder.Id, folder.FolderName); - await Connection.UpdateAsync(folder).ConfigureAwait(false); + await Connection.UpdateAsync(folder, typeof(MailItemFolder)).ConfigureAwait(false); } private async Task DeleteFolderAsync(MailItemFolder folder) @@ -504,7 +504,7 @@ public class FolderService : BaseDatabaseService, IFolderService _logger.Debug("Deleting folder {FolderName}", folder.FolderName); - await Connection.DeleteAsync(folder).ConfigureAwait(false); + await Connection.DeleteAsync(folder).ConfigureAwait(false); // Delete all existing mails from this folder. await Connection.ExecuteAsync("DELETE FROM MailCopy WHERE FolderId = ?", folder.Id); diff --git a/Wino.Services/KeyboardShortcutService.cs b/Wino.Services/KeyboardShortcutService.cs index 262cc53d..1344bdbe 100644 --- a/Wino.Services/KeyboardShortcutService.cs +++ b/Wino.Services/KeyboardShortcutService.cs @@ -51,11 +51,11 @@ public class KeyboardShortcutService : BaseDatabaseService, IKeyboardShortcutSer { shortcut.Id = Guid.NewGuid(); shortcut.CreatedAt = DateTime.UtcNow; - await Connection.InsertAsync(shortcut); + await Connection.InsertAsync(shortcut, typeof(KeyboardShortcut)); } else { - await Connection.UpdateAsync(shortcut); + await Connection.UpdateAsync(shortcut, typeof(KeyboardShortcut)); } return shortcut; diff --git a/Wino.Services/MailService.cs b/Wino.Services/MailService.cs index f01abc2a..67403037 100644 --- a/Wino.Services/MailService.cs +++ b/Wino.Services/MailService.cs @@ -99,7 +99,7 @@ public class MailService : BaseDatabaseService, IMailService copy.ThreadId = draftCreationOptions.ReferencedMessage.MailCopy.ThreadId; } - await Connection.InsertAsync(copy); + await Connection.InsertAsync(copy, typeof(MailCopy)); await _mimeFileService.SaveMimeMessageAsync(copy.FileId, createdDraftMimeMessage, composerAccount.Id); @@ -527,7 +527,7 @@ public class MailService : BaseDatabaseService, IMailService _logger.Debug("Inserting mail {MailCopyId} to {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName); - await Connection.InsertAsync(mailCopy).ConfigureAwait(false); + await Connection.InsertAsync(mailCopy, typeof(MailCopy)).ConfigureAwait(false); ReportUIChange(new MailAddedMessage(mailCopy)); } @@ -543,7 +543,7 @@ public class MailService : BaseDatabaseService, IMailService _logger.Debug("Updating mail {MailCopyId} with Folder {FolderId}", mailCopy.Id, mailCopy.FolderId); - await Connection.UpdateAsync(mailCopy).ConfigureAwait(false); + await Connection.UpdateAsync(mailCopy, typeof(MailCopy)).ConfigureAwait(false); ReportUIChange(new MailUpdatedMessage(mailCopy)); } @@ -559,7 +559,7 @@ public class MailService : BaseDatabaseService, IMailService _logger.Debug("Deleting mail {Id} from folder {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName); - await Connection.DeleteAsync(mailCopy).ConfigureAwait(false); + await Connection.DeleteAsync(mailCopy).ConfigureAwait(false); // If there are no more copies exists of the same mail, delete the MIME file as well. var isMailExists = await IsMailExistsAsync(mailCopy.Id).ConfigureAwait(false); diff --git a/Wino.Services/SignatureService.cs b/Wino.Services/SignatureService.cs index 1a7f08b9..d6ceb6ff 100644 --- a/Wino.Services/SignatureService.cs +++ b/Wino.Services/SignatureService.cs @@ -20,7 +20,7 @@ public class SignatureService(IDatabaseService databaseService) : BaseDatabaseSe public async Task CreateSignatureAsync(AccountSignature signature) { - await Connection.InsertAsync(signature); + await Connection.InsertAsync(signature, typeof(AccountSignature)); return signature; } @@ -36,21 +36,21 @@ public class SignatureService(IDatabaseService databaseService) : BaseDatabaseSe HtmlBody = @"

Sent from Wino Mail for Windows

" }; - await Connection.InsertAsync(defaultSignature); + await Connection.InsertAsync(defaultSignature, typeof(AccountSignature)); return defaultSignature; } public async Task UpdateSignatureAsync(AccountSignature signature) { - await Connection.UpdateAsync(signature); + await Connection.UpdateAsync(signature, typeof(AccountSignature)); return signature; } public async Task DeleteSignatureAsync(AccountSignature signature) { - await Connection.DeleteAsync(signature); + await Connection.DeleteAsync(signature); return signature; }