-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigurationManagerWrapper.cs
46 lines (43 loc) · 1.45 KB
/
ConfigurationManagerWrapper.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.ServiceModel.Configuration;
namespace MailClient
{
public class ConfigurationManagerWrapper : IConfigurationManager
{
private Configuration cfg;
public ConfigurationManagerWrapper()
{
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var fileMap = new ExeConfigurationFileMap
{
ExeConfigFilename = string.Concat(path, "\\mail.config")
};
cfg = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
}
public string GetSetting(string key)
{
AppSettingsSection section = (cfg.GetSection("appSettings") as AppSettingsSection);
var value = section.Settings[key].Value;
return value;
}
public ChannelEndpointElement GetClient(string key)
{
var serviceModel = ServiceModelSectionGroup.GetSectionGroup(cfg);
var endpoints = serviceModel.Client.Endpoints;
if (endpoints.Count > 0)
return endpoints[0];
return null;
}
public T GetSection<T>(string sectionName)
{
return (T)ConfigurationManager.GetSection(sectionName);
}
}
}