using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace WebAPIBase.NetCore.BusinessCore
{
    public sealed class ClassBuilderManager
    {
        private static Hashtable builderNames = new Hashtable();

        public static void LoadClassBuilderDefine()
        {
            try
            {
                XmlDocument xmlDoc = XmlDefineFileManage.GetXmlDoc("ClassBuilders");
                XmlNodeList xmlNodeList = xmlDoc.DocumentElement.SelectNodes("Class");
                int count = xmlNodeList.Count;
                for (int i = 0; i < count; i++)
                {
                    XmlNode xmlNode = xmlNodeList.Item(i);
                    string innerText = xmlNode.Attributes["Name"].InnerText;
                    string innerText2 = xmlNode.Attributes["Type"].InnerText;
                    if (builderNames.Contains(innerText))
                    {
                        throw new ApplicationException("在ClassBuilders.xml中有重复定义: " + innerText);
                    }
                    builderNames.Add(innerText, innerText2);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static string GetClassBuilderName(string className)
        {
            try
            {
                if (!builderNames.Contains(className))
                {
                    throw new ApplicationException("没有在ClassBuilders.xml中定义" + className);
                }
                return (string)builderNames[className];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
