public static async Task <ISampledService> GetServiceAsync(this IAsyncServiceProvider self, FileSample sample) { if (self is null) { throw new ArgumentNullException(nameof(self)); } if (sample is null) { throw new ArgumentNullException(nameof(sample)); } if (!ServiceMapping.TryGetValue(sample.GetType(), out Type serviceType)) { return(null); } PlaySpaceManager playSpace = await self.GetServiceAsync <PlaySpaceManager> ().ConfigureAwait(false); await playSpace.Loading.ConfigureAwait(false); IEnumerable <IEnvironmentService> services = await self.GetServicesAsync <IEnvironmentService> ().ConfigureAwait(false); services = services.Where(s => serviceType.IsAssignableFrom(s.GetType())); PlaySpaceElement space = playSpace.SelectedElement; if (space != null) { services = services.Where(s => space.Services.Contains(s.GetType().GetSimpleTypeName())); } return((ISampledService)services.FirstOrDefault()); }
private async Task LoadServicesAsync() { this.availableServices = this.serviceProvider.GetServicesAsync <IEnvironmentService> (); this.sync = await this.serviceProvider.GetServiceAsync <ISyncService> ().ConfigureAwait(false); this.playSpaceManager = await this.serviceProvider.GetServiceAsync <PlaySpaceManager> ().ConfigureAwait(false); this.playSpaceManager.PropertyChanged += OnPlayspaceManagerPropertyChanged; this.downloadManager = await this.serviceProvider.GetServiceAsync <DownloadManager> ().ConfigureAwait(false); this.storage = await this.serviceProvider.GetServiceAsync <ILocalStorageService> ().ConfigureAwait(false); await(this.loadedServices = UpdateServicesAsync()); }