Exemple #1
0
        public int GetSpeciesID(String genus, String species, String common)
        {
            String speciesName = genus + " " + species;
            int    speciesID   = GetSpeciesID(speciesName);

            if (speciesID != 0)
            {
                return(speciesID);
            }
            int taxonID = 0;
            int wormsID = 0;


            Worms.AphiaRecord record = FindSpecies(genus, species, common);
            if (record != null)
            {
                wormsID = record.AphiaID;
                GenericList gl = new GenericList(null);
                if (record.scientificname == null || record.scientificname.Trim() == "")
                {
                    record.scientificname = "Unknown";
                }
                taxonID = int.Parse(gl.getTaxonID(int.Parse(record.AphiaID.ToString()), record.scientificname));
                AddSpecies(genus, species, common, taxonID, wormsID);
            }

            return(GetSpeciesID(speciesName));
        }
Exemple #2
0
 public Worms.AphiaRecord FindSpecies(String Genus, String Species, String Common)
 {
     Worms.AphiaRecord record = null;
     if (Genus != "" && Species != "")
     {
         String search = Genus + " " + Species;
         record = FindSpeciesByScientificName(search);
     }
     if (record == null && Genus != "")
     {
         record = FindSpeciesByScientificName(Genus);
     }
     if (record == null && Species != "")
     {
         record = FindSpeciesByScientificName(Species);
     }
     if (record == null && Common != "")
     {
         record = FindSpeciesByCommonName(Common);
     }
     return(record);
 }
        public void ProcessRequest(HttpContext context)
        {
            String             name = context.Request["name"];
            List <TaxonRecord> list = new List <TaxonRecord>();

            // get records from worms service
            Worms.AphiaNameServicePortTypeClient client = new Worms.AphiaNameServicePortTypeClient();

            Worms.AphiaRecord[] records = null;

            // check if the AphiaID is given
            if (name.IndexOf(':') != -1 && name.IndexOf('(') != -1 && name.IndexOf(')') != -1)
            {
                int s       = name.IndexOf('(');
                int e       = name.IndexOf(')');
                int AphiaID = int.Parse(name.Substring(s + 1, e - s - 1));
                Worms.AphiaRecord record = client.getAphiaRecordByID(AphiaID);
                if (record == null)
                {
                    context.Response.Write("[]");
                    context.Response.End();
                }
                List <Worms.AphiaRecord> alist = new List <Worms.AphiaRecord>();
                alist.Add(record);
                records = alist.ToArray();
            }
            else
            {
                records = client.getAphiaRecordsByVernacular(name, true, 0);
            }

            if (records == null)
            {
                context.Response.Write("[]");
                context.Response.End();
            }

            for (int i = 0; i < records.Length; i++)
            {
                Worms.AphiaRecord record = records[i];
                TaxonRecord       taxon  = new TaxonRecord();
                taxon.AphiaID        = record.AphiaID;
                taxon.authority      = record.authority;
                taxon.citation       = record.citation;
                taxon.@class         = record.@class;
                taxon.family         = record.family;
                taxon.genus          = record.genus;
                taxon.isBrackish     = record.isBrackish;
                taxon.isExtinct      = record.isExtinct;
                taxon.isFreshwater   = record.isFreshwater;
                taxon.kingdom        = record.kingdom;
                taxon.lsid           = record.lsid;
                taxon.match_type     = record.match_type;
                taxon.modified       = record.modified;
                taxon.order          = record.order;
                taxon.phylum         = record.phylum;
                taxon.rank           = record.rank;
                taxon.scientificname = record.scientificname;
                taxon.status         = record.status;
                taxon.url            = record.url;
                taxon.valid_name     = record.valid_name;
                taxon.vernacular     = "???";
                list.Add(taxon);
            }

            // spawn threads to get vernacular name
            foreach (TaxonRecord taxon in list)
            {
                taxon.thread = new Thread(taxon.GetVernacular);
                taxon.thread.Start();
            }

            // wait to all treads to complete
            foreach (TaxonRecord taxon in list)
            {
                taxon.thread.Join();
                taxon.thread = null;
            }

            var json = new JavaScriptSerializer().Serialize(list);

            context.Response.ContentType = "text/json";
            context.Response.Write(json);
        }