Browse Source

Added RuntimePlatformInfo

pull/695/merge
Nikita Tsukanov 10 years ago
parent
commit
07fea3befa
  1. 3
      Avalonia.sln
  2. 1
      src/Android/Avalonia.Android/Avalonia.Android.csproj
  3. 18
      src/Android/Avalonia.Android/RuntimeInfo.cs
  4. 22
      src/Avalonia.Base/Platform/IRuntimePlatform.cs
  5. 5
      src/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj
  6. 44
      src/Avalonia.DotNetFrameworkRuntime/RuntimeInfo.cs
  7. 2
      src/Shared/PlatformSupport/StandardRuntimePlatform.cs
  8. 1
      src/iOS/Avalonia.iOS/Avalonia.iOS.csproj
  9. 17
      src/iOS/Avalonia.iOS/RuntimeInfo.cs
  10. 5
      tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj
  11. 2
      tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs
  12. 5
      tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj
  13. 5
      tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj
  14. 2
      tests/Avalonia.UnitTests/TestServices.cs

3
Avalonia.sln

@ -177,7 +177,6 @@ Global
src\Shared\PlatformSupport\PlatformSupport.projitems*{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}*SharedItemsImports = 4 src\Shared\PlatformSupport\PlatformSupport.projitems*{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}*SharedItemsImports = 4
samples\TestApplicationShared\TestApplicationShared.projitems*{78345174-5b52-4a14-b9fd-d5f2428137f0}*SharedItemsImports = 13 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*{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 samples\TestApplicationShared\TestApplicationShared.projitems*{8c923867-8a8f-4f6b-8b80-47d9e8436166}*SharedItemsImports = 4
src\Shared\RenderHelpers\RenderHelpers.projitems*{925dd807-b651-475f-9f7c-cbeb974ce43d}*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 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 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*{d35a9f3d-8bb0-496e-bf72-444038a7debb}*SharedItemsImports = 4
tests\Avalonia.RenderTests\Avalonia.RenderTests.projitems*{dabfd304-d6a4-4752-8123-c2ccf7ac7831}*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 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 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\PlatformSupport\PlatformSupport.projitems*{e4d9629c-f168-4224-3f51-a5e482ffbc42}*SharedItemsImports = 13
src\Shared\RenderHelpers\RenderHelpers.projitems*{fb05ac90-89ba-4f2f-a924-f37875fb547c}*SharedItemsImports = 4 src\Shared\RenderHelpers\RenderHelpers.projitems*{fb05ac90-89ba-4f2f-a924-f37875fb547c}*SharedItemsImports = 4

1
src/Android/Avalonia.Android/Avalonia.Android.csproj

@ -77,6 +77,7 @@
<Compile Include="Platform\AndroidTopLevelRenderer.cs" /> <Compile Include="Platform\AndroidTopLevelRenderer.cs" />
<Compile Include="Resources\Resource.Designer.cs" /> <Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RuntimeInfo.cs" />
<Compile Include="SystemDialogImpl.cs" /> <Compile Include="SystemDialogImpl.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

18
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
};
}
}

22
src/Avalonia.Base/Platform/IRuntimePlatform.cs

@ -13,5 +13,27 @@ namespace Avalonia.Platform
void PostThreadPoolItem(Action cb); void PostThreadPoolItem(Action cb);
IDisposable StartSystemTimer(TimeSpan interval, Action tick); IDisposable StartSystemTimer(TimeSpan interval, Action tick);
string GetStackTrace(); 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
} }
} }

5
src/Avalonia.DotNetFrameworkRuntime/Avalonia.DotNetFrameworkRuntime.csproj

@ -18,7 +18,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>TRACE;DEBUG;FULLDOTNET</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Avalonia.DotNetFrameworkRuntime.xml</DocumentationFile> <DocumentationFile>bin\Debug\Avalonia.DotNetFrameworkRuntime.xml</DocumentationFile>
@ -27,7 +27,7 @@
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE;FULLDOTNET</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Avalonia.DotNetFrameworkRuntime.xml</DocumentationFile> <DocumentationFile>bin\Release\Avalonia.DotNetFrameworkRuntime.xml</DocumentationFile>
@ -53,6 +53,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="AppBuilder.cs" /> <Compile Include="AppBuilder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RuntimeInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj"> <ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj">

44
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<RuntimePlatformInfo> Info = new Lazy<RuntimePlatformInfo>(() =>
{
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;
}
}

2
src/Shared/PlatformSupport/StandardRuntimePlatform.cs

@ -10,7 +10,7 @@ using Avalonia.Platform;
namespace Avalonia.Shared.PlatformSupport namespace Avalonia.Shared.PlatformSupport
{ {
internal class StandardRuntimePlatform : IRuntimePlatform internal partial class StandardRuntimePlatform : IRuntimePlatform
{ {
public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies(); public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies();
public void PostThreadPoolItem(Action cb) => ThreadPool.UnsafeQueueUserWorkItem(_ => cb(), null); public void PostThreadPoolItem(Action cb) => ThreadPool.UnsafeQueueUserWorkItem(_ => cb(), null);

1
src/iOS/Avalonia.iOS/Avalonia.iOS.csproj

@ -43,6 +43,7 @@
<Compile Include="PlatformSettings.cs" /> <Compile Include="PlatformSettings.cs" />
<Compile Include="PlatformThreadingInterface.cs" /> <Compile Include="PlatformThreadingInterface.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RuntimeInfo.cs" />
<Compile Include="Specific\KeyboardEventsHelper.cs" /> <Compile Include="Specific\KeyboardEventsHelper.cs" />
<Compile Include="WindowingPlatformImpl.cs" /> <Compile Include="WindowingPlatformImpl.cs" />
</ItemGroup> </ItemGroup>

17
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
};
}
}

5
tests/Avalonia.Layout.UnitTests/Avalonia.Layout.UnitTests.csproj

@ -109,6 +109,10 @@
<Project>{7062AE20-5DCC-4442-9645-8195BDECE63E}</Project> <Project>{7062AE20-5DCC-4442-9645-8195BDECE63E}</Project>
<Name>Avalonia.Diagnostics</Name> <Name>Avalonia.Diagnostics</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.DotNetFrameworkRuntime\Avalonia.DotNetFrameworkRuntime.csproj">
<Project>{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}</Project>
<Name>Avalonia.DotNetFrameworkRuntime</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj"> <ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj">
<Project>{62024B2D-53EB-4638-B26B-85EEAA54866E}</Project> <Project>{62024B2D-53EB-4638-B26B-85EEAA54866E}</Project>
<Name>Avalonia.Input</Name> <Name>Avalonia.Input</Name>
@ -149,7 +153,6 @@
<ItemGroup> <ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup> </ItemGroup>
<Import Project="..\..\src\Shared\PlatformSupport\PlatformSupport.projitems" Label="Shared" />
<Choose> <Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup> <ItemGroup>

2
tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs

@ -149,7 +149,7 @@ namespace Avalonia.Layout.UnitTests
.Bind<IInputManager>().ToConstant(new Mock<IInputManager>().Object) .Bind<IInputManager>().ToConstant(new Mock<IInputManager>().Object)
.Bind<IGlobalStyles>().ToConstant(globalStyles.Object) .Bind<IGlobalStyles>().ToConstant(globalStyles.Object)
.Bind<ILayoutManager>().ToConstant(new LayoutManager()) .Bind<ILayoutManager>().ToConstant(new LayoutManager())
.Bind<IRuntimePlatform>().ToConstant(new StandardRuntimePlatform()) .Bind<IRuntimePlatform>().ToConstant(new AppBuilder().RuntimePlatform)
.Bind<IPlatformRenderInterface>().ToConstant(renderInterface) .Bind<IPlatformRenderInterface>().ToConstant(renderInterface)
.Bind<IRenderQueueManager>().ToConstant(renderManager) .Bind<IRenderQueueManager>().ToConstant(renderManager)
.Bind<IStyler>().ToConstant(new Styler()) .Bind<IStyler>().ToConstant(new Styler())

5
tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj

@ -105,6 +105,10 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.DotNetFrameworkRuntime\Avalonia.DotNetFrameworkRuntime.csproj">
<Project>{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}</Project>
<Name>Avalonia.DotNetFrameworkRuntime</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj"> <ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj">
<Project>{3e53a01a-b331-47f3-b828-4a5717e77a24}</Project> <Project>{3e53a01a-b331-47f3-b828-4a5717e77a24}</Project>
<Name>Avalonia.Markup.Xaml</Name> <Name>Avalonia.Markup.Xaml</Name>
@ -164,7 +168,6 @@
<ItemGroup> <ItemGroup>
<Content Include="Readme.txt" /> <Content Include="Readme.txt" />
</ItemGroup> </ItemGroup>
<Import Project="..\..\src\Shared\PlatformSupport\PlatformSupport.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

5
tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj

@ -64,6 +64,10 @@
<Compile Include="MockWindowingPlatform.cs" /> <Compile Include="MockWindowingPlatform.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.DotNetFrameworkRuntime\Avalonia.DotNetFrameworkRuntime.csproj">
<Project>{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}</Project>
<Name>Avalonia.DotNetFrameworkRuntime</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj"> <ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj">
<Project>{3e53a01a-b331-47f3-b828-4a5717e77a24}</Project> <Project>{3e53a01a-b331-47f3-b828-4a5717e77a24}</Project>
<Name>Avalonia.Markup.Xaml</Name> <Name>Avalonia.Markup.Xaml</Name>
@ -113,7 +117,6 @@
<None Include="app.config" /> <None Include="app.config" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="..\..\src\Shared\PlatformSupport\PlatformSupport.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

2
tests/Avalonia.UnitTests/TestServices.cs

@ -19,7 +19,7 @@ namespace Avalonia.UnitTests
public static readonly TestServices StyledWindow = new TestServices( public static readonly TestServices StyledWindow = new TestServices(
assetLoader: new AssetLoader(), assetLoader: new AssetLoader(),
layoutManager: new LayoutManager(), layoutManager: new LayoutManager(),
platform: new StandardRuntimePlatform(), platform: new AppBuilder().RuntimePlatform,
renderInterface: CreateRenderInterfaceMock(), renderInterface: CreateRenderInterfaceMock(),
standardCursorFactory: Mock.Of<IStandardCursorFactory>(), standardCursorFactory: Mock.Of<IStandardCursorFactory>(),
styler: new Styler(), styler: new Styler(),

Loading…
Cancel
Save