Horizon – Diff between revs 1 and 27
?pathlinks?
Rev 1 | Rev 27 | |||
---|---|---|---|---|
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; |
||
6 | |
9 | |
|
7 | namespace Horizon.Snapshots |
10 | namespace Horizon.Snapshots |
|
8 | { |
11 | { |
|
9 | public partial class SnapshotPreviewForm : Form |
12 | public partial class SnapshotPreviewForm : Form |
|
10 | { |
13 | { |
|
11 | #region Private Methods |
14 | #region Private Methods |
|
12 | |
15 | |
|
13 | private void Relocate() |
16 | private void Relocate() |
|
14 | { |
17 | { |
|
15 | _snapshotManagerForm.InvokeIfRequired(snapshotForm => |
18 | _snapshotManagerForm.InvokeIfRequired(snapshotForm => |
|
16 | { |
19 | { |
|
17 | var snapshotPreviewLocation = snapshotForm.Location; |
20 | var snapshotPreviewLocation = snapshotForm.Location; |
|
18 | Location = new Point(snapshotPreviewLocation.X + snapshotForm.Size.Width, |
21 | Location = new Point(snapshotPreviewLocation.X + snapshotForm.Size.Width, |
|
19 | snapshotPreviewLocation.Y); |
22 | snapshotPreviewLocation.Y); |
|
20 | }); |
23 | }); |
|
21 | } |
24 | } |
|
22 | |
25 | |
|
23 | #endregion |
26 | #endregion |
|
24 | |
27 | |
|
25 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
28 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
26 | |
29 | |
|
27 | private readonly SnapshotDatabase _snapshotDatabase; |
30 | private readonly SnapshotDatabase _snapshotDatabase; |
|
28 | |
31 | |
|
29 | private readonly SnapshotManagerForm _snapshotManagerForm; |
32 | private readonly SnapshotManagerForm _snapshotManagerForm; |
|
- | 33 | private readonly string _snapshotHash; |
||
- | 34 | private readonly CancellationToken _cancellationToken; |
||
30 | |
35 | |
|
31 | #endregion |
36 | #endregion |
|
32 | |
37 | |
|
33 | #region Constructors, Destructors and Finalizers |
38 | #region Constructors, Destructors and Finalizers |
|
34 | |
39 | |
|
35 | public SnapshotPreviewForm() |
40 | public SnapshotPreviewForm() |
|
36 | { |
41 | { |
|
37 | InitializeComponent(); |
42 | InitializeComponent(); |
|
38 | Utilities.WindowState.FormTracker.Track(this); |
43 | Utilities.WindowState.FormTracker.Track(this); |
|
39 | } |
44 | } |
|
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; |
- | ||
47 | ; |
52 | _snapshotManagerForm.Resize += SnapshotManagerFormResize; |
|
48 | |
53 | |
|
49 | _snapshotDatabase = snapshotDatabase; |
54 | _snapshotDatabase = snapshotDatabase; |
|
50 | _snapshotDatabase.SnapshotNoteUpdate += SnapshotDatabase_SnapshotNoteUpdate; |
55 | _snapshotDatabase.SnapshotNoteUpdate += SnapshotDatabase_SnapshotNoteUpdate; |
|
- | 56 | |
||
- | 57 | _cancellationToken = cancellationToken; |
||
51 | } |
58 | } |
|
52 | |
59 | |
|
53 | /// <summary> |
60 | /// <summary> |
|
54 | /// Clean up any resources being used. |
61 | /// Clean up any resources being used. |
|
55 | /// </summary> |
62 | /// </summary> |
|
56 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
63 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
|
57 | protected override void Dispose(bool disposing) |
64 | protected override void Dispose(bool disposing) |
|
58 | { |
65 | { |
|
59 | if (disposing && components != null) |
66 | if (disposing && components != null) |
|
60 | { |
67 | { |
|
61 | components.Dispose(); |
68 | components.Dispose(); |
|
62 | } |
69 | } |
|
63 | |
70 | |
|
64 | _snapshotDatabase.SnapshotNoteUpdate -= SnapshotDatabase_SnapshotNoteUpdate; |
71 | _snapshotDatabase.SnapshotNoteUpdate -= SnapshotDatabase_SnapshotNoteUpdate; |
|
65 | _snapshotManagerForm.PreviewRetrieved -= SnapshotManagerForm_PreviewRetrieved; |
- | ||
66 | |
72 | |
|
67 | _snapshotManagerForm.Move -= SnapshotManagerFormMove; |
73 | _snapshotManagerForm.Move -= SnapshotManagerFormMove; |
|
68 | _snapshotManagerForm.Resize -= SnapshotManagerFormResize; |
74 | _snapshotManagerForm.Resize -= SnapshotManagerFormResize; |
|
69 | |
75 | |
|
70 | base.Dispose(disposing); |
76 | base.Dispose(disposing); |
|
71 | } |
77 | } |
|
72 | |
78 | |
|
73 | #endregion |
79 | #endregion |
|
74 | |
80 | |
|
75 | #region Event Handlers |
81 | #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 | } |
- | ||
90 | |
- | ||
91 | splitContainer1.Panel2Collapsed = false; |
- | ||
92 | } |
82 | |
|
93 | |
83 | |
|
94 | private void SnapshotDatabase_SnapshotNoteUpdate(object sender, SnapshotNoteUpdateEventArgs e) |
84 | private void SnapshotDatabase_SnapshotNoteUpdate(object sender, SnapshotNoteUpdateEventArgs e) |
|
95 | { |
85 | { |
|
96 | switch (e) |
86 | switch (e) |
|
97 | { |
87 | { |
|
98 | case SnapshotNoteUpdateSuccessEventArgs snapshotNoteUpdateSuccessEventArgs: |
88 | case SnapshotNoteUpdateSuccessEventArgs snapshotNoteUpdateSuccessEventArgs: |
|
99 | |
89 | |
|
100 | richTextBox1.InvokeIfRequired(richTextBox => |
90 | richTextBox1.InvokeIfRequired(richTextBox => |
|
101 | { |
91 | { |
|
102 | richTextBox.Text = snapshotNoteUpdateSuccessEventArgs.Note; |
92 | richTextBox.Text = snapshotNoteUpdateSuccessEventArgs.Note; |
|
103 | }); |
93 | }); |
|
104 | |
94 | |
|
105 | splitContainer1.InvokeIfRequired(splitContainer => |
95 | splitContainer1.InvokeIfRequired(splitContainer => |
|
106 | { |
96 | { |
|
107 | if (string.IsNullOrEmpty(snapshotNoteUpdateSuccessEventArgs.Note)) |
97 | if (string.IsNullOrEmpty(snapshotNoteUpdateSuccessEventArgs.Note)) |
|
108 | { |
98 | { |
|
109 | splitContainer.Panel2Collapsed = true; |
99 | splitContainer.Panel2Collapsed = true; |
|
110 | return; |
100 | return; |
|
111 | } |
101 | } |
|
112 | |
102 | |
|
113 | splitContainer.Panel2Collapsed = false; |
103 | splitContainer.Panel2Collapsed = false; |
|
114 | }); |
104 | }); |
|
115 | break; |
105 | break; |
|
116 | case SnapshotNoteUpdateFailureEventArgs _: |
106 | case SnapshotNoteUpdateFailureEventArgs _: |
|
117 | break; |
107 | break; |
|
118 | } |
108 | } |
|
119 | } |
109 | } |
|
120 | |
110 | |
|
121 | private void SnapshotManagerFormResize(object sender, EventArgs e) |
111 | private void SnapshotManagerFormResize(object sender, EventArgs e) |
|
122 | { |
112 | { |
|
123 | Relocate(); |
113 | Relocate(); |
|
124 | } |
114 | } |
|
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 | } |
|
129 | } |
150 | } |
|
130 | |
151 | |
|
131 | private void SnapshotManagerFormMove(object sender, EventArgs e) |
152 | private void SnapshotManagerFormMove(object sender, EventArgs e) |
|
132 | { |
153 | { |
|
133 | Relocate(); |
154 | Relocate(); |
|
134 | } |
155 | } |
|
135 | |
156 | |
|
136 | private void SplitContainer1_Paint(object sender, PaintEventArgs e) |
157 | private void SplitContainer1_Paint(object sender, PaintEventArgs e) |
|
137 | { |
158 | { |
|
138 | var control = (SplitContainer)sender; |
159 | var control = (SplitContainer)sender; |
|
139 | // paint the three dots |
160 | // paint the three dots |
|
140 | var points = new Point[3]; |
161 | var points = new Point[3]; |
|
141 | var w = control.Width; |
162 | var w = control.Width; |
|
142 | var h = control.Height; |
163 | var h = control.Height; |
|
143 | var d = control.SplitterDistance; |
164 | var d = control.SplitterDistance; |
|
144 | var sW = control.SplitterWidth; |
165 | var sW = control.SplitterWidth; |
|
145 | |
166 | |
|
146 | //calculate the position of the points |
167 | //calculate the position of the points |
|
147 | if (control.Orientation == Orientation.Horizontal) |
168 | if (control.Orientation == Orientation.Horizontal) |
|
148 | { |
169 | { |
|
149 | points[0] = new Point(w / 2, d + sW / 2); |
170 | points[0] = new Point(w / 2, d + sW / 2); |
|
150 | points[1] = new Point(points[0].X - 10, points[0].Y); |
171 | points[1] = new Point(points[0].X - 10, points[0].Y); |
|
151 | points[2] = new Point(points[0].X + 10, points[0].Y); |
172 | points[2] = new Point(points[0].X + 10, points[0].Y); |
|
152 | } |
173 | } |
|
153 | else |
174 | else |
|
154 | { |
175 | { |
|
155 | points[0] = new Point(d + sW / 2, h / 2); |
176 | points[0] = new Point(d + sW / 2, h / 2); |
|
156 | points[1] = new Point(points[0].X, points[0].Y - 10); |
177 | points[1] = new Point(points[0].X, points[0].Y - 10); |
|
157 | points[2] = new Point(points[0].X, points[0].Y + 10); |
178 | points[2] = new Point(points[0].X, points[0].Y + 10); |
|
158 | } |
179 | } |
|
159 | |
180 | |
|
160 | foreach (var p in points) |
181 | foreach (var p in points) |
|
161 | { |
182 | { |
|
162 | p.Offset(-2, -2); |
183 | p.Offset(-2, -2); |
|
163 | e.Graphics.FillEllipse(SystemBrushes.ControlDark, |
184 | e.Graphics.FillEllipse(SystemBrushes.ControlDark, |
|
164 | new Rectangle(p, new Size(3, 3))); |
185 | new Rectangle(p, new Size(3, 3))); |
|
165 | |
186 | |
|
166 | p.Offset(1, 1); |
187 | p.Offset(1, 1); |
|
167 | e.Graphics.FillEllipse(SystemBrushes.ControlLight, |
188 | e.Graphics.FillEllipse(SystemBrushes.ControlLight, |
|
168 | new Rectangle(p, new Size(3, 3))); |
189 | new Rectangle(p, new Size(3, 3))); |
|
169 | } |
190 | } |
|
170 | } |
191 | } |
|
171 | |
192 | |
|
172 | #endregion |
193 | #endregion |
|
173 | } |
194 | } |
|
174 | } |
195 | } |
|
175 | |
196 | |
|
176 |
|
197 |
|
|
177 | |
198 | |
|
178 | |
199 | |
|
179 | |
200 | |