Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tizen backend #1546

Merged
merged 8 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Task("GenerateEvents")
generate("ios", "src/ReactiveUI.Events/");
generate("mac", "src/ReactiveUI.Events/");
generate("uwp", "src/ReactiveUI.Events/");
generate("tizen", "src/ReactiveUI.Events/");
generate("wpf", "src/ReactiveUI.Events.WPF/");
generate("xamforms", "src/ReactiveUI.Events.XamForms/");
generate("winforms", "src/ReactiveUI.Events.Winforms/");
Expand Down
5 changes: 4 additions & 1 deletion src/Directory.build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0.0'">
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'tizen40'">
<DefineConstants>$(DefineConstants);Tizen</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0.16299' ">
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.8" />
</ItemGroup>
</Project>
</Project>
45 changes: 36 additions & 9 deletions src/EventBuilder/Cecil/EventTemplateInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ public static class EventTemplateInformation
{"Windows.UI.Xaml.Data.PropertyChangedEventHandler", "global::System.ComponentModel.PropertyChangedEventHandler"},
{"Windows.Foundation.EventHandler", "EventHandler"},
{"Windows.Foundation.EventHandler`1", "EventHandler"},
{"Windows.Foundation.EventHandler`2", "EventHandler"}
{"Windows.Foundation.EventHandler`2", "EventHandler"},
{"System.Boolean", "Boolean"},
{"System.Boolean`1", "Boolean"},
{"System.EventHandler", "EventHandler"},
{"System.EventHandler`1", "EventHandler"},
{"System.EventHandler`2", "EventHandler"},
{"System.EventArgs", "EventArgs"},
{"System.EventArgs`1", "EventArgs"},
{"System.EventArgs`2", "EventArgs"},
{"Tizen.NUI.EventHandlerWithReturnType", "Tizen.NUI.EventHandlerWithReturnType"},
{"Tizen.NUI.EventHandlerWithReturnType`1", "Tizen.NUI.EventHandlerWithReturnType"},
{"Tizen.NUI.EventHandlerWithReturnType`2", "Tizen.NUI.EventHandlerWithReturnType"},
{"Tizen.NUI.EventHandlerWithReturnType`3", "Tizen.NUI.EventHandlerWithReturnType"},
};

private static string RenameBogusWinRTTypes(string typeName)
private static string RenameBogusTypes(string typeName)
{
if (SubstitutionList.ContainsKey(typeName)) return SubstitutionList[typeName];
if (SubstitutionList.ContainsKey(typeName)) {
return SubstitutionList[typeName];
}
return typeName;
}

Expand All @@ -34,7 +48,7 @@ private static string GetEventArgsTypeForEvent(EventDefinition ei)
if (invoke.Parameters.Count < 2) return null;

var param = invoke.Parameters[1];
var ret = RenameBogusWinRTTypes(param.ParameterType.FullName);
var ret = RenameBogusTypes(param.ParameterType.FullName);

var generic = ei.EventType as GenericInstanceType;
if (generic != null) {
Expand All @@ -43,7 +57,12 @@ var kvp in
type.GenericParameters.Zip(generic.GenericArguments, (name, actual) => new { name, actual })) {
var realType = GetRealTypeName(kvp.actual);

ret = ret.Replace(kvp.name.FullName, realType);
var temp = ret.Replace(kvp.name.FullName, realType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I quite get this change, shouldn't we be replacing type names for multiple generic type arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix to resolve the potential issues (to avoid unintended replacement) mentioned above with minimal changes. It's nothing more, nothing less.

if (temp != ret)
{
ret = temp;
break;
}
}
}

Expand All @@ -53,10 +72,10 @@ var kvp in

private static string GetRealTypeName(TypeDefinition t)
{
if (t.GenericParameters.Count == 0) return RenameBogusWinRTTypes(t.FullName);
if (t.GenericParameters.Count == 0) return RenameBogusTypes(t.FullName);

var ret = string.Format("{0}<{1}>",
RenameBogusWinRTTypes(t.Namespace + "." + t.Name),
RenameBogusTypes(t.Namespace + "." + t.Name),
string.Join(",", t.GenericParameters.Select(x => GetRealTypeName(x.Resolve()))));

// NB: Inner types in Mono.Cecil get reported as 'Foo/Bar'
Expand All @@ -66,12 +85,20 @@ private static string GetRealTypeName(TypeDefinition t)
private static string GetRealTypeName(TypeReference t)
{
var generic = t as GenericInstanceType;
if (generic == null) return RenameBogusWinRTTypes(t.FullName);
if (generic == null) return RenameBogusTypes(t.FullName);

var ret = string.Format("{0}<{1}>",
RenameBogusWinRTTypes(generic.Namespace + "." + generic.Name),
RenameBogusTypes(generic.Namespace + "." + generic.Name),
string.Join(",", generic.GenericArguments.Select(x => GetRealTypeName(x))));

// NB: Handy place to hook to troubleshoot if something needs to be added to SubstitutionList
//if (generic.FullName.Contains("MarkReachedEventArgs")) {
// // Tizen.NUI.EventHandlerWithReturnType`3
// //<System.Object,Tizen.NUI.UIComponents.Slider/
// //MarkReachedEventArgs,
// //System.Boolean>
//}

// NB: Inner types in Mono.Cecil get reported as 'Foo/Bar'
return ret.Replace('/', '.');
}
Expand Down
3 changes: 2 additions & 1 deletion src/EventBuilder/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum AutoPlatform
Android,
iOS,
Mac,
Tizen,
WPF,
XamForms,
UWP,
Expand All @@ -27,7 +28,7 @@ public class CommandLineOptions

[Option('p', "platform", Required = true,
HelpText =
"Platform to automatically generate. Possible options include: NONE, ANDROID, IOS, WPF, MAC, UWP, XAMFORMS, WINFORMS"
"Platform to automatically generate. Possible options include: NONE, ANDROID, IOS, WPF, MAC, TIZEN, UWP, XAMFORMS, WINFORMS"
)]
public AutoPlatform Platform { get; set; }

Expand Down
13 changes: 8 additions & 5 deletions src/EventBuilder/EventBuilder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.9
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventBuilder", "EventBuilder.csproj", "{A6B86E12-057F-4591-98A3-FD50E9CEAE69}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBuilder", "EventBuilder.csproj", "{A6B86E12-057F-4591-98A3-FD50E9CEAE69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,14 +15,17 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|x86.ActiveCfg = Debug|x86
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|x86.Build.0 = Debug|x86
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|x86.ActiveCfg = Debug|Any CPU
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Debug|x86.Build.0 = Debug|Any CPU
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|Any CPU.Build.0 = Release|Any CPU
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|x86.ActiveCfg = Release|x86
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|x86.Build.0 = Release|x86
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|x86.ActiveCfg = Release|Any CPU
{A6B86E12-057F-4591-98A3-FD50E9CEAE69}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8AD09057-1163-45D2-A260-CB034E6DFD07}
EndGlobalSection
EndGlobal
56 changes: 56 additions & 0 deletions src/EventBuilder/Platforms/Tizen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.

using NuGet;
using Polly;
using Serilog;
using System;
using System.IO;
using System.Linq;

namespace EventBuilder.Platforms
{
public class Tizen : BasePlatform
{
private const string _packageName = "Tizen.NET";

public Tizen()
{
var packageUnzipPath = Environment.CurrentDirectory;

Log.Debug($"Package unzip path is {packageUnzipPath}");

var retryPolicy = Policy
.Handle<Exception>()
.WaitAndRetry(
5,
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
(exception, timeSpan, context) => {
Log.Warning(
"An exception was thrown whilst retrieving or installing {0}: {1}",
_packageName, exception);
});

retryPolicy.Execute(() => {
var repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
var packageManager = new PackageManager(repo, packageUnzipPath);
var package = repo.FindPackagesById(_packageName).Single(x => x.Version.ToString() == "4.0.0");

Log.Debug("Using Tizen.NET {0} released on {1}", package.Version, package.Published);
Log.Debug("{0}", package.ReleaseNotes);

packageManager.InstallPackage(package, ignoreDependencies: true, allowPrereleaseVersions: false);
});

var elmSharp = Directory.GetFiles(packageUnzipPath, "ElmSharp*.dll", SearchOption.AllDirectories);
Assemblies.AddRange(elmSharp);

var tizenNet = Directory.GetFiles(packageUnzipPath, "Tizen*.dll", SearchOption.AllDirectories);
Assemblies.AddRange(tizenNet);

CecilSearchDirectories.Add($"{packageUnzipPath}\\Tizen.NET.4.0.0\\build\\tizen40\\ref");
CecilSearchDirectories.Add($"{packageUnzipPath}\\Tizen.NET.4.0.0\\lib\\netstandard2.0");
}
}
}
10 changes: 9 additions & 1 deletion src/EventBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static void Main(string[] args)
// allow app to be debugged in visual studio.
if (Debugger.IsAttached) {
//args = "--help ".Split(' ');
args = "--platform=ios".Split(' ');
args = "--platform=tizen".Split(' ');
//args = new[]
//{
// "--platform=none",
Expand Down Expand Up @@ -101,6 +101,10 @@ private static void Main(string[] args)
platform = new XamForms();
break;

case AutoPlatform.Tizen:
platform = new Tizen();
break;

case AutoPlatform.UWP:
platform = new UWP();
break;
Expand All @@ -118,6 +122,10 @@ private static void Main(string[] args)
Environment.Exit((int)ExitCode.Success);
} catch (Exception ex) {
Log.Fatal(ex.ToString());

if (Debugger.IsAttached) {
Debugger.Break();
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/ReactiveUI.Events/ReactiveUI.Events.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80</TargetFrameworks>
<TargetFrameworks>uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80;tizen40</TargetFrameworks>
<AssemblyName>ReactiveUI.Events</AssemblyName>
<RootNamespace>ReactiveUI.Events</RootNamespace>
<Description>Provides Observable-based events API for common UI controls/eventhandlers. The contents of this package is automatically generated, please target pull-requests to the code generator.</Description>
Expand Down Expand Up @@ -36,5 +36,11 @@
<Compile Include="Events_ANDROID.cs" Condition="Exists('Events_ANDROID.cs')" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'tizen40' ">
<Compile Include="Events_TIZEN.cs" Condition="Exists('Events_TIZEN.cs')" />
<PackageReference Include="Tizen.NET" Version="4.0.0" />
</ItemGroup>


<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project>
52 changes: 52 additions & 0 deletions src/ReactiveUI/Platforms/tizen/EcoreMainloopScheduler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.

using System;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using ElmSharp;

namespace ReactiveUI
{
class EcoreMainloopScheduler : IScheduler
{
public static IScheduler MainThreadScheduler = new EcoreMainloopScheduler();

public DateTimeOffset Now => DateTimeOffset.Now;

public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
{
var innerDisp = new SingleAssignmentDisposable();
EcoreMainloop.PostAndWakeUp(() => {
if (!innerDisp.IsDisposed) innerDisp.Disposable = action(this, state);
});
return innerDisp;
}

public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
{
var innerDisp = Disposable.Empty;
bool isCancelled = false;

IntPtr timer = EcoreMainloop.AddTimer(dueTime.TotalSeconds, () => {
if (!isCancelled) innerDisp = action(this, state);
return false;
});

return Disposable.Create(() => {
isCancelled = true;
EcoreMainloop.RemoveTimer(timer);
innerDisp.Dispose();
});
}

public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
{
if (dueTime <= Now) {
return Schedule(state, action);
}
return Schedule(state, dueTime - Now, action);
}
}
}
17 changes: 17 additions & 0 deletions src/ReactiveUI/Platforms/tizen/PlatformOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.

namespace ReactiveUI
{
/// <summary>
/// Returns the current orientation of the device on tizen.
/// </summary>
public class PlatformOperations : IPlatformOperations
{
public string GetOrientation()
{
return null;
}
}
}
20 changes: 20 additions & 0 deletions src/ReactiveUI/Platforms/tizen/PlatformRegistrations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.

using System;
using System.Reactive.Concurrency;

namespace ReactiveUI
{
public class PlatformRegistrations : IWantsToRegisterStuff
{
public void Register(Action<Func<object>, Type> registerFunction)
{
registerFunction(() => new PlatformOperations(), typeof(IPlatformOperations));
registerFunction(() => new ComponentModelTypeConverter(), typeof(IBindingTypeConverter));
RxApp.TaskpoolScheduler = TaskPoolScheduler.Default;
RxApp.MainThreadScheduler = EcoreMainloopScheduler.MainThreadScheduler;
}
}
}
8 changes: 7 additions & 1 deletion src/ReactiveUI/ReactiveUI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80;netcoreapp2.0;tizen40</TargetFrameworks>
<AssemblyName>ReactiveUI</AssemblyName>
<RootNamespace>ReactiveUI</RootNamespace>
<Description>A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. Supports Xamarin.iOS, Xamarin.Android, Xamarin.Mac, Xamarin Forms, WPF, Windows Forms, Windows Phone 8.1, Windows Store and Universal Windows Platform (UWP).</Description>
Expand Down Expand Up @@ -59,6 +59,12 @@
<Compile Include="Platforms\netcoreapp2.0\**\*.cs" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'tizen40' ">
<Compile Include="Platforms\tizen\**\*.cs" />
<Compile Include="Platforms\xamarin-common\**\*.cs" />
<PackageReference Include="Tizen.NET" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="VariadicTemplates.tt" Generator="TextTemplatingFileGenerator" LastGenOutput="VariadicTemplates.cs" />
Expand Down