Beispiel #1
0
        public TDK.APaF.Model.FishClass Import(int fishbaseId, string genus, string species, string xmlSummary, string xmlPointData, string xmlCommonNames, string xmlPhotos)
        {
            Model.FishClass theFish = new Model.FishClass();
            theFish.ScientificName = new Model.LatinNameClass() { Genus = genus, Species = species };
            importXMLCommonNames(xmlCommonNames, theFish);
            importXMLPhotos(xmlPhotos, theFish);
            importXMLPointData(xmlPointData, theFish);
            importXMLSummary(xmlSummary, theFish);

            return theFish;
        }
Beispiel #2
0
        public TDK.APaF.Model.FishClass Import(int fishbaseId, string genus, string species, string xmlSummary, string xmlPointData, string xmlCommonNames, string xmlPhotos)
        {
            Model.FishClass theFish = new Model.FishClass();
            theFish.ScientificName = new Model.LatinNameClass()
            {
                Genus = genus, Species = species
            };
            importXMLCommonNames(xmlCommonNames, theFish);
            importXMLPhotos(xmlPhotos, theFish);
            importXMLPointData(xmlPointData, theFish);
            importXMLSummary(xmlSummary, theFish);


            return(theFish);
        }
Beispiel #3
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private CreatureIdentification selectCreature(int itemId, CreatureTypes creatureType)
        {
            CreatureIdentification item = null;

            switch (creatureType)
            {
                case CreatureTypes.Crustacean:
                    item = new Model.CrustaceanClass();
                    break;
                case CreatureTypes.Fish:
                    item = new Model.FishClass();
                    break;
                case CreatureTypes.Gastropoda:
                    item = new Model.GastropodaClass();
                    break;
                case CreatureTypes.Plant:
                    item = new Model.PlantClass();
                    break;
                case CreatureTypes.Reptile:
                    item = new Model.ReptileClass();
                    break;
            }
            if (item != null) // Could check if the creatureType is valid, instead of using 1 switch statement to create the object, and another to set properties
            {
                using (MySqlConnection conn = getAConnection())
                {
                    if (conn.State != System.Data.ConnectionState.Open)
                    {
                        using (MySqlCommand cmd = new MySqlCommand(SELECT_CREATURE, conn))
                        {
                            cmd.Parameters.AddWithValue("id", itemId);
                            try
                            {
                                using (MySqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                                {
                                    if (reader.Read())
                                    {
                                        //TODO: Set commen fields
                                        switch (creatureType)
                                        {
                                            case CreatureTypes.Crustacean:
                                                //TODO: Set special Crustacean fields
                                                break;
                                            case CreatureTypes.Fish:
                                                //TODO: Set special Crustacean fields
                                                break;
                                            case CreatureTypes.Gastropoda:
                                                //TODO: Set special Crustacean fields
                                                break;
                                            case CreatureTypes.Plant:
                                                //TODO: Set special Crustacean fields
                                                break;
                                            case CreatureTypes.Reptile:
                                                //TODO: Set special Crustacean fields
                                                break;
                                        }
                                    }
                                }
                            }
                            catch (SqlException ex)
                            {
                                handleDBError(new Delegates.DatabaseArgs(ex));
                            }
                        }
                    }
                    else
                    {
                        handleDBError(new Delegates.DatabaseArgs("Connection not open"));
                    }
                }
            }
            else
            {
                handleDBError(new Delegates.DatabaseArgs("creature type is unknown"));
            }
            return item;
        }