private async Task InitializeCrashReport()
        {
            Crashes.SendingErrorReport += (sender, e) =>
            {
                AppCenterLog.Info(AppConstants.AppCenterLogTag, "Sending error report");

                var args   = e;
                var report = args.Report;
                LogReport(report, null);
            };

            Crashes.SentErrorReport += (sender, e) =>
            {
                AppCenterLog.Info(AppConstants.AppCenterLogTag, "Sent error report");

                var args   = e;
                var report = args.Report;
                LogReport(report, null);
            };

            Crashes.FailedToSendErrorReport += (sender, e) =>
            {
                AppCenterLog.Info(AppConstants.AppCenterLogTag, "Failed to send error report");

                var args   = e;
                var report = args.Report;
                LogReport(report, e.Exception);
            };

            Crashes.ShouldAwaitUserConfirmation = () => true;

            await Crashes.SetEnabledAsync(true);
        }
Beispiel #2
0
        // In Mono 4.8, it is possible to chain the mono signal handlers to the PLCrashReporter signal handlers, so
        // if the APIs for this are available, it is preferable to use them.
        public override void DidSetUpCrashHandlers()
        {
            if (Crashes.UseMonoRuntimeSignalMethods)
            {
                var type = Type.GetType("Mono.Runtime");
                var installSignalHandlers = type?.GetMethod("InstallSignalHandlers", BindingFlags.Public | BindingFlags.Static);
                if (installSignalHandlers != null)
                {
                    installSignalHandlers.Invoke(null, null);
                    AppCenterLog.Info(Crashes.LogTag, "Restore signal handlers for Mono 4.8+.");
                    return;
                }
            }

            // Mono 4.8+ APIs must be unavailable

            // Restore Mono SIGSEGV, SIGBUS, and SIGFPE handlers
            sigaction(Signal.SIGBUS, sigbus, IntPtr.Zero);
            sigaction(Signal.SIGSEGV, sigsegv, IntPtr.Zero);
            sigaction(Signal.SIGFPE, sigfpe, IntPtr.Zero);

            // Release previously allocated space
            Marshal.FreeHGlobal(sigbus);
            Marshal.FreeHGlobal(sigsegv);
            Marshal.FreeHGlobal(sigfpe);
            AppCenterLog.Info(Crashes.LogTag, "Restore signal handlers for Mono < 4.8.");
        }
Beispiel #3
0
        // In Mono 4.8, it is possible to chain the mono signal handlers to the PLCrashReporter signal handlers, so
        // if the APIs for this are available, it is preferable to use them.
        public override void WillSetUpCrashHandlers()
        {
            if (Crashes.UseMonoRuntimeSignalMethods)
            {
                var type = Type.GetType("Mono.Runtime");
                var removeSignalHandlers = type?.GetMethod("RemoveSignalHandlers", BindingFlags.Public | BindingFlags.Static);
                if (removeSignalHandlers != null)
                {
                    removeSignalHandlers.Invoke(null, null);
                    AppCenterLog.Info(Crashes.LogTag, "Temporarily remove signal handlers while native crash reporter is initialized (Mono 4.8+).");
                    return;
                }
            }

            // Mono 4.8+ APIs must be unavailable

            // Allocate space to store the Mono handlers
            sigbus  = Marshal.AllocHGlobal(512);
            sigsegv = Marshal.AllocHGlobal(512);
            sigfpe  = Marshal.AllocHGlobal(512);

            // Store Mono's SIGSEGV, SIGBUS, and SIGFPE handlers
            sigaction(Signal.SIGBUS, IntPtr.Zero, sigbus);
            sigaction(Signal.SIGSEGV, IntPtr.Zero, sigsegv);
            sigaction(Signal.SIGFPE, IntPtr.Zero, sigfpe);
            AppCenterLog.Info(Crashes.LogTag, "Temporarily remove signal handlers while native crash reporter is initialized (Mono < 4.8).");
        }
Beispiel #4
0
        private void CheckPendingLogs(State state)
        {
            if (!_enabled)
            {
                AppCenterLog.Info(AppCenterLog.LogTag, "The service has been disabled. Stop processing logs.");
                return;
            }

            AppCenterLog.Debug(AppCenterLog.LogTag, $"CheckPendingLogs({Name}) pending log count: {_pendingLogCount}");
            using (_mutex.GetLock())
            {
                if (_pendingLogCount >= _maxLogsPerBatch)
                {
                    _batchScheduled = true;
                    Task.Run(async() =>
                    {
                        await TriggerIngestionAsync(state).ConfigureAwait(false);
                    });
                }
                else if (_pendingLogCount > 0 && !_batchScheduled)
                {
                    _batchScheduled = true;

                    // No need wait _batchTimeInterval here.
                    Task.Run(async() =>
                    {
                        await Task.Delay((int)_batchTimeInterval.TotalMilliseconds).ConfigureAwait(false);
                        if (_batchScheduled)
                        {
                            await TriggerIngestionAsync(_mutex.State).ConfigureAwait(false);
                        }
                    });
                }
            }
        }
Beispiel #5
0
        private static bool OnReleaseAvailable(ReleaseDetails release)
        {
            AppCenterLog.Info(Constants.AppCenterLogTag, $"{nameof(OnReleaseAvailable)} id={release.Id} version={release.Version} mandatory={release.MandatoryUpdate}");

            var message = $"New release {release.ShortVersion}({release.Version}) available";

            // On mandatory update, user cannot postpone
            var answer = release.MandatoryUpdate ? UserDialogs.Instance.AlertAsync(message, "Warning!", "Download and install") :
                         UserDialogs.Instance.ConfirmAsync(message, "Warning!", "Download and install", "Not now");

            answer.ContinueWith(task =>
            {
                // If mandatory or if answer was positive
                if (release.MandatoryUpdate || ((Task <bool>)task).Result)
                {
                    // Notify SDK that user selected update
                    AppCenterLog.Info(Constants.AppCenterLogTag, "Notify Update");
                    Distribute.NotifyUpdateAction(UpdateAction.Update);
                }
                else
                {
                    // Notify SDK that user selected postpone (for 1 day)
                    // Note that this method call is ignored by the SDK if the update is mandatory
                    AppCenterLog.Info(Constants.AppCenterLogTag, "Notify Postpone");
                    Distribute.NotifyUpdateAction(UpdateAction.Postpone);
                }
            });

            // Return true if you are using your own dialog, false otherwise
            return(true);
        }
 protected override void OnStart()
 {
     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);
         });
     }
 }
Beispiel #7
0
 static OthersContentPage()
 {
     Data.RemoteOperationCompleted += (sender, eventArgs) =>
     {
         AppCenterLog.Info(App.LogTag, "Remote operation completed event=" + eventArgs.Operation + " " + eventArgs.DocumentMetadata.ETag, eventArgs.Error);
     };
 }
Beispiel #8
0
        protected override void OnStart()
        {
            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         = GetErrorAttachmentsCallback;
                Distribute.ReleaseAvailable         = OnReleaseAvailable;

                // Event handlers
                Crashes.SendingErrorReport      += SendingErrorReportHandler;
                Crashes.SentErrorReport         += SentErrorReportHandler;
                Crashes.FailedToSendErrorReport += FailedToSendErrorReportHandler;
                Push.PushNotificationReceived   += PrintNotification;

                AppCenterLog.Assert(LogTag, "AppCenter.Configured=" + AppCenter.Configured);

                if (!StartType.OneCollector.Equals(StartTypeUtils.GetPersistedStartType()))
                {
                    AppCenter.SetLogUrl("https://in-integration.dev.avalanch.es");
                }

                Distribute.SetInstallUrl("https://install.portal-server-core-integration.dev.avalanch.es");
                Distribute.SetApiUrl("https://api-gateway-core-integration.dev.avalanch.es/v0.1");
                Auth.SetConfigUrl("https://config-integration.dev.avalanch.es");
                Data.SetTokenExchangeUrl("https://token-exchange-mbaas-integration.dev.avalanch.es/v0.1");

                AppCenter.Start(GetTokensString(), typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Auth), typeof(Data));
                if (Current.Properties.ContainsKey(Constants.UserId) && Current.Properties[Constants.UserId] is string id)
                {
                    AppCenter.SetUserId(id);
                }

                // Work around for SetUserId race condition.
                AppCenter.Start(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(task =>
                {
                    AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.StackTrace=" + task.Result?.StackTrace);
                });
            }
        }
 static OthersContentPage()
 {
     Data.RemoteOperationCompleted += (sender, eventArgs) =>
     {
         AppCenterLog.Info(App.LogTag, "Remote operation completed event=" + JsonConvert.SerializeObject(eventArgs) + " sender=" + sender);
     };
 }
Beispiel #10
0
        bool OnReleaseAvailable(ReleaseDetails releaseDetails)
        {
            AppCenterLog.Info(LogTag, "OnReleaseAvailable id=" + releaseDetails.Id
                              + " version=" + releaseDetails.Version
                              + " releaseNotesUrl=" + releaseDetails.ReleaseNotesUrl);
            var custom = releaseDetails.ReleaseNotes?.ToLowerInvariant().Contains("custom") ?? false;

            if (custom)
            {
                var  title = "Version " + releaseDetails.ShortVersion + " available!";
                Task answer;
                if (releaseDetails.MandatoryUpdate)
                {
                    answer = Current.MainPage.DisplayAlert(title, releaseDetails.ReleaseNotes, "Update now!");
                }
                else
                {
                    answer = Current.MainPage.DisplayAlert(title, releaseDetails.ReleaseNotes, "Update now!", "Maybe tomorrow...");
                }
                answer.ContinueWith((task) =>
                {
                    if (releaseDetails.MandatoryUpdate || ((Task <bool>)task).Result)
                    {
                        Distribute.NotifyUpdateAction(UpdateAction.Update);
                    }
                    else
                    {
                        Distribute.NotifyUpdateAction(UpdateAction.Postpone);
                    }
                });
            }
            return(custom);
        }
Beispiel #11
0
        bool OnReleaseAvailable(ReleaseDetails releaseDetails)
        {
            AppCenterLog.Info(LogTag, "OnReleaseAvailable id=" + releaseDetails.Id
                              + " version=" + releaseDetails.Version
                              + " releaseNotesUrl=" + releaseDetails.ReleaseNotesUrl);
            var custom = releaseDetails.ReleaseNotes?.ToLowerInvariant().Contains("custom") ?? false;

            if (custom)
            {
                var builder = new AlertDialog.Builder(this);
                builder.SetTitle(string.Format(GetString(Resource.String.version_x_available), releaseDetails.ShortVersion));
                builder.SetMessage(releaseDetails.ReleaseNotes);
                builder.SetPositiveButton(Microsoft.AppCenter.Distribute.Resource.String.appcenter_distribute_update_dialog_download, delegate
                {
                    Distribute.NotifyUpdateAction(UpdateAction.Update);
                });
                builder.SetCancelable(false);
                if (!releaseDetails.MandatoryUpdate)
                {
                    builder.SetNegativeButton(Microsoft.AppCenter.Distribute.Resource.String.appcenter_distribute_update_dialog_postpone, delegate
                    {
                        Distribute.NotifyUpdateAction(UpdateAction.Postpone);
                    });
                }
                builder.Create().Show();
            }
            return(custom);
        }
Beispiel #12
0
        protected override void OnStart()
        {
            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         = GetErrorAttachmentsCallback;
                Distribute.ReleaseAvailable         = OnReleaseAvailable;

                // Event handlers
                Crashes.SendingErrorReport      += SendingErrorReportHandler;
                Crashes.SentErrorReport         += SentErrorReportHandler;
                Crashes.FailedToSendErrorReport += FailedToSendErrorReportHandler;
                Push.PushNotificationReceived   += PrintNotification;

                AppCenterLog.Assert(LogTag, "AppCenter.Configured=" + AppCenter.Configured);

                var updateTrack = TrackUpdateUtils.GetPersistedUpdateTrack();
                if (updateTrack != null)
                {
                    Distribute.UpdateTrack = updateTrack.Value;
                }
                if (Current.Properties.TryGetValue(Constants.AutomaticUpdateCheckKey, out object persistedObject) && !(bool)persistedObject)
                {
                    Distribute.DisableAutomaticCheckForUpdate();
                }
                AppCenter.Start(GetTokensString(), typeof(Analytics), typeof(Crashes), typeof(Distribute));
                if (Current.Properties.ContainsKey(Constants.UserId) && Current.Properties[Constants.UserId] is string id)
                {
                    AppCenter.SetUserId(id);
                }

                // Work around for SetUserId race condition.
                AppCenter.Start(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(task =>
                {
                    AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.StackTrace=" + task.Result?.StackTrace);
                });
            }
        }
Beispiel #13
0
        async void RunMBaaSAsync(object sender, EventArgs e)
        {
            try
            {
                userInfo = await Auth.SignInAsync();

                if (userInfo.AccountId != null)
                {
                    Application.Current.Properties[AccountId] = userInfo.AccountId;
                    SignInInformationButton.Text = "User authenticated";
                }
                AppCenterLog.Info(App.LogTag, "Auth.SignInAsync succeeded accountId=" + userInfo.AccountId);
            }
            catch (Exception ex)
            {
                AppCenterLog.Error(App.LogTag, "Auth scenario failed", ex);
                Crashes.TrackError(ex);
            }
            try
            {
                var list = await Data.ListAsync <CustomDocument>(DefaultPartitions.UserDocuments);

                foreach (var doc in list)
                {
                    AppCenterLog.Info(App.LogTag, "List result=" + doc.DeserializedValue.id);
                }
                var document = list.CurrentPage.Items.First();
                AppCenterLog.Info(App.LogTag, "List first result=" + document.DeserializedValue.id);
                document = await Data.DeleteAsync <CustomDocument>(document.Id, DefaultPartitions.UserDocuments);

                AppCenterLog.Info(App.LogTag, "Delete result=" + document.DeserializedValue);
            }
            catch (Exception ex)
            {
                AppCenterLog.Error(App.LogTag, "Data list/delete first scenario failed", ex);
                Crashes.TrackError(ex);
            }
            try
            {
                var customDoc = new CustomDocument
                {
                    id        = Guid.NewGuid(),
                    timestamp = DateTime.UtcNow
                };
                var id       = customDoc.id.ToString();
                var document = await Data.ReplaceAsync(id, customDoc, DefaultPartitions.UserDocuments);

                AppCenterLog.Info(App.LogTag, "Replace result=" + document.DeserializedValue.id);
                document = await Data.ReadAsync <CustomDocument>(id, DefaultPartitions.UserDocuments);

                AppCenterLog.Info(App.LogTag, "Read result=" + document.DeserializedValue.id);
            }
            catch (Exception ex)
            {
                AppCenterLog.Error(App.LogTag, "Data person scenario failed", ex);
                Crashes.TrackError(ex);
            }
        }
Beispiel #14
0
        private static async Task SetCountryCode()
        {
            // The following country code is used only as a fallback for the main implementation.
            // This fallback country code does not reflect the physical device location, but rather the
            // country that corresponds to the culture it uses.
            var countryCode  = new GeographicRegion().CodeTwoLetter;
            var accessStatus = await Geolocator.RequestAccessAsync();

            switch (accessStatus)
            {
            case GeolocationAccessStatus.Allowed:
                var geoLocator = new Geolocator
                {
                    DesiredAccuracyInMeters = 100
                };
                var position = await geoLocator.GetGeopositionAsync();

                var myLocation = new BasicGeoposition
                {
                    Longitude = position.Coordinate.Point.Position.Longitude,
                    Latitude  = position.Coordinate.Point.Position.Latitude
                };
                var pointToReverseGeocode = new Geopoint(myLocation);
                try
                {
                    MapService.ServiceToken = Constants.BingMapsAuthKey;
                }
                catch (SEHException)
                {
                    AppCenterLog.Info(LogTag, "Please provide a valid Bing Maps authentication key. For more info see: https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/authentication-key");
                }
                var result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

                if (result.Status != MapLocationFinderStatus.Success || result.Locations == null || result.Locations.Count == 0)
                {
                    break;
                }

                // The returned country code is in 3-letter format (ISO 3166-1 alpha-3).
                // Below we convert it to ISO 3166-1 alpha-2 (two letter).
                var country = result.Locations[0].Address.CountryCode;
                countryCode = new GeographicRegion(country).CodeTwoLetter;
                break;

            case GeolocationAccessStatus.Denied:
                AppCenterLog.Info(LogTag, "Geolocation access denied. In order to set country code in App Center, enable location service in Windows 10.");
                break;

            case GeolocationAccessStatus.Unspecified:
                break;
            }
            AppCenter.SetCountryCode(countryCode);
        }
Beispiel #15
0
        async void RunMBaaSAsync(object sender, EventArgs e)
        {
            try
            {
                var userInfo = await Auth.SignInAsync();

                AppCenterLog.Info(App.LogTag, "Auth.SignInAsync succeeded accountId=" + userInfo.AccountId);
            }
            catch (Exception ex)
            {
                AppCenterLog.Error(App.LogTag, "Auth scenario failed", ex);
                Crashes.TrackError(ex);
            }
            try
            {
                var list = await Data.ListAsync <CustomDocument>(DefaultPartitions.UserDocuments);

                foreach (var doc in list)
                {
                    AppCenterLog.Info(App.LogTag, "List result=" + JsonConvert.SerializeObject(doc));
                }
                var document = list.CurrentPage.Items.First();
                AppCenterLog.Info(App.LogTag, "List first result=" + JsonConvert.SerializeObject(document));
                document = await Data.DeleteAsync <CustomDocument>(document.Id, DefaultPartitions.UserDocuments);

                AppCenterLog.Info(App.LogTag, "Delete result=" + JsonConvert.SerializeObject(document));
            }
            catch (Exception ex)
            {
                AppCenterLog.Error(App.LogTag, "Data list/delete first scenario failed", ex);
                Crashes.TrackError(ex);
            }
            try
            {
                var customDoc = new CustomDocument
                {
                    Id        = Guid.NewGuid(),
                    TimeStamp = DateTime.UtcNow
                };
                var id       = customDoc.Id.ToString();
                var document = await Data.ReplaceAsync(id, customDoc, DefaultPartitions.UserDocuments);

                AppCenterLog.Info(App.LogTag, "Replace result=" + JsonConvert.SerializeObject(document));
                document = await Data.ReadAsync <CustomDocument>(id, DefaultPartitions.UserDocuments);

                AppCenterLog.Info(App.LogTag, "Read result=" + JsonConvert.SerializeObject(document));
            }
            catch (Exception ex)
            {
                AppCenterLog.Error(App.LogTag, "Data person scenario failed", ex);
                Crashes.TrackError(ex);
            }
        }
Beispiel #16
0
        protected override void OnStart()
        {
            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);

                var appSecrets = GetAppSecretDictionary();
                AppCenter.Start($"uwp={appSecrets[XamarinDevice.UWP]};android={appSecrets[XamarinDevice.Android]};ios={appSecrets[XamarinDevice.iOS]}", typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Auth), typeof(Data));
                if (Current.Properties.ContainsKey(Constants.UserId) && Current.Properties[Constants.UserId] is string id)
                {
                    AppCenter.SetUserId(id);
                }

                // Work around for SetUserId race condition.
                AppCenter.Start(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(task =>
                {
                    AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.StackTrace=" + task.Result?.StackTrace);
                });
            }
        }
        public bool SetMaxStorageSize(long sizeInBytes)
        {
            var db = _db ?? throw new StorageException("The database wasn't initialized.");

            // Check the current number of pages in the database to determine whether the requested size will shrink the database.
            var currentPageCount = GetPageCount();
            var pageSize         = GetPageSize();

            AppCenterLog.Info(AppCenterLog.LogTag, $"Found {currentPageCount} pages in the database.");
            var requestedMaxPageCount = Convert.ToBoolean(sizeInBytes % pageSize) ? sizeInBytes / pageSize + 1 : sizeInBytes / pageSize;

            if (currentPageCount > requestedMaxPageCount)
            {
                AppCenterLog.Warn(AppCenterLog.LogTag, $"Cannot change database size to {sizeInBytes} bytes as it would cause a loss of data. " +
                                  "Maximum database size will not be changed.");
                return(false);
            }
            else
            {
                // Attempt to set the limit and check the page count to make sure the given limit works.
                var result = raw.sqlite3_exec(db, $"PRAGMA max_page_count = {requestedMaxPageCount};");
                if (result != raw.SQLITE_OK)
                {
                    AppCenterLog.Error(AppCenterLog.LogTag, $"Could not change maximum database size to {sizeInBytes} bytes. SQLite error code: {result}.");
                    return(false);
                }
                else
                {
                    var currentMaxPageCount = GetMaxPageCount();
                    var actualMaxSize       = currentMaxPageCount * pageSize;
                    if (requestedMaxPageCount != currentMaxPageCount)
                    {
                        AppCenterLog.Error(AppCenterLog.LogTag, $"Could not change maximum database size to {sizeInBytes} bytes, current maximum size is {actualMaxSize} bytes.");
                        return(false);
                    }
                    else
                    {
                        if (sizeInBytes == actualMaxSize)
                        {
                            AppCenterLog.Info(AppCenterLog.LogTag, $"Changed maximum database size to {actualMaxSize} bytes.");
                        }
                        else
                        {
                            AppCenterLog.Info(AppCenterLog.LogTag, $"Changed maximum database size to {actualMaxSize} bytes (next multiple of 4KiB).");
                        }
                        return(true);
                    }
                }
            }
        }
 private void RestoreConfigurationFile()
 {
     try
     {
         if (File.Exists(FilePath))
         {
             File.Delete(FilePath);
             configuration = OpenConfiguration();
             AppCenterLog.Info(AppCenterLog.LogTag, "Configuration is successfully restored.");
         }
     }
     catch (Exception e)
     {
         AppCenterLog.Warn(AppCenterLog.LogTag, "Could not restore configuration.", e);
     }
 }
Beispiel #19
0
        static void SendingErrorReportHandler(object sender, SendingErrorReportEventArgs e)
        {
            AppCenterLog.Info(LogTag, "Sending error report");

            var report = e.Report;

            // Test some values
            if (report.Exception != null)
            {
                AppCenterLog.Info(LogTag, report.Exception.ToString());
            }
            else if (report.AndroidDetails != null)
            {
                AppCenterLog.Info(LogTag, report.AndroidDetails.ThreadName);
            }
        }
        private void ReportError_clicked(object sender, EventArgs e)
        {
            Exception exception = new Exception("test error");

            var properties = new Dictionary <string, string>
            {
                { "Category", "Chat" },
                { "Wifi", "On" }
            };

            Crashes.TrackError(exception, properties);
            Analytics.TrackEvent("test event");
            AppCenterLog.Info("Test Log", "Sending error report");

            DependencyService.Get <ICrashReporting>().LogException();
        }
Beispiel #21
0
        protected override void OnStart()
        {
            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("https://install.portal-server-core-integration.dev.avalanch.es");
                Distribute.SetApiUrl("https://api-gateway-core-integration.dev.avalanch.es/v0.1");
                Auth.SetConfigUrl("https://config-integration.dev.avalanch.es");
                Data.SetTokenExchangeUrl("https://token-exchange-mbaas-integration.dev.avalanch.es/v0.1");
                AppCenter.Start($"uwp={UwpKey};android={AndroidKey};ios={IosKey}", typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Push), typeof(Auth), typeof(Data));
                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(task =>
                {
                    AppCenterLog.Info(LogTag, "Crashes.LastSessionCrashReport.Exception=" + task.Result?.Exception);
                });
            }
        }
Beispiel #22
0
        static Crashes()
        {
            // Set up 2 different handlers, some exceptions are caught by one or the other or both (all scenarios are possible).
            // When caught on both, only the first invocation will actually be saved by the native SDK.
            // Android environment is called before app domain in case of both called, and that's what we want as
            // Android environment has a better stack trace object (no JavaProxyThrowable wrapper that cannot be serialized).
            // Client side exception object after restart not possible most of the time with AppDomain when it's JavaProxyThrowable.
            // AndroidEnvironment is also called before Java SDK exception handler (which itself not always called...).
            // App domain fallback is thus used only when both android environment and Java SDK handler cannot catch.
            // From our tests if only app domain is called, then it's not a JavaProxyThrowable, so stack trace looks fine.
            AppCenterLog.Info(LogTag, "Set up Xamarin crash handlers.");
            AndroidEnvironment.UnhandledExceptionRaiser += OnUnhandledException;
            AppDomain.CurrentDomain.UnhandledException  += OnUnhandledException;

            // Set up bridge between Java listener and .NET events/callbacks.
            AndroidCrashes.SetListener(new AndroidCrashListener());
        }
 public virtual void InstanceRemoveStoredExceptionFile(Guid errorId)
 {
     lock (LockObject)
     {
         var file = GetStoredExceptionFile(errorId);
         if (file != null)
         {
             AppCenterLog.Info(Crashes.LogTag, $"Deleting exception file {file.Name}.");
             try
             {
                 file.Delete();
             }
             catch (System.Exception ex)
             {
                 AppCenterLog.Warn(Crashes.LogTag, $"Failed to delete exception file {file.Name}.", ex);
             }
         }
     }
 }
Beispiel #24
0
        static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var systemException = e.ExceptionObject as Exception;

            AppCenterLog.Error(LogTag, "Unhandled Exception:", systemException);
            var exception            = GenerateiOSException(systemException, true);
            var exceptionBytes       = CrashesUtils.SerializeException(systemException) ?? new byte[0];
            var wrapperExceptionData = NSData.FromArray(exceptionBytes);
            var wrapperException     = new MSACWrapperException
            {
                Exception     = exception,
                ExceptionData = wrapperExceptionData,
                ProcessId     = new NSNumber(Process.GetCurrentProcess().Id)
            };

            AppCenterLog.Info(LogTag, "Saving wrapper exception...");
            MSACWrapperExceptionManager.SaveWrapperException(wrapperException);
            AppCenterLog.Info(LogTag, "Saved wrapper exception.");
        }
Beispiel #25
0
        static void FailedToSendErrorReportHandler(object sender, FailedToSendErrorReportEventArgs e)
        {
            AppCenterLog.Info(LogTag, "Failed to send error report");

            var report = e.Report;

            // Test some values
            if (report.Exception != null)
            {
                AppCenterLog.Info(LogTag, report.Exception.ToString());
            }
            else if (report.AndroidDetails != null)
            {
                AppCenterLog.Info(LogTag, report.AndroidDetails.ThreadName);
            }

            if (e.Exception != null)
            {
                AppCenterLog.Info(LogTag, "There is an exception associated with the failure");
            }
        }
Beispiel #26
0
        void SentErrorReportHandler(object sender, SentErrorReportEventArgs e)
        {
            AppCenterLog.Info(LogTag, "Sent error report");

            var         args   = e as SentErrorReportEventArgs;
            ErrorReport report = args.Report;

            //test some values
            if (report.Exception != null)
            {
                AppCenterLog.Info(LogTag, report.Exception.ToString());
            }
            else
            {
                AppCenterLog.Info(LogTag, "No system exception was found");
            }

            if (report.AndroidDetails != null)
            {
                AppCenterLog.Info(LogTag, report.AndroidDetails.ThreadName);
            }
        }
Beispiel #27
0
        protected override void OnStart()
        {
            AppCenter.LogLevel = LogLevel.Verbose;
            Crashes.ShouldProcessErrorReport    = ShouldProcess;
            Crashes.ShouldAwaitUserConfirmation = ConfirmationHandler;
            Crashes.GetErrorAttachments         = GetErrorAttachments;
            AppCenter.Start($"android={androidKey}",
                            typeof(Analytics), typeof(Crashes));

            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);
            });
        }
Beispiel #28
0
        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");
            RealUserMeasurements.SetRumKey("b1919553367d44d8b0ae72594c74e0ff");
            AppCenter.Start($"uwp={UwpKey};android={AndroidKey};ios={IosKey}",
                            typeof(Analytics), typeof(Crashes), typeof(Distribute), typeof(Push), typeof(RealUserMeasurements));
            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);
            });
        }
Beispiel #29
0
        private void FailedToSendErrorReportHandler(object sender, FailedToSendErrorReportEventArgs e)
        {
            AppCenterLog.Info(LogTag, "Failed to send error report");

            var         args         = e as FailedToSendErrorReportEventArgs;
            ErrorReport report       = args.Report;
            string      AccountsJson = Newtonsoft.Json.JsonConvert.SerializeObject(Settings.Person.Accounts);

            //test some values
            if (report.Exception != null)
            {
                AppCenterLog.Info(LogTag, report.Exception.ToString());
            }
            else if (report.AndroidDetails != null)
            {
                AppCenterLog.Info(LogTag, report.AndroidDetails.ThreadName);
            }

            if (e.Exception != null)
            {
                AppCenterLog.Info(LogTag, "There is an exception associated with the failure");
            }
        }
Beispiel #30
0
        private void SentErrorReportHandler(object sender, SentErrorReportEventArgs e)
        {
            AppCenterLog.Info(LogTag, "Sent error report");

            var         args         = e as SentErrorReportEventArgs;
            ErrorReport report       = args.Report;
            string      AccountsJson = Newtonsoft.Json.JsonConvert.SerializeObject(Settings.Person.Accounts);

            //test some values
            if (report.Exception != null)
            {
                AppCenterLog.Info(LogTag, report.Exception.ToString());
            }
            else
            {
                AppCenterLog.Info(LogTag, "No system exception was found");
            }

            if (report.AndroidDetails != null)
            {
                AppCenterLog.Info(LogTag, report.AndroidDetails.ThreadName);
            }
        }