-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogController.cs
More file actions
109 lines (97 loc) · 2.83 KB
/
Copy pathLogController.cs
File metadata and controls
109 lines (97 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Threading;
namespace BoughtItems
{
public class LogController
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
private LogController()
{
//do nothing
myTextBox = null;
}
private static LogController _instance;
private TextBox myTextBox;
private ProgressBar bar;
private Label labelPercentage;
public string CurrentURL;
public static LogController Instance
{
get
{
if (_instance == null)
{
_instance = new LogController();
}
return _instance;
}
}
public void SetTextBox(TextBox t)
{
myTextBox = t;
}
public void SetProgressBar(ProgressBar b)
{
this.bar = b;
}
public void SetLabelPercentage(Label b)
{
this.labelPercentage = b;
}
public void SetValueProgress(int t, string additionText = "")
{
if (t < 0)
{
t = 0;
}
else if (t > 100)
{
t = 100;
}
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
{
bar.Value = t;
labelPercentage.Content = additionText.Length > 0 ? t + "% (" + additionText + ")" : t + "%";
}));
}
private void PrintToTextbox(string s, string tag = "")
{
log.Debug("Textbox: " + s);
string message = DateTime.Now.ToString("HH:mm:ss") + tag + " - " + s + Environment.NewLine;
if (myTextBox != null)
{
if (!myTextBox.Dispatcher.CheckAccess())
{
myTextBox.Dispatcher.BeginInvoke(new Action(() => myTextBox.AppendText(message)));
}
else
{
myTextBox.AppendText(message);
}
}
}
public void Error(string s)
{
PrintToTextbox(s, " Error");
}
public void Error(string s, Exception e1)
{
string message = "";
while (e1 != null)
{
message += e1.GetType().Name + " " + (e1.Message ?? "No message.") + " ";
e1 = e1.InnerException;
}
PrintToTextbox(s + " " + message, " Error");
}
public void Debug(string s)
{
PrintToTextbox(s);
}
}
}