Horizon – Diff between revs 1 and 27

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 27
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Drawing; 2 using System.Drawing;
-   3 using System.Security.Policy;
-   4 using System.Threading;
3 using System.Windows.Forms; 5 using System.Windows.Forms;
4 using Horizon.Database; 6 using Horizon.Database;
5 using Horizon.Utilities; 7 using Horizon.Utilities;
-   8 using Serilog;
Line 6... Line 9...
6   9  
7 namespace Horizon.Snapshots 10 namespace Horizon.Snapshots
8 { 11 {
9 public partial class SnapshotPreviewForm : Form 12 public partial class SnapshotPreviewForm : Form
Line 25... Line 28...
25 #region Private Delegates, Events, Enums, Properties, Indexers and Fields 28 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
Line 26... Line 29...
26   29  
Line 27... Line 30...
27 private readonly SnapshotDatabase _snapshotDatabase; 30 private readonly SnapshotDatabase _snapshotDatabase;
-   31  
-   32 private readonly SnapshotManagerForm _snapshotManagerForm;
Line 28... Line 33...
28   33 private readonly string _snapshotHash;
Line 29... Line 34...
29 private readonly SnapshotManagerForm _snapshotManagerForm; 34 private readonly CancellationToken _cancellationToken;
Line 36... Line 41...
36 { 41 {
37 InitializeComponent(); 42 InitializeComponent();
38 Utilities.WindowState.FormTracker.Track(this); 43 Utilities.WindowState.FormTracker.Track(this);
39 } 44 }
Line 40... Line 45...
40   45  
-   46 public SnapshotPreviewForm(SnapshotManagerForm snapshotManagerForm, string hash,
41 public SnapshotPreviewForm(SnapshotManagerForm snapshotManagerForm, SnapshotDatabase snapshotDatabase) : this() 47 SnapshotDatabase snapshotDatabase, CancellationToken cancellationToken) : this()
42 { 48 {
-   49 _snapshotManagerForm = snapshotManagerForm;
43 _snapshotManagerForm = snapshotManagerForm; 50 _snapshotHash = hash;
44 _snapshotManagerForm.Move += SnapshotManagerFormMove; 51 _snapshotManagerForm.Move += SnapshotManagerFormMove;
45 _snapshotManagerForm.Resize += SnapshotManagerFormResize; -  
46 _snapshotManagerForm.PreviewRetrieved += SnapshotManagerForm_PreviewRetrieved; -  
Line 47... Line 52...
47 ; 52 _snapshotManagerForm.Resize += SnapshotManagerFormResize;
48   53  
-   54 _snapshotDatabase = snapshotDatabase;
-   55 _snapshotDatabase.SnapshotNoteUpdate += SnapshotDatabase_SnapshotNoteUpdate;
49 _snapshotDatabase = snapshotDatabase; 56  
Line 50... Line 57...
50 _snapshotDatabase.SnapshotNoteUpdate += SnapshotDatabase_SnapshotNoteUpdate; 57 _cancellationToken = cancellationToken;
51 } 58 }
52   59  
Line 60... Line 67...
60 { 67 {
61 components.Dispose(); 68 components.Dispose();
62 } 69 }
Line 63... Line 70...
63   70  
64 _snapshotDatabase.SnapshotNoteUpdate -= SnapshotDatabase_SnapshotNoteUpdate; -  
Line 65... Line 71...
65 _snapshotManagerForm.PreviewRetrieved -= SnapshotManagerForm_PreviewRetrieved; 71 _snapshotDatabase.SnapshotNoteUpdate -= SnapshotDatabase_SnapshotNoteUpdate;
66   72  
Line 67... Line 73...
67 _snapshotManagerForm.Move -= SnapshotManagerFormMove; 73 _snapshotManagerForm.Move -= SnapshotManagerFormMove;
Line 72... Line 78...
72   78  
Line 73... Line 79...
73 #endregion 79 #endregion
Line 74... Line -...
74   -  
75 #region Event Handlers -  
76   -  
77 private void SnapshotManagerForm_PreviewRetrieved(object sender, PreviewRetrievedEventArgs e) -  
78 { -  
79 using (var image = pictureBox1.Image) -  
80 { -  
81 pictureBox1.Image = e.SnapshotPreview.Shot; -  
82 richTextBox1.Text = e.SnapshotPreview.Note; -  
83 } -  
84   -  
85 if (string.IsNullOrEmpty(e.SnapshotPreview.Note)) -  
86 { -  
87 splitContainer1.Panel2Collapsed = true; -  
88 return; -  
89 } -  
Line 90... Line 80...
90   80  
91 splitContainer1.Panel2Collapsed = false; 81 #region Event Handlers
92 } 82  
93   83  
Line 121... Line 111...
121 private void SnapshotManagerFormResize(object sender, EventArgs e) 111 private void SnapshotManagerFormResize(object sender, EventArgs e)
122 { 112 {
123 Relocate(); 113 Relocate();
124 } 114 }
Line 125... Line 115...
125   115  
126 private void SnapshotPreviewForm_Load(object sender, EventArgs e) 116 private async void SnapshotPreviewForm_Load(object sender, EventArgs e)
127 { 117 {
-   118 Relocate();
-   119  
-   120 try
-   121 {
-   122 var snapshotPreview = await _snapshotDatabase.RetrievePreviewAsync(_snapshotHash, _cancellationToken);
-   123  
-   124 if (snapshotPreview == null)
-   125 {
-   126 return;
-   127 }
-   128  
-   129 this.InvokeIfRequired(form =>
-   130 {
-   131 using (var image = form.pictureBox1.Image)
-   132 {
-   133 form.pictureBox1.Image = snapshotPreview.Shot;
-   134 form.richTextBox1.Text = snapshotPreview.Note;
-   135 }
-   136  
-   137 if (string.IsNullOrEmpty(snapshotPreview.Note))
-   138 {
-   139 form.splitContainer1.Panel2Collapsed = true;
-   140 return;
-   141 }
-   142  
-   143 form.splitContainer1.Panel2Collapsed = false;
-   144 });
-   145 }
-   146 catch (Exception exception)
-   147 {
-   148 Log.Error(exception, "Could not retrieve preview.");
128 Relocate(); 149 }
Line 129... Line 150...
129 } 150 }
130   151  
131 private void SnapshotManagerFormMove(object sender, EventArgs e) 152 private void SnapshotManagerFormMove(object sender, EventArgs e)