/
KBInfo.cs
115 lines (107 loc) · 4.27 KB
/
KBInfo.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.Windows.Forms;
namespace DirtyThingsRemover
{
class KBInfo
{
public Int64 number { get; private set; }
public String description { get; private set; }
public String title { get; private set; }
/// <summary>
/// Construct a KBInfo object from usual parameter
/// </summary>
/// <param name="number">The Kb number (found in KNXXXXXXX)</param>
/// <param name="description">The description given by the db can differ from the official</param>
/// <param name="title">the official title of the KB</param>
public KBInfo(Int64 number, String description, String title)
{
this.number = number;
this.description = description;
this.title = title;
}
/// <summary>
/// Construct a KBInfo object from a file in the db
/// </summary>
/// <param name="path">the path to a file in the db/param>
public KBInfo(String path)
{
try
{
using (StreamReader sr = new StreamReader(path))
{
decomposeNumber(sr.ReadLine());
decomposeDescription(sr.ReadLine());
decomposeTitle(sr.ReadLine());
}
}
catch (Exception e)
{
MessageBox.Show("The File : \n" + path + " was not read\nThe message was :\n" + e.Message);
}
MessageBox.Show("Constructed KBINFO" + Environment.NewLine +
"Number : " + this.number.ToString() + Environment.NewLine +
"Title : " + this.title + Environment.NewLine +
"Description : " + this.description);
}
/// <summary>
/// Read the first line of the file, if it is effectivly the correct line assign it to the value, exception otherwise
/// </summary>
/// <param name="toDec">string to decode</param>
private void decomposeNumber(String toDec)
{
//TODO
if (toDec.StartsWith("number=", StringComparison.InvariantCultureIgnoreCase))
{
toDec = toDec.Substring(7);
this.number = Int64.Parse(toDec);
}
else
throw new Exception("Bad KB NUmber was read \nEither the markup is bad or the file is not in correct order");
}
/// <summary>
/// Read the first line of the file, if it is effectivly the correct line assign it to the value, exception otherwise
/// </summary>
/// <param name="toDec">string to decode</param>
private void decomposeDescription(String toDec)
{
//TODO
if(toDec.StartsWith("description=",StringComparison.InvariantCultureIgnoreCase))
{
toDec = toDec.Substring(12);
this.description = toDec;
}
else
throw new Exception("Bad Description was read \nEither the markup is bad or the file is not in correct order");
}
/// <summary>
/// Read the first line of the file, if it is effectivly the correct line assign it to the value, exception otherwise
/// </summary>
/// <param name="toDec">string to decode</param>
private void decomposeTitle(String toDec)
{
//TODO
if (toDec.StartsWith("title=", StringComparison.InvariantCultureIgnoreCase))
{
toDec = toDec.Substring(6);
this.title = toDec;
}
else
throw new Exception("Bad KB Title was read \nEither the markup is bad or the file is not in correct order");
}
/// <summary>
/// Well you guess it it's an equals methode to test equality
/// kinda useless in this software
/// </summary>
/// <param name="other">the parameter that will be tested against</param>
/// <returns>true if equals</returns>
public bool Equals(KBInfo other)
{
// Return true if the fields match:
return this.number == other.number;
}
}
}