UIMessage communication. Single instancing for server and re-connection mechanism on suspension.
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
using Serilog;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.Background;
|
||||
using Windows.UI.Notifications;
|
||||
using Wino.Core;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Core.UWP.Services;
|
||||
using Wino.Services;
|
||||
|
||||
namespace Wino.Activation
|
||||
{
|
||||
@@ -21,7 +18,6 @@ namespace Wino.Activation
|
||||
private const string BackgroundExecutionLogTag = "[BackgroundExecution] ";
|
||||
|
||||
private readonly IWinoRequestDelegator _winoRequestDelegator;
|
||||
private readonly IBackgroundSynchronizer _backgroundSynchronizer;
|
||||
private readonly INativeAppService _nativeAppService;
|
||||
private readonly IWinoRequestProcessor _winoRequestProcessor;
|
||||
private readonly IWinoSynchronizerFactory _winoSynchronizerFactory;
|
||||
@@ -30,14 +26,12 @@ namespace Wino.Activation
|
||||
|
||||
BackgroundTaskDeferral _deferral;
|
||||
public BackgroundActivationHandler(IWinoRequestDelegator winoRequestDelegator,
|
||||
IBackgroundSynchronizer backgroundSynchronizer,
|
||||
INativeAppService nativeAppService,
|
||||
IWinoRequestProcessor winoRequestProcessor,
|
||||
IWinoSynchronizerFactory winoSynchronizerFactory,
|
||||
IMailService mailService)
|
||||
{
|
||||
_winoRequestDelegator = winoRequestDelegator;
|
||||
_backgroundSynchronizer = backgroundSynchronizer;
|
||||
_nativeAppService = nativeAppService;
|
||||
_winoRequestProcessor = winoRequestProcessor;
|
||||
_winoSynchronizerFactory = winoSynchronizerFactory;
|
||||
@@ -104,18 +98,6 @@ namespace Wino.Activation
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (taskName == BackgroundTaskService.BackgroundSynchronizationTimerTaskNameEx)
|
||||
{
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
// Run timer based background synchronization.
|
||||
|
||||
await _backgroundSynchronizer.RunBackgroundSynchronizationAsync(BackgroundSynchronizationReason.Timer);
|
||||
|
||||
watch.Stop();
|
||||
Log.Information($"{BackgroundExecutionLogTag}Background synchronization is completed in {watch.Elapsed.TotalSeconds} seconds.");
|
||||
}
|
||||
|
||||
instance.Canceled -= OnBackgroundExecutionCanceled;
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ namespace Wino
|
||||
UnhandledException += OnAppUnhandledException;
|
||||
EnteredBackground += OnEnteredBackground;
|
||||
LeavingBackground += OnLeavingBackground;
|
||||
|
||||
Resuming += OnResuming;
|
||||
Suspending += OnSuspending;
|
||||
|
||||
Services = ConfigureServices();
|
||||
@@ -87,6 +89,15 @@ namespace Wino
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
|
||||
private async void OnResuming(object sender, object e)
|
||||
{
|
||||
// App Service connection was lost on suspension.
|
||||
// We must restore it.
|
||||
// Server might be running already, but re-launching it will trigger a new connection attempt.
|
||||
|
||||
await _appServiceConnectionManager.ConnectAsync();
|
||||
}
|
||||
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
@@ -328,10 +339,12 @@ namespace Wino
|
||||
yield return Services.GetService<FileActivationHandler>();
|
||||
}
|
||||
|
||||
public void OnBackgroundTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
|
||||
public async void OnBackgroundTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
|
||||
{
|
||||
Log.Information($"Background task {sender.Task.Name} was canceled. Reason: {reason}");
|
||||
|
||||
await _appServiceConnectionManager.DisconnectAsync();
|
||||
|
||||
backgroundTaskDeferral?.Complete();
|
||||
backgroundTaskDeferral = null;
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@
|
||||
Padding="14"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom">
|
||||
<TextBlock Text="{x:Bind ViewModel.ServerConnectionManager.Status, Mode=OneWay}" />
|
||||
<TextBlock Text="{x:Bind ViewModel.ActiveConnectionStatus, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</muxc:NavigationView>
|
||||
|
||||
@@ -20,7 +20,7 @@ using Wino.Core.Messages.Shell;
|
||||
using Wino.Core.Messages.Synchronization;
|
||||
using Wino.Core.UWP.Extensions;
|
||||
using Wino.Dialogs;
|
||||
using Wino.Messages.Server;
|
||||
using Wino.Messaging.Server;
|
||||
|
||||
namespace Wino.Services
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ using Windows.UI.Xaml.Navigation;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messages.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Views.Abstract;
|
||||
using Wino.Views.Account;
|
||||
using Wino.Views.Settings;
|
||||
|
||||
@@ -801,9 +801,9 @@
|
||||
<Project>{d62f1c03-da57-4709-a640-0283296a8e66}</Project>
|
||||
<Name>Wino.Mail.ViewModels</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Wino.Messages\Wino.Messages.csproj">
|
||||
<ProjectReference Include="..\Wino.Messages\Wino.Messaging.csproj">
|
||||
<Project>{0c307d7e-256f-448c-8265-5622a812fbcc}</Project>
|
||||
<Name>Wino.Messages</Name>
|
||||
<Name>Wino.Messaging</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -811,9 +811,7 @@
|
||||
<Name>Windows Desktop Extensions for the UWP</Name>
|
||||
</SDKReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Server\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user