diff --git a/Wino.Core.Domain/Interfaces/IAppInitializerService.cs b/Wino.Core.Domain/Interfaces/IAppInitializerService.cs
index 0ff1fe76..a5d9d280 100644
--- a/Wino.Core.Domain/Interfaces/IAppInitializerService.cs
+++ b/Wino.Core.Domain/Interfaces/IAppInitializerService.cs
@@ -1,12 +1,8 @@
-using System.Threading.Tasks;
-
-namespace Wino.Core.Domain.Interfaces
+namespace Wino.Core.Domain.Interfaces
{
public interface IAppInitializerService
{
string GetApplicationDataFolder();
string GetPublisherSharedFolder();
-
- Task MigrateAsync();
}
}
diff --git a/Wino.Core.UWP/Services/AppInitializerService.cs b/Wino.Core.UWP/Services/AppInitializerService.cs
index 87e78bc9..dab80991 100644
--- a/Wino.Core.UWP/Services/AppInitializerService.cs
+++ b/Wino.Core.UWP/Services/AppInitializerService.cs
@@ -1,50 +1,13 @@
-using System;
-using System.Threading.Tasks;
-using Windows.Storage;
+using Windows.Storage;
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.UWP.Services
{
public class AppInitializerService : IAppInitializerService
{
- private readonly IBackgroundTaskService _backgroundTaskService;
+ public const string SharedFolderName = "WinoShared";
- public AppInitializerService(IBackgroundTaskService backgroundTaskService)
- {
- _backgroundTaskService = backgroundTaskService;
- }
-
- public string GetPublisherSharedFolder() => ApplicationData.Current.GetPublisherCacheFolder("WinoShared").Path;
+ public string GetPublisherSharedFolder() => ApplicationData.Current.GetPublisherCacheFolder(SharedFolderName).Path;
public string GetApplicationDataFolder() => ApplicationData.Current.LocalFolder.Path;
-
- public Task MigrateAsync()
- {
- UnregisterAllBackgroundTasks();
-
- return Task.CompletedTask;
- }
-
- #region 1.6.8 -> 1.6.9
-
- private void UnregisterAllBackgroundTasks()
- {
- _backgroundTaskService.UnregisterAllBackgroundTask();
- }
-
- #endregion
-
- #region 1.7.0
-
- ///
- /// We decided to use publisher cache folder as a database going forward.
- /// This migration will move the file from application local folder and delete it.
- /// Going forward database will be initialized from publisher cache folder.
- ///
- private async Task MoveExistingDatabaseToSharedCacheFolderAsync()
- {
- throw new NotImplementedException();
- }
-
- #endregion
}
}
diff --git a/Wino.Server/App.xaml.cs b/Wino.Server/App.xaml.cs
index b0a9260a..484c4b0b 100644
--- a/Wino.Server/App.xaml.cs
+++ b/Wino.Server/App.xaml.cs
@@ -1,6 +1,9 @@
-using System.Threading;
+using System;
+using System.Threading;
using System.Windows;
using H.NotifyIcon;
+using Microsoft.Extensions.DependencyInjection;
+using Wino.Core;
namespace Wino.Server
{
@@ -16,11 +19,27 @@ namespace Wino.Server
private const string WinoServerAppName = "Wino.Server";
private const string WinoServerActiatedName = "Wino.Server.Activated";
+ public new static App Current => (App)Application.Current;
+
private TaskbarIcon? notifyIcon;
private static Mutex _mutex = null;
private EventWaitHandle _eventWaitHandle;
- protected override void OnStartup(StartupEventArgs e)
+ public IServiceProvider Services { get; private set; }
+
+ private IServiceProvider ConfigureServices()
+ {
+ var services = new ServiceCollection();
+
+ services.AddTransient();
+ services.AddTransient();
+
+ services.RegisterCoreServices();
+
+ return services.BuildServiceProvider();
+ }
+
+ protected override async void OnStartup(StartupEventArgs e)
{
bool isCreatedNew;
@@ -36,11 +55,11 @@ namespace Wino.Server
{
if (notifyIcon == null) return;
- Current.Dispatcher.BeginInvoke(() =>
+ Current.Dispatcher.BeginInvoke(async () =>
{
if (notifyIcon.DataContext is TrayIconViewModel trayIconViewModel)
{
- trayIconViewModel.Reconnect();
+ await trayIconViewModel.ReconnectAsync();
}
});
}
@@ -48,13 +67,19 @@ namespace Wino.Server
// It is important mark it as background otherwise it will prevent app from exiting.
thread.IsBackground = true;
-
thread.Start();
+ Services = ConfigureServices();
+
base.OnStartup(e);
// Create taskbar icon for the new server.
notifyIcon = (TaskbarIcon)FindResource("NotifyIcon");
+
+ var viewModel = Services.GetRequiredService();
+ await viewModel.Context.InitializeAsync();
+
+ notifyIcon.DataContext = viewModel;
notifyIcon.ForceCreate(enablesEfficiencyMode: true);
}
else
diff --git a/Wino.Server/ServerContext.cs b/Wino.Server/ServerContext.cs
index 305df65c..6a11dcbd 100644
--- a/Wino.Server/ServerContext.cs
+++ b/Wino.Server/ServerContext.cs
@@ -4,23 +4,23 @@ using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.AppService;
using Windows.Foundation.Collections;
-using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Interfaces;
+using Wino.Core.Services;
using Wino.Messaging;
using Wino.Messaging.Enums;
-using Wino.Messaging.Server;
namespace Wino.Server
{
- public class ServerContext
+ public class ServerContext : IInitializeAsync
{
private static object connectionLock = new object();
private AppServiceConnection connection = null;
+ private readonly IDatabaseService _databaseService;
- public ServerContext()
+ public ServerContext(IDatabaseService databaseService)
{
- InitializeAppServiceConnection();
+ _databaseService = databaseService;
}
private string GetAppPackagFamilyName()
@@ -42,7 +42,7 @@ namespace Wino.Server
///
/// Open connection to UWP app service
///
- public async void InitializeAppServiceConnection()
+ public async Task InitializeAppServiceConnectionAsync()
{
if (connection != null) DisposeConnection();
@@ -65,12 +65,6 @@ namespace Wino.Server
}
}
- public Task SendTestMessageAsync()
- {
- var message = new MailAddedMessage(new MailCopy());
- return SendMessageAsync(MessageType.UIMessage, message);
- }
-
private async Task SendMessageAsync(MessageType messageType, object message)
{
if (connection == null) return;
@@ -119,5 +113,11 @@ namespace Wino.Server
connection = null;
}
}
+
+ public async Task InitializeAsync()
+ {
+ await InitializeAppServiceConnectionAsync();
+ await _databaseService.InitializeAsync();
+ }
}
}
diff --git a/Wino.Server/TrayIconResources.xaml b/Wino.Server/TrayIconResources.xaml
index 7ab56338..8d0225bf 100644
--- a/Wino.Server/TrayIconResources.xaml
+++ b/Wino.Server/TrayIconResources.xaml
@@ -16,10 +16,6 @@
ToolTipText="Wino Mail"
LeftClickCommand="{Binding LaunchWinoCommand}"
NoLeftClickDelay="True"
- ContextMenu="{StaticResource SysTrayMenu}">
+ ContextMenu="{StaticResource SysTrayMenu}" />
-
-
-
-
diff --git a/Wino.Server/TrayIconViewModel.cs b/Wino.Server/TrayIconViewModel.cs
index 2c89ea39..73dea57a 100644
--- a/Wino.Server/TrayIconViewModel.cs
+++ b/Wino.Server/TrayIconViewModel.cs
@@ -1,4 +1,5 @@
-using System.Windows;
+using System.Threading.Tasks;
+using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -6,12 +7,18 @@ namespace Wino.Server
{
public partial class TrayIconViewModel : ObservableObject
{
- private readonly ServerContext _context = new ServerContext();
+ public ServerContext Context { get; }
+
+ public TrayIconViewModel(ServerContext serverContext)
+ {
+ Context = serverContext;
+ }
[RelayCommand]
public void LaunchWino()
{
- _context.SendTestMessageAsync();
+
+ // ServerContext.SendTestMessageAsync();
}
///
@@ -25,6 +32,6 @@ namespace Wino.Server
Application.Current.Shutdown();
}
- public void Reconnect() => _context.InitializeAppServiceConnection();
+ public async Task ReconnectAsync() => await Context.InitializeAppServiceConnectionAsync();
}
}
diff --git a/Wino.Server/Wino.Server.csproj b/Wino.Server/Wino.Server.csproj
index ee95a4bc..9f48c856 100644
--- a/Wino.Server/Wino.Server.csproj
+++ b/Wino.Server/Wino.Server.csproj
@@ -1,11 +1,14 @@
- net8.0-windows
+ net8.0-windows10.0.22621.0
+ 10.0.19041.0
WinExe
true
true
true
- net8.0-windows10.0.17763.0
+
+ true
+ 10.0.22621.0
Wino.Server.App