-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplicationConfig.cs
executable file
·137 lines (125 loc) · 4.12 KB
/
ApplicationConfig.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Reflection;
using System.IO;
using System.Xml.Linq;
using System.Net;
namespace Strider.Client.TextMiner.Utils
{
/**
* This class reads parameteres defined in AppConfig
* and provides getter methods for each of the parameter.
*/
public class ApplicationConfig
{
private static NameValueCollection appSettings = null;
/**
* Defines static constructor
*/
static ApplicationConfig()
{
// Read the AppSettings section.
appSettings = ConfigurationManager.AppSettings;
// Configuration Manager is not set to Strider's default configuration file.
if (appSettings["textMinerEndPoint"] == null)
{
appSettings = new NameValueCollection();
try
{
string path = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
var configAsFlatText = File.ReadAllText(Path.Combine(path, "App.config"));
ParseXmlConfiguration(configAsFlatText);
}
catch (Exception exc)
{
// using default values here, which we can download from the server with a simple get request.
// ideally this should be abstracted away, but not far away ;-)
string remoteAppConfig = new WebClient().DownloadString("http://striderdi.com/App.config");
ParseXmlConfiguration(remoteAppConfig);
System.Diagnostics.Debug.WriteLine(exc.Message);
}
}
}
private static void ParseXmlConfiguration(string configAsFlatText)
{
var parsedXmlConfig = XElement.Parse(configAsFlatText);
var endPoints = parsedXmlConfig.Element("appSettings").Elements()
.Select(eachEndPoint => new
{
Key = eachEndPoint.Attribute("key").Value,
Value = eachEndPoint.Attribute("value").Value
});
foreach (var endPoint in endPoints)
{
appSettings.Add(endPoint.Key, endPoint.Value);
}
}
public ApplicationConfig()
{
}
/**
* Returns synnet endpoint defined in AppConfig.cs.
* If appSettings is null, returns null.
*/
public string GetSynNetEndPoint()
{
if (appSettings != null)
{
return appSettings["synNetEndPoint"];
}
else
{
return null;
}
}
/**
* Returns synnet endpoint defined in AppConfig.cs.
* If appSettings is null, returns null.
*/
public string GetWordDefinitionEndPoint()
{
if (appSettings != null)
{
return appSettings["wordDefinitionEndPoint"];
}
else
{
return null;
}
}
/**
* Returns synnet endpoint defined in AppConfig.cs.
* If appSettings is null, returns null.
*/
public string GetTextMinerEndPoint()
{
if (appSettings != null)
{
return appSettings["textMinerEndPoint"];
}
else
{
return null;
}
}
/**
* Returns client service endpoint defined in AppConfig.cs.
* If appSettings is null, returns null.
*/
public string GetClientServiceEndPoint()
{
if (appSettings != null)
{
return appSettings["clientServiceEndPoint"];
}
else
{
return null;
}
}
}
}