-
Notifications
You must be signed in to change notification settings - Fork 2
/
WarningLog.cs
115 lines (101 loc) · 3.06 KB
/
WarningLog.cs
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
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace OCDataImporter
{
public class WarningMessage
{
public String messageText {get; set;}
public String timeStamp { get; set; }
public WarningMessage(String messageText, String timeStamp)
{
this.messageText = messageText;
this.timeStamp = timeStamp;
}
/// <summary>
/// Checks if the warning message is equal to an other, based only on
/// the message: the time stamp is ignored
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public override bool Equals(System.Object other)
{
if (other == null)
{
return false;
}
WarningMessage that = other as WarningMessage;
if ((System.Object) that == null)
{
return false;
}
return (this.messageText == that.messageText);
}
public override String ToString()
{
return timeStamp + " " + messageText;
}
public override int GetHashCode()
{
return messageText.GetHashCode();
}
}
class WarningLog
{
private List<WarningMessage> warningMessageList;
private static string LINE_SEPARATOR = System.Environment.NewLine;
public WarningLog()
{
warningMessageList = new List<WarningMessage>();
}
public void reset()
{
warningMessageList.Clear();
}
public int getWarningCount()
{
return warningMessageList.Count;
}
/// <summary>
/// Returns a list of the message contained in the list
/// </summary>
/// <returns></returns>
public override String ToString()
{
String ret = "";
foreach (WarningMessage warningMessage in warningMessageList)
{
ret += warningMessage.ToString() + LINE_SEPARATOR;
}
return ret;
}
public void dumpToFile(String fileName)
{
StreamWriter SW;
SW = File.AppendText(fileName);
SW.WriteLine(this.ToString());
SW.Close();
}
public void appendMessage(String aMessageText)
{
bool found = false;
String timeStamp = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
WarningMessage messageToAdd = new WarningMessage(aMessageText, timeStamp);
foreach (WarningMessage warningMessage in warningMessageList)
{
if (warningMessage.Equals(messageToAdd))
{
found = true;
break;
}
}
if (!found)
{
warningMessageList.Add(messageToAdd);
}
}
}
}