HamBook – Blame information for rev 53

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using HamBook.Utilities;
2 using System;
3 using System.Collections.Generic;
4 using System.Collections.Specialized;
5 using System.ComponentModel;
6 using System.Data;
7 using System.Drawing;
8 using System.Linq;
9 using System.Text;
10 using System.Threading;
11 using System.Threading.Tasks;
12 using System.Windows.Forms;
13  
14 namespace HamBook
15 {
16 public partial class ViewLogsForm : Form
17 {
18 private readonly CancellationToken _cancellationToken;
19  
20 private readonly Form1 _mainForm;
21  
22 private readonly LogMemorySink _memorySink;
23  
24 public ViewLogsForm()
25 {
26 InitializeComponent();
53 office 27 Utilities.WindowState.FormTracker.Track(this);
1 office 28 }
29  
30 public ViewLogsForm(Form1 mainForm) : this()
31 {
32 _mainForm = mainForm;
33 _mainForm.MemorySinkEnabled = true;
34 }
35  
36 public ViewLogsForm(Form1 mainForm, LogMemorySink memorySink, CancellationToken cancellationToken) :
37 this(mainForm)
38 {
39 _memorySink = memorySink;
40 _memorySink.Events.CollectionChanged += Events_CollectionChanged;
41  
42 _cancellationToken = cancellationToken;
43 }
44 /// <summary>
45 /// Clean up any resources being used.
46 /// </summary>
47 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
48 protected override void Dispose(bool disposing)
49 {
50 if (disposing && components != null)
51 {
52 components.Dispose();
53 }
54  
55 _memorySink.Events.CollectionChanged -= Events_CollectionChanged;
56  
57 _mainForm.MemorySinkEnabled = false;
58 _memorySink.Clear();
59  
60 base.Dispose(disposing);
61 }
62  
63 private void Events_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
64 {
65 switch (e.Action)
66 {
67 case NotifyCollectionChangedAction.Add:
68 foreach (var item in e.NewItems)
69 {
70 var line = (string)item;
71  
72 textBox1.InvokeIfRequired(textbox => { textbox.AppendText(line); });
73 }
74  
75 break;
76 }
77 }
78 }
79 }