public int InsertEvent(Event ev, IEnumerable<EventProperty> properties, UserCredentials login) { using (var db = login.GetConnection()) using (var t = new Transaction(db)) { db.Insert(ev); var geoString = SerializeLocalization(ev.Latitude, ev.Longitude, ev.Altitude); foreach (var loc in ev.GetLocalisations(login)) { db.Insert(loc); if (!string.IsNullOrWhiteSpace(geoString)) { db.Execute("UPDATE [dbo].[CollectionEventLocalisation] SET geography=GEOGRAPHY::STGeomFromText(@0, 4326) WHERE CollectionEventID=@1 AND LocalisationSystemID=@2", geoString, loc.CollectionEventID, loc.LocalisationSystemID); } } if (properties != null) foreach (var p in properties) { p.CollectionEventID = ev.CollectionEventID; db.Insert(p); } t.Complete(); return ev.CollectionEventID; } }
public IObservable<Unit> downloadAndStoreDependencies(Event ev) { if (ev == null) throw new ArgumentNullException(); //Avoid undesirable interactions ev = ev.MemberwiseClone(); IObservable<EventSeries> series_future = getOrDownloadSeries(ev.SeriesID); IObservable<Event> event_future = addEvent(series_future, ev); IObservable<Unit> props_future = downloadProperties(event_future); IObservable<Specimen> specimen_future = downloadSpecimen(event_future); IObservable<IdentificationUnit> iu_future = downloadUnits(specimen_future); IObservable<Unit> an_future = downloadAnalyses(iu_future); return Observable.Merge( series_future.Select(_ => Unit.Default), event_future.Select(_ => Unit.Default), props_future, specimen_future.Select(_ => Unit.Default), iu_future.Select(_ => Unit.Default), an_future ); }
public IObservable<Unit> InsertEvent(Event ev, IEnumerable<EventProperty> properties) { var res = InsertEVCompleted.FilterByUserState(ev) .PipeErrors() .Select(p => p.Result) .StoreMapping(ev, Mapping) .ReplayOnlyFirst(); var svcProps = new ObservableCollection<Svc.EventProperty>(properties.Select(l => l.ToServiceObject())); WithCredentials(c => _svc.InsertEventAsync(ev.ToServiceObject(Mapping), svcProps, c, ev)); return res; }
private IObservable<Event> IfNotDownloadedYet(Event ev) { if (ev == null) return Observable.Empty<Event>(); return Observable.Return(ev) .Where(e => { if (!Mappings.ResolveToLocalKey(DBObjectType.Event, e.CollectionEventID.Value).HasValue) { return true; } else { Notifications.showNotification(DiversityResources.Download_EventAlreadyDownloaded); return false; } }); }
internal static IQueryable<EventProperty> Properties(Event ev, DiversityDataContext ctx) { return from p in ctx.EventProperties where p.EventID == ev.EventID select p; }
internal static IQueryable<Specimen> Specimen(Event ev, DiversityDataContext ctx) { return from s in ctx.Specimen where s.EventID == ev.EventID select s; }
public IObservable<Event> addEvent(IObservable<EventSeries> series_future, Event ev) { var insertion_future = series_future .Select(es => { ev.SeriesID = NoEventSeriesMixin.IsNoEventSeries(es) ? null as int? : es.SeriesID; Storage.add(ev); return ev; }).Replay() .RefCount(); return insertion_future; }
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); }