HamBook – Blame information for rev 54

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