Skip to content

Commit 06026d9

Browse files
committed
Merge pull request #152 from anjdreas/uwp
Add UnitsNet.WindowsRuntimeComponent nuget
2 parents fbc663a + 50defd2 commit 06026d9

File tree

153 files changed

+202034
-1740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+202034
-1740
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
4+
<metadata>
5+
<id>UnitsNet.WindowsRuntimeComponent</id>
6+
<version>3.33.0</version>
7+
<title>Units.NET - Windows Runtime Component</title>
8+
<authors>Andreas Gullberg Larsen</authors>
9+
<owners>Andreas Gullberg Larsen</owners>
10+
<licenseUrl>https://github.com/anjdreas/UnitsNet/blob/master/LICENSE</licenseUrl>
11+
<projectUrl>https://github.com/anjdreas/UnitsNet</projectUrl>
12+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
13+
<description>For C#/VB Universal Windows code (UWP), use UnitsNet instead. This is a Windows Runtime Component with reduced functionality to support all UWP languages, such as JavaScript and C++, and other runtime components.</description>
14+
<summary>For C#/VB Universal Windows code (UWP), use UnitsNet instead.</summary>
15+
<iconUrl>https://raw.githubusercontent.com/anjdreas/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png</iconUrl>
16+
<releaseNotes></releaseNotes>
17+
<copyright>Copyright © 2015 Andreas Gullberg Larsen</copyright>
18+
<language>en-US</language>
19+
<tags>unit units measurement si metric imperial abbreviation abbreviations convert conversion parse c# .net immutable uwp uap winrt win10 windows runtime component</tags>
20+
</metadata>
21+
<files>
22+
<file src="Artifacts\Bin\Src\AnyCPU_Release\uap10.0\UnitsNet.*" target="lib/uap10.0" />
23+
<file src="UnitsNet\**\*.cs" exclude="UnitsNet\**\obj\**\*.cs" target="src" />
24+
</files>
25+
</package>

Build/UpdateAssemblyInfo.ps1

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
.EXAMPLE
77
Set new version.
88
powershell UpdateAssemblyInfo.ps1 1.2.3.4
9-
9+
1010
.NOTES
1111
Author: Andreas Gullberg Larsen
1212
Date: May 2, 2014
@@ -40,37 +40,38 @@ function Get-VersionFromNuspec ([string] $nuspecFilePath) {
4040
}
4141

4242
#-------------------------------------------------------------------------------
43-
# Description: Sets the AssemblyVersion and AssemblyFileVersion of
43+
# Description: Sets the AssemblyVersion and AssemblyFileVersion of
4444
# AssemblyInfo.cs files.
4545
#
4646
# Author: Andreas Larsen
4747
# Version: 1.0
4848
#-------------------------------------------------------------------------------
49-
function Update-AssemblyInfoFiles ([string] $libName) {
49+
function Update-AssemblyInfoFiles ([string] $nuspecFilePath, [string] $assemblyInfoFilePath) {
5050

51-
[Version]$version = Get-VersionFromNuspec "$root\Build\$libName.nuspec"
51+
[Version]$version = Get-VersionFromNuspec "$root\$nuspecFilePath"
5252

5353
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
5454
$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
5555
$assemblyVersion = 'AssemblyVersion("' + $version + '")';
5656
$fileVersion = 'AssemblyFileVersion("' + $version + '")';
57-
58-
Get-ChildItem "$root\$libName\Properties" | Where { $_.PSChildName -match "^AssemblyInfo\.cs$"} | ForEach-Object {
57+
58+
Get-ChildItem "$root\$assemblyInfoFilePath" | ForEach-Object {
5959
$filename = $_.Directory.ToString() + '\' + $_.Name
6060
$filename + ' -> ' + $version
61-
61+
6262
(Get-Content $filename -Encoding UTF8) | ForEach-Object {
6363
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
6464
% {$_ -replace $fileVersionPattern, $fileVersion }
6565
} | Set-Content $filename -Encoding UTF8
66-
}
66+
}
6767
}
6868

6969
try {
7070
"Updating assembly info to version: $setVersion"
7171
""
72-
Update-AssemblyInfoFiles "UnitsNet"
73-
Update-AssemblyInfoFiles "UnitsNet.Serialization.JsonNet"
72+
Update-AssemblyInfoFiles "Build\UnitsNet.nuspec" "UnitsNet\Properties\AssemblyInfo.cs"
73+
Update-AssemblyInfoFiles "Build\UnitsNet.WindowsRuntimeComponent.nuspec" "UnitsNet\Properties\AssemblyInfo.WindowsRuntimeComponent.cs"
74+
Update-AssemblyInfoFiles "Build\UnitsNet.Serialization.JsonNet.nuspec" "UnitsNet.Serialization.JsonNet\Properties\AssemblyInfo.cs"
7475
}
7576
catch {
7677
$myError = $_.Exception.ToString()

Build/nuget-restore.bat

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@echo off
22
SET ROOT=%~dp0..
33
SET NuGetExe=%ROOT%\Tools\NuGet.exe
4-
SET SolutionFile=%ROOT%\UnitsNet.sln
5-
%NuGetExe% restore %SolutionFile%
4+
5+
%NuGetExe% restore %ROOT%\UnitsNet.sln
6+
if %errorlevel% neq 0 exit /b %errorlevel%
7+
8+
%NuGetExe% restore %ROOT%\UnitsNet.WindowsRuntimeComponent.sln
69
if %errorlevel% neq 0 exit /b %errorlevel%

Build/pack-nuget.bat

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
@echo off
22
SET ROOT=%~dp0..
3-
SET MainLibNuspec=%ROOT%\Build\UnitsNet.nuspec
4-
SET SerializationLibNuspec=%ROOT%\Build\UnitsNet.Serialization.JsonNet.nuspec
3+
SET MainNuspec=%ROOT%\Build\UnitsNet.nuspec
4+
SET UwpNuspec=%ROOT%\Build\UnitsNet.WindowsRuntimeComponent.nuspec
5+
SET SerializationNuspec=%ROOT%\Build\UnitsNet.Serialization.JsonNet.nuspec
56
SET NuGetExe=%ROOT%\Tools\NuGet.exe
67
SET NuGetOutDir=%ROOT%\Artifacts\NuGet
78

89
mkdir "%NuGetOutDir%"
910

10-
%NuGetExe% pack %MainLibNuspec% -Verbosity detailed -OutputDirectory "%NuGetOutDir%" -BasePath "%ROOT%" -Symbols
11+
%NuGetExe% pack %MainNuspec% -Verbosity detailed -OutputDirectory "%NuGetOutDir%" -BasePath "%ROOT%" -Symbols
12+
if %errorlevel% neq 0 exit /b %errorlevel%
13+
%NuGetExe% pack %UwpNuspec% -Verbosity detailed -OutputDirectory "%NuGetOutDir%" -BasePath "%ROOT%" -Symbols
14+
if %errorlevel% neq 0 exit /b %errorlevel%
15+
%NuGetExe% pack %SerializationNuspec% -Verbosity detailed -OutputDirectory "%NuGetOutDir%" -BasePath "%ROOT%" -Symbols
1116
if %errorlevel% neq 0 exit /b %errorlevel%
12-
%NuGetExe% pack %SerializationLibNuspec% -Verbosity detailed -OutputDirectory "%NuGetOutDir%" -BasePath "%ROOT%" -Symbols
13-
if %errorlevel% neq 0 exit /b %errorlevel%

Build/run-tests.bat

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ set LogDir=%ROOT%\Artifacts\Logs
44
set TestsBinDir=%ROOT%\Artifacts\Bin\Tests\AnyCPU_Release
55
mkdir %LogDir%
66

7-
%ROOT%\Tools\NUnit\nunit-console.exe "%TestsBinDir%\UnitsNet.Tests.dll" /framework="net-4.0" /xml:%LogDir%\UnitsNet.Tests.xml
7+
%ROOT%\Tools\NUnit\nunit-console.exe "%TestsBinDir%\UnitsNet.Tests.dll" /framework="net-4.5" /xml:%LogDir%\UnitsNet.Tests.xml
88
if %errorlevel% neq 0 exit /b %errorlevel%
99

10-
%ROOT%\Tools\NUnit\nunit-console.exe "%TestsBinDir%\UnitsNet.Serialization.JsonNet.Tests.dll" /framework="net-3.5" /xml:%LogDir%\UnitsNet.Serialization.JsonNet.Tests.xml
10+
%ROOT%\Tools\NUnit\nunit-console.exe "%TestsBinDir%\UnitsNet.WindowsRuntimeComponent.Tests.dll" /framework="net-4.5" /xml:%LogDir%\UnitsNet.WindowsRuntimeComponent.Tests.xml
11+
if %errorlevel% neq 0 exit /b %errorlevel%
12+
13+
%ROOT%\Tools\NUnit\nunit-console.exe "%TestsBinDir%\UnitsNet.Serialization.JsonNet.Tests.dll" /framework="net-4.5" /xml:%LogDir%\UnitsNet.Serialization.JsonNet.Tests.xml
1114
if %errorlevel% neq 0 exit /b %errorlevel%

Build/src.msbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<MSBuild Projects="
2121
$(SrcPath)\UnitsNet.Net35.csproj;
2222
$(SrcPath)\UnitsNet.Portable40.csproj;
23+
$(SrcPath)\UnitsNet.WindowsRuntimeComponent.csproj;
2324
$(SerializationSrcPath)\UnitsNet.Serialization.JsonNet.Net35.csproj"
2425
Properties="Platform=$(Platform);Configuration=$(Configuration);VisualStudioVersion=$(VisualStudioVersion);AllowUnsafeBlocks=true;Retries=15;RetryDelayMilliseconds=5"
2526
Targets="Build">

Build/tests.msbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<MSBuild Projects="
2121
$(TestsSrcPath)\UnitsNet.Tests.csproj;
22+
$(TestsSrcPath)\UnitsNet.WindowsRuntimeComponent.Tests.csproj;
2223
$(SerializationTestsSrcPath)\UnitsNet.Serialization.JsonNet.Tests.csproj"
2324
Properties="Platform=$(Platform);Configuration=$(Configuration);VisualStudioVersion=$(VisualStudioVersion);AllowUnsafeBlocks=true"
2425
Targets="Build">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/project.lock.json

UnitsNet.TestApps.Uwp.Csharp/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application
2+
x:Class="UWP.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:UWP"
6+
RequestedTheme="Light">
7+
8+
</Application>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.ApplicationModel;
7+
using Windows.ApplicationModel.Activation;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
namespace UWP
19+
{
20+
/// <summary>
21+
/// Provides application-specific behavior to supplement the default Application class.
22+
/// </summary>
23+
sealed partial class App : Application
24+
{
25+
/// <summary>
26+
/// Initializes the singleton application object. This is the first line of authored code
27+
/// executed, and as such is the logical equivalent of main() or WinMain().
28+
/// </summary>
29+
public App()
30+
{
31+
this.InitializeComponent();
32+
this.Suspending += OnSuspending;
33+
}
34+
35+
/// <summary>
36+
/// Invoked when the application is launched normally by the end user. Other entry points
37+
/// will be used such as when the application is launched to open a specific file.
38+
/// </summary>
39+
/// <param name="e">Details about the launch request and process.</param>
40+
protected override void OnLaunched(LaunchActivatedEventArgs e)
41+
{
42+
43+
#if DEBUG
44+
if (System.Diagnostics.Debugger.IsAttached)
45+
{
46+
this.DebugSettings.EnableFrameRateCounter = true;
47+
}
48+
#endif
49+
50+
Frame rootFrame = Window.Current.Content as Frame;
51+
52+
// Do not repeat app initialization when the Window already has content,
53+
// just ensure that the window is active
54+
if (rootFrame == null)
55+
{
56+
// Create a Frame to act as the navigation context and navigate to the first page
57+
rootFrame = new Frame();
58+
59+
rootFrame.NavigationFailed += OnNavigationFailed;
60+
61+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
62+
{
63+
//TODO: Load state from previously suspended application
64+
}
65+
66+
// Place the frame in the current Window
67+
Window.Current.Content = rootFrame;
68+
}
69+
70+
if (rootFrame.Content == null)
71+
{
72+
// When the navigation stack isn't restored navigate to the first page,
73+
// configuring the new page by passing required information as a navigation
74+
// parameter
75+
rootFrame.Navigate(typeof(MainPage), e.Arguments);
76+
}
77+
// Ensure the current window is active
78+
Window.Current.Activate();
79+
}
80+
81+
/// <summary>
82+
/// Invoked when Navigation to a certain page fails
83+
/// </summary>
84+
/// <param name="sender">The Frame which failed navigation</param>
85+
/// <param name="e">Details about the navigation failure</param>
86+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
87+
{
88+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
89+
}
90+
91+
/// <summary>
92+
/// Invoked when application execution is being suspended. Application state is saved
93+
/// without knowing whether the application will be terminated or resumed with the contents
94+
/// of memory still intact.
95+
/// </summary>
96+
/// <param name="sender">The source of the suspend request.</param>
97+
/// <param name="e">Details about the suspend request.</param>
98+
private void OnSuspending(object sender, SuspendingEventArgs e)
99+
{
100+
var deferral = e.SuspendingOperation.GetDeferral();
101+
//TODO: Save application state and stop any background activity
102+
deferral.Complete();
103+
}
104+
}
105+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Page
2+
x:Class="UWP.MainPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:UWP"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
10+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
11+
<TextBlock x:Name="MyTextBlock" Text="REPLACE ME" FontSize="30" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
12+
</Grid>
13+
</Page>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Windows.UI.Xaml.Controls;
2+
using UnitsNet;
3+
using UnitsNet.Units;
4+
5+
namespace UWP
6+
{
7+
/// <summary>
8+
/// An empty page that can be used on its own or navigated to within a Frame.
9+
/// </summary>
10+
public sealed partial class MainPage : Page
11+
{
12+
/// <summary>
13+
/// Example of public property returning WinRT component compatible type.
14+
/// </summary>
15+
public Temperature MyTemperature { get; set; }
16+
17+
public MainPage()
18+
{
19+
InitializeComponent();
20+
21+
// Test some variations, From() constructors, Parse(), As()
22+
string celsius = Temperature.FromDegreesCelsius(100).ToString(TemperatureUnit.DegreeCelsius);
23+
string fahrenheit = Temperature.Parse("100 °C").ToString(TemperatureUnit.DegreeFahrenheit);
24+
string kelvin = Temperature.FromDegreesCelsius(Temperature.Parse(fahrenheit).As(TemperatureUnit.DegreeCelsius)).ToString(TemperatureUnit.Kelvin);
25+
26+
// Arithmetic operators not allowed in WinRT Components, but SHOULD be allowed in UWP C# apps
27+
// new Temperature(5) + new Temperature(6)
28+
29+
MyTextBlock.Text = $"{celsius} = {fahrenheit} = {kelvin}";
30+
}
31+
}
32+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Package
4+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
6+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
7+
IgnorableNamespaces="uap mp">
8+
9+
<Identity
10+
Name="45616dde-b0ee-4de6-932f-5e98afa042c8"
11+
Publisher="CN=Andreas"
12+
Version="1.0.0.0" />
13+
14+
<mp:PhoneIdentity PhoneProductId="45616dde-b0ee-4de6-932f-5e98afa042c8" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
15+
16+
<Properties>
17+
<DisplayName>UWP</DisplayName>
18+
<PublisherDisplayName>Andreas</PublisherDisplayName>
19+
<Logo>Assets\StoreLogo.png</Logo>
20+
</Properties>
21+
22+
<Dependencies>
23+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
24+
</Dependencies>
25+
26+
<Resources>
27+
<Resource Language="x-generate"/>
28+
</Resources>
29+
30+
<Applications>
31+
<Application Id="App"
32+
Executable="$targetnametoken$.exe"
33+
EntryPoint="UWP.App">
34+
<uap:VisualElements
35+
DisplayName="UWP"
36+
Square150x150Logo="Assets\Square150x150Logo.png"
37+
Square44x44Logo="Assets\Square44x44Logo.png"
38+
Description="UWP"
39+
BackgroundColor="transparent">
40+
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
41+
<uap:SplashScreen Image="Assets\SplashScreen.png" />
42+
</uap:VisualElements>
43+
</Application>
44+
</Applications>
45+
46+
<Capabilities>
47+
<Capability Name="internetClient" />
48+
</Capabilities>
49+
</Package>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("UWP")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("UWP")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Version information for an assembly consists of the following four values:
18+
//
19+
// Major Version
20+
// Minor Version
21+
// Build Number
22+
// Revision
23+
//
24+
// You can specify all the values or you can default the Build and Revision Numbers
25+
// by using the '*' as shown below:
26+
// [assembly: AssemblyVersion("1.0.*")]
27+
[assembly: AssemblyVersion("1.0.0.0")]
28+
[assembly: AssemblyFileVersion("1.0.0.0")]
29+
[assembly: ComVisible(false)]

0 commit comments

Comments
 (0)