Horizon – Rev 27

Subversion Repositories:
Rev:
using System;
using System.Security.Policy;
using System.Threading;
using System.Windows.Forms;
using Horizon.Database;
using Horizon.Utilities;
using Serilog;
using static System.Net.Mime.MediaTypeNames;

namespace Horizon.Snapshots
{
    public partial class SnapshotNoteForm : Form
    {
        #region Private Delegates, Events, Enums, Properties, Indexers and Fields

        private readonly CancellationToken _cancellationToken;
        private readonly string _hash;
        private readonly SnapshotDatabase _snapshotDatabase;

        #endregion

        #region Public Events & Delegates

        public event EventHandler<SaveNoteEventArgs> SaveNote;

        #endregion

        #region Constructors, Destructors and Finalizers

        public SnapshotNoteForm()
        {
            InitializeComponent();
        }

        public SnapshotNoteForm(string hash, SnapshotDatabase snapshotDatabase, CancellationToken cancellationToken) : this()
        {
            _hash = hash;
            _snapshotDatabase = snapshotDatabase;
            _cancellationToken = cancellationToken;
        }

        /// <summary>
        ///     Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && components != null)
            {
                components.Dispose();
            }

            base.Dispose(disposing);
        }

        #endregion

        #region Event Handlers
        private async void SnapshotNoteForm_Load(object sender, EventArgs e)
        {
            Utilities.WindowState.FormTracker.Track(this);

            try
            {
                var snapshotPreview = await _snapshotDatabase.RetrievePreviewAsync(_hash, _cancellationToken);

                if (snapshotPreview == null)
                {
                    return;
                }
                
                richTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = snapshotPreview.Note; });
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Unable to load note.");
            }
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            richTextBox1.InvokeIfRequired(richTextBox =>
            {
                SaveNote?.Invoke(this, new SaveNoteEventArgs(richTextBox.Text));
            });
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        #endregion


    }
}

Generated by GNU Enscript 1.6.5.90.