private void save_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.errorTitle.Text) || string.IsNullOrEmpty(this.errorText.Text))
            {
                MessageBox.Show(
                    "You must provide a title and exception details.",
                    "Save Error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
            else
            {
                var entry = new ExceptionEntry
                {
                    Title   = this.errorTitle.Text,
                    Details = this.errorText.Text
                };

                var savePath = this.GenerateSavePath();

                ExceptionSerializer.Serialize(entry, savePath);

                MessageBox.Show(
                    "Exception saved.",
                    "Save Successful",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                this.ResetUI();
                this.LoadExistingEntries();
            }
        }
        /// <summary>
        /// Serializes an exception.
        /// </summary>
        /// <param name="entry">The exception entry to serialize.</param>
        /// <param name="path">The file path.</param>
        public static void Serialize(ExceptionEntry entry, string path)
        {
            if (entry == null)
            {
                throw new NullReferenceException("entry");
            }

            // TODO 02: Convert object to JSON string
        }
        /// <summary>
        /// Serializes an exception.
        /// </summary>
        /// <param name="entry">The exception entry to serialize.</param>
        /// <param name="path">The file path.</param>
        public static void Serialize(ExceptionEntry entry, string path)
        {
            if (entry == null)
            {
                throw new NullReferenceException("entry");
            }

            // TODO 02: Convert object to JSON string
            var jsonAsString = JsonConvert.SerializeObject(entry);

            File.WriteAllText(path, jsonAsString);
        }
Beispiel #4
0
        /// <summary>
        /// Serializes an exception.
        /// </summary>
        /// <param name="entry">The exception entry to serialize.</param>
        /// <param name="path">The file path.</param>
        public static void Serialize(ExceptionEntry entry, string path)
        {
            if (entry == null)
            {
                throw new NullReferenceException("entry");
            }

            var stream = File.Create(path);

            // TODO: 04: Create a SoapFormatter object and serialize the entry object.


            stream.Close();
            stream.Dispose();
        }
        /// <summary>
        /// Serializes an exception.
        /// </summary>
        /// <param name="entry">The exception entry to serialize.</param>
        /// <param name="path">The file path.</param>
        public static void Serialize(ExceptionEntry entry, string path)
        {
            if (entry == null)
            {
                throw new NullReferenceException("entry");
            }

            var stream = File.Create(path);

            var formatter = new SoapFormatter();

            formatter.Serialize(stream, entry);

            stream.Close();
            stream.Dispose();
        }