HamBook – Blame information for rev 1

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();
27 }
28  
29 public ViewLogsForm(Form1 mainForm) : this()
30 {
31 _mainForm = mainForm;
32 _mainForm.MemorySinkEnabled = true;
33 }
34  
35 public ViewLogsForm(Form1 mainForm, LogMemorySink memorySink, CancellationToken cancellationToken) :
36 this(mainForm)
37 {
38 _memorySink = memorySink;
39 _memorySink.Events.CollectionChanged += Events_CollectionChanged;
40  
41 _cancellationToken = cancellationToken;
42 }
43 /// <summary>
44 /// Clean up any resources being used.
45 /// </summary>
46 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
47 protected override void Dispose(bool disposing)
48 {
49 if (disposing && components != null)
50 {
51 components.Dispose();
52 }
53  
54 _memorySink.Events.CollectionChanged -= Events_CollectionChanged;
55  
56 _mainForm.MemorySinkEnabled = false;
57 _memorySink.Clear();
58  
59 base.Dispose(disposing);
60 }
61  
62 private void Events_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
63 {
64 switch (e.Action)
65 {
66 case NotifyCollectionChangedAction.Add:
67 foreach (var item in e.NewItems)
68 {
69 var line = (string)item;
70  
71 textBox1.InvokeIfRequired(textbox => { textbox.AppendText(line); });
72 }
73  
74 break;
75 }
76 }
77 }
78 }