private void Send(BugSenseRequest request)
        {
            string json = GetJson(request);
            if (!string.IsNullOrEmpty(json))
            {
                SaveToFile(json);
#if WINDOWS_RT
                Task.Run( () => ProccessSavedErrors() );
#elif iOS
                // TODO: Thread this.
                
                ProccessSavedErrors();
                //UIApplication.SharedApplication.BeginInvokeOnMainThread(ProccessSavedErrors);
#else
                Scheduler.NewThread.Schedule(ProccessSavedErrors);
#endif
            }
        }
        private string GetJson(BugSenseRequest request)
        {
            try
            {
                Log("Sending json ");
                using (MemoryStream ms = new MemoryStream())
                {
#if WINDOWS_RT
                    new DataContractJsonSerializer(typeof(BugSenseRequest)).WriteObject(ms, request);
#else
                    JsonSerializer.SerializeToStream(request, typeof(BugSenseRequest), ms);
#endif
                    var array = ms.ToArray();
                    string json = Encoding.UTF8.GetString(array, 0, array.Length);
                    json = json.Replace("ScreenDpi", "screen_dpi(x:y)")
                        .Replace("ScreenOrientation", "screen:orientation")
                        .Replace("ScreenHeight", "screen:height")
                        .Replace("ScreenWidth", "screen:width");
                    return json;
                }
            }
            catch
            {
                Log("Error during BugSenseRequest serialization");
                return string.Empty;
            }
        }
 private string GetJson(BugSenseRequest request)
 {
     try {
         Helpers.Log("Sending json ");
         using (MemoryStream ms = new MemoryStream()) {
             _jsonSerializer.WriteObject(ms, request);
             var array = ms.ToArray();
             string json = Encoding.UTF8.GetString(array, 0, array.Length);
             return json;
         }
     }
     catch {
         Helpers.Log("Error during BugSenseRequest serialization");
         return string.Empty;
     }
 }
 /// <summary>
 /// Make sure to set screen size/orientation before calling this!
 /// </summary>
 public static void HandleError(Exception e, string comment)
 {
     var request = new BugSenseRequest(e.ToBugSenseEx(comment), Instance.GetEnvironment());
     try
     {
         Instance.Send(request);
     }
     catch (Exception ex1)
     {
     }
 }
 public LogErrorTask(BugSenseRequest request)
 {
     _request = request;
 }
 private void LogAndSend(BugSenseRequest request, bool throwAfterComplete = false)
 {
     ThreadPool.QueueUserWorkItem(state => {
         var eventArgs = new BugSenseLogErrorCompletedEventArgs(request, request.Exception != null ? request.Exception.OriginalException : null);
         //eventArgs.ExitApp = throwAfterComplete;
         var logTask = new LogErrorTask(request);
         var sendTask = new SendErrorTask();
         var tasks = new List<IResult> { logTask, sendTask };
         EventHandler<ResultCompletionEventArgs> callback = (sender, args) => Scheduler.Dispatcher.Schedule(() => {
             //OnUnhandledExceptionSent(eventArgs);
             //if (eventArgs.ExitApp)
             throw new BugSenseUnhandledException();
         });
         Coroutine.BeginExecute(tasks.GetEnumerator(), callback: throwAfterComplete ? callback : null);
     });
 }
 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);
         }
     }
 }
 private void Send(BugSenseRequest request)
 {
     string json = GetJson(request);
     if (!string.IsNullOrEmpty(json)) {
         SaveToFile(json);
         Scheduler.NewThread.Schedule(ProccessSavedErrors);
     }
 }
 //private void OnBugSenseUnhandledException(BugSenseUnhandledExceptionEventArgs e)
 //{
 //    EventHandler<BugSenseUnhandledExceptionEventArgs> handler = UnhandledException;
 //    if (handler != null)
 //        handler(this, e);
 //}
 private void Handle(Exception e, string comment)
 {
     var request = new BugSenseRequest(e.ToBugSenseEx(comment), GetEnvironment());
     try {
         Send(request);
     }
     catch (Exception ex1) {
     }
 }