/Horizon/Snapshots/SnapshotNoteForm.cs |
@@ -1,6 +1,11 @@ |
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 |
{ |
@@ -8,7 +13,9 @@ |
{ |
#region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
private readonly SnapshotManagerForm _snapshotManagerForm; |
private readonly CancellationToken _cancellationToken; |
private readonly string _hash; |
private readonly SnapshotDatabase _snapshotDatabase; |
|
#endregion |
|
@@ -25,12 +32,11 @@ |
InitializeComponent(); |
} |
|
public SnapshotNoteForm(SnapshotManagerForm snapshotManagerForm, SnapshotPreview snapshotPreview) : this() |
public SnapshotNoteForm(string hash, SnapshotDatabase snapshotDatabase, CancellationToken cancellationToken) : this() |
{ |
_snapshotManagerForm = snapshotManagerForm; |
_snapshotManagerForm.PreviewRetrieved += SnapshotManagerForm_PreviewRetrieved; |
|
richTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = snapshotPreview.Note; }); |
_hash = hash; |
_snapshotDatabase = snapshotDatabase; |
_cancellationToken = cancellationToken; |
} |
|
/// <summary> |
@@ -44,8 +50,6 @@ |
components.Dispose(); |
} |
|
_snapshotManagerForm.PreviewRetrieved -= SnapshotManagerForm_PreviewRetrieved; |
|
base.Dispose(disposing); |
} |
|
@@ -52,14 +56,26 @@ |
#endregion |
|
#region Event Handlers |
private void SnapshotNoteForm_Load(object sender, EventArgs e) |
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 SnapshotManagerForm_PreviewRetrieved(object sender, PreviewRetrievedEventArgs e) |
{ |
richTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = e.SnapshotPreview.Note; }); |
} |
|
private void Button1_Click(object sender, EventArgs e) |
{ |