public void AddDataSource(string dbName, string dbType, string connectionString)
        {
            if (m_DatabasePool.Contains(dbName))
            {
                m_DatabasePool.Remove(dbName);
            }

            IPersistenceProvider rdb = null;

            try
            {
                string dbClassName = ContextManager.GetDbClassName(dbType);
                rdb = (IPersistenceProvider)this.GetType().Assembly.CreateInstance(dbClassName);
            }
            catch
            {
                Assert.Fail(Error.DatabaseConnectError, "Create a data source" + dbName + "failed");
            }
            rdb.Name = dbName;
            rdb.Initialize(connectionString);
            if (rdb != null)
            {
                m_DatabasePool.Add(rdb.Name, rdb);
            }
        }
Beispiel #2
0
        public FileMetadata(IPersistenceProvider provider, StorageConfiguration configuration)
        {
            _provider     = provider;
            _providerType = configuration.StorageProvider.StorageProviderType;
            _filePath     = configuration.StorageProvider.DatabasePath;
            _databaseId   = configuration.StorageProvider.DatabaseId;

            _provider.Initialize(configuration);
        }
        private IPersistenceProvider GetPersistenceProvider(XmlNodeReader node)
        {
            string dbName = node.GetAttribute("name");
            string dbType = node.GetAttribute("type");

            IPersistenceProvider rdb = null;

            if (dbName != null)
            {
                if (dbType == null || dbType == "")
                {
                    Assert.Fail(Error.NoSupportDatabase);
                }
                else
                {
                    string dbClassName = GetDbClassName(dbType);

                    try
                    {
                        rdb = (IPersistenceProvider)this.GetType().Assembly.CreateInstance(dbClassName);
                        if (rdb == null)
                        {
                            throw new Exception();
                        }
                    }
                    catch
                    {
                        Assert.Fail(Error.DatabaseConnectError);
                    }
                }
                rdb.Name = dbName;
                this.m_DatabaseMaps.Add(dbName, new DatabaseMap(dbName));
                int i = node.Depth;

                string pName            = "";
                string pValue           = "";
                string connectionString = "";
                string strPassword      = "";
                bool   blnEncrypt       = false;
                string strEncryptClass  = "";

                while (node.Read() && node.Depth > i)
                {
                    if ((node.NodeType == XmlNodeType.Element) && (node.Name == "parameter"))
                    {
                        pName  = node.GetAttribute("name");
                        pValue = node.GetAttribute("value");
                        if ((pName != null) && (pValue != null))
                        {
                            if (pName.ToLower() == "password")
                            {
                                strPassword = pValue;
                            }
                            else if (pName.ToLower() == "encrypt")
                            {
                                blnEncrypt      = true;
                                strEncryptClass = pValue;
                            }
                            else
                            {
                                connectionString += pName + "=" + pValue + ";";
                            }
                            //add window verification processing
                            if (pName.ToLower() == "windows connection")
                            {
                                blnEncrypt       = false;
                                connectionString = pValue;
                                break;
                            }
                        }
                    }
                }
                if (blnEncrypt)
                {
                    if (strEncryptClass.Equals(""))
                    {
                        BaseEncryptClass baseEncry = new BaseEncryptClass();
                        pValue = baseEncry.Decrypt(strPassword);
                    }
                    else
                    {
                        try
                        {
                            BaseEncryptClass baseEncry = (BaseEncryptClass)LoadType(strEncryptClass).Assembly.CreateInstance(strEncryptClass);
                            pValue = baseEncry.Decrypt(strPassword);
                        }
                        catch (Exception)
                        {
                            Assert.Fail("Load custom decryption function" + strEncryptClass + "Error,Please check if the decryption function exists!!!");
                        }
                    }
                    //Access
                    if (dbType == "MSAccess")
                    {
                        connectionString += string.Format("Jet OLEDB:Database Password={0}", pValue);
                    }
                    else
                    {
                        connectionString += "password="******";";
                    }
                }
                rdb.Initialize(connectionString);
            }
            return(rdb);
        }