diff --git a/Apps/Contoso.Forms.Demo/Contoso.Forms.Demo/App.xaml.cs b/Apps/Contoso.Forms.Demo/Contoso.Forms.Demo/App.xaml.cs index f0930ab70..49c1a5da0 100644 --- a/Apps/Contoso.Forms.Demo/Contoso.Forms.Demo/App.xaml.cs +++ b/Apps/Contoso.Forms.Demo/Contoso.Forms.Demo/App.xaml.cs @@ -19,14 +19,6 @@ public partial class App : Application const string androidKey = "987b5941-4fac-4968-933e-98a7ff29237c"; const string iosKey = "fe2bf05d-f4f9-48a6-83d9-ea8033fbb644"; - static App() - { - Crashes.SendingErrorReport += SendingErrorReportHandler; - Crashes.SentErrorReport += SentErrorReportHandler; - Crashes.FailedToSendErrorReport += FailedToSendErrorReportHandler; - Push.PushNotificationReceived += OnPushNotificationReceived; - } - public App() { InitializeComponent(); @@ -35,26 +27,33 @@ public App() protected override void OnStart() { - AppCenter.LogLevel = LogLevel.Verbose; - Crashes.ShouldProcessErrorReport = ShouldProcess; - Crashes.ShouldAwaitUserConfirmation = ConfirmationHandler; - Crashes.GetErrorAttachments = GetErrorAttachments; - Distribute.ReleaseAvailable = OnReleaseAvailable; - AppCenter.Start($"uwp={uwpKey};android={androidKey};ios={iosKey}", - typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Push)); - - AppCenter.GetInstallIdAsync().ContinueWith(installId => - { - AppCenterLog.Info(LogTag, "AppCenter.InstallId=" + installId.Result); - }); - Crashes.HasCrashedInLastSessionAsync().ContinueWith(hasCrashed => - { - AppCenterLog.Info(LogTag, "Crashes.HasCrashedInLastSession=" + hasCrashed.Result); - }); - Crashes.GetLastSessionCrashReportAsync().ContinueWith(report => - { - AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.Exception=" + report.Result?.Exception); - }); + if (!AppCenter.Configured) + { + AppCenter.LogLevel = LogLevel.Verbose; + Crashes.SendingErrorReport += SendingErrorReportHandler; + Crashes.SendingErrorReport += SendingErrorReportHandler; + Crashes.SentErrorReport += SentErrorReportHandler; + Crashes.FailedToSendErrorReport += FailedToSendErrorReportHandler; + Crashes.ShouldProcessErrorReport = ShouldProcess; + Crashes.ShouldAwaitUserConfirmation = ConfirmationHandler; + Crashes.GetErrorAttachments = GetErrorAttachments; + Distribute.ReleaseAvailable = OnReleaseAvailable; + Push.PushNotificationReceived += OnPushNotificationReceived; + AppCenter.Start($"uwp={uwpKey};android={androidKey};ios={iosKey}", + typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Push)); + AppCenter.GetInstallIdAsync().ContinueWith(installId => + { + AppCenterLog.Info(LogTag, "AppCenter.InstallId=" + installId.Result); + }); + Crashes.HasCrashedInLastSessionAsync().ContinueWith(hasCrashed => + { + AppCenterLog.Info(LogTag, "Crashes.HasCrashedInLastSession=" + hasCrashed.Result); + }); + Crashes.GetLastSessionCrashReportAsync().ContinueWith(report => + { + AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.Exception=" + report.Result?.Exception); + }); + } } protected override void OnSleep() diff --git a/Apps/Contoso.Forms.Puppet/Contoso.Forms.Puppet/App.xaml.cs b/Apps/Contoso.Forms.Puppet/Contoso.Forms.Puppet/App.xaml.cs index 33cfef79b..f29699224 100644 --- a/Apps/Contoso.Forms.Puppet/Contoso.Forms.Puppet/App.xaml.cs +++ b/Apps/Contoso.Forms.Puppet/Contoso.Forms.Puppet/App.xaml.cs @@ -16,18 +16,9 @@ public partial class App public const string LogTag = "AppCenterXamarinPuppet"; // App Center keys - private const string UwpKey = "a678b499-1912-4a94-9d97-25b569284d3a"; - private const string AndroidKey = "bff0949b-7970-439d-9745-92cdc59b10fe"; - private const string IosKey = "b889c4f2-9ac2-4e2e-ae16-dae54f2c5899"; - - static App() - { - // Set event handlers in static constructor to avoid duplication - Crashes.SendingErrorReport += SendingErrorReportHandler; - Crashes.SentErrorReport += SentErrorReportHandler; - Crashes.FailedToSendErrorReport += FailedToSendErrorReportHandler; - Push.PushNotificationReceived += PrintNotification; - } + const string UwpKey = "a678b499-1912-4a94-9d97-25b569284d3a"; + const string AndroidKey = "bff0949b-7970-439d-9745-92cdc59b10fe"; + const string IosKey = "b889c4f2-9ac2-4e2e-ae16-dae54f2c5899"; public App() { @@ -37,39 +28,48 @@ public App() protected override void OnStart() { - AppCenterLog.Assert(LogTag, "AppCenter.LogLevel=" + AppCenter.LogLevel); - AppCenter.LogLevel = LogLevel.Verbose; - AppCenterLog.Info(LogTag, "AppCenter.LogLevel=" + AppCenter.LogLevel); - AppCenterLog.Info(LogTag, "AppCenter.Configured=" + AppCenter.Configured); - - // Set callbacks - Crashes.ShouldProcessErrorReport = ShouldProcess; - Crashes.ShouldAwaitUserConfirmation = ConfirmationHandler; - Crashes.GetErrorAttachments = GetErrorAttachments; - Distribute.ReleaseAvailable = OnReleaseAvailable; - - AppCenterLog.Assert(LogTag, "AppCenter.Configured=" + AppCenter.Configured); - AppCenter.SetLogUrl("https://in-integration.dev.avalanch.es"); - Distribute.SetInstallUrl("http://install.appcenter-int.trafficmanager.net"); - Distribute.SetApiUrl("https://appcenter-int.trafficmanager.net/api/v0.1"); - AppCenter.Start($"uwp={UwpKey};android={AndroidKey};ios={IosKey}", typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Push)); - AppCenter.IsEnabledAsync().ContinueWith(enabled => - { - AppCenterLog.Info(LogTag, "AppCenter.Enabled=" + enabled.Result); - }); - AppCenter.GetInstallIdAsync().ContinueWith(installId => - { - AppCenterLog.Info(LogTag, "AppCenter.InstallId=" + installId.Result); - }); - AppCenterLog.Info(LogTag, "AppCenter.SdkVersion=" + AppCenter.SdkVersion); - Crashes.HasCrashedInLastSessionAsync().ContinueWith(hasCrashed => - { - AppCenterLog.Info(LogTag, "Crashes.HasCrashedInLastSession=" + hasCrashed.Result); - }); - Crashes.GetLastSessionCrashReportAsync().ContinueWith(report => - { - AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.Exception=" + report.Result?.Exception); - }); + if (!AppCenter.Configured) + { + AppCenterLog.Assert(LogTag, "AppCenter.LogLevel=" + AppCenter.LogLevel); + AppCenter.LogLevel = LogLevel.Verbose; + AppCenterLog.Info(LogTag, "AppCenter.LogLevel=" + AppCenter.LogLevel); + AppCenterLog.Info(LogTag, "AppCenter.Configured=" + AppCenter.Configured); + + // Set callbacks + Crashes.ShouldProcessErrorReport = ShouldProcess; + Crashes.ShouldAwaitUserConfirmation = ConfirmationHandler; + Crashes.GetErrorAttachments = GetErrorAttachments; + Distribute.ReleaseAvailable = OnReleaseAvailable; + + // Event handlers + Crashes.SendingErrorReport += SendingErrorReportHandler; + Crashes.SentErrorReport += SentErrorReportHandler; + Crashes.FailedToSendErrorReport += FailedToSendErrorReportHandler; + Push.PushNotificationReceived += PrintNotification; + + AppCenterLog.Assert(LogTag, "AppCenter.Configured=" + AppCenter.Configured); + AppCenter.SetLogUrl("https://in-integration.dev.avalanch.es"); + Distribute.SetInstallUrl("http://install.appcenter-int.trafficmanager.net"); + Distribute.SetApiUrl("https://appcenter-int.trafficmanager.net/api/v0.1"); + AppCenter.Start($"uwp={UwpKey};android={AndroidKey};ios={IosKey}", typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Push)); + AppCenter.IsEnabledAsync().ContinueWith(enabled => + { + AppCenterLog.Info(LogTag, "AppCenter.Enabled=" + enabled.Result); + }); + AppCenter.GetInstallIdAsync().ContinueWith(installId => + { + AppCenterLog.Info(LogTag, "AppCenter.InstallId=" + installId.Result); + }); + AppCenterLog.Info(LogTag, "AppCenter.SdkVersion=" + AppCenter.SdkVersion); + Crashes.HasCrashedInLastSessionAsync().ContinueWith(hasCrashed => + { + AppCenterLog.Info(LogTag, "Crashes.HasCrashedInLastSession=" + hasCrashed.Result); + }); + Crashes.GetLastSessionCrashReportAsync().ContinueWith(report => + { + AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.Exception=" + report.Result?.Exception); + }); + } } static void PrintNotification(object sender, PushNotificationReceivedEventArgs e)