Skip to content

Commit

Permalink
Merge pull request #17 from felipebaltazar/features/server-driven-ui
Browse files Browse the repository at this point in the history
Using Server Driven UI
  • Loading branch information
felipebaltazar authored Feb 18, 2024
2 parents 948e2ba + 99ae532 commit 10d156d
Show file tree
Hide file tree
Showing 49 changed files with 123 additions and 2,718 deletions.
8 changes: 0 additions & 8 deletions Maui.AzurePipelines.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.AzurePipelines", "Maui.AzurePipelines\Maui.AzurePipelines.csproj", "{0A1E9EFA-1B0F-428F-B937-6D564D95DC1B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualListView", "VirtualListView\VirtualListView.csproj", "{41C4E8D9-565E-4C85-8ECF-2143A7F4C69B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -19,12 +17,6 @@ Global
{0A1E9EFA-1B0F-428F-B937-6D564D95DC1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A1E9EFA-1B0F-428F-B937-6D564D95DC1B}.Release|Any CPU.Build.0 = Release|Any CPU
{0A1E9EFA-1B0F-428F-B937-6D564D95DC1B}.Release|Any CPU.Deploy.0 = Release|Any CPU
{41C4E8D9-565E-4C85-8ECF-2143A7F4C69B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41C4E8D9-565E-4C85-8ECF-2143A7F4C69B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41C4E8D9-565E-4C85-8ECF-2143A7F4C69B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{41C4E8D9-565E-4C85-8ECF-2143A7F4C69B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41C4E8D9-565E-4C85-8ECF-2143A7F4C69B}.Release|Any CPU.Build.0 = Release|Any CPU
{41C4E8D9-565E-4C85-8ECF-2143A7F4C69B}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 10 additions & 0 deletions Maui.AzurePipelines/Abstractions/Data/IServerDrivenUIApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Maui.ServerDrivenUI;
using Refit;

namespace PipelineApproval.Abstractions.Data;

public interface IServerDrivenUIApi
{
[Get("/ServerDrivenUI?key={key}")]
Task<ServerUIElement> GetUIElementAsync(string key);
}
2 changes: 2 additions & 0 deletions Maui.AzurePipelines/Infrastructure/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static class Url

public const string GITHUB_REPOSIOTRY = "https://github.com/felipebaltazar/Maui.AzurePipelines";

public const string SERVER_DRIVEN_UI_API = "https://serverdrivenui.azurewebsites.net/";

public const string VISUALSTUDIO_API = "https://app.vssps.visualstudio.com";

public const string VSAEX_API = "https://vsaex.dev.azure.com";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using PipelineApproval.Abstractions;
using Newtonsoft.Json;
using PipelineApproval.Abstractions;
using PipelineApproval.Abstractions.Data;
using PipelineApproval.Abstractions.Views;
using PipelineApproval.Infrastructure.Services;
using Refit;
using System.Diagnostics;
using System.Text.Json.Serialization;
using static PipelineApproval.Infrastructure.Constants.Url;

namespace PipelineApproval.Infrastructure.Extensions;
Expand Down Expand Up @@ -51,6 +53,14 @@ public static IServiceCollection AddAzureApiService(this IServiceCollection serv
return serviceCollection;
}

public static IServiceCollection AddServerDrivenUIApi(this IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton((s) =>
BuildWithFactory<IServerDrivenUIApi>(s, SERVER_DRIVEN_UI_API));

return serviceCollection;
}

private static T BuildWithFactory<T>(IServiceProvider s, string url)
{
var factory = s.GetService<IHttpClientFactory>();
Expand Down
123 changes: 60 additions & 63 deletions Maui.AzurePipelines/Maui.AzurePipelines.csproj
Original file line number Diff line number Diff line change
@@ -1,89 +1,86 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0-android;net7.0-ios</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>PipelineApproval</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios17</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>PipelineApproval</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>
<!-- Display name -->
<ApplicationTitle>Pipeline Approval</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.maui.azurepipeline.approval</ApplicationId>
<ApplicationIdGuid>0ca34389-c908-4e1f-a379-616128afa759</ApplicationIdGuid>

<!-- Versions -->
<ApplicationDisplayVersion>1.2</ApplicationDisplayVersion>
<ApplicationVersion>3</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
<CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
<!-- Display name -->
<ApplicationTitle>Pipeline Approval</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.maui.azurepipeline.approval</ApplicationId>
<ApplicationIdGuid>0ca34389-c908-4e1f-a379-616128afa759</ApplicationIdGuid>

<!-- Versions -->
<ApplicationDisplayVersion>1.2</ApplicationDisplayVersion>
<ApplicationVersion>3</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios17|AnyCPU'">
<CreatePackage>false</CreatePackage>
<CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios17|AnyCPU'">
<CreatePackage>false</CreatePackage>
<ArchiveOnBuild>true</ArchiveOnBuild>
<CodesignKey>Apple Distribution: Felipe Baltazar (2L36GLR2GS)</CodesignKey>
<CodesignProvision>Apple Distribution Devops Approval</CodesignProvision>
<CodesignKey>Apple Distribution: Felipe Baltazar (2L36GLR2GS)</CodesignKey>
<CodesignProvision>Apple Distribution Devops Approval</CodesignProvision>
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-android|AnyCPU'">
<AndroidKeyStore>True</AndroidKeyStore>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
<AndroidKeyStore>True</AndroidKeyStore>
<AndroidSigningKeyStore>devopsapproval.keystore</AndroidSigningKeyStore>
</PropertyGroup>
<ItemGroup>
</PropertyGroup>

<ItemGroup>
<!-- Icons for IOS -->
<MauiIcon Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'" Include="Resources\AppIcon\appicon.svg" BaseSize="512,512" Color="#000000" />

<!-- Splash for IOS -->
<MauiSplashScreen Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'" Include="Resources\Splash\splash.svg" Color="#000000" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Include="Resources\Images\*" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />

<Folder Include="Resources\AppIcon\" />

<!-- Android native resources -->
<AndroidResource Include="Platforms\Android\drawable\**" />
<AndroidResource Include="Platforms\Android\drawable\**" />
<AndroidResource Include="Platforms\Android\layout\**" />
<AndroidResource Include="Platforms\Android\mipmap*\**" />
<None Remove="pre-release.apk" />
<AndroidEnvironment Include="Platforms\Android\GarbageCollector.config" />
</ItemGroup>


<!-- Packages -->
<ItemGroup>
<PackageReference Include="CompiledBindings.MAUI" Version="1.0.16" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Mopups" Version="1.1.1" />
<PackageReference Include="Polly" Version="7.2.4" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="DotNetMeteor.HotReload.Plugin" Version="3.*" />
<ProjectReference Include="..\VirtualListView\VirtualListView.csproj" />
<ItemGroup>
<PackageReference Include="CompiledBindings.MAUI" Version="1.0.17.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Mopups" Version="1.3.0" />
<PackageReference Include="Polly" Version="8.3.0" />
<PackageReference Include="Redth.Maui.VirtualListView" Version="0.3.1" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="DotNetMeteor.HotReload.Plugin" Version="3.*" />
<PackageReference Include="ServerDrivenUI.Maui" Version="8.0.31-pre" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
</ItemGroup>
<ItemGroup>
<MauiXaml Update="Presentation\Views\Controls\OrganizationLoginPopup.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\AppIcon\" />
</ItemGroup>

</Project>
30 changes: 24 additions & 6 deletions Maui.AzurePipelines/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
using PipelineApproval.Presentation.Views.Controls;
using PipelineApproval.Presentation.Views.Pages;
using Microsoft.Maui.Handlers;

using Maui.ServerDrivenUI;
using PipelineApproval.Abstractions.Data;
using System.Diagnostics;
using TaskExtensions = PipelineApproval.Infrastructure.Extensions.TaskExtensions;

#if DEBUG
using DotNet.Meteor.HotReload.Plugin;
Expand All @@ -22,6 +25,13 @@ public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
TaskExtensions.SetDefaultExceptionHandling(ex => {
Debug.Write(ex.ToString());

if(Debugger.IsAttached)
Debugger.Break();
});

var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
Expand All @@ -33,8 +43,17 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("DevOpsIcons.ttf", "DevOpsIcons");
fonts.AddFont("FontAwesomeSolid.otf", "FontAwesomeSolid");
})
.ConfigureServerDrivenUI(s =>
{
s.UIElementCacheExpiration = TimeSpan.FromMinutes(1);

s.RegisterElementGetter((key, provider) =>
provider.GetService<IServerDrivenUIApi>().GetUIElementAsync(key));

s.AddServerElement("595597a8-25df-4d60-99f4-4b5bad595403");
})
.ConfigureMopups();

#if DEBUG
builder.EnableHotReload()
.Logging.AddDebug();
Expand All @@ -51,12 +70,10 @@ public static MauiApp CreateMauiApp()

private static void ConfigureHandlers()
{
EntryHandler.Mapper.AppendToMapping(nameof(Entry), (handler, view) =>
{
#if ANDROID
handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Transparent);
EntryHandler.Mapper.AppendToMapping(nameof(Entry),
(handler, view) => handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Transparent));
#endif
});
}

private static void RegisterPopups(IServiceCollection sCollection)
Expand Down Expand Up @@ -93,5 +110,6 @@ private static void RegisterServices(IServiceCollection sCollection)
sCollection.AddSingleton<ILazyDependency<ILoaderService>, LazyDependency<ILoaderService>>();

sCollection.AddAzureApiService();
sCollection.AddServerDrivenUIApi();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using Maui.ServerDrivenUI;
using Microsoft.Extensions.Logging;
using PipelineApproval.Abstractions;
using PipelineApproval.Abstractions.Views;
using PipelineApproval.Infrastructure.Commands;
Expand All @@ -15,7 +16,7 @@ public class MainPageViewModel : BaseViewModel, IInitializeAware
private readonly ISecureStorageService _secureStorageService;
private readonly IPreferencesService _preferencesService;
private readonly IAzureService _azureService;

private readonly IServerDrivenUIService _serverDrivenUIService;
private string _url;

private string company;
Expand Down Expand Up @@ -93,6 +94,7 @@ public MainPageViewModel(
ISecureStorageService secureStorageService,
IPreferencesService preferencesService,
IMainThreadService mainThreadService,
IServerDrivenUIService serverDrivenUIService,
IAzureService azureService,
ILogger logger)
: base(
Expand All @@ -104,10 +106,12 @@ public MainPageViewModel(
_secureStorageService = secureStorageService;
_preferencesService = preferencesService;
_azureService = azureService;
_serverDrivenUIService = serverDrivenUIService;
}

public async Task InitializeAsync(IDictionary<string, string> parameters)
{
//await _serverDrivenUIService.ClearCacheAsync();
accountApiResponse = parameters.GetValueOrDefault<AccountResponseApi>(Constants.Navigation.ACCOUNT_PARAMETER);

await ExecuteBusyActionAsync(async () =>
Expand Down
Loading

0 comments on commit 10d156d

Please sign in to comment.