Skip to content

Commit

Permalink
test: Add more Package properties to sample page
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Oct 5, 2022
1 parent df1af0d commit fa4033c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,25 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_ApplicationModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:generic="using:System.Collections.Generic"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<Style TargetType="TextBlock" x:Key="LabelStyle">
<Setter Property="FontWeight" Value="Bold" />
</Style>
</UserControl.Resources>
<StackPanel Margin="12" Spacing="4">
<TextBlock Text="Display Name" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind DisplayName}" />
<TextBlock Text="Architecture" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind Architecture}" />
<TextBlock Text="FamilyName" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind FamilyName}" />
<TextBlock Text="FullName" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind FullName}" />
<TextBlock Text="Name" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind Name}" />
<TextBlock Text="ProductId" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind ProductId}" />
<TextBlock Text="Publisher" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind Publisher}" />
<TextBlock Text="PublisherId" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind PublisherId}" />
<TextBlock Text="ResourceId" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind ResourceId}" />
<TextBlock Text="Version" Style="{StaticResource LabelStyle}" />
<TextBlock Text="{x:Bind Version}" />
</StackPanel>
<ListView ItemsSource="{x:Bind Items}" Margin="12">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:PackageProperty">
<StackPanel Orientation="Horizontal">
<TextBlock>
<Run Text="{x:Bind Name}" FontWeight="Bold" /><Run Text=":" />
<Run Text="{x:Bind Value}" />
</TextBlock>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Uno.UI.Samples.Controls;
using Windows.ApplicationModel;
using Windows.System;
Expand All @@ -13,31 +15,68 @@ public sealed partial class PackageTests : UserControl
public PackageTests()
{
this.InitializeComponent();
DisplayName = SafeSet(() => Package.Current.DisplayName);
var packageId = Package.Current.Id;
Architecture = SafeSet(() => packageId.Architecture);
FamilyName = SafeSet(() => packageId.FamilyName);
FullName = SafeSet(() => packageId.FullName);
Name = SafeSet(() => packageId.Name);
Publisher = SafeSet(() => packageId.Publisher);
PublisherId = SafeSet(() => packageId.PublisherId);
ResourceId = SafeSet(() => packageId.ResourceId);
Version = SafeSet(() => $"{packageId.Version.Major}.{packageId.Version.Minor}.{packageId.Version.Revision}.{packageId.Version.Build}");

AddProperties(Package.Current);
}

private string SafeSet(Func<object> propertyGetter)
public void AddProperties(Package package)
{
SafeAdd("DisplayName", () => package.DisplayName);
SafeAdd("Description", () => package.Description);
SafeAdd("EffectiveExternalLocation", () => package.EffectiveExternalLocation.Path);
SafeAdd("EffectiveExternalPath", () => package.EffectiveExternalPath);
SafeAdd("EffectiveLocation", () => package.EffectiveLocation.Path);
SafeAdd("EffectivePath", () => package.EffectivePath);
SafeAdd("Status", () => package.Status);
SafeAdd("PublisherDisplayName", () => package.PublisherDisplayName);
SafeAdd("InstallDate", () => package.InstallDate);
SafeAdd("InstalledDate", () => package.InstalledDate);
SafeAdd("InstalledLocation", () => package.InstalledLocation.Path);
SafeAdd("InstalledPath", () => package.InstalledPath);
SafeAdd("IsBundle", () => package.IsBundle);
SafeAdd("IsDevelopmentMode", () => package.IsDevelopmentMode);
SafeAdd("IsFramework", () => package.IsFramework);
SafeAdd("IsOptional", () => package.IsOptional);
SafeAdd("IsResourcePackage", () => package.IsResourcePackage);
SafeAdd("IsStub", () => package.IsStub);
SafeAdd("Logo", () => package.Logo);
SafeAdd("MachineExternalLocation", () => package.MachineExternalLocation.Path);
SafeAdd("MachineExternalPath", () => package.MachineExternalPath);
SafeAdd("MutableLocation", () => package.MutableLocation);
SafeAdd("MutablePath", () => package.MutablePath);
SafeAdd("SignatureKind", () => package.SignatureKind);
SafeAdd("UserExternalLocation", () => package.UserExternalLocation.Path);
SafeAdd("UserExternalPath", () => package.UserExternalPath);
SafeAdd("Id.Architecture", () => package.Id.Architecture);
SafeAdd("Id.FamilyName", () => package.Id.FamilyName);
SafeAdd("Id.FullName", () => package.Id.FullName);
SafeAdd("Id.Name", () => package.Id.Name);
SafeAdd("Id.Publisher", () => package.Id.Publisher);
SafeAdd("Id.PublisherId", () => package.Id.PublisherId);
SafeAdd("Id.ResourceId", () => package.Id.ResourceId);
SafeAdd("Id.Version", () => $"{package.Id.Version.Major}.{package.Id.Version.Minor}.{package.Id.Version.Revision}.{package.Id.Version.Build}");
}

public ObservableCollection<PackageProperty> Items { get; } = new ObservableCollection<PackageProperty>();

private void SafeAdd(string propertyName, Func<object> propertyGetter)
{
try
{
return propertyGetter()?.ToString() ?? "(null)";
var value = propertyGetter()?.ToString() ?? "(null)";
Items.Add(new PackageProperty(propertyName, value));
}
catch (NotImplementedException)
{
return "Not implemented";
Items.Add(new PackageProperty(propertyName, "Not implemented"));
}
catch (NotSupportedException)
{
Items.Add(new PackageProperty(propertyName, "Not supported"));
}
catch (Exception ex)
{
return $"Exception thrown - {ex.Message}";
Items.Add(new PackageProperty(propertyName, $"Exception thrown - {ex.Message}"));
}
}

Expand All @@ -61,4 +100,17 @@ private string SafeSet(Func<object> propertyGetter)

public string Version { get; }
}

public class PackageProperty
{
public PackageProperty(string name, string value)
{
Name = name;
Value = value;
}

public string Name { get; }

public string Value { get; }
}
}

0 comments on commit fa4033c

Please sign in to comment.