Exemplo n.º 1
0
 DMHelper()
 {
     this._sessionfactory = InitSession();
     if (string.IsNullOrEmpty(_sessionfactory.DbProviderName))
     {
         _sessionfactory.DbProviderName = DefaultProvider;
     }
     this.ProviderEx = SetParameterType(_sessionfactory.DbProviderName);
     SetDMSessionArrayProvider();
 }
Exemplo n.º 2
0
        DMSessionArray GetSessionArray(DMSessionFactory dm, string dmsKey)
        {
            DMSessionArray dms = dm.SessionArray.FirstOrDefault(s => s.SessionKey == dmsKey);

            if (dms == null)
            {
                dms            = new DMSessionArray();
                dms.SessionKey = dmsKey;
                dm.SessionArray.Add(dms);
            }
            return(dms);
        }
Exemplo n.º 3
0
        internal DMSessionFactory InitSession()
        {
            DMSessionFactory dm       = new DMSessionFactory();
            string           basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (!basePath.EndsWith(@"\"))
            {
                basePath += @"\";
            }
            string fileName = basePath + @"Config\" + CfgFileName;
            //if (type == DbConntionType.OnlyRead)
            //{
            //    fileName = basePath + @"Config\" + ReadCfgFileName;
            //}
            XmlReaderSettings sett = new XmlReaderSettings()
            {
                IgnoreComments = true, IgnoreWhitespace = true
            };

            using (XmlReader assReader = XmlReader.Create(fileName, sett))
            {
                while (assReader.Read())
                {
                    if (assReader.NodeType == XmlNodeType.Element)
                    {
                        switch (assReader.LocalName)
                        {
                        case "mapping":
                            string   assembly = assReader.ReadString();
                            Assembly ass      = Assembly.Load(assembly);
                            if (!dm.Mapping.Contains(ass))
                            {
                                dm.Mapping.Add(ass);
                            }
                            break;

                        case "property":
                            string propertyName = assReader.GetAttribute("name").ToLower();
                            switch (propertyName)
                            {
                            case "connection.string": dm.ConnectionString = assReader.ReadString(); break;

                            case "connection.string.read": dm.ConnectionStringRead = assReader.ReadString(); break;

                            case "connection.provider": dm.DbProviderName = assReader.ReadString().Trim(); break;

                            case "connection.timeout": dm.Timeout = Convert.ToInt32(assReader.ReadString()); break;

                            case "connection.showsql": dm.ShowSql = Convert.ToBoolean(assReader.ReadString()); break;
                            }
                            if (propertyName != "connection.string" && propertyName != "connection.string.read" && propertyName != "connection.provider")
                            {
                                if (propertyName.StartsWith("connection.string.read."))
                                {
                                    string         dmsKey = propertyName.Replace("connection.string.read.", "");
                                    DMSessionArray dms    = GetSessionArray(dm, dmsKey);
                                    dms.ConnectionStringRead = assReader.ReadString();
                                }
                                else if (propertyName.StartsWith("connection.string."))
                                {
                                    string         dmsKey = propertyName.Replace("connection.string.", "");
                                    DMSessionArray dms    = GetSessionArray(dm, dmsKey);
                                    dms.ConnectionString = assReader.ReadString();
                                }
                                else if (propertyName.StartsWith("connection.provider."))
                                {
                                    string         dmsKey = propertyName.Replace("connection.provider.", "");
                                    DMSessionArray dms    = GetSessionArray(dm, dmsKey);
                                    dms.DbProviderName = assReader.ReadString();
                                    dms.ProviderEx     = SetParameterType(dms.DbProviderName);
                                }
                            }
                            break;
                        }
                    }
                }
            }
            return(dm);
        }