示例#1
0
        protected void SendErrors()
        {
            // Check for errors (do nothing when none)
            var errorFiles = LocalErrorStore.List();

            if (errorFiles == null || errorFiles.Length == 0)
            {
                return;
            }

            // Report all errors
            foreach (var errorFile in errorFiles)
            {
                // Get next error
                var error = LocalErrorStore.Get(errorFile);

                // Post error to service
                using var client = new HttpClient();
                using var buffer = new MemoryStream();
                var serializer = new DataContractJsonSerializer(typeof(ErrorReportData[]));
                serializer.WriteObject(buffer, error);
                var json = Encoding.UTF8.GetString(buffer.ToArray(), 0, (int)buffer.Length);
                using var content  = new StringContent(json, Encoding.UTF8, "application/json");
                using var response = client.PostAsync(ErrorReportUri, content).Result;
                if (response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.BadRequest)
                {
                    // Remove when successful or invalid data
                    LocalErrorStore.Remove(errorFile);
                }
            }
        }
示例#2
0
        protected void OnSuspending(object sender, SuspendingEventArgs @event)
        {
            // Validate.
            if (@event is null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            // Delay
            var deferral = @event.SuspendingOperation.GetDeferral();

            try
            {
                // Save state
                SaveState();
            }
            catch (Exception error)
            {
                // Log error saving state then continue
                LocalErrorStore.Add(error);
            }
            finally
            {
                // End delay
                deferral.Complete();
            }
        }
示例#3
0
        protected static void OnError(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs @event)
        {
            // Validate.
            if (@event is null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            // Store error to send later
            LocalErrorStore.Add(@event.Exception);
        }
示例#4
0
        public async void CheckErrors()
        {
            // Check for errors (do nothing when none)
            var errors = LocalErrorStore.List();

            if (errors == null || errors.Length == 0)
            {
                return;
            }

            // Prompt user
            await ShowSendErrorsDialog().ConfigureAwait(false);
        }
示例#5
0
 protected void OnResuming(object sender, object @event)
 {
     try
     {
         // Load state
         LoadState();
     }
     catch (Exception error)
     {
         // Log error restoring state then create new model
         LocalErrorStore.Add(error);
     }
 }
示例#6
0
        protected static void DiscardErrors()
        {
            // Check for errors (do nothing when none)
            var errors = LocalErrorStore.List();

            if (errors == null)
            {
                return;
            }

            // Delete all errors
            foreach (var errorFileName in errors)
            {
                LocalErrorStore.Remove(errorFileName);
            }
        }
示例#7
0
 /// <summary>
 /// Logs unhandled errors.
 /// </summary>
 protected static void OnError(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs @event)
 {
     // Store error to send later
     LocalErrorStore.Add(@event.Exception);
 }