public DownloadVM( IDiversityServiceClient Service, IConnectivityService Connectivity, IFieldDataService Storage, IKeyMappingService Mappings, EventHierarchyLoader HierarchyLoader, [Dispatcher] IScheduler Dispatcher ) { this.Service = Service; this.Connectivity = Connectivity; this.Storage = Storage; this.Mappings = Mappings; this.HierarchyLoader = HierarchyLoader; QueryResult = new ReactiveCollection<Event>(); _IsOnlineAvailable = Connectivity.Status().Select(s => s == ConnectionStatus.Wifi).Do(_ => { this.GetType(); }, ex => { }, () => { }) .ToProperty(this, x => x.IsOnlineAvailable); SearchEvents = new ReactiveAsyncCommand(this.WhenAny(x => x.IsOnlineAvailable, x => x.Value)); SearchEvents.ShowInFlightNotification(Notifications, DiversityResources.Download_SearchingEvents); SearchEvents.ThrownExceptions .ShowServiceErrorNotifications(Notifications) .ShowErrorNotifications(Notifications) .Subscribe(); SearchEvents .RegisterAsyncObservable(query => Service.GetEventsByLocality(query as string ?? string.Empty) .TakeUntil(this.OnDeactivation()) ) .Do(_ => QueryResult.Clear()) .Subscribe(QueryResult.AddRange); CancelDownload = new ReactiveCommand(); DownloadElement = new ReactiveAsyncCommand(this.WhenAny(x => x.IsOnlineAvailable, x => x.Value)); DownloadElement.ThrownExceptions .ShowServiceErrorNotifications(Notifications) .ShowErrorNotifications(Notifications) .Subscribe(); DownloadElement .RegisterAsyncObservable(ev => IfNotDownloadedYet(ev as Event) .Select(HierarchyLoader.downloadAndStoreDependencies) .SelectMany(dl => dl.TakeUntil(CancelDownload)) .Scan(0, (acc, _) => ++acc) .Do(_ElementsDownloadedSubject.OnNext) ); _IsDownloading = DownloadElement.ItemsInflight .Select(x => x > 0) .ToProperty(this, x => x.IsDownloading); this.OnDeactivation() .Subscribe(_ => Messenger.SendMessage(EventMessage.Default, MessageContracts.INIT)); _ElementsDownloadedSubject = new Subject<int>(); _ElementsDownloaded = _ElementsDownloadedSubject.ToProperty(this, x => x.ElementsDownloaded, 0, Dispatcher); }
public EventHierarchyLoader( IDiversityServiceClient Service, IFieldDataService Storage, IKeyMappingService Mappings, [ThreadPool] IScheduler ThreadPool ) { this.Service = Service; this.Storage = Storage; this.Mappings = Mappings; this.ThreadPool = ThreadPool; }
public static Svc.Event ToServiceObject(this Event ev, IKeyMappingService mapping) { if (ev.CollectionEventID != null) throw new ArgumentException("Event already uploaded"); var seriesID = (ev.SeriesID.HasValue) ? mapping.EnsureKey(DBObjectType.EventSeries, ev.SeriesID.Value) as int? : null; return new Svc.Event() { CollectionEventID = Int32.MinValue, CollectionSeriesID = seriesID, Altitude = ev.Altitude, CollectionDate = ev.CollectionDate, HabitatDescription = ev.HabitatDescription, Latitude = ev.Latitude, LocalityDescription = ev.LocalityDescription, Longitude = ev.Longitude, }; }
public DiversityServiceClient(ICredentialsService Credentials, IKeyMappingService Mapping) { this.Mapping = Mapping; this.Credentials = Credentials; Credentials.CurrentCredentials().Where(c => c != null).Subscribe(c => _CurrentCredentials = c); GetUserInfoCompleted = Observable.FromEventPattern<GetUserInfoCompletedEventArgs>(h => _svc.GetUserInfoCompleted += h, h => _svc.GetUserInfoCompleted -= h); GetRepositoriesCompleted = Observable.FromEventPattern<GetRepositoriesCompletedEventArgs>(h => _svc.GetRepositoriesCompleted += h, h => _svc.GetRepositoriesCompleted -= h); GetPropertiesForUserCompleted = Observable.FromEventPattern<GetPropertiesForUserCompletedEventArgs>(h => _svc.GetPropertiesForUserCompleted += h, h => _svc.GetPropertiesForUserCompleted -= h); GetProjectsForUserCompleted = Observable.FromEventPattern<GetProjectsForUserCompletedEventArgs>(h => _svc.GetProjectsForUserCompleted += h, h => _svc.GetProjectsForUserCompleted -= h); GetStandardVocabularyCompleted = Observable.FromEventPattern<GetStandardVocabularyCompletedEventArgs>(d => _svc.GetStandardVocabularyCompleted += d, d => _svc.GetStandardVocabularyCompleted -= d); GetAnalysesForProjectCompleted = Observable.FromEventPattern<GetAnalysesForProjectCompletedEventArgs>(d => _svc.GetAnalysesForProjectCompleted += d, d => _svc.GetAnalysesForProjectCompleted -= d); GetAnalysisResultsForProjectCompleted = Observable.FromEventPattern<GetAnalysisResultsForProjectCompletedEventArgs>( d => _svc.GetAnalysisResultsForProjectCompleted += d, d => _svc.GetAnalysisResultsForProjectCompleted -= d); GetAnalysisTaxonomicGroupsForProjectCompleted = Observable.FromEventPattern<GetAnalysisTaxonomicGroupsForProjectCompletedEventArgs>(d => _svc.GetAnalysisTaxonomicGroupsForProjectCompleted += d, d => _svc.GetAnalysisTaxonomicGroupsForProjectCompleted -= d); GetTaxonListsForUser = Observable.FromEventPattern<GetTaxonListsForUserCompletedEventArgs>( d => _svc.GetTaxonListsForUserCompleted += d, d => _svc.GetTaxonListsForUserCompleted -= d); DownloadTaxonList = Observable.FromEventPattern<DownloadTaxonListCompletedEventArgs>( d => _svc.DownloadTaxonListCompleted += d, d => _svc.DownloadTaxonListCompleted -= d); GetQualificationsCompleted = Observable.FromEventPattern<GetQualificationsCompletedEventArgs>( d => _svc.GetQualificationsCompleted += d, d => _svc.GetQualificationsCompleted -= d); InsertMMOCompleted = Observable.FromEventPattern<AsyncCompletedEventArgs>(h => _svc.InsertMMOCompleted += h, h => _svc.InsertMMOCompleted -= h); InsertESCompleted = Observable.FromEventPattern<InsertEventSeriesCompletedEventArgs>(h => _svc.InsertEventSeriesCompleted += h, h => _svc.InsertEventSeriesCompleted -= h); InsertEVCompleted = Observable.FromEventPattern<InsertEventCompletedEventArgs>(h => _svc.InsertEventCompleted += h, h => _svc.InsertEventCompleted -= h); InsertSPCompleted = Observable.FromEventPattern<InsertSpecimenCompletedEventArgs>(h => _svc.InsertSpecimenCompleted += h, h => _svc.InsertSpecimenCompleted -= h); InsertIUCompleted = Observable.FromEventPattern<InsertIdentificationUnitCompletedEventArgs>(h => _svc.InsertIdentificationUnitCompleted += h, h => _svc.InsertIdentificationUnitCompleted -= h); UploadMultimediaCompleted = Observable.FromEventPattern<SubmitCompletedEventArgs>(h => _multimedia.SubmitCompleted += h, h => _multimedia.SubmitCompleted -= h); EventSeriesByIDCompleted = Observable.FromEventPattern<EventSeriesByIDCompletedEventArgs>(h => _svc.EventSeriesByIDCompleted += h, h => _svc.EventSeriesByIDCompleted -= h); LocalizationsForSeriesCompleted = Observable.FromEventPattern<LocalizationsForSeriesCompletedEventArgs>(h => _svc.LocalizationsForSeriesCompleted += h, h => _svc.LocalizationsForSeriesCompleted -= h); EventsByLocalityCompleted = Observable.FromEventPattern<EventsByLocalityCompletedEventArgs>(h => _svc.EventsByLocalityCompleted += h, h => _svc.EventsByLocalityCompleted -= h); PropertiesForEventCompleted = Observable.FromEventPattern<PropertiesForEventCompletedEventArgs>(h => _svc.PropertiesForEventCompleted += h, h => _svc.PropertiesForEventCompleted -= h); SpecimenForEventCompleted = Observable.FromEventPattern<SpecimenForEventCompletedEventArgs>(h => _svc.SpecimenForEventCompleted += h, h => _svc.SpecimenForEventCompleted -= h); UnitsForSpecimenCompleted = Observable.FromEventPattern<UnitsForSpecimenCompletedEventArgs>(h => _svc.UnitsForSpecimenCompleted += h, h => _svc.UnitsForSpecimenCompleted -= h); SubUnitsForIUCompleted = Observable.FromEventPattern<SubUnitsForIUCompletedEventArgs>(h => _svc.SubUnitsForIUCompleted += h, h => _svc.SubUnitsForIUCompleted -= h); AnalysesForIUCompleted = Observable.FromEventPattern<AnalysesForIUCompletedEventArgs>(h => _svc.AnalysesForIUCompleted += h, h => _svc.AnalysesForIUCompleted -= h); }
public static Svc.MultimediaObject ToServiceObject(this MultimediaObject mmo, IKeyMappingService mapping) { var relID = mapping.EnsureKey(mmo.OwnerType, mmo.RelatedId); return new Svc.MultimediaObject() { MediaType = mmo.MediaType.ToServiceObject(), OwnerType = mmo.OwnerType.ToServiceObject(), RelatedCollectionID = relID, Uri = mmo.CollectionURI }; }
public static Svc.IdentificationUnit ToServiceObject(this IdentificationUnit iu, IKeyMappingService mapping) { var specID = mapping.EnsureKey(DBObjectType.Specimen, iu.SpecimenID); var relUnitID = (iu.RelatedUnitID.HasValue) ? mapping.EnsureKey(DBObjectType.IdentificationUnit, iu.RelatedUnitID.Value) as int? : null; return new Svc.IdentificationUnit() { CollectionUnitID = Int32.MinValue, CollectionSpecimenID = specID, CollectionRelatedUnitID = relUnitID, Altitude = iu.Altitude, AnalysisDate = iu.AnalysisDate, IdentificationUri = iu.IdentificationUri, LastIdentificationCache = iu.WorkingName, Qualification = iu.Qualification, Latitude = iu.Latitude, Longitude = iu.Longitude, OnlyObserved = iu.OnlyObserved, RelationType = iu.RelationType, TaxonomicGroup = iu.TaxonomicGroup, }; }
public static Svc.Specimen ToServiceObject(this Specimen spec, IKeyMappingService mapping) { var eventID = mapping.EnsureKey(DBObjectType.Event, spec.EventID); return new Svc.Specimen() { CollectionSpecimenID = Int32.MinValue, CollectionEventID = eventID, AccessionNumber = spec.AccessionNumber, }; }