-
Notifications
You must be signed in to change notification settings - Fork 0
/
IConfig.cs
105 lines (97 loc) · 3.8 KB
/
IConfig.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SoftwareTelephone
{
public interface IConfig
{
string getSavedConfigurationInformation(string ForWhat);
void setSavedConfigurationInformation(string ForWhat, string Value);
}
internal class Config : IConfig
{
Properties.Settings mSettings;
public Config(Properties.Settings setSettings)
{
mSettings = setSettings;
if (mSettings.SavedConfigurationInformation == null)
{
mSettings.SavedConfigurationInformation = new System.Collections.Specialized.StringCollection();
mSettings.Save();
}
}
private int findSavedConfigurationInformation(string ForWhat)
{
if (mSettings.SavedConfigurationInformation == null)
{
throw (new Exception("mSettings.SavedConfigurationInformation is null"));
}
int travItems = 0;
while (travItems < mSettings.SavedConfigurationInformation.Count)
{
char[] splitOn = { '|' };
string[] Values = mSettings.SavedConfigurationInformation[travItems].Split(splitOn, StringSplitOptions.RemoveEmptyEntries);
if (Values.Length != 2)
{
mSettings.SavedConfigurationInformation.RemoveAt(travItems); // test if safe to do here
continue;
}
if (Values[0] == ForWhat)
{
return travItems;
}
++travItems;
}
return -1;
}
public string getSavedConfigurationInformation(string ForWhat)
{
if (mSettings.SavedConfigurationInformation == null)
{
throw (new Exception("mSettings.SavedConfigurationInformation is null"));
}
int ItemIndex = findSavedConfigurationInformation(ForWhat);
if (ItemIndex != -1)
{
if (ItemIndex >= mSettings.SavedConfigurationInformation.Count)
{
throw (new Exception("Invalid index from findSavedConfigurationInformation in getSavedConfigurationInformation, exceeds length"));
}
char[] splitOn = { '|' };
string[] Values = mSettings.SavedConfigurationInformation[ItemIndex].Split(splitOn, StringSplitOptions.RemoveEmptyEntries);
if (Values.Length == 2)
{
if (Values[0] != ForWhat)
{
throw (new Exception("findSavedConfigurationInformation found incorrect entry"));
}
return Values[1];
}
}
return String.Empty;
}
public void setSavedConfigurationInformation( string ForWhat, string Value)
{
if (mSettings.SavedConfigurationInformation == null)
{
throw (new Exception("SavedConfigurationInformation is null"));
}
int ItemIndex = findSavedConfigurationInformation(ForWhat);
if (ItemIndex != -1)
{
if (ItemIndex >= mSettings.SavedConfigurationInformation.Count)
{
throw (new Exception("Invalid index from findSavedConfigurationInformation in getSavedConfigurationInformation, exceeds length"));
}
mSettings.SavedConfigurationInformation[ItemIndex] = ForWhat + "|" + Value;
mSettings.Save();
}
else
{
mSettings.SavedConfigurationInformation.Add(ForWhat + "|" + Value);
mSettings.Save();
}
}
}
}