|
|
@@ -4,15 +4,15 @@ namespace CallCenter.Utility
|
|
4
|
4
|
{
|
|
5
|
5
|
public static class Configs
|
|
6
|
6
|
{
|
|
7
|
|
- public static System.Xml.XmlDocument xDoc;
|
|
8
|
|
- public static System.Xml.XmlNode xNode;
|
|
|
7
|
+ //public static System.Xml.XmlDocument xDoc;
|
|
|
8
|
+ //public static System.Xml.XmlNode xNode;
|
|
9
|
9
|
|
|
10
|
|
- static Configs()
|
|
11
|
|
- {
|
|
12
|
|
- xDoc = new System.Xml.XmlDocument();
|
|
13
|
|
- xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
|
|
14
|
|
- xNode = xDoc.SelectSingleNode("//appSettings");
|
|
15
|
|
- }
|
|
|
10
|
+ //static Configs()
|
|
|
11
|
+ //{
|
|
|
12
|
+ // xDoc = new System.Xml.XmlDocument();
|
|
|
13
|
+ // xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
|
|
|
14
|
+ // xNode = xDoc.SelectSingleNode("//appSettings");
|
|
|
15
|
+ //}
|
|
16
|
16
|
|
|
17
|
17
|
|
|
18
|
18
|
|
|
|
@@ -22,8 +22,18 @@ namespace CallCenter.Utility
|
|
22
|
22
|
/// <param name="key"></param>
|
|
23
|
23
|
public static string GetValue(string key)
|
|
24
|
24
|
{
|
|
25
|
|
- var xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
|
|
26
|
|
- return xElem1?.GetAttribute("value") ?? "";
|
|
|
25
|
+ try
|
|
|
26
|
+ {
|
|
|
27
|
+ System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
|
|
|
28
|
+ xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
|
|
|
29
|
+ System.Xml.XmlNode xNode = xDoc.SelectSingleNode("//appSettings");
|
|
|
30
|
+ var xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
|
|
|
31
|
+ return xElem1?.GetAttribute("value") ?? "";
|
|
|
32
|
+ }
|
|
|
33
|
+ catch
|
|
|
34
|
+ {
|
|
|
35
|
+ return "";
|
|
|
36
|
+ }
|
|
27
|
37
|
}
|
|
28
|
38
|
/// <summary>
|
|
29
|
39
|
/// 根据Key修改Value
|
|
|
@@ -33,18 +43,27 @@ namespace CallCenter.Utility
|
|
33
|
43
|
public static void SetValue(string key, string value)
|
|
34
|
44
|
{
|
|
35
|
45
|
|
|
36
|
|
- System.Xml.XmlElement xElem1;
|
|
37
|
|
- System.Xml.XmlElement xElem2;
|
|
38
|
|
- xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
|
|
39
|
|
- if (xElem1 != null) xElem1.SetAttribute("value", value);
|
|
40
|
|
- else
|
|
|
46
|
+ try
|
|
41
|
47
|
{
|
|
42
|
|
- xElem2 = xDoc.CreateElement("add");
|
|
43
|
|
- xElem2.SetAttribute("key", key);
|
|
44
|
|
- xElem2.SetAttribute("value", value);
|
|
45
|
|
- xNode.AppendChild(xElem2);
|
|
|
48
|
+ System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
|
|
|
49
|
+ xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
|
|
|
50
|
+ System.Xml.XmlNode xNode = xDoc.SelectSingleNode("//appSettings");
|
|
|
51
|
+ //System.Xml.XmlNode xNode;
|
|
|
52
|
+ System.Xml.XmlElement xElem1;
|
|
|
53
|
+ System.Xml.XmlElement xElem2;
|
|
|
54
|
+ xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
|
|
|
55
|
+ if (xElem1 != null) xElem1.SetAttribute("value", value);
|
|
|
56
|
+ else
|
|
|
57
|
+ {
|
|
|
58
|
+ xElem2 = xDoc.CreateElement("add");
|
|
|
59
|
+ xElem2.SetAttribute("key", key);
|
|
|
60
|
+ xElem2.SetAttribute("value", value);
|
|
|
61
|
+ xNode.AppendChild(xElem2);
|
|
|
62
|
+ }
|
|
|
63
|
+ xDoc.Save(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
|
|
46
|
64
|
}
|
|
47
|
|
- xDoc.Save(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
|
|
|
65
|
+ catch
|
|
|
66
|
+ { }
|
|
48
|
67
|
}
|
|
49
|
68
|
}
|
|
50
|
69
|
}
|