コード例 #1
0
        /// <summary>
        /// Loads XML from local database
        /// </summary>
        public void ImportFromMySQL(Database.DatabaseConfig xmlSource, Database.DatabaseConfig destination)
        {
            _xmlSource   = xmlSource;
            _destination = destination;

            XMLImport importer = new XMLImport();

            Database.MySQL.Database myDB = new Database.MySQL.Database(_destination);

            string connString = string.Format(DBConnectString, _xmlSource.ServerIp, _xmlSource.Schema, _xmlSource.Username, _xmlSource.Password);

            using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(connString))
            {
                conn.Open();
                using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "SELECT `fishbaseId`, `genus`, `species`, `xmlSummary`, `xmlPointData`, `xmlCommonNames`, `xmlPhotos` FROM `fishbaseraw`;";

                    using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Model.FishClass fc = importer.Import(
                                reader.GetInt32("fishbaseId"),
                                reader.GetString("genus"),
                                reader.GetString("species"),
                                reader.GetString("xmlSummary"),
                                reader.GetString("xmlPointData"),
                                reader.GetString("xmlCommonNames"),
                                reader.GetString("xmlPhotos")
                                );
                            if (fc != null)
                            {
                                try
                                {
                                    myDB.CreateFish(fc);
                                }
                                catch (Database.Exceptions.CreatureAlreadyExists ex)
                                {
                                    myDB.UpdateFish(fc);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: FishBaseImport.cs プロジェクト: tdkryger/APaF
        /// <summary>
        /// Loads XML from local database
        /// </summary>
        public void ImportFromMySQL(Database.DatabaseConfig xmlSource, Database.DatabaseConfig destination)
        {
            _xmlSource = xmlSource;
            _destination = destination;

            XMLImport importer = new XMLImport();
            Database.MySQL.Database myDB = new Database.MySQL.Database(_destination);

            string connString = string.Format(DBConnectString, _xmlSource.ServerIp, _xmlSource.Schema, _xmlSource.Username, _xmlSource.Password);
            using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(connString))
            {
                conn.Open();
                using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandText = "SELECT `fishbaseId`, `genus`, `species`, `xmlSummary`, `xmlPointData`, `xmlCommonNames`, `xmlPhotos` FROM `fishbaseraw`;";

                    using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while(reader.Read())
                        {
                            Model.FishClass fc = importer.Import(
                                reader.GetInt32("fishbaseId"),
                                reader.GetString("genus"),
                                reader.GetString("species"),
                                reader.GetString("xmlSummary"),
                                reader.GetString("xmlPointData"),
                                reader.GetString("xmlCommonNames"),
                                reader.GetString("xmlPhotos")
                                );
                            if (fc != null)
                            {
                                try
                                {
                                    myDB.CreateFish(fc);
                                }
                                catch (Database.Exceptions.CreatureAlreadyExists ex)
                                {
                                    myDB.UpdateFish(fc);
                                }
                            }
                        }
                    }

                }
            }
        }