diff --git a/Wino.Core.Domain/Interfaces/IAppInitializerService.cs b/Wino.Core.Domain/Interfaces/IAppInitializerService.cs
deleted file mode 100644
index a5d9d280..00000000
--- a/Wino.Core.Domain/Interfaces/IAppInitializerService.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace Wino.Core.Domain.Interfaces
-{
- public interface IAppInitializerService
- {
- string GetApplicationDataFolder();
- string GetPublisherSharedFolder();
- }
-}
diff --git a/Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs b/Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs
new file mode 100644
index 00000000..4a9aca60
--- /dev/null
+++ b/Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs
@@ -0,0 +1,21 @@
+namespace Wino.Core.Domain.Interfaces
+{
+ ///
+ /// Singleton object that holds the application data folder path and the publisher shared folder path.
+ /// Load the values before calling any service.
+ /// App data folder is used for storing files.
+ /// Pubhlisher cache folder is only used for database file so other apps can access it in the same package by same publisher.
+ ///
+ public interface IApplicationConfiguration
+ {
+ ///
+ /// Application data folder.
+ ///
+ string ApplicationDataFolderPath { get; set; }
+
+ ///
+ /// Publisher shared folder path.
+ ///
+ string PublisherSharedFolderPath { get; set; }
+ }
+}
diff --git a/Wino.Core.Domain/Interfaces/INativeAppService.cs b/Wino.Core.Domain/Interfaces/INativeAppService.cs
index b6d14249..93162f73 100644
--- a/Wino.Core.Domain/Interfaces/INativeAppService.cs
+++ b/Wino.Core.Domain/Interfaces/INativeAppService.cs
@@ -11,6 +11,7 @@ namespace Wino.Core.Domain.Interfaces
Task GetEditorBundlePathAsync();
Task LaunchFileAsync(string filePath);
Task LaunchUriAsync(Uri uri);
+
bool IsAppRunning();
string GetFullAppVersion();
diff --git a/Wino.Core.UWP/CoreUWPContainerSetup.cs b/Wino.Core.UWP/CoreUWPContainerSetup.cs
index cde45f8e..b2c4f89c 100644
--- a/Wino.Core.UWP/CoreUWPContainerSetup.cs
+++ b/Wino.Core.UWP/CoreUWPContainerSetup.cs
@@ -20,7 +20,7 @@ namespace Wino.Core.UWP
services.AddSingleton();
services.AddSingleton();
- services.AddTransient();
+
services.AddTransient();
services.AddTransient();
services.AddTransient();
diff --git a/Wino.Core.UWP/Services/AppInitializerService.cs b/Wino.Core.UWP/Services/AppInitializerService.cs
deleted file mode 100644
index dab80991..00000000
--- a/Wino.Core.UWP/Services/AppInitializerService.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using Windows.Storage;
-using Wino.Core.Domain.Interfaces;
-
-namespace Wino.Core.UWP.Services
-{
- public class AppInitializerService : IAppInitializerService
- {
- public const string SharedFolderName = "WinoShared";
-
- public string GetPublisherSharedFolder() => ApplicationData.Current.GetPublisherCacheFolder(SharedFolderName).Path;
- public string GetApplicationDataFolder() => ApplicationData.Current.LocalFolder.Path;
- }
-}
diff --git a/Wino.Core.UWP/Services/NativeAppService.cs b/Wino.Core.UWP/Services/NativeAppService.cs
index 27d4b3cc..9c1521b1 100644
--- a/Wino.Core.UWP/Services/NativeAppService.cs
+++ b/Wino.Core.UWP/Services/NativeAppService.cs
@@ -9,11 +9,14 @@ using Windows.Storage;
using Windows.Storage.Streams;
using Windows.System;
using Windows.UI.Shell;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Authorization;
+#if WINDOWS_UWP
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+#endif
+
namespace Wino.Services
{
public class NativeAppService : INativeAppService
@@ -21,7 +24,14 @@ namespace Wino.Services
private string _mimeMessagesFolder;
private string _editorBundlePath;
- public string GetWebAuthenticationBrokerUri() => WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri;
+ public string GetWebAuthenticationBrokerUri()
+ {
+#if WINDOWS_UWP
+ return WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri;
+#endif
+
+ return string.Empty;
+ }
public async Task GetMimeMessageStoragePath()
{
@@ -91,7 +101,15 @@ namespace Wino.Services
return _editorBundlePath;
}
- public bool IsAppRunning() => (Window.Current?.Content as Frame)?.Content != null;
+ public bool IsAppRunning()
+ {
+#if WINDOWS_UWP
+ return (Window.Current?.Content as Frame)?.Content != null;
+#endif
+
+ return true;
+ }
+
public async Task LaunchFileAsync(string filePath)
{
diff --git a/Wino.Mail/Services/PreferencesService.cs b/Wino.Core.UWP/Services/PreferencesService.cs
similarity index 99%
rename from Wino.Mail/Services/PreferencesService.cs
rename to Wino.Core.UWP/Services/PreferencesService.cs
index 7b2fe0fa..173d7f22 100644
--- a/Wino.Mail/Services/PreferencesService.cs
+++ b/Wino.Core.UWP/Services/PreferencesService.cs
@@ -7,7 +7,7 @@ using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Reader;
using Wino.Core.Services;
-namespace Wino.Services
+namespace Wino.Core.UWP.Services
{
public class PreferencesService : ObservableObject, IPreferencesService
{
diff --git a/Wino.Mail/Services/StatePersistenceService.cs b/Wino.Core.UWP/Services/StatePersistenceService.cs
similarity index 90%
rename from Wino.Mail/Services/StatePersistenceService.cs
rename to Wino.Core.UWP/Services/StatePersistenceService.cs
index 4c995ef9..e94067ed 100644
--- a/Wino.Mail/Services/StatePersistenceService.cs
+++ b/Wino.Core.UWP/Services/StatePersistenceService.cs
@@ -2,7 +2,6 @@
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
-using Microsoft.AppCenter.Crashes;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Messages.Shell;
@@ -116,17 +115,10 @@ namespace Wino.Services
private void UpdateAppCoreWindowTitle()
{
- try
- {
- var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
+ var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
- if (appView != null)
- appView.Title = CoreWindowTitle;
- }
- catch (System.Exception ex)
- {
- Crashes.TrackError(ex);
- }
+ if (appView != null)
+ appView.Title = CoreWindowTitle;
}
}
}
diff --git a/Wino.Core.UWP/Services/WinoServerConnectionManager.cs b/Wino.Core.UWP/Services/WinoServerConnectionManager.cs
index 80a21ee3..2d382d2c 100644
--- a/Wino.Core.UWP/Services/WinoServerConnectionManager.cs
+++ b/Wino.Core.UWP/Services/WinoServerConnectionManager.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics;
using System.Text.Json;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
@@ -140,6 +141,8 @@ namespace Wino.Core.UWP.Services
/// Message data in json format.
private void HandleUIMessage(string messageJson, string typeName)
{
+ Debug.WriteLine($"C: UImessage ({typeName})");
+
switch (typeName)
{
case nameof(MailAddedMessage):
diff --git a/Wino.Core.UWP/Wino.Core.UWP.csproj b/Wino.Core.UWP/Wino.Core.UWP.csproj
index f90c481e..04ef24b8 100644
--- a/Wino.Core.UWP/Wino.Core.UWP.csproj
+++ b/Wino.Core.UWP/Wino.Core.UWP.csproj
@@ -128,7 +128,8 @@
-
+
+
diff --git a/Wino.Core/Authenticators/OutlookAuthenticator.cs b/Wino.Core/Authenticators/OutlookAuthenticator.cs
index 878d1c91..72e5d847 100644
--- a/Wino.Core/Authenticators/OutlookAuthenticator.cs
+++ b/Wino.Core/Authenticators/OutlookAuthenticator.cs
@@ -29,10 +29,17 @@ namespace Wino.Core.Authenticators
{
var authenticationRedirectUri = nativeAppService.GetWebAuthenticationBrokerUri();
- _publicClientApplication = PublicClientApplicationBuilder.Create(ClientId)
- .WithAuthority(Authority)
- .WithRedirectUri(authenticationRedirectUri)
- .Build();
+ var outlookAppBuilder = PublicClientApplicationBuilder.Create(ClientId)
+ .WithAuthority(Authority);
+
+#if WINDOWS_UWP
+ outlookAppBuilder.WithRedirectUri(authenticationRedirectUri);
+#else
+ outlookAppBuilder.WithDefaultRedirectUri();
+#endif
+ _publicClientApplication = outlookAppBuilder.Build();
+
+
}
#pragma warning disable S1133 // Deprecated code should be removed
diff --git a/Wino.Core/CoreContainerSetup.cs b/Wino.Core/CoreContainerSetup.cs
index 0a89f203..6047a089 100644
--- a/Wino.Core/CoreContainerSetup.cs
+++ b/Wino.Core/CoreContainerSetup.cs
@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Serilog.Core;
+using Wino.Core.Authenticators;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Integration.Processors;
using Wino.Core.Integration.Threading;
@@ -16,6 +17,7 @@ namespace Wino.Core
services.AddSingleton(loggerLevelSwitcher);
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -41,6 +43,10 @@ namespace Wino.Core
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
services.AddTransient();
services.AddTransient();
services.AddTransient();
diff --git a/Wino.Core/Services/ApplicationConfiguration.cs b/Wino.Core/Services/ApplicationConfiguration.cs
new file mode 100644
index 00000000..e920a12e
--- /dev/null
+++ b/Wino.Core/Services/ApplicationConfiguration.cs
@@ -0,0 +1,13 @@
+using Wino.Core.Domain.Interfaces;
+
+namespace Wino.Core.Services
+{
+ public class ApplicationConfiguration : IApplicationConfiguration
+ {
+ public const string SharedFolderName = "WinoShared";
+
+ public string ApplicationDataFolderPath { get; set; }
+
+ public string PublisherSharedFolderPath { get; set; }
+ }
+}
diff --git a/Wino.Core/Services/DatabaseService.cs b/Wino.Core/Services/DatabaseService.cs
index 8abac819..246f9a63 100644
--- a/Wino.Core/Services/DatabaseService.cs
+++ b/Wino.Core/Services/DatabaseService.cs
@@ -14,16 +14,16 @@ namespace Wino.Core.Services
public class DatabaseService : IDatabaseService
{
- private string DatabaseName => "Wino172.db";
+ private const string DatabaseName = "Wino172.db";
private bool _isInitialized = false;
- private readonly IAppInitializerService _appInitializerService;
+ private readonly IApplicationConfiguration _folderConfiguration;
public SQLiteAsyncConnection Connection { get; private set; }
- public DatabaseService(IAppInitializerService appInitializerService)
+ public DatabaseService(IApplicationConfiguration folderConfiguration)
{
- _appInitializerService = appInitializerService;
+ _folderConfiguration = folderConfiguration;
}
public async Task InitializeAsync()
@@ -31,8 +31,8 @@ namespace Wino.Core.Services
if (_isInitialized)
return;
- var applicationData = _appInitializerService.GetPublisherSharedFolder();
- var databaseFileName = Path.Combine(applicationData, DatabaseName);
+ var publisherCacheFolder = _folderConfiguration.PublisherSharedFolderPath;
+ var databaseFileName = Path.Combine(publisherCacheFolder, DatabaseName);
Connection = new SQLiteAsyncConnection(databaseFileName)
{
@@ -45,7 +45,6 @@ namespace Wino.Core.Services
})
};
-
await CreateTablesAsync();
_isInitialized = true;
diff --git a/Wino.Core/Services/ImapTestService.cs b/Wino.Core/Services/ImapTestService.cs
index b9cc54bf..ae7f92c3 100644
--- a/Wino.Core/Services/ImapTestService.cs
+++ b/Wino.Core/Services/ImapTestService.cs
@@ -11,11 +11,11 @@ namespace Wino.Core.Services
public const string ProtocolLogFileName = "ImapProtocolLog.log";
private readonly IPreferencesService _preferencesService;
- private readonly IAppInitializerService _appInitializerService;
+ private readonly IApplicationConfiguration _appInitializerService;
private Stream _protocolLogStream;
- public ImapTestService(IPreferencesService preferencesService, IAppInitializerService appInitializerService)
+ public ImapTestService(IPreferencesService preferencesService, IApplicationConfiguration appInitializerService)
{
_preferencesService = preferencesService;
_appInitializerService = appInitializerService;
@@ -24,7 +24,7 @@ namespace Wino.Core.Services
private void EnsureProtocolLogFileExists()
{
// Create new file for protocol logger.
- var localAppFolderPath = _appInitializerService.GetApplicationDataFolder();
+ var localAppFolderPath = _appInitializerService.ApplicationDataFolderPath;
var logFile = Path.Combine(localAppFolderPath, ProtocolLogFileName);
diff --git a/Wino.Mail.ViewModels/AboutPageViewModel.cs b/Wino.Mail.ViewModels/AboutPageViewModel.cs
index 3b363854..a8403a1a 100644
--- a/Wino.Mail.ViewModels/AboutPageViewModel.cs
+++ b/Wino.Mail.ViewModels/AboutPageViewModel.cs
@@ -12,7 +12,7 @@ namespace Wino.Mail.ViewModels
{
private readonly IStoreRatingService _storeRatingService;
private readonly INativeAppService _nativeAppService;
- private readonly IAppInitializerService _appInitializerService;
+ private readonly IApplicationConfiguration _appInitializerService;
private readonly IFileService _fileService;
private readonly ILogInitializer _logInitializer;
@@ -31,7 +31,7 @@ namespace Wino.Mail.ViewModels
IDialogService dialogService,
INativeAppService nativeAppService,
IPreferencesService preferencesService,
- IAppInitializerService appInitializerService,
+ IApplicationConfiguration appInitializerService,
IFileService fileService,
ILogInitializer logInitializer) : base(dialogService)
{
@@ -77,7 +77,7 @@ namespace Wino.Mail.ViewModels
private async Task SaveLogInternalAsync(string sourceFileName)
{
- var appDataFolder = _appInitializerService.GetApplicationDataFolder();
+ var appDataFolder = _appInitializerService.ApplicationDataFolderPath;
var logFile = Path.Combine(appDataFolder, sourceFileName);
diff --git a/Wino.Mail.ViewModels/AppShellViewModel.cs b/Wino.Mail.ViewModels/AppShellViewModel.cs
index 96226233..b5c9d16d 100644
--- a/Wino.Mail.ViewModels/AppShellViewModel.cs
+++ b/Wino.Mail.ViewModels/AppShellViewModel.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AppCenter.Crashes;
using MoreLinq;
@@ -129,6 +130,9 @@ namespace Wino.Mail.ViewModels
_winoRequestDelegator = winoRequestDelegator;
}
+ [RelayCommand]
+ private Task ReconnectServerAsync() => ServerConnectionManager.ConnectAsync();
+
protected override void OnDispatcherAssigned()
{
base.OnDispatcherAssigned();
diff --git a/Wino.Mail/App.xaml.cs b/Wino.Mail/App.xaml.cs
index 02de9c11..b6243f88 100644
--- a/Wino.Mail/App.xaml.cs
+++ b/Wino.Mail/App.xaml.cs
@@ -45,8 +45,9 @@ namespace Wino
private readonly ILogInitializer _logInitializer;
private readonly IThemeService _themeService;
private readonly IDatabaseService _databaseService;
- private readonly IAppInitializerService _appInitializerService;
+ private readonly IApplicationConfiguration _appInitializerService;
private readonly ITranslationService _translationService;
+ private readonly IApplicationConfiguration _applicationFolderConfiguration;
// Order matters.
private List initializeServices => new List()
@@ -77,10 +78,16 @@ namespace Wino
ConfigurePrelaunch();
ConfigureXbox();
+ _applicationFolderConfiguration = Services.GetService();
+
+ // Make sure the paths are setup on app start.
+ _applicationFolderConfiguration.ApplicationDataFolderPath = ApplicationData.Current.LocalFolder.Path;
+ _applicationFolderConfiguration.PublisherSharedFolderPath = ApplicationData.Current.GetPublisherCacheFolder(ApplicationConfiguration.SharedFolderName).Path;
+
_appServiceConnectionManager = Services.GetService>();
_themeService = Services.GetService();
_databaseService = Services.GetService();
- _appInitializerService = Services.GetService();
+ _appInitializerService = Services.GetService();
_translationService = Services.GetService();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
diff --git a/Wino.Mail/AppShell.xaml b/Wino.Mail/AppShell.xaml
index 031e964c..cfb36585 100644
--- a/Wino.Mail/AppShell.xaml
+++ b/Wino.Mail/AppShell.xaml
@@ -521,7 +521,7 @@
Padding="14"
HorizontalAlignment="Right"
VerticalAlignment="Bottom">
-
+
diff --git a/Wino.Mail/Wino.Mail.csproj b/Wino.Mail/Wino.Mail.csproj
index 267333b0..b28dc21a 100644
--- a/Wino.Mail/Wino.Mail.csproj
+++ b/Wino.Mail/Wino.Mail.csproj
@@ -336,8 +336,6 @@
-
-
diff --git a/Wino.Packaging/Wino.Packaging.wapproj b/Wino.Packaging/Wino.Packaging.wapproj
index 09aa5a5a..3779c414 100644
--- a/Wino.Packaging/Wino.Packaging.wapproj
+++ b/Wino.Packaging/Wino.Packaging.wapproj
@@ -57,6 +57,44 @@
false
$(NoWarn);NU1702
..\Wino.Mail\Wino.Mail.csproj
+ False
+ SHA256
+ False
+ C:\Users\bkaan\Desktop\Packages\
+ True
+ x64
+ True
+ 0
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
@@ -115,6 +153,7 @@
+
diff --git a/Wino.Server/App.xaml.cs b/Wino.Server/App.xaml.cs
index 484c4b0b..3e9ce04f 100644
--- a/Wino.Server/App.xaml.cs
+++ b/Wino.Server/App.xaml.cs
@@ -1,9 +1,15 @@
using System;
using System.Threading;
+using System.Threading.Tasks;
using System.Windows;
using H.NotifyIcon;
using Microsoft.Extensions.DependencyInjection;
+using Windows.Storage;
using Wino.Core;
+using Wino.Core.Domain.Interfaces;
+using Wino.Core.Services;
+using Wino.Core.UWP.Services;
+using Wino.Services;
namespace Wino.Server
{
@@ -16,6 +22,7 @@ namespace Wino.Server
///
public partial class App : Application
{
+ private const string NotifyIconResourceKey = "NotifyIcon";
private const string WinoServerAppName = "Wino.Server";
private const string WinoServerActiatedName = "Wino.Server.Activated";
@@ -32,18 +39,42 @@ namespace Wino.Server
var services = new ServiceCollection();
services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
services.RegisterCoreServices();
+ // Below services belongs to UWP.Core package and some APIs are not available for WPF.
+ // We register them here to avoid compilation errors.
+
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+
return services.BuildServiceProvider();
}
+ private async Task InitializeNewServerAsync()
+ {
+ // TODO: Error handling.
+
+ var databaseService = Services.GetService();
+ var applicationFolderConfiguration = Services.GetService();
+
+ applicationFolderConfiguration.ApplicationDataFolderPath = ApplicationData.Current.LocalFolder.Path;
+ applicationFolderConfiguration.PublisherSharedFolderPath = ApplicationData.Current.GetPublisherCacheFolder(ApplicationConfiguration.SharedFolderName).Path;
+
+ await databaseService.InitializeAsync();
+
+ var serverViewModel = Services.GetRequiredService();
+
+ await serverViewModel.InitializeAsync();
+
+ return serverViewModel;
+ }
+
protected override async void OnStartup(StartupEventArgs e)
{
- bool isCreatedNew;
-
- _mutex = new Mutex(true, WinoServerAppName, out isCreatedNew);
+ _mutex = new Mutex(true, WinoServerAppName, out bool isCreatedNew);
_eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, WinoServerActiatedName);
if (isCreatedNew)
@@ -57,7 +88,7 @@ namespace Wino.Server
Current.Dispatcher.BeginInvoke(async () =>
{
- if (notifyIcon.DataContext is TrayIconViewModel trayIconViewModel)
+ if (notifyIcon.DataContext is ServerViewModel trayIconViewModel)
{
await trayIconViewModel.ReconnectAsync();
}
@@ -73,18 +104,16 @@ namespace Wino.Server
base.OnStartup(e);
+ var serverViewModel = await InitializeNewServerAsync();
+
// Create taskbar icon for the new server.
- notifyIcon = (TaskbarIcon)FindResource("NotifyIcon");
-
- var viewModel = Services.GetRequiredService();
- await viewModel.Context.InitializeAsync();
-
- notifyIcon.DataContext = viewModel;
+ notifyIcon = (TaskbarIcon)FindResource(NotifyIconResourceKey);
+ notifyIcon.DataContext = serverViewModel;
notifyIcon.ForceCreate(enablesEfficiencyMode: true);
}
else
{
- // Notify other instance so it could bring itself to foreground.
+ // Notify other instance so it could reconnect to UWP app if needed.
_eventWaitHandle.Set();
// Terminate this instance.
diff --git a/Wino.Server/ServerContext.cs b/Wino.Server/ServerContext.cs
index 6a11dcbd..168bf7cc 100644
--- a/Wino.Server/ServerContext.cs
+++ b/Wino.Server/ServerContext.cs
@@ -1,44 +1,84 @@
using System;
+using System.Diagnostics;
+using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
+using CommunityToolkit.Mvvm.Messaging;
+using Microsoft.Extensions.DependencyInjection;
using Windows.ApplicationModel;
using Windows.ApplicationModel.AppService;
using Windows.Foundation.Collections;
+using Wino.Core.Authenticators;
using Wino.Core.Domain.Interfaces;
+using Wino.Core.Domain.Models.Synchronization;
+using Wino.Core.Integration.Processors;
using Wino.Core.Services;
+using Wino.Core.Synchronizers;
using Wino.Messaging;
using Wino.Messaging.Enums;
+using Wino.Messaging.Server;
namespace Wino.Server
{
- public class ServerContext : IInitializeAsync
+ public class ServerContext :
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient,
+ IRecipient
{
private static object connectionLock = new object();
private AppServiceConnection connection = null;
- private readonly IDatabaseService _databaseService;
- public ServerContext(IDatabaseService databaseService)
+ private readonly IDatabaseService _databaseService;
+ private readonly IApplicationConfiguration _applicationFolderConfiguration;
+
+ public ServerContext(IDatabaseService databaseService, IApplicationConfiguration applicationFolderConfiguration)
{
_databaseService = databaseService;
+ _applicationFolderConfiguration = applicationFolderConfiguration;
+
+ WeakReferenceMessenger.Default.RegisterAll(this);
}
- private string GetAppPackagFamilyName()
- {
- // If running as a standalone app, Package will throw exception.
- // Return hardcoded value for debugging purposes.
- // Connection will not be available in this case.
+ #region Message Handlers
- try
- {
- return Package.Current.Id.FamilyName;
- }
- catch (Exception)
- {
- return "Debug.Wino.Server.FamilyName";
- }
- }
+ public async void Receive(MailAddedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
+ public async void Receive(AccountCreatedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(AccountUpdatedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(AccountRemovedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(DraftCreated message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(DraftFailed message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(DraftMapped message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(FolderRenamed message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(FolderSynchronizationEnabled message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(MailDownloadedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(MailRemovedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(MailUpdatedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ public async void Receive(MergedInboxRenamed message) => await SendMessageAsync(MessageType.UIMessage, message);
+
+ #endregion
///
/// Open connection to UWP app service
///
@@ -65,6 +105,51 @@ namespace Wino.Server
}
}
+ public async Task TestOutlookSynchronizer()
+ {
+ var accountService = App.Current.Services.GetService();
+
+ var accs = await accountService.GetAccountsAsync();
+ var acc = accs.ElementAt(0);
+
+ var authenticator = App.Current.Services.GetService();
+ var processor = App.Current.Services.GetService();
+
+ var sync = new OutlookSynchronizer(acc, authenticator, processor);
+
+ var options = new SynchronizationOptions()
+ {
+ AccountId = acc.Id,
+ Type = Core.Domain.Enums.SynchronizationType.Full
+ };
+
+ var result = await sync.SynchronizeAsync(options);
+ }
+
+ ///
+ /// Disposes current connection to UWP app service.
+ ///
+ private void DisposeConnection()
+ {
+ lock (connectionLock)
+ {
+ if (connection == null) return;
+
+ connection.RequestReceived -= OnWinRTMessageReceived;
+ connection.ServiceClosed -= OnConnectionClosed;
+
+ connection.Dispose();
+ connection = null;
+ }
+ }
+
+ ///
+ /// Sends a serialized object to UWP application if connection exists with given type.
+ ///
+ /// Type of the message.
+ /// IServerMessage object that will be serialized.
+ ///
+ /// When the message is not IServerMessage.
private async Task SendMessageAsync(MessageType messageType, object message)
{
if (connection == null) return;
@@ -81,6 +166,7 @@ namespace Wino.Server
{ MessageConstants.MessageDataTypeKey, message.GetType().Name }
};
+ Debug.WriteLine($"S: {messageType} ({message.GetType().Name})");
await connection.SendMessageAsync(set);
}
@@ -98,26 +184,38 @@ namespace Wino.Server
private void OnWinRTMessageReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
{
// TODO: Handle incoming messages from UWP/WINUI Application.
+
}
- private void DisposeConnection()
+ #region Init
+
+ private string GetAppPackagFamilyName()
{
- lock (connectionLock)
+ // If running as a standalone app, Package will throw exception.
+ // Return hardcoded value for debugging purposes.
+ // Connection will not be available in this case.
+
+ try
{
- if (connection == null) return;
-
- connection.RequestReceived -= OnWinRTMessageReceived;
- connection.ServiceClosed -= OnConnectionClosed;
-
- connection.Dispose();
- connection = null;
+ return Package.Current.Id.FamilyName;
+ }
+ catch (Exception)
+ {
+ return "Debug.Wino.Server.FamilyName";
}
}
public async Task InitializeAsync()
{
+
await InitializeAppServiceConnectionAsync();
- await _databaseService.InitializeAsync();
}
+
+ #endregion
+
+
+
+
+
}
}
diff --git a/Wino.Server/TrayIconViewModel.cs b/Wino.Server/ServerViewModel.cs
similarity index 68%
rename from Wino.Server/TrayIconViewModel.cs
rename to Wino.Server/ServerViewModel.cs
index 73dea57a..42a2574f 100644
--- a/Wino.Server/TrayIconViewModel.cs
+++ b/Wino.Server/ServerViewModel.cs
@@ -2,22 +2,23 @@
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
+using Wino.Core.Domain.Interfaces;
namespace Wino.Server
{
- public partial class TrayIconViewModel : ObservableObject
+ public partial class ServerViewModel : ObservableObject, IInitializeAsync
{
public ServerContext Context { get; }
- public TrayIconViewModel(ServerContext serverContext)
+ public ServerViewModel(ServerContext serverContext)
{
Context = serverContext;
}
[RelayCommand]
- public void LaunchWino()
+ public async Task LaunchWinoAsync()
{
-
+ await Context.TestOutlookSynchronizer();
// ServerContext.SendTestMessageAsync();
}
@@ -33,5 +34,7 @@ namespace Wino.Server
}
public async Task ReconnectAsync() => await Context.InitializeAppServiceConnectionAsync();
+
+ public Task InitializeAsync() => Context.InitializeAppServiceConnectionAsync();
}
}
diff --git a/Wino.Server/Wino.Server.csproj b/Wino.Server/Wino.Server.csproj
index 9f48c856..fea550e4 100644
--- a/Wino.Server/Wino.Server.csproj
+++ b/Wino.Server/Wino.Server.csproj
@@ -16,6 +16,12 @@
+
+
+
+
+
+
Always
@@ -30,4 +36,7 @@
+
+
+
\ No newline at end of file