Exemple #1
0
        internal bool RegisterProvidersViaMetaProvider(IMetaProvider provider, FourPartVersion asmVersion, IHostApi request)
        {
            var             found               = false;
            var             metaProviderName    = provider.GetMetaProviderName();
            FourPartVersion metaProviderVersion = provider.GetProviderVersion();

                                                                              if (!_metaProviders.ContainsKey(metaProviderName))
            {
                // Meta Providers can't be replaced at this point
                _metaProviders.AddOrSet(metaProviderName, provider);
            }

                                                                              try {
                provider.InitializeProvider(request.As <IRequest>());
                var metaProvider = provider;
                provider.GetProviderNames().ParallelForEach(name => {
                    // foreach (var name in provider.GetProviderNames()) {
                    var instance = metaProvider.CreateProvider(name);
                    if (instance != null)
                    {
                        // check if it's a Package Provider
                        if (typeof(IPackageProvider).CanDynamicCastFrom(instance))
                        {
                            try {
                                found = found | RegisterPackageProvider(instance.As <IPackageProvider>(), asmVersion, request);
                            } catch (Exception e) {
                                e.Dump();
                            }
                        }

                        // check if it's a Services Provider
                        if (typeof(IArchiver).CanDynamicCastFrom(instance))
                        {
                            try {
                                found = found | RegisterArchiver(instance.As <IArchiver>(), asmVersion, request);
                            } catch (Exception e) {
                                e.Dump();
                            }
                        }

                        if (typeof(IDownloader).CanDynamicCastFrom(instance))
                        {
                            try {
                                found = found | RegisterDownloader(instance.As <IDownloader>(), asmVersion, request);
                            } catch (Exception e) {
                                e.Dump();
                            }
                        }
                    }
                });
            } catch (Exception e) {
                e.Dump();
            }
                                                                              return(found);
        }
Exemple #2
0
        internal static bool AcquireProvidersViaMetaProvider(IMetaProvider provider, YieldMetaProvider yieldMetaProvider, YieldPackageProvider yieldPackageProvider, YieldArchiver yieldArchiver, YieldDownloader yieldDownloader, FourPartVersion asmVersion,
                                                             IRequest request)
        {
            var             found               = false;
            var             metaProviderName    = provider.GetMetaProviderName();
            FourPartVersion metaProviderVersion = provider.GetProviderVersion();
            var             reloading           = yieldMetaProvider(metaProviderName, provider, (metaProviderVersion == 0 ? asmVersion : metaProviderVersion), request);

            try {
                provider.InitializeProvider(request);
                var metaProvider = provider;
                Parallel.ForEach(provider.GetProviderNames(), name => {
                    // foreach (var name in provider.GetProviderNames()) {
                    var instance = metaProvider.CreateProvider(name);
                    if (instance != null)
                    {
                        // check if it's a Package Provider
                        if (DynamicInterface.Instance.IsInstanceCompatible <IPackageProvider>(instance))
                        {
                            try {
                                found = found | ProcessPackageProvider(DynamicInterface.Instance.Create <IPackageProvider>(instance), yieldPackageProvider, asmVersion, request);
                            } catch (Exception e) {
                                e.Dump();
                            }
                        }

                        // check if it's a Services Provider
                        if (DynamicInterface.Instance.IsInstanceCompatible <IArchiver>(instance))
                        {
                            try {
                                found = found | ProcessArchiver(DynamicInterface.Instance.Create <IArchiver>(instance), yieldArchiver, asmVersion, request);
                            } catch (Exception e) {
                                e.Dump();
                            }
                        }

                        if (DynamicInterface.Instance.IsInstanceCompatible <IDownloader>(instance))
                        {
                            try {
                                found = found | ProcessDownloader(DynamicInterface.Instance.Create <IDownloader>(instance), yieldDownloader, asmVersion, request);
                            } catch (Exception e) {
                                e.Dump();
                            }
                        }
                    }
                });
            } catch (Exception e) {
                e.Dump();
            }
            return(found);
        }
        internal bool RegisterProvidersViaMetaProvider(IMetaProvider provider, FourPartVersion asmVersion, IHostApi request)
        {
            var found            = false;
            var metaProviderName = provider.GetMetaProviderName();

            lock (_metaProviders)
            {
                if (!_metaProviders.ContainsKey(metaProviderName))
                {
                    // Meta Providers can't be replaced at this point
                    _metaProviders.AddOrSet(metaProviderName, provider);
                }
            }

                  try {
                provider.InitializeProvider(request.As <IRequest>());
                provider.GetProviderNames().ParallelForEach(name => {
                    found = LoadViaMetaProvider(provider, name, asmVersion, request);
                });
            } catch (Exception e) {
                e.Dump();
            }
                  return(found);
        }
        /// <summary>
        /// Get available provider if -ListAvailable present;load a provider specified in providerName.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="providerName">provider to be loaded.</param>
        /// <param name="powerShellMetaProvider"></param>
        private IEnumerable<PackageProvider> GetAvailableProvider(IHostApi request, string providerName, IMetaProvider powerShellMetaProvider)
        {
            var results = _packageProviders.Values.Where(each => each.ProviderName.IsWildcardMatch(providerName)).ReEnumerable();

            if (results.Any()) {
                //the provider is already loaded and tracked in the loaded master list: _packageProviders 
                yield break;
            }

            //Get available powershell providers
            var availableProviders = powerShellMetaProvider.GetAvailableLocallyProviders(request.As<IRequest>()).ReEnumerable();                        

            if (!availableProviders.Any()) {
                //No available providers.
                if (!String.IsNullOrWhiteSpace(providerName)) {
                    //Error out if a user specific -Name
                    request.Error(Constants.Messages.UnknownProvider, ErrorCategory.InvalidOperation.ToString(),
                        providerName, request.FormatMessageString(Constants.Messages.UnknownProvider, providerName));
                }
                yield break;
            }

            if (String.IsNullOrWhiteSpace(providerName)) {
                // "-Name" does not exist, we return all we can find
                foreach (var module in availableProviders) {
                    yield return new PackageProvider(module.As<DefaultPackageProvider>());
                }
            } else {
                //A user inputs both -Name and -ListAvailable


                var matches = powerShellMetaProvider.GetProviderNames().Where(each => each.IsWildcardMatch(providerName)).ReEnumerable();
                if (!matches.Any()) {
                    request.Error(Constants.Messages.UnknownProvider, ErrorCategory.InvalidOperation.ToString(),
                        providerName, request.FormatMessageString(Constants.Messages.UnknownProvider, providerName));
                }

                foreach (var match in matches) {
                    yield return new PackageProvider(powerShellMetaProvider.GetAvailableLocallyProvider(match).As<DefaultPackageProvider>());
                    //yield return new PackageProvider(availableProviders[match].As<DefaultPackageProvider>());
                }
            }
        }
        internal bool RegisterProvidersViaMetaProvider(IMetaProvider provider, FourPartVersion asmVersion, IHostApi request) {
            var found = false;
            var metaProviderName = provider.GetMetaProviderName();

            lock (_metaProviders) {
                if (!_metaProviders.ContainsKey(metaProviderName)) {
                    // Meta Providers can't be replaced at this point
                    _metaProviders.AddOrSet(metaProviderName.ToLowerInvariant(), provider);
                }
            }

            try {
                provider.InitializeProvider(request.As<IRequest>());
                provider.GetProviderNames().ParallelForEach(name => {
                    found = LoadViaMetaProvider(provider, name,asmVersion, request);
                });
            } catch (Exception e) {
                e.Dump();
            }
            return found;
        }