Horizon

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 8  →  ?path2? @ 27
/Horizon/Snapshots/HexViewForm.cs
@@ -1,8 +1,12 @@
using System;
using System.Security.Policy;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Markup;
using Be.Windows.Forms;
using Horizon.Database;
using Horizon.Utilities;
using Serilog;
 
namespace Horizon.Snapshots
{
@@ -35,11 +39,10 @@
private readonly SnapshotDatabase _snapshotDatabase;
 
private DynamicByteProvider _dynamicByteProvider;
 
private byte[] _originalData;
private string _hash;
private readonly CancellationToken _cancellationToken;
 
private byte[] _originalData;
 
#endregion
 
#region Constructors, Destructors and Finalizers
@@ -49,16 +52,12 @@
InitializeComponent();
}
 
public HexViewForm(SnapshotDatabase snapshotDatabase, string hash, byte[] data) : this()
public HexViewForm(string hash, SnapshotDatabase snapshotDatabase, CancellationToken cancellationToken) : this()
{
_originalData = (byte[])data.Clone();
_hash = hash;
 
_snapshotDatabase = snapshotDatabase;
_snapshotDatabase.SnapshotDataUpdate += SnapshotDatabaseSnapshotDataUpdate;
 
_dynamicByteProvider = new DynamicByteProvider(data);
hexBox1.ByteProvider = _dynamicByteProvider;
_cancellationToken = cancellationToken;
}
 
/// <summary>
@@ -80,9 +79,30 @@
#endregion
 
#region Event Handlers
private void HexViewForm_Load(object sender, EventArgs e)
private async void HexViewForm_Load(object sender, EventArgs e)
{
Utilities.WindowState.FormTracker.Track(this);
 
try
{
using var memoryStream = await _snapshotDatabase.RetrieveFileStreamAsync(_hash, _cancellationToken);
 
if (memoryStream == null)
{
return;
}
 
var data = memoryStream.ToArray();
 
_originalData = (byte[])data.Clone();
 
_dynamicByteProvider = new DynamicByteProvider(data);
hexBox1.ByteProvider = _dynamicByteProvider;
}
catch (Exception exception)
{
Log.Error(exception, "Could not retrieve snapshot data.");
}
}
private void SnapshotDatabaseSnapshotDataUpdate(object sender, SnapshotDataUpdateEventArgs e)
{