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