Refactor build script for AppService tokens

このコミットが含まれているのは:
Sergio Pedri committed 2023-01-17 00:28:53 +01:00
1 親 5010c90ef8
コミット 271012dc51
6ファイル変更
+96 -57

検索条件に一致するファイルはありません

-34
ファイルの表示
@@ -1,34 +0,0 @@
# Create the tokens folder
$TOKENS_FOLDER_RELATIVE_PATH = Join-Path -Path $PSScriptRoot -ChildPath "..\samples\ComputeSharp.SwapChain.Uwp\Assets\ServiceTokens"
if(!(Test-Path -Path $TOKENS_FOLDER_RELATIVE_PATH)) {
New-Item -ItemType directory -Path $TOKENS_FOLDER_RELATIVE_PATH
}
$TOKENS_FOLDER_PATH = Resolve-Path -Path $TOKENS_FOLDER_RELATIVE_PATH
# AppCenter tokens
$APPCENTER_TOKENS_NAME = "App.AppCenter.cs"
$APPCENTER_TOKENS_PATH = Join-Path -Path $TOKENS_FOLDER_PATH -ChildPath $APPCENTER_TOKENS_NAME
if (!(Test-Path -Path $APPCENTER_TOKENS_PATH))
{
# Prepare the generated source
$APP_APPCENTER_TEXT =
@"
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace ComputeSharp.SwapChain.Uwp;
/// <inheritdoc/>
partial class App
{
/// <summary>
/// The secret token for the AppService connection.
/// </summary>
private const string AppServiceSecret = "";
}
"@.Trim()
# Output the source to the target file
Add-Content $APP_APPCENTER_TEXT -Path $APPCENTER_TOKENS_PATH -NoNewline
}
+40
ファイルの表示
@@ -0,0 +1,40 @@
# Create the service tokens folder
$SERVICE_TOKENS_FOLDER_RELATIVE_PATH = Join-Path -Path $PSScriptRoot -ChildPath "..\samples\ComputeSharp.SwapChain.Uwp\Assets\Generated"
if(!(Test-Path -Path $SERVICE_TOKENS_FOLDER_RELATIVE_PATH)) {
New-Item -ItemType directory -Path $SERVICE_TOKENS_FOLDER_RELATIVE_PATH
}
$SERVICE_TOKENS_FOLDER_PATH = Resolve-Path -Path $SERVICE_TOKENS_FOLDER_RELATIVE_PATH
# Service tokens
$SERVICE_TOKENS_NAME = "ServiceTokens.g.cs"
$SERVICE_TOKENS_PATH = Join-Path -Path $SERVICE_TOKENS_FOLDER_PATH -ChildPath $SERVICE_TOKENS_NAME
if (!(Test-Path -Path $SERVICE_TOKENS_PATH))
{
# Prepare the generated source
$SERVICE_TOKENS_TEXT =
@"
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace ComputeSharp.SwapChain.Uwp;
/// <summary>
/// A <see langword="class"/> with some secret service tokens.
/// </summary>
public static class ServiceTokens
{
/// <summary>
/// The secret token for the AppService connection.
/// </summary>
#if RELEASE
internal const string AppService = "<APP_CENTER_TOKEN>";
#else
internal const string AppService = "";
#endif
}
"@.Trim()
# Output the source to the target file
Add-Content $SERVICE_TOKENS_TEXT -Path $SERVICE_TOKENS_PATH -NoNewline
}
+2 -21
ファイルの表示
@@ -1,13 +1,6 @@
#if !DEBUG
using System;
using System.Diagnostics;
#endif
using CommunityToolkit.Mvvm.DependencyInjection;
using ComputeSharp.SwapChain.Core.Services;
using ComputeSharp.SwapChain.Core.ViewModels;
#if !DEBUG
using ComputeSharp.SwapChain.Uwp.Services;
#endif
using ComputeSharp.SwapChain.Uwp.Views;
using Microsoft.Extensions.DependencyInjection;
using Windows.ApplicationModel.Activation;
@@ -59,20 +52,8 @@ sealed partial class App : Application
{
ServiceCollection services = new();
#if !DEBUG
if (Guid.TryParse(AppServiceSecret, out _) && !Debugger.IsAttached)
{
services.AddSingleton<IAnalyticsService>(new AppCenterService(AppServiceSecret));
}
else
{
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
}
#else
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
#endif
services.AddTransient<MainViewModel>();
_ = services.AddAnalyticsService();
_ = services.AddTransient<MainViewModel>();
Ioc.Default.ConfigureServices(services.BuildServiceProvider());
}
+20
ファイルの表示
@@ -0,0 +1,20 @@
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace ComputeSharp.SwapChain.Uwp;
/// <summary>
/// A <see langword="class"/> with some secret service tokens.
/// </summary>
public static class ServiceTokens
{
/// <summary>
/// The secret token for the AppService connection.
/// </summary>
#if RELEASE
internal const string AppService = "<APP_CENTER_TOKEN>";
#else
internal const string AppService = "";
#endif
}
+3 -2
ファイルの表示
@@ -78,9 +78,10 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Assets\ServiceTokens\App.AppCenter.cs" />
<Compile Include="Assets\Generated\ServiceTokens.g.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\AppCenterService.cs" />
<Compile Include="Services\ServiceCollectionExtensions.cs" />
<Compile Include="Views\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
</Compile>
@@ -209,6 +210,6 @@
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)\build\CreateBlankAppCenterToken.ps1</PreBuildEvent>
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)\build\CreateBlankServiceTokens.ps1</PreBuildEvent>
</PropertyGroup>
</Project>
+31
ファイルの表示
@@ -0,0 +1,31 @@
using System;
using System.Diagnostics;
using ComputeSharp.SwapChain.Core.Services;
using Microsoft.Extensions.DependencyInjection;
namespace ComputeSharp.SwapChain.Uwp.Services;
/// <summary>
/// Extensions for the <see cref="ServiceCollection"/> type.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the correct <see cref="IAnalyticsService"/> registration to the given <see cref="IServiceCollection"/> instance.
/// </summary>
/// <param name="services">The input <see cref="IServiceCollection"/> instance to use to register services.</param>
/// <returns>The same instance as <paramref name="services"/>.</returns>
public static IServiceCollection AddAnalyticsService(this IServiceCollection services)
{
if (Guid.TryParse(ServiceTokens.AppService, out _) && !Debugger.IsAttached)
{
_ = services.AddSingleton<IAnalyticsService>(new AppCenterService(ServiceTokens.AppService));
}
else
{
_ = services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
}
return services;
}
}