Пример #1
0
        /// <summary>
        /// Tries to load a SQL IO Manager based on information from the Configuration Graph
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Output Object</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out Object obj)
        {
            ISqlIOManager manager = null;
            String server, port, db, user, pwd;

            //Create the URI Nodes we're going to use to search for things
            INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer),
                  propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase);

            //Get Server and Database details
            server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
            if (server == null) server = "localhost";
            db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb);
            if (db == null)
            {
                obj = null;
                return false;
            }

            //Get user credentials
            ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

            //Based on this information create a Manager if possible
            switch (targetType.FullName)
            {
                case MicrosoftSqlManager:
                    if (user == null || pwd == null)
                    {
                        manager = new MicrosoftSqlStoreManager(server, db);
                    }
                    else
                    {
                        manager = new MicrosoftSqlStoreManager(server, db, user, pwd);
                    }
                    break;

                case MySqlManager:
                    if (user != null && pwd != null)
                    {
                        manager = new MySqlStoreManager(server, db, user, pwd);
                    }
                    break;

            }
            obj = manager;
            return (manager != null);
        }
 protected override void InitialiseManager()
 {
     if (_port == -1)
     {
         _manager = new MySqlStoreManager(_server, _dbname, _user, _pwd);
     }
     else
     {
         _manager = new MySqlStoreManager(_server, _port, _dbname, _user, _pwd);
     }
 }