Exemplo n.º 1
0
        private static Task RunServiceDiscoveryAsync(IAsyncServiceProvider services)
        {
            return(Task.Run(async() => {
                IAuthenticationService auth = null;

                List <Task> tasks = new List <Task> ();

                IDiscoverableService[] discoverableServices = await services.GetServicesAsync <IDiscoverableService> ();
                foreach (IDiscoverableService discoverable in discoverableServices)
                {
                    tasks.Add(DiscoverService(discoverable));
                }

                IAuthenticatedService[] authenticatedServices = await services.GetServicesAsync <IAuthenticatedService> ();
                foreach (IAuthenticatedService authed in authenticatedServices)
                {
                    if (auth == null)
                    {
                        auth = await services.GetServiceAsync <IAuthenticationService> ();
                    }

                    tasks.Add(TryAuth(auth, authed));
                }

                await Task.WhenAll(tasks);
            }));
        }
Exemplo n.º 2
0
        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());
        }