Exemple #1
0
        private WolframTaxonomyData GetTaxonomyDataFromDB(String tag)
        {
            using (var sqlConnection = new SqlConnection(WhatIsThatDbConnString))
            {
                sqlConnection.Open();
                var cmd = new SqlCommand("SELECT TOP 1 * FROM TagToTaxonomy WHERE Tag=@Tag ")
                {
                    CommandType = CommandType.Text,
                    Connection  = sqlConnection
                };

                cmd.Parameters.AddWithValue("@Tag", tag.Trim().ToLower());

                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var kingdom = reader["Kingdom"].ToString();
                            var phylum  = reader["Phylum"].ToString();
                            var tclass  = reader["Class"].ToString();
                            var order   = reader["Order"].ToString();
                            var family  = reader["Family"].ToString();
                            var genus   = reader["Genus"].ToString();
                            var species = reader["Species"].ToString();

                            return(WolframTaxonomyData.GetInstance(kingdom, phylum, tclass, order, family, genus, species));
                        }
                    }
                }
            }

            return(null);
        }
Exemple #2
0
        public void PopulateImageTagToTaxonomicDataDb()
        {
            var cacheDirectoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory() + "/WolframCache/TaxonomicData");
            var cacheFilesList     = cacheDirectoryInfo.GetFiles("*.xml");

            foreach (var fileInfo in cacheFilesList)
            {
                var responseDto  = ReadFromXmlFile <WolframResponseDto>(fileInfo.FullName);
                var taxonomyData = WolframTaxonomyData.GetInstance(responseDto);
                var tagName      = fileInfo.Name.Replace("WolframResponseDto_", "").Replace(".xml", "");
                UpdateDatabaseWithTagToTaxonomicInfo(tagName, taxonomyData);
            }
        }
Exemple #3
0
        public TaxonomicClassification GetTaxonomyData(String tag)
        {
            var cachedTaxonomyData = TaxonomicDataCache.Get(tag);

            if (cachedTaxonomyData != null)
            {
                return(TaxonomicClassification.GetInstance(cachedTaxonomyData.Kingdom, cachedTaxonomyData.Phylum,
                                                           cachedTaxonomyData.Class, cachedTaxonomyData.Order, cachedTaxonomyData.Family,
                                                           cachedTaxonomyData.Genus, cachedTaxonomyData.Species));
            }

            var parameters   = new List <Parameter>();
            var tagParameter = new Parameter {
                Name = "tag", Value = tag, Type = ParameterType.QueryString
            };

            parameters.Add(tagParameter);

            var taxonomicDataDto = ExecuteGetRequest <WolframResponseDto>(TaxonomicDataPath, parameters);

            if (taxonomicDataDto != null)
            {
                var wolframTaxonomyData = WolframTaxonomyData.GetInstance(taxonomicDataDto);
                TaxonomicDataCache.Set(tag, wolframTaxonomyData);

                return(TaxonomicClassification.GetInstance(wolframTaxonomyData.Kingdom, wolframTaxonomyData.Phylum,
                                                           wolframTaxonomyData.Class, wolframTaxonomyData.Order, wolframTaxonomyData.Family,
                                                           wolframTaxonomyData.Genus, wolframTaxonomyData.Species));
            }

            var nullData = WolframTaxonomyData.NULL;

            return(TaxonomicClassification.GetInstance(nullData.Kingdom, nullData.Phylum,
                                                       nullData.Class, nullData.Order, nullData.Family,
                                                       nullData.Genus, nullData.Species));
        }