public IEnumerable<TaxonName> DownloadTaxonList(TaxonList list, int page, UserCredentials login) { Diversity db; if (list.IsPublicList) { var taxa = ServiceConfiguration.PublicTaxa; db = new Diversity(taxa.Login, taxa.Server, taxa.Catalog); } else db = login.GetConnection(CATALOG_DIVERSITYMOBILE); return loadTablePaged<Model.TaxonName>(list.Table, page, db); }
private void AddUnitExternalInformation(IdentificationUnit iu, Diversity db) { var id = db.SingleOrDefault<Identification>("WHERE [CollectionSpecimenID]=@0 AND [IdentificationUnitID]=@1", iu.CollectionSpecimenID, iu.CollectionUnitID); if (id != null) { iu.IdentificationUri = id.NameURI; iu.LastIdentificationCache = id.TaxonomicName; iu.Qualification = id.IdentificationQualifier; iu.AnalysisDate = (id.IdentificationYear.HasValue && id.IdentificationMonth.HasValue && id.IdentificationDay.HasValue) ? new DateTime(id.IdentificationYear.Value, id.IdentificationMonth.Value, id.IdentificationDay.Value, 0, 0, 0) : DateTime.Now; } iu.Altitude = db.ExecuteScalar<double?>(string.Format("SELECT [dbo].[DiversityMobile_IdentificationUnitAltitude] ( {0} )", iu.CollectionUnitID)); iu.Latitude = db.ExecuteScalar<double?>(string.Format("SELECT [dbo].[DiversityMobile_IdentificationUnitLatitude] ( {0} )", iu.CollectionUnitID)); iu.Longitude = db.ExecuteScalar<double?>(string.Format("SELECT [dbo].[DiversityMobile_IdentificationUnitLongitude] ( {0} )", iu.CollectionUnitID)); }
public IEnumerable<Repository> GetRepositories(UserCredentials login) { List<Repository> result = new List<Repository>(); Parallel.ForEach(Configuration.ServiceConfiguration.Repositories, repo => { using (var ctx = new Diversity(login, repo.Server, repo.Catalog)) { try { ctx.OpenSharedConnection(); // validate Credentials lock (result) { result.Add(new Repository() { Database = repo.Catalog, DisplayText = repo.name }); } } catch (Exception) { } } }); return result; }
public IEnumerable<Model.TaxonList> GetTaxonListsForUser(UserCredentials login) { List<Model.TaxonList> result = new List<TaxonList>(); using (var db = login.GetConnection(CATALOG_DIVERSITYMOBILE)) { result.AddRange( taxonListsForUser(login.LoginName,db) .Select(l => {l.IsPublicList = false; return l;}) ); } var publicTaxa = ServiceConfiguration.PublicTaxa; using (var db = new DiversityORM.Diversity(publicTaxa.Login, publicTaxa.Server, publicTaxa.Catalog)) { result.AddRange( taxonListsForUser(db) .Select(l => { l.IsPublicList = true; return l; }) ); } return result; }
private void AddUnitExternalInformation(IdentificationUnit iu, Diversity db) { var id = db.SingleOrDefault<Identification>("WHERE [CollectionSpecimenID]=@0 AND [IdentificationUnitID]=@1", iu.CollectionSpecimenID, iu.CollectionUnitID); if (id != null) { iu.IdentificationUri = id.NameURI; iu.LastIdentificationCache = id.TaxonomicName; iu.Qualification = id.IdentificationQualifier; iu.AnalysisDate = (id.IdentificationYear.HasValue && id.IdentificationMonth.HasValue && id.IdentificationDay.HasValue) ? new DateTime(id.IdentificationYear.Value, id.IdentificationMonth.Value, id.IdentificationDay.Value, 0, 0, 0) : DateTime.Now; } AddLocalization(iu, db); }
private void AddLocalization(Event ev, Diversity db) { // The decimal -> double dance ensures the coordinates round trip correctly ev.Altitude = DecimalToDouble(db.SingleOrDefault<decimal?>("SELECT CAST([AverageAltitudeCache] AS DECIMAL(25, 20)) FROM [CollectionEventLocalisation] WHERE [CollectionEventID]=@0 AND [LocalisationSystemID]=@1", ev.CollectionEventID, ClientServiceConversions.ALTITUDE_LOC_SYS_ID)); var lat = db.SingleOrDefault<decimal?>("SELECT CAST([AverageLatitudeCache] AS DECIMAL(25, 20)) FROM [CollectionEventLocalisation] WHERE [CollectionEventID]=@0 AND [LocalisationSystemID]=@1", ev.CollectionEventID, ClientServiceConversions.WGS84_LOC_SYS_ID); ev.Latitude = DecimalToDouble(lat); var lon = db.SingleOrDefault<decimal?>("SELECT CAST([AverageLongitudeCache] AS DECIMAL(25, 20)) FROM [CollectionEventLocalisation] WHERE [CollectionEventID]=@0 AND [LocalisationSystemID]=@1", ev.CollectionEventID, ClientServiceConversions.WGS84_LOC_SYS_ID); ev.Longitude = DecimalToDouble(lon); }
private void AddLocalization(IdentificationUnit iu, Diversity db) { // The decimal -> double dance ensures the coordinates round trip correctly iu.Altitude = DecimalToDouble(db.SingleOrDefault<decimal?>("SELECT CAST([Geography].Z AS DECIMAL(25, 20)) FROM [IdentificationUnitGeoAnalysis] WHERE [CollectionSpecimenID]=@0 AND [IdentificationUnitID]=@1", iu.CollectionSpecimenID, iu.CollectionUnitID)); var lat = db.SingleOrDefault<decimal?>("SELECT CAST([Geography].Lat AS DECIMAL(25, 20)) FROM [IdentificationUnitGeoAnalysis] WHERE [CollectionSpecimenID]=@0 AND [IdentificationUnitID]=@1", iu.CollectionSpecimenID, iu.CollectionUnitID); iu.Latitude = DecimalToDouble(lat); var lon = db.SingleOrDefault<decimal?>("SELECT CAST([Geography].Long AS DECIMAL(25, 20)) FROM [IdentificationUnitGeoAnalysis] WHERE [CollectionSpecimenID]=@0 AND [IdentificationUnitID]=@1", iu.CollectionSpecimenID, iu.CollectionUnitID); iu.Longitude = DecimalToDouble(lon); }
public static CollectionSpecimenImage ToSpecimenImage(this MultimediaObject mmo, Diversity db) { if (mmo.OwnerType != MultimediaOwner.Specimen && mmo.OwnerType != MultimediaOwner.IdentificationUnit) throw new ArgumentException("Related type mismatch"); if (mmo.Uri == null) throw new ArgumentException("image not uploaded"); CollectionSpecimenImage export = new CollectionSpecimenImage(); switch (mmo.OwnerType) { case MultimediaOwner.Specimen: export.CollectionSpecimenID = mmo.RelatedCollectionID; break; case MultimediaOwner.IdentificationUnit: var iu = db.Single<IdentificationUnit>(mmo.RelatedCollectionID); export.CollectionSpecimenID = iu.CollectionSpecimenID; export.IdentificationUnitID = mmo.RelatedCollectionID; break; default: throw new NotImplementedException("Case overlooked"); } export.ImageType = MediaTypeToString(mmo.MediaType); export.Uri = mmo.Uri.ToString(); export.Description = mmo.Description; export.Notes = "Generated via DiversityMobile"; return export; }