private bool LoadViaMetaProvider(IMetaProvider metaProvider, string name, FourPartVersion asmVersion, IHostApi request)
        {
            var found = false;

            var instance = metaProvider.CreateProvider(name);

            if (instance != null)
            {
                // check if it's a Package Provider
                if (typeof(IPackageProvider).CanDynamicCastFrom(instance))
                {
                    try {
                        var packageProvider = RegisterPackageProvider(instance.As <IPackageProvider>(), asmVersion, request);
                        if (packageProvider != null)
                        {
                            found = true;
                            packageProvider.ProviderPath = metaProvider.GetProviderPath(name);
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                }

                // check if it's a Services Provider
                if (typeof(IArchiver).CanDynamicCastFrom(instance))
                {
                    try {
                        var archiver = RegisterArchiver(instance.As <IArchiver>(), asmVersion, request);
                        if (archiver != null)
                        {
                            found = true;
                            archiver.ProviderPath = metaProvider.GetProviderPath(name);
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                }

                if (typeof(IDownloader).CanDynamicCastFrom(instance))
                {
                    try {
                        var downloader = RegisterDownloader(instance.As <IDownloader>(), asmVersion, request);
                        if (downloader != null)
                        {
                            found = true;
                            downloader.ProviderPath = metaProvider.GetProviderPath(name);
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                }
            }
            return(found);
        }
        private PackageProvider ImportProvider(IHostApi request, string providerName, IMetaProvider powerShellMetaProvider)
        {


            //foreach (var providerName in providers)
            {
                //var matchedProviderName = provider.As<DefaultPackageProvider>().GetPackageProviderName();
                //TODO pass in Maxi, mini, and requiredVersion to LoadAvailableProvider
                var instance = powerShellMetaProvider.LoadAvailableProvider(request.As<IRequest>(), providerName);
                if (instance == null)
                {
                   return null;
                }

                //Register newly created provider
                if (typeof(IPackageProvider).CanDynamicCastFrom(instance))
                {

                    var packageProvider = RegisterPackageProvider(instance.As<IPackageProvider>(), providerName, String.Empty, request);

                    if (packageProvider != null)
                    {
                        packageProvider.ProviderPath = powerShellMetaProvider.GetProviderPath(providerName);
                        return packageProvider;
                    }
                }
                else
                {
                    //A provider is not found
                    request.Error(Constants.Messages.UnknownProvider, ErrorCategory.InvalidOperation.ToString(),
                        providerName, request.FormatMessageString(Constants.Messages.UnknownProvider, providerName));
                }
            }
        }
        private bool LoadViaMetaProvider(IMetaProvider metaProvider, string name, FourPartVersion asmVersion, IHostApi request ) {
            var found = false;

            var instance = metaProvider.CreateProvider(name);
            if (instance != null) {
                // check if it's a Package Provider
                if (typeof (IPackageProvider).CanDynamicCastFrom(instance)) {
                    try {
                        var packageProvider = RegisterPackageProvider(instance.As<IPackageProvider>(), name, asmVersion, request);
                        if (packageProvider != null) {
                            found = true;
                            packageProvider.IsLoaded = true;
                            packageProvider.ProviderPath = metaProvider.GetProviderPath(name);
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                }

                // check if it's a Services Provider
                if (typeof (IArchiver).CanDynamicCastFrom(instance)) {
                    try {
                        var archiver = RegisterArchiver(instance.As<IArchiver>(), asmVersion, request);
                        if (archiver != null) {
                            found = true;
                            archiver.ProviderPath = metaProvider.GetProviderPath(name);
                            archiver.IsLoaded = true;
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                }

                if (typeof (IDownloader).CanDynamicCastFrom(instance)) {
                    try {
                        var downloader = RegisterDownloader(instance.As<IDownloader>(), asmVersion, request);
                        if (downloader != null) {
                            found = true;
                            downloader.ProviderPath = metaProvider.GetProviderPath(name);
                            downloader.IsLoaded = true;
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                }
            }
            return found;
        }