HamBook – Diff between revs 53 and 54

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 53 Rev 54
Line 1... Line -...
1 using Configuration; -  
2 using HamBook.Properties; -  
3 using HamBook.Radios; -  
4 using HamBook.Radios.Generic; -  
5 using HamBook.Utilities; -  
6 using HamBook.Utilities.Controls; -  
7 using HamBook.Utilities.Serialization; -  
8 using Serilog; -  
9 using System; 1 using System;
10 using System.Collections.Concurrent; 2 using System.Collections.Concurrent;
11 using System.Collections.Generic; 3 using System.Collections.Generic;
12 using System.ComponentModel; 4 using System.ComponentModel;
13 using System.Data; -  
14 using System.Drawing; 5 using System.Drawing;
15 using System.Linq; 6 using System.Linq;
16 using System.Media; 7 using System.Media;
17 using System.Reflection; 8 using System.Reflection;
18 using System.Runtime.Remoting.Channels; -  
19 using System.Threading; 9 using System.Threading;
20 using System.Threading.Tasks; 10 using System.Threading.Tasks;
21 using System.Windows.Forms; 11 using System.Windows.Forms;
-   12 using HamBook.Properties;
-   13 using HamBook.Radios;
-   14 using HamBook.Radios.Generic;
-   15 using HamBook.Utilities.Serialization;
-   16 using Serilog;
22 using MemoryChannel = HamBook.Radios.Generic.MemoryChannel; 17 using MemoryRadioMode = HamBook.Radios.Yaesu.FT_891.MemoryRadioMode;
Line 23... Line 18...
23   18  
24 namespace HamBook 19 namespace HamBook
25 { 20 {
26 public partial class MemoryOrganizerForm : Form 21 public partial class MemoryOrganizerForm : Form
27 { 22 {
Line 28... Line 23...
28 private Configuration.Configuration Configuration { get; set; } 23 private readonly CancellationTokenSource _cancellationTokenSource;
-   24  
-   25 private readonly CatAssemblies _catAssemblies;
-   26 private readonly CancellationToken _localCancellationToken;
29   27 private readonly CancellationTokenSource _localCancellationTokenSource;
30 private CatAssemblies _catAssemblies; -  
31 private CancellationToken _cancellationToken; -  
32 private Radios.Generic.MemoryBanks _memoryBanks; -  
33 private CancellationTokenSource _cancellationTokenSource; -  
34 private CancellationTokenSource _localCancellationTokenSource; 28 private readonly MemoryBanks _memoryBanks;
-   29 private CancellationToken _cancellationToken;
-   30 private List<DataGridViewRow> _clipboardRows;
-   31 private CancellationTokenSource _writeCancellationTokenSource;
-   32 private CancellationTokenSource _writeLinkedCancellationTokenSource;
-   33 private Task _writeMemoryBanksTask;
-   34 private CancellationTokenSource _readCancellationTokenSource;
Line 35... Line 35...
35 private CancellationToken _localCancellationToken; 35 private CancellationTokenSource _readLinkedCancellationTokenSource;
36 private List<DataGridViewRow> _clipboardRows; 36 private Task _readMemoryBanksTask;
37   37  
38 public MemoryOrganizerForm() 38 public MemoryOrganizerForm()
Line 39... Line 39...
39 { 39 {
40 InitializeComponent(); 40 InitializeComponent();
41 Utilities.WindowState.FormTracker.Track(this); 41 Utilities.WindowState.FormTracker.Track(this);
Line 42... Line 42...
42   42  
-   43 _localCancellationTokenSource = new CancellationTokenSource();
43 _localCancellationTokenSource = new CancellationTokenSource(); 44 _localCancellationToken = _localCancellationTokenSource.Token;
44 _localCancellationToken = _localCancellationTokenSource.Token; 45 }
45 } 46  
Line -... Line 47...
-   47 public MemoryOrganizerForm(Configuration.Configuration configuration, CatAssemblies catAssemblies,
46   48 CancellationToken cancellationToken) : this()
47 public MemoryOrganizerForm(Configuration.Configuration configuration, CatAssemblies catAssemblies, CancellationToken cancellationToken) : this() 49 {
Line 48... Line 50...
48 { 50 Configuration = configuration;
49 Configuration = configuration; 51 _catAssemblies = catAssemblies;
Line -... Line 52...
-   52  
-   53 _cancellationTokenSource =
50 _catAssemblies = catAssemblies; 54 CancellationTokenSource.CreateLinkedTokenSource(_localCancellationToken, cancellationToken);
51   55 _cancellationToken = _cancellationTokenSource.Token;
52 _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_localCancellationToken, cancellationToken); 56  
53 _cancellationToken = _cancellationTokenSource.Token; 57 _memoryBanks = MemoryBanks.Create(Configuration.Radio);
54   58 }
55 _memoryBanks = Radios.Generic.MemoryBanks.Create(Configuration.Radio); 59  
56 } 60 private Configuration.Configuration Configuration { get; }
57   61  
58 /// <summary> -  
59 /// Clean up any resources being used. -  
60 /// </summary> 62 /// <summary>
61 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> -  
Line 62... Line 63...
62 protected override void Dispose(bool disposing) 63 /// Clean up any resources being used.
63 { 64 /// </summary>
-   65 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
64 if (disposing && (components != null)) 66 protected override void Dispose(bool disposing)
65 { 67 {
Line 66... Line 68...
66 if (_cancellationTokenSource != null) 68 if (disposing && components != null)
67 { 69 {
68 _cancellationTokenSource.Cancel(); 70 if (_cancellationTokenSource != null) _cancellationTokenSource.Cancel();
69 } 71  
Line 70... Line 72...
70   72 components.Dispose();
71 components.Dispose(); 73 }
-   74  
Line 72... Line 75...
72 } 75 base.Dispose(disposing);
73 base.Dispose(disposing); 76 }
74 } 77  
75   78 private async void button1_Click(object sender, EventArgs e)
76 private async void button1_Click(object sender, EventArgs e) 79 {
77 { 80 var rows = dataGridView1.Rows.OfType<DataGridViewRow>().OrderBy(row => row.Index).ToList();
78 var rows = dataGridView1.Rows.OfType<DataGridViewRow>().OrderBy(row => row.Index).ToList(); 81 var count = rows.Count;
79 var count = rows.Count; 82  
-   83 toolStripProgressBar1.Minimum = 0;
Line 80... Line 84...
80   84 toolStripProgressBar1.Maximum = count;
81 toolStripProgressBar1.Minimum = 0; 85 toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
82 toolStripProgressBar1.Maximum = count; 86  
83   87 var progress = new Progress<DataGridViewRowProgress>(rowProgress =>
Line 84... Line 88...
84 var progress = new Progress<DataGridViewRowProgress>(rowProgress => 88 {
85 { 89 try
-   90 {
86 try 91 switch (rowProgress)
87 { 92 {
88 switch (rowProgress) 93 case DataGridViewRowProgressSuccess<MemoryChannel> rowProgressSuccess:
89 { 94 dataGridView1.Rows[rowProgressSuccess.Row.Index].DefaultCellStyle.BackColor =
90 case DataGridViewRowProgressSuccess<MemoryChannel> rowProgressSuccess: 95 DefaultBackColor;
Line 108... Line 113...
108 break; 113 break;
109 } 114 }
Line 110... Line 115...
110   115  
111 toolStripStatusLabel1.Text = $"{Resources.Read_memory_bank} {rowProgress.Index + 1}"; 116 toolStripStatusLabel1.Text = $"{Resources.Read_memory_bank} {rowProgress.Index + 1}";
112 break; 117 break;
113 case DataGridViewRowProgressFailure rowProgressFailure: 118 case DataGridViewRowProgressFailure<int> rowProgressFailure:
114 Log.Error(rowProgressFailure.Exception, $"{Resources.Could_not_read_memory_bank}"); 119 Log.Error(rowProgressFailure.Exception, $"{Resources.Could_not_read_memory_bank}");
Line -... Line 120...
-   120 dataGridView1.Rows[rowProgressFailure.Row.Index].DefaultCellStyle.BackColor = Color.Red;
115 dataGridView1.Rows[rowProgressFailure.Row.Index].DefaultCellStyle.BackColor = Color.Red; 121  
116   122 toolStripStatusLabel1.Text =
117 toolStripStatusLabel1.Text = $"{Resources.Could_not_read_memory_bank} {rowProgress.Index + 1}"; 123 $"{Resources.Could_not_read_memory_bank} {rowProgress.Index + 1}";
Line 118... Line 124...
118 break; 124 break;
119 } 125 }
Line 141... Line 147...
141 var rows = dataGridView1.Rows.OfType<DataGridViewRow>().OrderBy(row => row.Index).ToList(); 147 var rows = dataGridView1.Rows.OfType<DataGridViewRow>().OrderBy(row => row.Index).ToList();
142 var count = rows.Count; 148 var count = rows.Count;
Line 143... Line 149...
143   149  
144 toolStripProgressBar1.Minimum = 0; 150 toolStripProgressBar1.Minimum = 0;
-   151 toolStripProgressBar1.Maximum = count;
Line 145... Line 152...
145 toolStripProgressBar1.Maximum = count; 152 toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
146   153  
147 var progress = new Progress<DataGridViewRowProgress>(rowProgress => 154 var progress = new Progress<DataGridViewRowProgress>(rowProgress =>
148 { 155 {
149 try 156 try
150 { 157 {
151 switch (rowProgress) 158 switch (rowProgress)
152 { 159 {
-   160 case DataGridViewRowProgressSuccess<bool> rowProgressSuccess:
153 case DataGridViewRowProgressSuccess<bool> rowProgressSuccess: 161 dataGridView1.Rows[rowProgressSuccess.Row.Index].DefaultCellStyle.BackColor =
154 dataGridView1.Rows[rowProgressSuccess.Row.Index].DefaultCellStyle.BackColor = DataGridView.DefaultBackColor; 162 DefaultBackColor;
155 var success = rowProgressSuccess.Data; 163 var success = rowProgressSuccess.Data;
156 164  
157 if (success) -  
158 { 165 if (success)
159   166 {
160 toolStripStatusLabel1.Text = 167 toolStripStatusLabel1.Text =
161 $"{Resources.Wrote_memory_bank} {rowProgress.Index + 1}"; 168 $"{Resources.Wrote_memory_bank} {rowProgress.Index + 1}";
162 toolStripProgressBar1.Increment(1); 169 toolStripProgressBar1.Increment(1);
163 statusStrip1.Update(); 170 statusStrip1.Update();
Line 164... Line 171...
164 return; 171 return;
165 } 172 }
166   173  
167 Log.Error($"{Resources.Could_not_write_memory_bank}"); 174 Log.Error($"{Resources.Could_not_write_memory_bank}");
168 break; 175 break;
169 case DataGridViewRowProgressFailure rowProgressFailure: 176 case DataGridViewRowProgressFailure<int> rowProgressFailure:
170 dataGridView1.Rows[rowProgressFailure.Row.Index].DefaultCellStyle.BackColor = Color.Red; 177 dataGridView1.Rows[rowProgressFailure.Row.Index].DefaultCellStyle.BackColor = Color.Red;
Line 179... Line 186...
179 } 186 }
180 catch (Exception exception) 187 catch (Exception exception)
181 { 188 {
182 Log.Error(exception, Resources.Unexpected_error_while_writing_memory_bank); 189 Log.Error(exception, Resources.Unexpected_error_while_writing_memory_bank);
183 } 190 }
184   -  
185 }); 191 });
Line 186... Line 192...
186   192  
Line 187... Line 193...
187 await Task.Run(() => WriteMemoryBanks(rows, progress, _cancellationToken), _cancellationToken); 193 await Task.Run(() => WriteMemoryBanks(rows, progress, _cancellationToken), _cancellationToken);
Line 194... Line 200...
194 } 200 }
Line 195... Line 201...
195   201  
196 private void MemoryOrganizerForm_Load(object sender, EventArgs e) 202 private void MemoryOrganizerForm_Load(object sender, EventArgs e)
197 { 203 {
198 // Generate columns based on radio type. 204 // Generate columns based on radio type.
199 switch(Configuration.Radio) 205 switch (Configuration.Radio)
200 { 206 {
-   207 case "Yaesu FT-891":
201 case "Yaesu FT-891": 208 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn
-   209 { Name = "LocationColumn", HeaderText = "Location", ReadOnly = true });
202 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { Name = "LocationColumn", HeaderText = "Location", ReadOnly = true }); 210 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn
-   211 { Name = "FrequencyColumn", HeaderText = "Frequency" });
203 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { Name = "FrequencyColumn", HeaderText = "Frequency" }); 212 var clarifierDropDownColumn = new DataGridViewComboBoxColumn
204 var clarifierDropDownColumn = new DataGridViewComboBoxColumn() { Name = "ClarifierDirectionColumn", HeaderText = "Clarifier" }; 213 { Name = "ClarifierDirectionColumn", HeaderText = "Clarifier" };
205 clarifierDropDownColumn.Items.AddRange( 214 clarifierDropDownColumn.Items.AddRange(
206 "+", 215 "+",
207 "-" 216 "-"
208 ); 217 );
-   218 dataGridView1.Columns.Add(clarifierDropDownColumn);
209 dataGridView1.Columns.Add(clarifierDropDownColumn); 219 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn
210 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { Name = "ClarifierOffsetColumn", HeaderText = "Offset" }); 220 { Name = "ClarifierOffsetColumn", HeaderText = "Offset" });
-   221 dataGridView1.Columns.Add(new DataGridViewCheckBoxColumn
211 dataGridView1.Columns.Add(new DataGridViewCheckBoxColumn() { Name = "ClarColumn", HeaderText = "Clar" }); 222 { Name = "ClarColumn", HeaderText = "Clar" });
212 var modeComboBoxColumn = new DataGridViewComboBoxColumn() { Name = "ModeColumn", HeaderText = "Mode" }; 223 var modeComboBoxColumn = new DataGridViewComboBoxColumn
213 foreach (var name in Radios.Yaesu.FT_891.MemoryRadioMode.Names) 224 { Name = "ModeColumn", HeaderText = "Mode" };
214 { 225 foreach (var name in MemoryRadioMode.Names)
215 modeComboBoxColumn.Items.Add( 226 modeComboBoxColumn.Items.Add(
216 name 227 name
217 ); -  
218 } 228 );
219 229  
220 dataGridView1.Columns.Add(modeComboBoxColumn); 230 dataGridView1.Columns.Add(modeComboBoxColumn);
-   231 var ctcssComboBoxColumn = new DataGridViewComboBoxColumn
221 var ctcssComboBoxColumn = new DataGridViewComboBoxColumn() { Name = "CtcssColumn", HeaderText = "CTCSS" }; 232 { Name = "CtcssColumn", HeaderText = "CTCSS" };
222 ctcssComboBoxColumn.Items.AddRange( 233 ctcssComboBoxColumn.Items.AddRange(
223 "Off", 234 "Off",
224 "Enc/Dec", 235 "Enc/Dec",
225 "Enc" 236 "Enc"
226 ); 237 );
227 dataGridView1.Columns.Add(ctcssComboBoxColumn); 238 dataGridView1.Columns.Add(ctcssComboBoxColumn);
-   239 var phaseComboBoxColumn = new DataGridViewComboBoxColumn
228 var phaseComboBoxColumn = new DataGridViewComboBoxColumn() { Name = "PhaseColumn", HeaderText = "Phase" }; 240 { Name = "PhaseColumn", HeaderText = "Phase" };
229 phaseComboBoxColumn.Items.AddRange( 241 phaseComboBoxColumn.Items.AddRange(
230 "Simplex", 242 "Simplex",
231 "Plus Shift", 243 "Plus Shift",
232 "Minus Shift" 244 "Minus Shift"
233 ); 245 );
234 dataGridView1.Columns.Add(phaseComboBoxColumn); 246 dataGridView1.Columns.Add(phaseComboBoxColumn);
-   247 dataGridView1.Columns.Add(new DataGridViewCheckBoxColumn
-   248 { Name = "TagColumn", HeaderText = "Tag" });
-   249 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn
-   250 {
235 dataGridView1.Columns.Add(new DataGridViewCheckBoxColumn() { Name = "TagColumn", HeaderText = "Tag" }); 251 Name = "TextColumn", HeaderText = "Text",
-   252 MaxInputLength = Radios.Yaesu.FT_891.Constants.MaxTagCharacters
236 dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { Name = "TextColumn", HeaderText = "Text", MaxInputLength = Radios.Yaesu.FT_891.Constants.MAX_TAG_CHARACTERS }); 253 });
237 break; 254 break;
Line 238... Line 255...
238 } 255 }
239   256  
-   257 toolStripProgressBar1.Minimum = 0;
Line 240... Line 258...
240 toolStripProgressBar1.Minimum = 0; 258 toolStripProgressBar1.Maximum = 98;
241 toolStripProgressBar1.Maximum = 98; 259 toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
Line 242... Line 260...
242   260  
Line 259... Line 277...
259 return; 277 return;
260 } 278 }
Line 261... Line 279...
261   279  
Line 262... Line 280...
262 var index = dataGridView1.Rows.Add(); 280 var index = dataGridView1.Rows.Add();
263   281  
264 switch(Configuration.Radio) 282 switch (Configuration.Radio)
265 { 283 {
266 case "Yaesu FT-891": 284 case "Yaesu FT-891":
267 dataGridView1.Rows[index].Cells["LocationColumn"].Value = memoryBank; 285 dataGridView1.Rows[index].Cells["LocationColumn"].Value = memoryBank;
Line 288... Line 306...
288 } 306 }
Line 289... Line 307...
289   307  
290 Application.Idle += IdleHandler; 308 Application.Idle += IdleHandler;
291 try 309 try
292 { 310 {
293 foreach (var memoryBank in _memoryBanks.GetMemoryBanks()) -  
294 { -  
295 memoryBankQueue.Enqueue(memoryBank); -  
Line 296... Line 311...
296 } 311 foreach (var memoryBank in _memoryBanks.GetMemoryBanks()) memoryBankQueue.Enqueue(memoryBank);
297   312  
298 memoryBankAddRowsTaskCompletionSource.TrySetResult(new { }); 313 memoryBankAddRowsTaskCompletionSource.TrySetResult(new { });
299 } 314 }
Line 308... Line 323...
308 private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) 323 private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
309 { 324 {
310 var dataGridView = (DataGridView)sender; 325 var dataGridView = (DataGridView)sender;
Line 311... Line 326...
311   326  
312 if (dataGridView.CurrentCell is DataGridViewCheckBoxCell) -  
313 { 327 if (dataGridView.CurrentCell is DataGridViewCheckBoxCell)
314 dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit); -  
315 } 328 dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
Line 316... Line 329...
316 } 329 }
317   330  
318 private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) 331 private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
Line 322... Line 335...
322 dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit); 335 dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
323 } 336 }
Line 324... Line 337...
324   337  
325 private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 338 private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
326 { -  
327   339 {
Line 328... Line 340...
328 } 340 }
329   341  
330 private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) 342 private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
Line 331... Line 343...
331 { 343 {
332 var dataGridView = (DataGridView)sender; -  
333   -  
334 if (e.RowIndex == -1 || e.ColumnIndex == -1) -  
Line 335... Line 344...
335 { 344 var dataGridView = (DataGridView)sender;
336 return; 345  
337 } 346 if (e.RowIndex == -1 || e.ColumnIndex == -1) return;
338   347  
Line 348... Line 357...
348 { 357 {
349 var dataGridView = (DataGridView)sender; 358 var dataGridView = (DataGridView)sender;
Line 350... Line 359...
350   359  
351 if (e.RowIndex == -1 || e.ColumnIndex == -1 || 360 if (e.RowIndex == -1 || e.ColumnIndex == -1 ||
352 !(dataGridView.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn)) -  
353 { 361 !(dataGridView.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn))
354 return; -  
Line 355... Line 362...
355 } 362 return;
356   363  
Line 357... Line 364...
357 dataGridView.EndEdit(); 364 dataGridView.EndEdit();
358 } 365 }
359   366  
Line 360... Line 367...
360 private void DataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) 367 private void DataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
361 { 368 {
362 var dataGridView = (DataGridView)sender; -  
363   369 var dataGridView = (DataGridView)sender;
364 if (e.RowIndex == -1 || e.ColumnIndex == -1 || -  
Line 365... Line 370...
365 !(dataGridView.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn)) 370  
366 { 371 if (e.RowIndex == -1 || e.ColumnIndex == -1 ||
Line 367... Line 372...
367 return; 372 !(dataGridView.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn))
Line 378... Line 383...
378 private static IEnumerable<DataGridViewRow> GetSelectedDataGridViewRows(DataGridView dataGridView) 383 private static IEnumerable<DataGridViewRow> GetSelectedDataGridViewRows(DataGridView dataGridView)
379 { 384 {
380 return dataGridView.SelectedRows.OfType<DataGridViewRow>().OrderBy(row => row.Index); 385 return dataGridView.SelectedRows.OfType<DataGridViewRow>().OrderBy(row => row.Index);
381 } 386 }
Line 382... Line 387...
382   387  
-   388 private async Task ReadMemoryBanks(IReadOnlyList<DataGridViewRow> rows,
383 private async Task ReadMemoryBanks(IReadOnlyList<DataGridViewRow> rows, IProgress<DataGridViewRowProgress> progress, 389 IProgress<DataGridViewRowProgress> progress,
384 CancellationToken cancellationToken) 390 CancellationToken cancellationToken)
385 { 391 {
Line 386... Line 392...
386 var count = rows.Count; 392 var count = rows.Count;
387   -  
388 for (var i = 0; i < count && !cancellationToken.IsCancellationRequested; ++i) 393  
389 { 394 for (var i = 0; i < count && !cancellationToken.IsCancellationRequested; ++i)
390 try 395 try
Line -... Line 396...
-   396 {
391 { 397 var location = $"{rows[i].Cells["LocationColumn"].Value}";
-   398  
Line 392... Line 399...
392 var location = $"{rows[i].Cells["LocationColumn"].Value}"; 399 var result =
393   400 await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { location },
394 var result = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { location }, _cancellationToken); 401 cancellationToken);
395   402  
396 progress.Report(new DataGridViewRowProgressSuccess<MemoryChannel>(rows[i], i, result)); 403 progress.Report(new DataGridViewRowProgressSuccess<MemoryChannel>(rows[i], i, result));
397 } 404 }
398 catch (UnexpectedRadioResponseException exception) 405 catch (UnexpectedRadioResponseException exception)
399 { 406 {
400 progress.Report(new DataGridViewRowProgressFailure(rows[i], i, exception)); 407 progress.Report(new DataGridViewRowProgressFailure<int>(rows[i], i, exception));
401 } 408 }
402 catch (Exception exception) -  
403 { 409 catch (Exception exception)
Line 404... Line 410...
404 progress.Report(new DataGridViewRowProgressFailure(rows[i], i, exception)); 410 {
-   411 progress.Report(new DataGridViewRowProgressFailure<int>(rows[i], i, exception));
405 } 412 }
406 } 413 }
407 } 414  
Line 408... Line 415...
408   415 private async Task WriteMemoryBanks(IReadOnlyList<DataGridViewRow> rows,
409 private async Task WriteMemoryBanks(IReadOnlyList<DataGridViewRow> rows, IProgress<DataGridViewRowProgress> progress, -  
410 CancellationToken cancellationToken) 416 IProgress<DataGridViewRowProgress> progress,
411 { 417 CancellationToken cancellationToken)
412 var count = rows.Count; 418 {
Line 413... Line 419...
413   419 var count = rows.Count;
414 for (var i = 0; i < count && !cancellationToken.IsCancellationRequested; ++i) 420  
415 { 421 for (var i = 0; i < count && !cancellationToken.IsCancellationRequested; ++i)
-   422 try
416 try 423 {
Line 417... Line 424...
417 { 424 var success = false;
418 var success = false; 425  
-   426 switch (Configuration.Radio)
419   427 {
-   428 case "Yaesu FT-891":
420 switch(Configuration.Radio) 429 var memoryChannel =
421 { 430 (Radios.Yaesu.FT_891.MemoryChannel)MemoryChannel.Create(Configuration.Radio);
422 case "Yaesu FT-891": 431  
-   432 memoryChannel.CurrentLocation = $"{rows[i].Cells["LocationColumn"].Value}";
423 var memoryChannel = (Radios.Yaesu.FT_891.MemoryChannel)MemoryChannel.Create(Configuration.Radio); 433 memoryChannel.Frequency = int.Parse($"{rows[i].Cells["FrequencyColumn"].Value}");
424   434 memoryChannel.ClarifierDirection =
425 memoryChannel.CurrentLocation = $"{rows[i].Cells["LocationColumn"].Value}"; 435 char.Parse($"{rows[i].Cells["ClarifierDirectionColumn"].Value}");
426 memoryChannel.Frequency = int.Parse($"{rows[i].Cells["FrequencyColumn"].Value}"); 436 memoryChannel.ClarifierOffset =
Line 427... Line 437...
427 memoryChannel.ClarifierDirection = char.Parse($"{rows[i].Cells["ClarifierDirectionColumn"].Value}"); 437 int.Parse($"{rows[i].Cells["ClarifierOffsetColumn"].Value}");
-   438 memoryChannel.Clar = Convert.ToBoolean(rows[i].Cells["ClarColumn"].Value);
428 memoryChannel.ClarifierOffset = int.Parse($"{rows[i].Cells["ClarifierOffsetColumn"].Value}"); 439 memoryChannel.MemoryRadioMode = Radios.Generic.MemoryRadioMode.Create(Configuration.Radio,
429 memoryChannel.Clar = Convert.ToBoolean(rows[i].Cells["ClarColumn"].Value); 440 $"{rows[i].Cells["ModeColumn"].Value}");
Line 430... Line 441...
430 memoryChannel.MemoryRadioMode = Radios.Generic.MemoryRadioMode.Create(Configuration.Radio, $"{rows[i].Cells["ModeColumn"].Value}"); 441 memoryChannel.Ctcss = new Ctcss($"{rows[i].Cells["CtcssColumn"].Value}");
431 memoryChannel.Ctcss = new Ctcss($"{rows[i].Cells["CtcssColumn"].Value}"); 442 memoryChannel.Phase = new Phase($"{rows[i].Cells["PhaseColumn"].Value}");
432 memoryChannel.Phase = new Phase($"{rows[i].Cells["PhaseColumn"].Value}"); 443 memoryChannel.Tag = Convert.ToBoolean(rows[i].Cells["TagColumn"].Value);
433 memoryChannel.Tag = Convert.ToBoolean(rows[i].Cells["TagColumn"].Value); 444 memoryChannel.Text = $"{rows[i].Cells["TextColumn"].Value,-12}";
434 memoryChannel.Text = $"{rows[i].Cells["TextColumn"].Value,-12}"; 445  
435   446 success = await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT",
436 success = await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT", new object[] { memoryChannel }, _cancellationToken); 447 new object[] { memoryChannel }, cancellationToken);
437 break; 448 break;
438 } 449 }
439   450  
440 progress.Report(new DataGridViewRowProgressSuccess<bool>(rows[i], i, success)); -  
441 } 451 progress.Report(new DataGridViewRowProgressSuccess<bool>(rows[i], i, success));
Line 442... Line 452...
442 catch (UnexpectedRadioResponseException exception) 452 }
443 { 453 catch (UnexpectedRadioResponseException exception)
444 progress.Report(new DataGridViewRowProgressFailure(rows[i], i, exception)); 454 {
Line 460... Line 470...
460 saveFileDialog1.ShowDialog(); 470 saveFileDialog1.ShowDialog();
461 } 471 }
Line 462... Line 472...
462   472  
463 private async void saveFileDialog1_FileOk(object sender, CancelEventArgs e) 473 private async void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
464 { 474 {
465 if (e.Cancel) -  
466 { -  
467 return; -  
Line 468... Line 475...
468 } 475 if (e.Cancel) return;
469   476  
470 var fileName = saveFileDialog1.FileName; 477 var fileName = saveFileDialog1.FileName;
471 var list = new List<MemoryChannelIndexed>(); -  
472 foreach(var row in dataGridView1.Rows.OfType<DataGridViewRow>().OrderBy(row => row.Index)) 478 var list = new List<MemoryChannelIndexed>();
473 { 479 foreach (var row in dataGridView1.Rows.OfType<DataGridViewRow>().OrderBy(row => row.Index))
474 if (row.Tag is MemoryChannel memoryChannel) 480 if (row.Tag is MemoryChannel memoryChannel)
475 { 481 {
476 var memoryChannelOrganizerBanks = new MemoryChannelIndexed(row.Index, memoryChannel); 482 var memoryChannelOrganizerBanks = new MemoryChannelIndexed(row.Index, memoryChannel);
477 list.Add(memoryChannelOrganizerBanks); -  
Line 478... Line 483...
478 } 483 list.Add(memoryChannelOrganizerBanks);
Line 479... Line 484...
479 } 484 }
480   485  
Line 493... Line 498...
493 } 498 }
494 } 499 }
Line 495... Line 500...
495   500  
496 private async void openFileDialog1_FileOk(object sender, CancelEventArgs e) 501 private async void openFileDialog1_FileOk(object sender, CancelEventArgs e)
497 { 502 {
498 if(e.Cancel) -  
499 { -  
500 return; -  
Line 501... Line 503...
501 } 503 if (e.Cancel) return;
502   504  
Line 503... Line 505...
503 var fileName = openFileDialog1.FileName; 505 var fileName = openFileDialog1.FileName;
504 MemoryChannelIndexed[] memoryBanks = null; 506 MemoryChannelIndexed[] memoryBanks = null;
505   507  
-   508 var deserializationResult =
Line 506... Line 509...
506 var deserializationResult = 509 await Serialization.Deserialize<MemoryChannelIndexed[]>(fileName,
507 await Serialization.Deserialize<MemoryChannelIndexed[]>(fileName, 510 "urn:hambook-memorychannelorganizerbank-schema", "MemoryChannelIndexed.xsd",
508 "urn:hambook-memorychannelorganizerbank-schema", "MemoryChannelIndexed.xsd", CancellationToken.None); 511 CancellationToken.None);
509   512  
Line 518... Line 521...
518 return; 521 return;
519 } 522 }
Line 520... Line 523...
520   523  
521 toolStripProgressBar1.Minimum = 0; 524 toolStripProgressBar1.Minimum = 0;
-   525 toolStripProgressBar1.Maximum = 98;
Line 522... Line 526...
522 toolStripProgressBar1.Maximum = 98; 526 toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
523   527  
Line 524... Line 528...
524 var memoryBankQueue = new ConcurrentQueue<MemoryChannelIndexed>(); 528 var memoryBankQueue = new ConcurrentQueue<MemoryChannelIndexed>();
Line 537... Line 541...
537 dataGridView1.Sort(dataGridView1.Columns["LocationColumn"], ListSortDirection.Ascending); 541 dataGridView1.Sort(dataGridView1.Columns["LocationColumn"], ListSortDirection.Ascending);
538 toolStripStatusLabel1.Text = "Done."; 542 toolStripStatusLabel1.Text = "Done.";
Line 539... Line 543...
539   543  
540 return; 544 return;
541 } 545 }
542 546  
543 switch(Configuration.Radio) 547 switch (Configuration.Radio)
544 { 548 {
545 case "Yaesu FT-891": 549 case "Yaesu FT-891":
Line 546... Line 550...
546 var memoryChannel = (Radios.Yaesu.FT_891.MemoryChannel)memoryBank.MemoryChannel; 550 var memoryChannel = (Radios.Yaesu.FT_891.MemoryChannel)memoryBank.MemoryChannel;
-   551  
547   552 dataGridView1.Rows[memoryBank.Index].Cells["FrequencyColumn"].Value =
-   553 memoryBank.MemoryChannel.Frequency;
548 dataGridView1.Rows[memoryBank.Index].Cells["FrequencyColumn"].Value = memoryBank.MemoryChannel.Frequency; 554 dataGridView1.Rows[memoryBank.Index].Cells["ClarifierDirectionColumn"].Value =
-   555 (char)memoryChannel.ClarifierDirection;
549 dataGridView1.Rows[memoryBank.Index].Cells["ClarifierDirectionColumn"].Value = (char)memoryChannel.ClarifierDirection; 556 dataGridView1.Rows[memoryBank.Index].Cells["ClarifierOffsetColumn"].Value =
550 dataGridView1.Rows[memoryBank.Index].Cells["ClarifierOffsetColumn"].Value = memoryChannel.ClarifierOffset; 557 memoryChannel.ClarifierOffset;
-   558 dataGridView1.Rows[memoryBank.Index].Cells["ClarColumn"].Value = memoryChannel.Clar;
551 dataGridView1.Rows[memoryBank.Index].Cells["ClarColumn"].Value = memoryChannel.Clar; 559 dataGridView1.Rows[memoryBank.Index].Cells["ModeColumn"].Value =
-   560 memoryBank.MemoryChannel.MemoryRadioMode.Name;
552 dataGridView1.Rows[memoryBank.Index].Cells["ModeColumn"].Value = memoryBank.MemoryChannel.MemoryRadioMode.Name; 561 dataGridView1.Rows[memoryBank.Index].Cells["CtcssColumn"].Value =
-   562 (string)memoryChannel.Ctcss;
553 dataGridView1.Rows[memoryBank.Index].Cells["CtcssColumn"].Value = (string)memoryChannel.Ctcss; 563 dataGridView1.Rows[memoryBank.Index].Cells["PhaseColumn"].Value =
-   564 (string)memoryChannel.Phase;
554 dataGridView1.Rows[memoryBank.Index].Cells["PhaseColumn"].Value = (string)memoryChannel.Phase; 565 dataGridView1.Rows[memoryBank.Index].Cells["TagColumn"].Value =
-   566 memoryBank.MemoryChannel.Tag;
555 dataGridView1.Rows[memoryBank.Index].Cells["TagColumn"].Value = memoryBank.MemoryChannel.Tag; 567 dataGridView1.Rows[memoryBank.Index].Cells["TextColumn"].Value =
556 dataGridView1.Rows[memoryBank.Index].Cells["TextColumn"].Value = memoryBank.MemoryChannel.Text; 568 memoryBank.MemoryChannel.Text;
557 dataGridView1.Rows[memoryBank.Index].Tag = memoryBank.MemoryChannel; 569 dataGridView1.Rows[memoryBank.Index].Tag = memoryBank.MemoryChannel;
Line 558... Line 570...
558 break; 570 break;
Line 568... Line 580...
568 } 580 }
Line 569... Line 581...
569   581  
570 Application.Idle += IdleHandler; 582 Application.Idle += IdleHandler;
571 try 583 try
572 { -  
573 foreach (var memoryChannel in memoryBanks) -  
574 { 584 {
575 memoryBankQueue.Enqueue(memoryChannel); -  
Line 576... Line 585...
576 } 585 foreach (var memoryChannel in memoryBanks) memoryBankQueue.Enqueue(memoryChannel);
577   586  
578 snapshotsQueuedTaskCompletionSource.TrySetResult(new { }); 587 snapshotsQueuedTaskCompletionSource.TrySetResult(new { });
579 } 588 }
Line 585... Line 594...
585 } 594 }
586 } 595 }
Line 587... Line 596...
587   596  
588 private void MemoryOrganizerForm_FormClosing(object sender, FormClosingEventArgs e) 597 private void MemoryOrganizerForm_FormClosing(object sender, FormClosingEventArgs e)
589 { -  
590 if(_cancellationTokenSource != null) -  
591 { 598 {
592 _cancellationTokenSource.Cancel(); -  
593 } 599 if (_cancellationTokenSource != null) _cancellationTokenSource.Cancel();
Line 594... Line 600...
594 } 600 }
595   601  
-   602 private async void readToolStripMenuItem_Click(object sender, EventArgs e)
-   603 {
596 private async void readToolStripMenuItem_Click(object sender, EventArgs e) 604 if (_readLinkedCancellationTokenSource != null)
-   605 {
-   606 _readLinkedCancellationTokenSource.Cancel();
Line 597... Line 607...
597 { 607 _readLinkedCancellationTokenSource = null;
598 var rows = GetSelectedDataGridViewRows(dataGridView1); 608 }
599   609  
-   610 if (_readMemoryBanksTask != null)
600 if(!rows.Any()) 611 {
Line -... Line 612...
-   612 await _readMemoryBanksTask;
-   613 _readMemoryBanksTask = null;
-   614 }
-   615  
-   616 _readCancellationTokenSource = new CancellationTokenSource();
-   617 _readLinkedCancellationTokenSource =
-   618 CancellationTokenSource.CreateLinkedTokenSource(new[]
-   619 { _cancellationTokenSource.Token, _cancellationToken });
-   620  
-   621 _readMemoryBanksTask = ReadMemoryBanks(_readLinkedCancellationTokenSource.Token);
-   622 }
-   623  
-   624 private async Task ReadMemoryBanks(CancellationToken cancellationToken)
-   625 {
601 { 626 var rows = GetSelectedDataGridViewRows(dataGridView1);
Line 602... Line 627...
602 return; 627  
Line 603... Line 628...
603 } 628 if (!rows.Any()) return;
604   629  
-   630 var list = rows.ToList();
Line 605... Line 631...
605 var list = rows.ToList(); 631  
606   632 var count = list.Count;
607 var count = list.Count; 633  
608   634 toolStripProgressBar1.Minimum = 0;
609 toolStripProgressBar1.Minimum = 0; 635 toolStripProgressBar1.Maximum = count;
610 toolStripProgressBar1.Maximum = count; 636 toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
611   637  
612 var progress = new Progress<DataGridViewRowProgress>(rowProgress => 638 var progress = new Progress<DataGridViewRowProgress>(rowProgress =>
-   639 {
Line 613... Line 640...
613 { 640 try
614 try 641 {
615 { 642 switch (rowProgress)
616 switch (rowProgress) 643 {
617 { 644 case DataGridViewRowProgressSuccess<MemoryChannel> rowProgressSuccess:
-   645 dataGridView1.Rows[rowProgressSuccess.Row.Index].DefaultCellStyle.BackColor =
618 case DataGridViewRowProgressSuccess<MemoryChannel> rowProgressSuccess: 646 DefaultBackColor;
-   647  
619 dataGridView1.Rows[rowProgressSuccess.Row.Index].DefaultCellStyle.BackColor = DataGridView.DefaultBackColor; 648 switch (rowProgressSuccess.Data)
620   649 {
621 switch (rowProgressSuccess.Data) 650 case Radios.Yaesu.FT_891.MemoryChannel memoryChannel:
622 { 651 rowProgress.Row.Cells["FrequencyColumn"].Value = memoryChannel.Frequency;
623 case Radios.Yaesu.FT_891.MemoryChannel memoryChannel: 652 rowProgress.Row.Cells["ClarifierDirectionColumn"].Value =
Line 634... Line 663...
634 break; 663 break;
635 } 664 }
Line 636... Line 665...
636   665  
637 toolStripStatusLabel1.Text = $"{Resources.Read_memory_bank} {rowProgress.Index + 1}"; 666 toolStripStatusLabel1.Text = $"{Resources.Read_memory_bank} {rowProgress.Index + 1}";
638 break; 667 break;
639 case DataGridViewRowProgressFailure rowProgressFailure: 668 case DataGridViewRowProgressFailure<int> rowProgressFailure:
640 Log.Error(rowProgressFailure.Exception, $"{Resources.Could_not_read_memory_bank}"); 669 Log.Error(rowProgressFailure.Exception, $"{Resources.Could_not_read_memory_bank}");
Line -... Line 670...
-   670 dataGridView1.Rows[rowProgressFailure.Row.Index].DefaultCellStyle.BackColor = Color.Red;
641 dataGridView1.Rows[rowProgressFailure.Row.Index].DefaultCellStyle.BackColor = Color.Red; 671  
642   672 toolStripStatusLabel1.Text =
643 toolStripStatusLabel1.Text = $"{Resources.Could_not_read_memory_bank} {rowProgress.Index + 1}"; 673 $"{Resources.Could_not_read_memory_bank} {rowProgress.Index + 1}";
Line 644... Line 674...
644 break; 674 break;
645 } 675 }
Line 651... Line 681...
651 { 681 {
652 Log.Error(exception, Resources.Unexpected_error_while_reading_memory_bank); 682 Log.Error(exception, Resources.Unexpected_error_while_reading_memory_bank);
653 } 683 }
654 }); 684 });
Line 655... Line 685...
655   685  
Line 656... Line 686...
656 await Task.Run(() => ReadMemoryBanks(list, progress, _cancellationToken), _cancellationToken); 686 await Task.Run(() => ReadMemoryBanks(list, progress, cancellationToken), cancellationToken);
657   687  
658 if (!_cancellationToken.IsCancellationRequested) 688 if (!_cancellationToken.IsCancellationRequested)
659 { 689 {
660 toolStripProgressBar1.Value = toolStripProgressBar1.Maximum; 690 toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
661 toolStripStatusLabel1.Text = "Done."; 691 toolStripStatusLabel1.Text = "Done.";
Line 662... Line 692...
662 } 692 }
663 } 693 }
-   694  
-   695 private async void writeToolStripMenuItem_Click(object sender, EventArgs e)
664   696 {
-   697 if (_writeLinkedCancellationTokenSource != null)
-   698 {
Line 665... Line 699...
665 private async void writeToolStripMenuItem_Click(object sender, EventArgs e) 699 _writeLinkedCancellationTokenSource.Cancel();
666 { 700 _writeLinkedCancellationTokenSource = null;
667 var rows = GetSelectedDataGridViewRows(dataGridView1); 701 }
-   702  
668   703 if (_writeMemoryBanksTask != null)
Line -... Line 704...
-   704 {
-   705 await _writeMemoryBanksTask;
-   706 _writeMemoryBanksTask = null;
-   707 }
-   708  
-   709 _writeCancellationTokenSource = new CancellationTokenSource();
-   710 _writeLinkedCancellationTokenSource =
-   711 CancellationTokenSource.CreateLinkedTokenSource(new[]
-   712 { _cancellationTokenSource.Token, _cancellationToken });
-   713  
-   714 _writeMemoryBanksTask = WriteMemoryBanks(_writeLinkedCancellationTokenSource.Token);
-   715 }
-   716  
-   717 private async Task WriteMemoryBanks(CancellationToken cancellationToken)
669 if (!rows.Any()) 718 {
Line 670... Line 719...
670 { 719 var rows = GetSelectedDataGridViewRows(dataGridView1);
Line 671... Line 720...
671 return; 720  
672 } 721 if (!rows.Any()) return;
-   722  
Line 673... Line 723...
673   723 var list = rows.ToList();
674 var list = rows.ToList(); 724  
675   725 var count = list.Count;
676 var count = list.Count; 726  
677   727 toolStripProgressBar1.Minimum = 0;
678 toolStripProgressBar1.Minimum = 0; 728 toolStripProgressBar1.Maximum = count;
679 toolStripProgressBar1.Maximum = count; 729 toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
680   730  
-   731 var progress = new Progress<DataGridViewRowProgress>(rowProgress =>
681 var progress = new Progress<DataGridViewRowProgress>(rowProgress => 732 {
Line 682... Line 733...
682 { 733 try
683 try 734 {
684 { -  
685 switch (rowProgress) 735 switch (rowProgress)
686 { 736 {
687 case DataGridViewRowProgressSuccess<bool> rowProgressSuccess: 737 case DataGridViewRowProgressSuccess<bool> rowProgressSuccess:
688 dataGridView1.Rows[rowProgressSuccess.Row.Index].DefaultCellStyle.BackColor = DataGridView.DefaultBackColor; 738 dataGridView1.Rows[rowProgressSuccess.Row.Index].DefaultCellStyle.BackColor =
689 var success = rowProgressSuccess.Data; 739 DefaultBackColor;
690   740 var success = rowProgressSuccess.Data;
691 if (success) 741  
Line 692... Line 742...
692 { 742 if (success)
693   743 {
694 toolStripStatusLabel1.Text = 744 toolStripStatusLabel1.Text =
695 $"{Resources.Wrote_memory_bank} {rowProgress.Index + 1}"; 745 $"{Resources.Wrote_memory_bank} {rowProgress.Index + 1}";
696 toolStripProgressBar1.Increment(1); 746 toolStripProgressBar1.Increment(1);
697 statusStrip1.Update(); 747 statusStrip1.Update();
698 748  
Line 714... Line 764...
714 } 764 }
715 catch (Exception exception) 765 catch (Exception exception)
716 { 766 {
717 Log.Error(exception, Resources.Unexpected_error_while_writing_memory_bank); 767 Log.Error(exception, Resources.Unexpected_error_while_writing_memory_bank);
718 } 768 }
719   -  
720 }); 769 });
Line 721... Line 770...
721   770  
Line 722... Line 771...
722 await Task.Run(() => WriteMemoryBanks(list, progress, _cancellationToken), _cancellationToken); 771 await Task.Run(() => WriteMemoryBanks(list, progress, cancellationToken), cancellationToken);
723   772  
724 if (!_cancellationToken.IsCancellationRequested) 773 if (!_cancellationToken.IsCancellationRequested)
725 { 774 {
Line 730... Line 779...
730   779  
731 private async void readFromVFOAToolStripMenuItem_Click(object sender, EventArgs e) 780 private async void readFromVFOAToolStripMenuItem_Click(object sender, EventArgs e)
732 { 781 {
Line 733... Line 782...
733 var rows = GetSelectedDataGridViewRows(dataGridView1); 782 var rows = GetSelectedDataGridViewRows(dataGridView1);
734   -  
735 if (!rows.Any()) -  
736 { -  
Line 737... Line 783...
737 return; 783  
Line 738... Line 784...
738 } 784 if (!rows.Any()) return;
739   785  
740 var list = rows.ToList(); 786 var list = rows.ToList();
741   787  
742 try 788 try
Line 743... Line 789...
743 { 789 {
744 foreach (var row in list) 790 foreach (var row in list)
745 { -  
746 var fa = await _catAssemblies.CatReadAsync<int>("FA", new object[] { }, _cancellationToken); 791 {
747   792 var fa = await _catAssemblies.CatReadAsync<int>("FA", new object[] { }, _cancellationToken);
748 row.Cells["FrequencyColumn"].Value = $"{ fa }"; 793  
749 } 794 row.Cells["FrequencyColumn"].Value = $"{fa}";
750   795 }
Line 757... Line 802...
757   802  
758 private async void readFromVFOBToolStripMenuItem_Click(object sender, EventArgs e) 803 private async void readFromVFOBToolStripMenuItem_Click(object sender, EventArgs e)
759 { 804 {
Line 760... Line 805...
760 var rows = GetSelectedDataGridViewRows(dataGridView1); 805 var rows = GetSelectedDataGridViewRows(dataGridView1);
761   -  
762 if (!rows.Any()) -  
763 { -  
Line 764... Line 806...
764 return; 806  
Line 765... Line 807...
765 } 807 if (!rows.Any()) return;
766   808  
Line 772... Line 814...
772 { 814 {
773 var fb = await _catAssemblies.CatReadAsync<int>("FB", new object[] { }, _cancellationToken); 815 var fb = await _catAssemblies.CatReadAsync<int>("FB", new object[] { }, _cancellationToken);
Line 774... Line 816...
774   816  
775 row.Cells["FrequencyColumn"].Value = $"{fb}"; 817 row.Cells["FrequencyColumn"].Value = $"{fb}";
776 } -  
777   818 }
778 } 819 }
779 catch (Exception exception) 820 catch (Exception exception)
780 { 821 {
781 Log.Error(exception, Resources.Failed_to_read_VFO_B); 822 Log.Error(exception, Resources.Failed_to_read_VFO_B);
Line 784... Line 825...
784   825  
785 private async void memoryChannelToolStripMenuItem_Click(object sender, EventArgs e) 826 private async void memoryChannelToolStripMenuItem_Click(object sender, EventArgs e)
786 { 827 {
Line 787... Line 828...
787 var rows = GetSelectedDataGridViewRows(dataGridView1); 828 var rows = GetSelectedDataGridViewRows(dataGridView1);
788   -  
789 if (!rows.Any()) -  
790 { -  
Line 791... Line 829...
791 return; 829  
Line 792... Line 830...
792 } 830 if (!rows.Any()) return;
793   831  
794 var row = rows.First(); 832 var row = rows.First();
-   833  
795   834 try
796 try 835 {
-   836 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly()
Line 797... Line 837...
797 { 837 .GetManifestResourceStream("HamBook.Effects.pot.wav")))
798 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) 838 {
799 { 839 await _catAssemblies.CatWriteAsync<string>("MC", new[] { row.Cells["LocationColumn"].Value },
800 await _catAssemblies.CatWriteAsync<string>("MC", new object[] { row.Cells["LocationColumn"].Value }, _cancellationToken); 840 _cancellationToken);
Line 810... Line 850...
810   850  
811 private async void frequencyToolStripMenuItem_Click(object sender, EventArgs e) 851 private async void frequencyToolStripMenuItem_Click(object sender, EventArgs e)
812 { 852 {
Line 813... Line 853...
813 var rows = GetSelectedDataGridViewRows(dataGridView1); 853 var rows = GetSelectedDataGridViewRows(dataGridView1);
814   -  
815 if (!rows.Any()) -  
816 { -  
Line 817... Line 854...
817 return; 854  
Line 818... Line 855...
818 } 855 if (!rows.Any()) return;
819   856  
820 var row = rows.First(); 857 var row = rows.First();
-   858  
821   859 try
822 try 860 {
823 { 861 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly()
824 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav"))) 862 .GetManifestResourceStream("HamBook.Effects.pot.wav")))
825 { -  
826 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { row.Cells["FrequencyColumn"].Value }, _cancellationToken)) 863 {
827 { -  
828 if (Configuration.Navigation.MouseScrollSound) -  
829 { 864 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new[] { row.Cells["FrequencyColumn"].Value },
830 soundPlayer.Play(); 865 _cancellationToken))
831 } 866 if (Configuration.Navigation.MouseScrollSound)
832 } 867 soundPlayer.Play();
833 } 868 }
Line 845... Line 880...
845 var hitTest = dataGridView.HitTest(e.X, e.Y); 880 var hitTest = dataGridView.HitTest(e.X, e.Y);
Line 846... Line 881...
846   881  
847 switch (e.Button) 882 switch (e.Button)
848 { 883 {
849 case MouseButtons.Right: 884 case MouseButtons.Right:
850 if(GetSelectedDataGridViewRows(dataGridView).Count() > 1) -  
851 { -  
852 return; -  
Line 853... Line 885...
853 } 885 if (GetSelectedDataGridViewRows(dataGridView).Count() > 1) return;
854   886  
855 dataGridView.ClearSelection(); 887 dataGridView.ClearSelection();
856 dataGridView.Rows[hitTest.RowIndex].Selected = true; 888 if (hitTest.RowIndex != -1) dataGridView.Rows[hitTest.RowIndex].Selected = true;
857 break; 889 break;
Line 858... Line 890...
858 } 890 }
Line 864... Line 896...
864 { 896 {
865 var clone = row.Clone() as DataGridViewRow; 897 var clone = row.Clone() as DataGridViewRow;
Line 866... Line 898...
866   898  
867 for (var i = 0; i < row.Cells.Count; ++i) 899 for (var i = 0; i < row.Cells.Count; ++i)
868 { 900 {
869 if (row.Cells[i].ReadOnly) -  
870 { -  
871 continue; -  
Line 872... Line 901...
872 } 901 if (row.Cells[i].ReadOnly) continue;
873   902  
Line 874... Line 903...
874 clone.Cells[i].Value = row.Cells[i].Value; 903 clone.Cells[i].Value = row.Cells[i].Value;
875 } 904 }
876   905  
-   906 yield return clone;
877 yield return clone; 907 }
878 } 908 }
879 } 909  
880 private void DeleteSelectedRows(DataGridView dataGridView) -  
881 { 910 private void DeleteSelectedRows(DataGridView dataGridView)
882 foreach (var row in GetSelectedDataGridViewRows(dataGridView)) 911 {
883 { 912 foreach (var row in GetSelectedDataGridViewRows(dataGridView))
884 for (var i = 0; i < row.Cells.Count; ++i) -  
885 { -  
886 if (row.Cells[i].ReadOnly) -  
Line 887... Line 913...
887 { 913 for (var i = 0; i < row.Cells.Count; ++i)
888 continue; 914 {
889 } -  
890   915 if (row.Cells[i].ReadOnly) continue;
Line 891... Line 916...
891 row.Cells[i].Value = default; 916  
892 } 917 row.Cells[i].Value = default;
893 } 918 }
894 } 919 }
895   -  
896   -  
897 private void PasteSelectedRows(DataGridView dataGridView, IEnumerable<DataGridViewRow> pasteRows) -  
Line 898... Line 920...
898 { 920  
899 var rows = pasteRows.ToList(); 921  
900 if(rows.Count == 0) 922 private void PasteSelectedRows(DataGridView dataGridView, IEnumerable<DataGridViewRow> pasteRows)
901 { -  
902 return; -  
903 } -  
Line 904... Line 923...
904   923 {
905 foreach (var row in GetSelectedDataGridViewRows(dataGridView)) 924 var rows = pasteRows.ToList();
906 { 925 if (rows.Count == 0) return;
907 if (rows.Count == 0) 926  
908 { -  
909 return; -  
910 } -  
911   927 foreach (var row in GetSelectedDataGridViewRows(dataGridView))
912 var paste = rows[0]; 928 {
Line 913... Line 929...
913 for (var i = 0; i < paste.Cells.Count; ++i) 929 if (rows.Count == 0) return;
914 { 930  
Line 929... Line 945...
929 { 945 {
930 var clone = row.Clone() as DataGridViewRow; 946 var clone = row.Clone() as DataGridViewRow;
Line 931... Line 947...
931   947  
932 for (var i = 0; i < row.Cells.Count; ++i) 948 for (var i = 0; i < row.Cells.Count; ++i)
933 { 949 {
934 if (row.Cells[i].ReadOnly) -  
935 { -  
936 continue; -  
Line 937... Line 950...
937 } 950 if (row.Cells[i].ReadOnly) continue;
Line 938... Line 951...
938   951  
939 clone.Cells[i].Value = row.Cells[i].Value; 952 clone.Cells[i].Value = row.Cells[i].Value;
940   953  
941 row.Cells[i].Value = default; 954 row.Cells[i].Value = default;
942 } 955 }
943 956  
Line 944... Line 957...
944 yield return clone; 957 yield return clone;
945 } 958 }
946 } 959 }
947   960  
948 private void cutToolStripMenuItem1_Click(object sender, EventArgs e) -  
949 { -  
950 _clipboardRows = new List<DataGridViewRow>(); -  
951 foreach (var row in CutSelectedRows(dataGridView1)) 961 private void cutToolStripMenuItem1_Click(object sender, EventArgs e)
Line 952... Line 962...
952 { 962 {
953 _clipboardRows.Add(row); 963 _clipboardRows = new List<DataGridViewRow>();
954 } 964 foreach (var row in CutSelectedRows(dataGridView1)) _clipboardRows.Add(row);
955 } 965 }
956   -  
957 private void copyToolStripMenuItem1_Click(object sender, EventArgs e) -  
958 { -  
959 _clipboardRows = new List<DataGridViewRow>(); 966  
Line 960... Line 967...
960 foreach (var row in CopySelectedRows(dataGridView1)) 967 private void copyToolStripMenuItem1_Click(object sender, EventArgs e)
961 { 968 {
962 _clipboardRows.Add(row); 969 _clipboardRows = new List<DataGridViewRow>();
Line 973... Line 980...
973 DeleteSelectedRows(dataGridView1); 980 DeleteSelectedRows(dataGridView1);
974 } 981 }
Line 975... Line 982...
975   982  
976 private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) 983 private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
977 { 984 {
978 DataGridView dataGridView = sender as DataGridView; 985 var dataGridView = sender as DataGridView;
979 foreach (DataGridViewCell cell in dataGridView.Rows[e.RowIndex].Cells) 986 foreach (DataGridViewCell cell in dataGridView.Rows[e.RowIndex].Cells)
980 { 987 {
981 if (cell.Selected == false) { continue; } 988 if (cell.Selected == false) continue;
982 var bgColorCell = Color.White; 989 var bgColorCell = Color.White;
-   990 if (cell.Style.BackColor != Color.Empty)
983 if (cell.Style.BackColor != Color.Empty) { bgColorCell = cell.Style.BackColor; } 991 bgColorCell = cell.Style.BackColor;
984 else if (cell.InheritedStyle.BackColor != Color.Empty) { bgColorCell = cell.InheritedStyle.BackColor; } 992 else if (cell.InheritedStyle.BackColor != Color.Empty) bgColorCell = cell.InheritedStyle.BackColor;
985 cell.Style.SelectionBackColor = MixColor(bgColorCell, Color.FromArgb(0, 150, 255), 10, 4); 993 cell.Style.SelectionBackColor = MixColor(bgColorCell, Color.FromArgb(0, 150, 255), 10, 4);
986 } 994 }
Line 987... Line 995...
987 } 995 }
988   996  
989 //Mix two colors 997 //Mix two colors
990 //Example: Steps=10 & Position=4 makes Color2 mix 40% into Color1 998 //Example: Steps=10 & Position=4 makes Color2 mix 40% into Color1
991 /// <summary> 999 /// <summary>
992 /// Mix two colors. 1000 /// Mix two colors.
993 /// </summary> 1001 /// </summary>
994 /// <param name="Color1"></param> 1002 /// <param name="color1"></param>
995 /// <param name="Color2"></param> 1003 /// <param name="color2"></param>
996 /// <param name="Steps"></param> 1004 /// <param name="steps"></param>
997 /// <param name="Position"></param> 1005 /// <param name="position"></param>
998 /// <example>Steps=10 & Positon=4 makes Color2 mix 40% into Color1</example> 1006 /// <example>Steps=10 & Positon=4 makes Color2 mix 40% into Color1</example>
999 /// <remarks>https://stackoverflow.com/questions/38337849/transparent-selectionbackcolor-for-datagridview-cell</remarks> 1007 /// <remarks>https://stackoverflow.com/questions/38337849/transparent-selectionbackcolor-for-datagridview-cell</remarks>
1000 /// <returns></returns> 1008 /// <returns></returns>
1001 public static Color MixColor(Color Color1, Color Color2, int Steps, int Position) 1009 public static Color MixColor(Color color1, Color color2, int steps, int position)
1002 { 1010 {
1003 if (Position <= 0 || Steps <= 1) { return Color1; } 1011 if (position <= 0 || steps <= 1) return color1;
1004 if (Position >= Steps) { return Color2; } 1012 if (position >= steps) return color2;
1005 return Color.FromArgb( 1013 return Color.FromArgb(
1006 Color1.R + ((Color2.R - Color1.R) / Steps * Position), 1014 color1.R + (color2.R - color1.R) / steps * position,
1007 Color1.G + ((Color2.G - Color1.G) / Steps * Position), 1015 color1.G + (color2.G - color1.G) / steps * position,
1008 Color1.B + ((Color2.B - Color1.B) / Steps * Position) 1016 color1.B + (color2.B - color1.B) / steps * position
1009 ); 1017 );
1010 } 1018 }
1011 } 1019 }