Skip to content

Commit

Permalink
Fix shinyorg#30 - Bridge was not rehydrating properly
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jul 21, 2019
1 parent feeca31 commit bab3f99
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 179 deletions.
16 changes: 0 additions & 16 deletions src/Shiny.Core/Platforms/Uwp/UwpBridgeImpl.cs

This file was deleted.

55 changes: 48 additions & 7 deletions src/Shiny.Core/Platforms/Uwp/UwpShinyHost.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
using System;
using Shiny.Infrastructure;
using Shiny.IO;
using Shiny.Jobs;
using Shiny.Net;
using Shiny.Power;
using Shiny.Settings;
using Shiny.Support.Uwp;
using Microsoft.Extensions.DependencyInjection;
using Windows.Storage;
using Windows.ApplicationModel.Background;


namespace Shiny
{
public class UwpShinyHost : ShinyHost
{
public static void Init(IShinyStartup startup = null, Action<IServiceCollection> platformBuild = null)
const string STARTUP_KEY = "ShinyStartupTypeName";
const string MODULE_KEY = "ShinyPlatformModuleTypeName";


public static void Init(IShinyStartup startup = null, IShinyModule platformModule = null)
=> InitPlatform(startup, services =>
{
services.AddSingleton<IEnvironment, EnvironmentImpl>();
Expand All @@ -25,11 +29,48 @@ public static void Init(IShinyStartup startup = null, Action<IServiceCollection>

services.AddSingleton<IJobManager, JobManager>();
services.AddSingleton<IBackgroundTaskProcessor, JobBackgroundTaskProcessor>();
services.RegisterPostBuildAction(sp =>
ShinyBackgroundTask.Bridge = sp.ResolveOrInstantiate<IUwpBridge>()
);

platformBuild?.Invoke(services);
if (platformModule != null)
services.RegisterModule(platformModule);

Dehydrate(STARTUP_KEY, startup);
Dehydrate(MODULE_KEY, platformModule);
});


public static void BackgroundRun(IBackgroundTaskInstance taskInstance)
{
var startup = Hydrate<IShinyStartup>(STARTUP_KEY);
var module = Hydrate<IShinyModule>(MODULE_KEY);

Init(startup, module);
Resolve<UwpContext>().Bridge(taskInstance);
}


static void Dehydrate(string key, object obj)
{
if (obj == null)
return;

ApplicationData.Current.LocalSettings.Values[key] = obj.GetType().AssemblyQualifiedName;
}


static T Hydrate<T>(string key) where T : class
{
var settings = ApplicationData.Current.LocalSettings.Values;
if (!settings.ContainsKey(key))
return null;

var typeName = settings[key].ToString();
var type = Type.GetType(typeName);
if (type != null)
{
var obj = Activator.CreateInstance(type) as T;
return obj;
}
return null;
}
}
}
11 changes: 0 additions & 11 deletions src/Shiny.Support.Uwp/IUwpBridge.cs

This file was deleted.

144 changes: 1 addition & 143 deletions src/Shiny.Support.Uwp/Shiny.Support.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,146 +24,4 @@
<Compile Remove="Properties\**\*.cs" />
<None Include="Properties\**\*.cs" />
</ItemGroup>
</Project>
<!--<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E1888C59-5C02-48F6-AE6E-7E6593597081}</ProjectGuid>
<OutputType>winmdobj</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Shiny.Support.Uwp</RootNamespace>
<AssemblyName>Shiny.Support.Uwp</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.17763.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AllowCrossPlatformRetargeting>false</AllowCrossPlatformRetargeting>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
<PlatformTarget>ARM64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
<PlatformTarget>ARM64</PlatformTarget>
<OutputPath>bin\ARM64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<Compile Include="ShinyBackgroundTask.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.8</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shiny.Core\Shiny.Core.csproj">
<Project>{84c6a1b8-0a57-4c6f-8738-3d3c03ce6f55}</Project>
<Name>Shiny.Core</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
</Project>-->
</Project>
8 changes: 6 additions & 2 deletions src/Shiny.Support.Uwp/ShinyBackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ namespace Shiny.Support.Uwp
{
public sealed class ShinyBackgroundTask : IBackgroundTask
{
public static IUwpBridge Bridge { get; set; }
public void Run(IBackgroundTaskInstance taskInstance) => Bridge.Bridge(taskInstance);
public void Run(IBackgroundTaskInstance taskInstance)
{
var host = Type.GetType("Shiny.UwpShinyHost, Shiny.Core");
var method = host.GetMethod("BackgroundRun");
method.Invoke(host, new [] { taskInstance });
}
}
}

0 comments on commit bab3f99

Please sign in to comment.