Skip to content

Commit

Permalink
feat(templates): add AppCenter monitoring to Boilerplate #7733 (#7734)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Jun 7, 2024
1 parent ab62d36 commit 25292df
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 24 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/admin-sample.cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
cd src\Templates\Boilerplate && dotnet build -c Release
dotnet pack -c Release -o . -p:ReleaseVersion=0.0.0 -p:PackageVersion=0.0.0
dotnet new install Bit.Boilerplate.0.0.0.nupkg
cd ..\..\..\ && dotnet new bit-bp --name AdminPanel --database SqlServer --sample Admin --windows --appInsights --serverUrl adminpanel.bitplatform.dev
cd ..\..\..\ && dotnet new bit-bp --name AdminPanel --database SqlServer --sample Admin --windows --appInsights --appCenter --serverUrl adminpanel.bitplatform.dev
- name: Update appsettings.json api server address
uses: devops-actions/[email protected]
Expand All @@ -151,6 +151,10 @@ jobs:
- name: Generate CSS/JS files
run: dotnet build AdminPanel\src\Client\AdminPanel.Client.Core\AdminPanel.Client.Core.csproj -t:InstallNodejsDependencies,BeforeBuildTasks -p:Version="${{ vars.APPLICATION_DISPLAY_VERSION}}" --no-restore

- name: Set app center secret
run: (Get-Content AdminPanel\src\Client\AdminPanel.Client.Windows\Program.cs) -Replace 'appCenterSecret = null;', 'appCenterSecret = "a9ed2257-fb82-496a-ba10-78c2d9ef33a6";' | Out-File -Encoding utf8 AdminPanel\src\Client\AdminPanel.Client.Windows\Program.cs
shell: pwsh

- name: Publish
run: |
cd AdminPanel\src\Client\AdminPanel.Client.Windows\
Expand Down Expand Up @@ -194,7 +198,7 @@ jobs:
cd src/Templates/Boilerplate && dotnet build -c Release
dotnet pack -c Release -o . -p:ReleaseVersion=0.0.0 -p:PackageVersion=0.0.0
dotnet new install Bit.Boilerplate.0.0.0.nupkg
cd ../../../ && dotnet new bit-bp --name AdminPanel --database SqlServer --sample Admin --appInsights --serverUrl adminpanel.bitplatform.dev
cd ../../../ && dotnet new bit-bp --name AdminPanel --database SqlServer --sample Admin --appInsights --appCenter --serverUrl adminpanel.bitplatform.dev
- uses: actions/setup-node@v4
with:
Expand All @@ -215,6 +219,10 @@ jobs:
ApiServerAddress: ${{ env.API_SERVER_ADDRESS }}
ApplicationInsights.ConnectionString: ${{ secrets.APPLICATION_INSIGHTS_CONNECTION_STRING }}

- name: Set app center secret
run: |
sed -i 's/appCenterSecret = null;/appCenterSecret = "ea9b98ea-93a0-48c7-982a-0a72f4ad6d04";/g' AdminPanel/src/Client/AdminPanel.Client.Maui/MauiProgram.cs
- name: Install maui
run: cd src && dotnet workload install maui-android

Expand Down Expand Up @@ -262,7 +270,7 @@ jobs:
cd src/Templates/Boilerplate && dotnet build -c Release
dotnet pack -c Release -o . -p:ReleaseVersion=0.0.0 -p:PackageVersion=0.0.0
dotnet new install Bit.Boilerplate.0.0.0.nupkg
cd ../../../ && dotnet new bit-bp --name AdminPanel --database SqlServer --sample Admin --appInsights --serverUrl adminpanel.bitplatform.dev
cd ../../../ && dotnet new bit-bp --name AdminPanel --database SqlServer --sample Admin --appInsights --appCenter --serverUrl adminpanel.bitplatform.dev
- name: Update appsettings.json api server address
uses: devops-actions/[email protected]
Expand All @@ -272,6 +280,10 @@ jobs:
ApiServerAddress: ${{ env.API_SERVER_ADDRESS }}
ApplicationInsights.ConnectionString: ${{ secrets.APPLICATION_INSIGHTS_CONNECTION_STRING }}

- name: Set app center secret
run: |
sed -i 's/appCenterSecret = null;/appCenterSecret = "0bc0d910-dc84-4887-a3a0-eee6b1b55797";/g' AdminPanel/src/Client/AdminPanel.Client.Maui/MauiProgram.cs
- name: Install maui
run: cd src && dotnet workload install maui

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bit.full.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Release build admin panel sample + SqlServer database
run: |
dotnet new bit-bp --name AdminBPSqlServer --database sqlserver --sample admin --pipeline github --serverUrl adminpanel.bitplatform.dev
dotnet new bit-bp --name AdminBPSqlServer --database sqlserver --sample admin --pipeline github --serverUrl adminpanel.bitplatform.dev --appInsights --appCenter
dotnet build AdminBPSqlServer/AdminBPSqlServer.sln -c Release
- name: Install Nodejs dependencies
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/todo-sample.cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
cd src\Templates\Boilerplate && dotnet build -c Release
dotnet pack -c Release -o . -p:ReleaseVersion=0.0.0 -p:PackageVersion=0.0.0
dotnet new install Bit.Boilerplate.0.0.0.nupkg
cd ..\..\..\ && dotnet new bit-bp --name TodoSample --database SqlServer --sample Todo --windows --appInsights --serverUrl todo.bitplatform.dev
cd ..\..\..\ && dotnet new bit-bp --name TodoSample --database SqlServer --sample Todo --windows --appInsights --appCenter --serverUrl todo.bitplatform.dev
- name: Update appsettings.json api server address
uses: devops-actions/[email protected]
Expand All @@ -162,6 +162,10 @@ jobs:
ApiServerAddress: ${{ env.API_SERVER_ADDRESS }}
WindowsUpdateSettings.FilesUrl: https://windows-todo.bitplatform.dev
ApplicationInsights.ConnectionString: ${{ secrets.APPLICATION_INSIGHTS_CONNECTION_STRING }}

- name: Set app center secret
run: (Get-Content TodoSample\src\Client\TodoSample.Client.Windows\Program.cs) -Replace 'appCenterSecret = null;', 'appCenterSecret = "39f576f2-7c16-4990-af3f-7b70509d41e2";' | Out-File -Encoding utf8 TodoSample\src\Client\TodoSample.Client.Windows\Program.cs
shell: pwsh

- name: Generate CSS/JS files
run: dotnet build TodoSample\src\Client\TodoSample.Client.Core\TodoSample.Client.Core.csproj -t:InstallNodejsDependencies,BeforeBuildTasks -p:Version="${{ vars.APPLICATION_DISPLAY_VERSION}}" --no-restore
Expand Down Expand Up @@ -213,7 +217,7 @@ jobs:
cd src/Templates/Boilerplate && dotnet build -c Release
dotnet pack -c Release -o . -p:ReleaseVersion=0.0.0 -p:PackageVersion=0.0.0
dotnet new install Bit.Boilerplate.0.0.0.nupkg
cd ../../../ && dotnet new bit-bp --name TodoSample --database SqlServer --sample Todo --appInsights --serverUrl todo.bitplatform.dev
cd ../../../ && dotnet new bit-bp --name TodoSample --database SqlServer --sample Todo --appInsights --appCenter --serverUrl todo.bitplatform.dev
- name: Extract Android signing key from env
uses: timheuer/[email protected]
Expand All @@ -230,6 +234,10 @@ jobs:
ApiServerAddress: ${{ env.API_SERVER_ADDRESS }}
ApplicationInsights.ConnectionString: ${{ secrets.APPLICATION_INSIGHTS_CONNECTION_STRING }}

- name: Set app center secret
run: |
sed -i 's/appCenterSecret = null;/appCenterSecret = "de0219a6-fdcd-44f7-8c28-c108331ed27c";/g' TodoSample/src/Client/TodoSample.Client.Maui/MauiProgram.cs
- name: Install maui
run: cd src && dotnet workload install maui-android

Expand Down Expand Up @@ -297,7 +305,7 @@ jobs:
cd src/Templates/Boilerplate && dotnet build -c Release
dotnet pack -c Release -o . -p:ReleaseVersion=0.0.0 -p:PackageVersion=0.0.0
dotnet new install Bit.Boilerplate.0.0.0.nupkg
cd ../../../ && dotnet new bit-bp --name TodoSample --database SqlServer --sample Todo --appInsights --serverUrl todo.bitplatform.dev
cd ../../../ && dotnet new bit-bp --name TodoSample --database SqlServer --sample Todo --appInsights --appCenter --serverUrl todo.bitplatform.dev
- name: Update appsettings.json api server address
uses: devops-actions/[email protected]
Expand All @@ -307,6 +315,10 @@ jobs:
ApiServerAddress: ${{ env.API_SERVER_ADDRESS }}
ApplicationInsights.ConnectionString: ${{ secrets.APPLICATION_INSIGHTS_CONNECTION_STRING }}

- name: Set app center secret
run: |
sed -i 's/appCenterSecret = null;/appCenterSecret = "f72e6774-1c83-404c-bca8-6e5198fb8e0e";/g' TodoSample/src/Client/TodoSample.Client.Maui/MauiProgram.cs
- name: Install maui
run: cd src && dotnet workload install maui

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@
"datatype": "bool",
"defaultValue": "false"
},
"appCenter": {
"displayName": "Add Visual Studio AppCenter to project?",
"type": "parameter",
"datatype": "bool",
"defaultValue": "false"
},
"nameToLower": {
"type": "generated",
"generator": "casing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
"LogLevel": {
"Default": "Information"
},
//#if (appCenter == true)
"AppCenterLoggerProvider": {
"LogLevel": {
"Default": "Information"
}
},
//#endif
//#if (appInsights == true)
"ApplicationInsights": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
"Boilerplate.Client.Core.Components.AuthenticationStateLogger": "Information",
"Microsoft.EntityFrameworkCore.Database.Command": "Information"
},
//#if (appCenter == true)
"AppCenterLoggerProvider": {
"LogLevel": {
"Default": "Warning",
"Boilerplate.Client.Core.Components.AuthenticationStateLogger": "Information",
"Microsoft.EntityFrameworkCore.Database.Command": "Information"
}
},
//#endif
//#if (appInsights == true)
"ApplicationInsights": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" Version="8.0.0" />
<!--/+:msbuild-conditional:noEmit -->
<PackageReference Condition=" '$(appCenter)' == 'true' OR '$(appCenter)' == '' " Include="Microsoft.AppCenter.Analytics" Version="5.0.5" />
<PackageReference Condition=" '$(appCenter)' == 'true' OR '$(appCenter)' == '' " Include="Microsoft.AppCenter.Crashes" Version="5.0.5" />
<PackageReference Condition=" '$(appCenter)' == 'true' OR '$(appCenter)' == '' " Include="West.Extensions.Logging.AppCenter" Version="2.2.2" />
<PackageReference Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.22.0" />
<!--/-:msbuild-conditional:noEmit -->
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public static void ConfigureServices(this MauiAppBuilder builder)
builder.Logging.AddEventSourceLogger();

//+:cnd:noEmit

//#if (appCenter == true)
if (Microsoft.AppCenter.AppCenter.Configured)
{
builder.Logging.AddAppCenter(options => { });
}
//#endif

//#if (appInsights == true)
builder.Logging.AddApplicationInsights(config =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//-:cnd:noEmit
using Microsoft.Maui.LifecycleEvents;
using Maui.AppStores;
using Maui.InAppReviews;
using Maui.Android.InAppUpdates;
using Microsoft.Maui.LifecycleEvents;
using Boilerplate.Client.Core;
#if IOS || MACCATALYST
using UIKit;
Expand All @@ -16,6 +16,16 @@ public static partial class MauiProgram
{
public static MauiApp CreateMauiApp()
{
//+:cnd:noEmit
//#if (appCenter == true)
string? appCenterSecret = null;
if (appCenterSecret is not null)
{
Microsoft.AppCenter.AppCenter.Start(appCenterSecret, typeof(Microsoft.AppCenter.Crashes.Crashes), typeof(Microsoft.AppCenter.Analytics.Analytics));
}
//#endif
//-:cnd:noEmit

AppRenderMode.IsBlazorHybrid = true;

var builder = MauiApp.CreateBuilder();
Expand Down Expand Up @@ -117,28 +127,28 @@ private static void SetupBlazorWebView()
}
}
#elif ANDROID
webView.SetBackgroundColor(Android.Graphics.Color.Transparent);
webView.SetBackgroundColor(Android.Graphics.Color.Transparent);

webView.OverScrollMode = Android.Views.OverScrollMode.Never;
webView.OverScrollMode = Android.Views.OverScrollMode.Never;

webView.HapticFeedbackEnabled = false;
webView.HapticFeedbackEnabled = false;

Android.Webkit.WebSettings settings = webView.Settings;
Android.Webkit.WebSettings settings = webView.Settings;

settings.AllowFileAccessFromFileURLs =
settings.AllowUniversalAccessFromFileURLs =
settings.AllowContentAccess =
settings.AllowFileAccess =
settings.DatabaseEnabled =
settings.JavaScriptCanOpenWindowsAutomatically =
settings.DomStorageEnabled = true;
settings.AllowFileAccessFromFileURLs =
settings.AllowUniversalAccessFromFileURLs =
settings.AllowContentAccess =
settings.AllowFileAccess =
settings.DatabaseEnabled =
settings.JavaScriptCanOpenWindowsAutomatically =
settings.DomStorageEnabled = true;

if (BuildConfiguration.IsDebug())
{
settings.MixedContentMode = Android.Webkit.MixedContentHandling.AlwaysAllow;
}
if (BuildConfiguration.IsDebug())
{
settings.MixedContentMode = Android.Webkit.MixedContentHandling.AlwaysAllow;
}

settings.BlockNetworkLoads = settings.BlockNetworkImage = false;
settings.BlockNetworkLoads = settings.BlockNetworkImage = false;
#endif
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2535.41" />
<PackageReference Include="Velopack" Version="0.0.503-gc69e323" />
<!--/+:msbuild-conditional:noEmit -->
<PackageReference Condition=" '$(appCenter)' == 'true' OR '$(appCenter)' == '' " Include="Microsoft.AppCenter.Analytics" Version="5.0.5" />
<PackageReference Condition=" '$(appCenter)' == 'true' OR '$(appCenter)' == '' " Include="Microsoft.AppCenter.Crashes" Version="5.0.5" />
<PackageReference Condition=" '$(appCenter)' == 'true' OR '$(appCenter)' == '' " Include="West.Extensions.Logging.AppCenter" Version="2.2.2" />
<PackageReference Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.22.0" />
<!--/-:msbuild-conditional:noEmit -->
<Content Include="..\Boilerplate.Client.Maui\wwwroot\index.html" Link="wwwroot\index.html">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public static void ConfigureServices(this IServiceCollection services)
loggingBuilder.AddDebug();
}
loggingBuilder.AddConsole();
//#if (appCenter == true)
if (Microsoft.AppCenter.AppCenter.Configured)
{
loggingBuilder.AddAppCenter(options => { });
}
//#endif
//#if (appInsights == true)
loggingBuilder.AddApplicationInsights(config =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ public partial class Program
[STAThread]
public static void Main(string[] args)
{
//+:cnd:noEmit
//#if (appCenter == true)
string? appCenterSecret = null;
if (appCenterSecret is not null)
{
Microsoft.AppCenter.AppCenter.Start(appCenterSecret, typeof(Microsoft.AppCenter.Crashes.Crashes), typeof(Microsoft.AppCenter.Analytics.Analytics));
}
//#endif
//-:cnd:noEmit

// https://github.com/velopack/velopack
VelopackApp.Build().Run();
var application = new App();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dotnet new bit-bp</pre>
<li>--offlineDb defaults to false: '--offlineDb true' adds sqlite database support to the client mobile, web and desktop apps</li>
<li>--windows default to false: '--windows true' adds support for exe output for windows 7+</li>
<li>--appInsights defaults to false: '--appInsights true' adds support for Azure application insights in all clients (Android, iOS, Windows, macOS, Web)</li>
<li>--appCenter defaults to false: '--appCenter true' adds support for Visual Studio AppCenter in hybrid clients (Android, iOS, Windows, macOS)</li>
</ul>
</div>
Examples:
Expand Down

0 comments on commit 25292df

Please sign in to comment.