From 07fea3befa9530f5d11bfde2308f08c3173f6a7b Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 26 Aug 2016 06:30:43 +0300 Subject: [PATCH] Added RuntimePlatformInfo --- Avalonia.sln | 3 -- .../Avalonia.Android/Avalonia.Android.csproj | 1 + src/Android/Avalonia.Android/RuntimeInfo.cs | 18 ++++++++ .../Platform/IRuntimePlatform.cs | 22 ++++++++++ .../Avalonia.DotNetFrameworkRuntime.csproj | 5 ++- .../RuntimeInfo.cs | 44 +++++++++++++++++++ .../StandardRuntimePlatform.cs | 2 +- src/iOS/Avalonia.iOS/Avalonia.iOS.csproj | 1 + src/iOS/Avalonia.iOS/RuntimeInfo.cs | 17 +++++++ .../Avalonia.Layout.UnitTests.csproj | 5 ++- .../FullLayoutTests.cs | 2 +- .../Avalonia.LeakTests.csproj | 5 ++- .../Avalonia.UnitTests.csproj | 5 ++- tests/Avalonia.UnitTests/TestServices.cs | 2 +- 14 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 src/Android/Avalonia.Android/RuntimeInfo.cs create mode 100644 src/Avalonia.DotNetFrameworkRuntime/RuntimeInfo.cs create mode 100644 src/iOS/Avalonia.iOS/RuntimeInfo.cs diff --git a/Avalonia.sln b/Avalonia.sln index eaf46118a8..b2245a2f89 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -177,7 +177,6 @@ Global src\Shared\PlatformSupport\PlatformSupport.projitems*{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}*SharedItemsImports = 4 samples\TestApplicationShared\TestApplicationShared.projitems*{78345174-5b52-4a14-b9fd-d5f2428137f0}*SharedItemsImports = 13 src\Shared\PlatformSupport\PlatformSupport.projitems*{7b92af71-6287-4693-9dcb-bd5b6e927e23}*SharedItemsImports = 4 - src\Shared\PlatformSupport\PlatformSupport.projitems*{88060192-33d5-4932-b0f9-8bd2763e857d}*SharedItemsImports = 4 samples\TestApplicationShared\TestApplicationShared.projitems*{8c923867-8a8f-4f6b-8b80-47d9e8436166}*SharedItemsImports = 4 src\Shared\RenderHelpers\RenderHelpers.projitems*{925dd807-b651-475f-9f7c-cbeb974ce43d}*SharedItemsImports = 4 src\Skia\Avalonia.Skia\Avalonia.Skia.projitems*{925dd807-b651-475f-9f7c-cbeb974ce43d}*SharedItemsImports = 4 @@ -185,9 +184,7 @@ Global src\Skia\Avalonia.Skia\Avalonia.Skia.projitems*{bd43f7c0-396b-4aa1-bad9-dfde54d51298}*SharedItemsImports = 4 tests\Avalonia.RenderTests\Avalonia.RenderTests.projitems*{d35a9f3d-8bb0-496e-bf72-444038a7debb}*SharedItemsImports = 4 tests\Avalonia.RenderTests\Avalonia.RenderTests.projitems*{dabfd304-d6a4-4752-8123-c2ccf7ac7831}*SharedItemsImports = 4 - src\Shared\PlatformSupport\PlatformSupport.projitems*{db070a10-bf39-4752-8456-86e9d5928478}*SharedItemsImports = 4 tests\Avalonia.RenderTests\Avalonia.RenderTests.projitems*{e106cf37-4066-4615-b684-172a6d30b058}*SharedItemsImports = 4 - src\Shared\PlatformSupport\PlatformSupport.projitems*{e1aa3dbf-9056-4530-9376-18119a7a3ffe}*SharedItemsImports = 4 samples\TestApplicationShared\TestApplicationShared.projitems*{e3a1060b-50d0-44e8-88b6-f44ef2e5bd72}*SharedItemsImports = 4 src\Shared\PlatformSupport\PlatformSupport.projitems*{e4d9629c-f168-4224-3f51-a5e482ffbc42}*SharedItemsImports = 13 src\Shared\RenderHelpers\RenderHelpers.projitems*{fb05ac90-89ba-4f2f-a924-f37875fb547c}*SharedItemsImports = 4 diff --git a/src/Android/Avalonia.Android/Avalonia.Android.csproj b/src/Android/Avalonia.Android/Avalonia.Android.csproj index 88e66c441a..9af96f0f93 100644 --- a/src/Android/Avalonia.Android/Avalonia.Android.csproj +++ b/src/Android/Avalonia.Android/Avalonia.Android.csproj @@ -77,6 +77,7 @@ + diff --git a/src/Android/Avalonia.Android/RuntimeInfo.cs b/src/Android/Avalonia.Android/RuntimeInfo.cs new file mode 100644 index 0000000000..bb2466c357 --- /dev/null +++ b/src/Android/Avalonia.Android/RuntimeInfo.cs @@ -0,0 +1,18 @@ +using Avalonia.Platform; + +namespace Avalonia.Shared.PlatformSupport +{ + internal partial class StandardRuntimePlatform + { + public RuntimePlatformInfo GetRuntimeInfo() => new RuntimePlatformInfo + { + IsCoreClr = false, + IsDesktop = false, + IsMobile = true, + IsDotNetFramework = false, + IsMono = true, + IsUnix = true, + OperatingSystem = OperatingSystemType.Android + }; + } +} \ No newline at end of file diff --git a/src/Avalonia.Base/Platform/IRuntimePlatform.cs b/src/Avalonia.Base/Platform/IRuntimePlatform.cs index 63a4795a74..e1a09f094d 100644 --- a/src/Avalonia.Base/Platform/IRuntimePlatform.cs +++ b/src/Avalonia.Base/Platform/IRuntimePlatform.cs @@ -13,5 +13,27 @@ namespace Avalonia.Platform void PostThreadPoolItem(Action cb); IDisposable StartSystemTimer(TimeSpan interval, Action tick); string GetStackTrace(); + RuntimePlatformInfo GetRuntimeInfo(); + } + + public struct RuntimePlatformInfo + { + public OperatingSystemType OperatingSystem { get; set; } + public bool IsDesktop { get; set; } + public bool IsMobile { get; set; } + public bool IsCoreClr { get; set; } + public bool IsMono { get; set; } + public bool IsDotNetFramework { get; set; } + public bool IsUnix { get; set; } + } + + public enum OperatingSystemType + { + Unknown, + WinNT, + Linux, + OSX, + Android, + iOS } } diff --git a/src/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj b/src/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj index f8c181f094..4f972ca4eb 100644 --- a/src/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj +++ b/src/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj @@ -18,7 +18,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;FULLDOTNET prompt 4 bin\Debug\Avalonia.DotNetFrameworkRuntime.xml @@ -27,7 +27,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;FULLDOTNET prompt 4 bin\Release\Avalonia.DotNetFrameworkRuntime.xml @@ -53,6 +53,7 @@ + diff --git a/src/Avalonia.DotNetFrameworkRuntime/RuntimeInfo.cs b/src/Avalonia.DotNetFrameworkRuntime/RuntimeInfo.cs new file mode 100644 index 0000000000..41545a146f --- /dev/null +++ b/src/Avalonia.DotNetFrameworkRuntime/RuntimeInfo.cs @@ -0,0 +1,44 @@ +using System; +using System.Runtime.InteropServices; +using Avalonia.Platform; + +namespace Avalonia.Shared.PlatformSupport +{ + internal partial class StandardRuntimePlatform + { + private static readonly Lazy Info = new Lazy(() => + { + var isMono = Type.GetType("Mono.Runtime") != null; + var isUnix = Environment.OSVersion.Platform == PlatformID.Unix || + Environment.OSVersion.Platform == PlatformID.MacOSX; + return new RuntimePlatformInfo + { + IsCoreClr = false, + IsDesktop = true, + IsDotNetFramework = !isMono, + IsMono = isMono, + IsMobile = false, + IsUnix = isUnix, + OperatingSystem = isUnix ? DetectUnix() : OperatingSystemType.WinNT, + }; + }); + + [DllImport("libc")] + static extern int uname(IntPtr buf); + + static OperatingSystemType DetectUnix() + { + var buffer = Marshal.AllocHGlobal(0x1000); + uname(buffer); + var unixName = Marshal.PtrToStringAnsi(buffer); + Marshal.FreeHGlobal(buffer); + if(unixName=="Darwin") + return OperatingSystemType.OSX; + if (unixName == "Linux") + return OperatingSystemType.Linux; + return OperatingSystemType.Unknown; + } + + public RuntimePlatformInfo GetRuntimeInfo() => Info.Value; + } +} diff --git a/src/Shared/PlatformSupport/StandardRuntimePlatform.cs b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs index 9c0b7bcc73..e5ede1c6b4 100644 --- a/src/Shared/PlatformSupport/StandardRuntimePlatform.cs +++ b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs @@ -10,7 +10,7 @@ using Avalonia.Platform; namespace Avalonia.Shared.PlatformSupport { - internal class StandardRuntimePlatform : IRuntimePlatform + internal partial class StandardRuntimePlatform : IRuntimePlatform { public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies(); public void PostThreadPoolItem(Action cb) => ThreadPool.UnsafeQueueUserWorkItem(_ => cb(), null); diff --git a/src/iOS/Avalonia.iOS/Avalonia.iOS.csproj b/src/iOS/Avalonia.iOS/Avalonia.iOS.csproj index fcaee22c5a..6385ef3352 100644 --- a/src/iOS/Avalonia.iOS/Avalonia.iOS.csproj +++ b/src/iOS/Avalonia.iOS/Avalonia.iOS.csproj @@ -43,6 +43,7 @@ + diff --git a/src/iOS/Avalonia.iOS/RuntimeInfo.cs b/src/iOS/Avalonia.iOS/RuntimeInfo.cs new file mode 100644 index 0000000000..101561b246 --- /dev/null +++ b/src/iOS/Avalonia.iOS/RuntimeInfo.cs @@ -0,0 +1,17 @@ +using Avalonia.Platform; +namespace Avalonia.Shared.PlatformSupport +{ + internal partial class StandardRuntimePlatform + { + public RuntimePlatformInfo GetRuntimeInfo() => new RuntimePlatformInfo + { + IsCoreClr = false, + IsDesktop = false, + IsMobile = true, + IsDotNetFramework = false, + IsMono = true, + IsUnix = true, + OperatingSystem = OperatingSystemType.Android + }; + } +} \ No newline at end of file diff --git a/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj b/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj index 0cab84f5ca..e70ecb7a5e 100644 --- a/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj +++ b/tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj @@ -109,6 +109,10 @@ {7062AE20-5DCC-4442-9645-8195BDECE63E} Avalonia.Diagnostics + + {4a1abb09-9047-4bd5-a4ad-a055e52c5ee0} + Avalonia.DotNetFrameworkRuntime + {62024B2D-53EB-4638-B26B-85EEAA54866E} Avalonia.Input @@ -149,7 +153,6 @@ - diff --git a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs index 19b6705a62..b1f39673c4 100644 --- a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs +++ b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs @@ -149,7 +149,7 @@ namespace Avalonia.Layout.UnitTests .Bind().ToConstant(new Mock().Object) .Bind().ToConstant(globalStyles.Object) .Bind().ToConstant(new LayoutManager()) - .Bind().ToConstant(new StandardRuntimePlatform()) + .Bind().ToConstant(new AppBuilder().RuntimePlatform) .Bind().ToConstant(renderInterface) .Bind().ToConstant(renderManager) .Bind().ToConstant(new Styler()) diff --git a/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj b/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj index 0e45e0fcdd..587deb4864 100644 --- a/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj +++ b/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj @@ -105,6 +105,10 @@ + + {4a1abb09-9047-4bd5-a4ad-a055e52c5ee0} + Avalonia.DotNetFrameworkRuntime + {3e53a01a-b331-47f3-b828-4a5717e77a24} Avalonia.Markup.Xaml @@ -164,7 +168,6 @@ -