using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Web;

namespace JuSNS.AppClient
{
    /// <summary>
    /// 应用程序基本配置
    /// </summary>
    public class Config
    {
        private static readonly string path = "App.config";
        static private Dictionary<string, string> _Config = new Dictionary<string, string>();

        /// <summary>
        /// 配置
        /// </summary>
        static Dictionary<string,string> config
        {
            get{return _Config;}
        }
        /// <summary>
        /// 服务器地址
        /// </summary>
        static public string ServerUrl
        {
            get
            {
                return config["ServerURL"];
            }
        }
        /// <summary>
        /// 应用程序Key
        /// </summary>
        static public string AppKey
        {
            get
            {
                return config["AppKey"];
            }
        }
        static Config()
        {
            reload();
        }
        static public void reload()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(HttpContext.Current.Server.MapPath(path));
            XmlNodeList nodelist = xmlDoc.SelectNodes("/configuration/appSettings/add");
            for (int i = 0; i < nodelist.Count; i++)
            {
                XmlNode node = nodelist[i];
                string key = string.Empty;
                string value = string.Empty;
                try
                {
                    key = node.Attributes["key"].InnerText;
                    value = node.Attributes["value"].InnerText;
                    _Config.Add(key, value);
                }
                catch { }                
            }
        }
    }
}
