コード例 #1
0
        public static ServiceConfig GetInstance()
        {
            if (_instance == null)
            {
                lock (_synRoot)
                {
                    if (_instance == null)
                    {
                        try
                        {
                            ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset);
                            DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
                            builder.ConfigureAndWatch("dao.config", handler);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        _instance = new ServiceConfig();
                        // TODO:默认为sqlMapDao指定的Context, 要提供对多个Context的支持.
                        _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao");
                    }
                }
            }
            return _instance;
        }
コード例 #2
0
ファイル: ServiceConfig.cs プロジェクト: dalinhuang/loosoft
        public static ServiceConfig GetInstance()
        {
            if (_instance == null)
            {
                lock (_synRoot)
                {
                    if (_instance == null)
                    {
                        ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset);
                        DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
                        builder.ConfigureAndWatch("dao.config", handler);

                        _instance = new ServiceConfig();
                        // TODO:Ĭ��ΪsqlMapDaoָ����Context, Ҫ�ṩ�Զ��Context��֧��.
                        _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao");

                    }
                }
            }
            return _instance;
        }
コード例 #3
0
ファイル: ServiceConfig.cs プロジェクト: jetwind/MyBatisNet
        public static ServiceConfig GetInstanceByFile()
        {
            if (_instance == null)
            {
                lock (_synRoot)
                {
                    if (_instance == null)
                    {
                        //Define the Absoluate File path to Found the Dao File [f**k this shit]
                        string filepath = @"E:\ADO.NEt Entity FrameWork Program\MyBatis_Demo\BatisDemonstarate_DUI\CustomerWeb_UI\Dao.Config";
                        if (File.Exists(filepath))
                        {
                            DomDaoManagerBuilder getbuilder = new DomDaoManagerBuilder();
                            getbuilder.Configure(filepath);

                            _instance = new ServiceConfig();
                            _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao");
                        }
                    }
                }
            }
            return _instance;
        }
コード例 #4
0
ファイル: ServiceConfig.cs プロジェクト: seafly/Jie
        /// <summary>
        /// 获取数据链接配置
        /// </summary>
        /// <param name="daoid">数据链接配置ID</param>
        /// <returns></returns>
        public static ServiceConfig GetInstance(string daoid)
        {
            if (_instance == null)
            {
                lock (_synRoot)
                {
                    if (_instance == null)
                    {
                        string[] str = projectlist.Split(',');
                        //生成配置文件SqlServerMap.config
                        string name = "SqlServerMap";
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.Load(fileName + name + "Pub.config");
                        XmlNode sqlMapConfig = xmlDoc.DocumentElement;//获取节点
                        XmlNodeList sqlMapList = sqlMapConfig.ChildNodes;//获取所有字节点
                        foreach (XmlNode child in sqlMapList)
                        {
                            if (child.Name.Equals("sqlMaps"))
                            {
                                foreach (string st in str)
                                {
                                    if (File.Exists(fileName + st + "Map.config"))
                                    {
                                        XmlDocument xmlDocOA = new XmlDocument();
                                        xmlDocOA.Load(fileName + st + "Map.config");
                                        XmlNode sqlMapConfigOA = xmlDocOA.DocumentElement;//获取节点
                                        XmlNode sqlMapsOA = sqlMapConfigOA.FirstChild;
                                        XmlNodeList courseNodeList = sqlMapsOA.ChildNodes;
                                        if (courseNodeList != null)
                                        {
                                            foreach (XmlNode courseNode in courseNodeList)
                                            {
                                                if (courseNode.Attributes != null)
                                                {
                                                    string value = courseNode.Attributes.GetNamedItem("resource").Value;
                                                    XmlNode newNode = xmlDoc.CreateElement("sqlMap", xmlDoc.DocumentElement.NamespaceURI);
                                                    CreateAttribute(newNode, "resource", value);
                                                    child.AppendChild(newNode);
                                                }
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                        xmlDoc.Save(fileName + name + ".config");

                        ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset);

                        DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
                        builder.ConfigureAndWatch("Config/dao.config", handler);

                        _instance = new ServiceConfig();
                        //清空数据库连接键值列表
                        daoManageKeyList = null;
                    }
                }
            }

            if (daoManageKeyList == null || !daoManageKeyList.Contains(daoid))
            {
                lock (_synRoot)
                {
                    if (daoManageKeyList == null || !daoManageKeyList.Contains(daoid))
                    {
                        // TODO:默认为sqlMapDao指定的Context, 要提供对多个Context的支持.
                        _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance(daoid);
                    }
                }
            }

            return _instance;
        }