public static void HandleError(Exception ex, string comment = null, NotificationOptions options = null) { Instance.LogError(ex, comment, options); }
public void LogError(Exception ex, string comment = null, NotificationOptions options = null) { if (!_initialized) throw new InvalidOperationException("BugSense Handler is not initialized."); Handle(ex, comment, options ?? Instance._options); }
private void Handle(Exception e, string comment, NotificationOptions options, bool throwExceptionAfterComplete = false) { if (DateTime.Now.AddSeconds(-1) < _lastMethodHandledCalledAt) { return; } _lastMethodHandledCalledAt = DateTime.Now; if (Debugger.IsAttached && !options.HandleWhileDebugging)//Dont send the error return; var request = new BugSenseRequest(e.ToBugSenseEx(comment), GetEnvironment()); if (throwExceptionAfterComplete) { LogAndSend(request, true); return; } try { switch (options.Type) { case enNotificationType.MessageBox: if (!NotificationBox.IsOpen()) NotificationBox.Show(options.Title, options.Text, new NotificationBoxCommand(Labels.OkMessage, () => { })); LogAndSend(request); break; case enNotificationType.MessageBoxConfirm: if (!NotificationBox.IsOpen()) Scheduler.Dispatcher.Schedule( () => { try { if (!NotificationBox.IsOpen()) NotificationBox.Show(options.Title, options.Text, new NotificationBoxCommand(Labels.OkMessage, () => LogAndSend(request)), new NotificationBoxCommand(Labels.CancelMessage, () => { })); } catch { } }); break; default: LogAndSend(request); break; } } catch (Exception) { if (options.Type != enNotificationType.MessageBoxConfirm) { LogAndSend(request); } } }
/// <summary> /// Initialized the BugSense handler. Must be called at App constructor. /// </summary> /// <param name="application">The Windows Phone application.</param> /// <param name="apiKey">The Api Key that can be retrieved at bugsense.com</param> /// <param name="options">Optional Options</param> public void Init(Application application, string apiKey, NotificationOptions options = null) { if (_initialized) return; //General Initializations _options = options ?? GetDefaultOptions(); _application = application; G.API_KEY = apiKey; //Getting version and app details var appDetails = Helpers.GetVersion(); _appName = appDetails[0];//nameHelper.Name; _appVersion = appDetails[1];//nameHelper.Version.ToString(); //Proccess errors from previous crashes var tasks = new List<IResult> { new ProccessErrorsTask() }; Coroutine.BeginExecute(tasks.GetEnumerator()); //Attaching the handler if (_application != null) _application.UnhandledException += OnUnhandledException; //Just in case Init is called again _initialized = true; }