private void OpenNuGetGallery()
        {
            try
            {
                INuGetGalleryDescriptor descriptor  = GalleryDescriptors.NuGet;
                Task <bool?>            galleryTask = this.Globals.Gallery.ShowGallery(descriptor, this.Host.WebSite.Path);

                galleryTask.ContinueWith((task) =>
                {
                    Exception exception = null;

                    if (task.IsFaulted)
                    {
                        exception = task.Exception.Flatten().InnerException;
                    }
                    else
                    {
                        try
                        {
                            // Send "Refresh" command to update the file tree
                            var refreshCommand = this.Host.HostCommands.GetCommand(CommonCommandIds.GroupId, (int)CommonCommandIds.Ids.Refresh);

                            // Passing true to the command forces a refresh from the root of the tree
                            if (refreshCommand.CanExecute(true))
                            {
                                refreshCommand.Execute(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            exception = ex;
                        }
                    }

                    if (exception != null)
                    {
                        this.Host.ShowExceptionMessage(Resources.String_Error, Resources.String_ErrorOccurred, exception);
                    }
                },
                                         NuGetExtension.GetCurrentTaskScheduler());
            }
            catch (Exception ex)
            {
                this.Host.ShowExceptionMessage(
                    Resources.String_Error,
                    Resources.String_ErrorOccurred,
                    ex);
            }
        }
예제 #2
0
        public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, string destination, Func <Uri, string, INuGetPackageManager> packageManagerCreator, TaskScheduler scheduler, bool includePrerelease = false)
        {
            if (destination == null)
            {
                var siteRoot = webMatrixHost.WebSite == null ? null : webMatrixHost.WebSite.Path;

                if (String.IsNullOrWhiteSpace(siteRoot))
                {
                    Debug.Fail("The NuGetModel needs a site with a physical path");
                    return(null);
                }

                destination = siteRoot;
            }

            NuGetModel model;

            lock (_cache)
            {
                var key = new Tuple <string, FeedSource, bool>(destination, remoteSource, includePrerelease);
                if (_cache.TryGetValue(key, out model))
                {
                    model.FromCache = true;
                }
                else
                {
                    INuGetPackageManager packageManager;
                    if (packageManagerCreator == null)
                    {
                        packageManager = new NuGetPackageManager(remoteSource.SourceUrl, destination, webMatrixHost);
                    }
                    else
                    {
                        packageManager = packageManagerCreator(remoteSource.SourceUrl, destination);
                    }

                    model = new NuGetModel(descriptor, webMatrixHost, remoteSource, destination, packageManager, scheduler);
                    packageManager.IncludePrerelease = includePrerelease;
                    _cache[key] = model;
                }
            }

            Debug.Assert(model != null, "model should be created");

            return(model);
        }
예제 #3
0
        public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, string destination, Func<Uri, string, INuGetPackageManager> packageManagerCreator, TaskScheduler scheduler, bool includePrerelease = false)
        {
            if (destination == null)
            {
                var siteRoot = webMatrixHost.WebSite == null ? null : webMatrixHost.WebSite.Path;

                if (String.IsNullOrWhiteSpace(siteRoot))
                {
                    Debug.Fail("The NuGetModel needs a site with a physical path");
                    return null;
                }

                destination = siteRoot;
            }

            NuGetModel model;
            lock (_cache)
            {
                var key = new Tuple<string, FeedSource, bool>(destination, remoteSource, includePrerelease);
                if (_cache.TryGetValue(key, out model))
                {
                    model.FromCache = true;
                }
                else
                {
                    INuGetPackageManager packageManager;
                    if (packageManagerCreator == null)
                    {
                        packageManager = new NuGetPackageManager(remoteSource.SourceUrl, destination, webMatrixHost);
                    }
                    else
                    {
                        packageManager = packageManagerCreator(remoteSource.SourceUrl, destination);
                    }

                    model = new NuGetModel(descriptor, webMatrixHost, remoteSource, destination, packageManager, scheduler);
                    packageManager.IncludePrerelease = includePrerelease;
                    _cache[key] = model;
                }
            }

            Debug.Assert(model != null, "model should be created");

            return model;
        }
예제 #4
0
        /// <summary>
        /// Shows a custom NuGet-style gallery.
        /// </summary>
        /// <param name="galleryId">A gallery descriptor for the gallery</param>
        /// <param name="installRoot">Root path for installing packages.</param>
        /// <returns>Task that shows the gallery.</returns>
        public Task <bool?> ShowGallery(
            INuGetGalleryDescriptor descriptor,
            string installRoot)
        {
            var feedSource = new FeedSource(descriptor.FeedUri, descriptor.FeedName)
            {
                IsBuiltIn = true,
                FilterTag = descriptor.FilterTag,
            };

            var preferences = this.Host.GetExtensionSpecificPreferences(descriptor.PreferencesStore);
            IFeedSourceStore feedSourceStore;

            // we special case the NuGet gallery to use the system-wide NuGet store
            feedSourceStore = new NuGetFeedSourceStore(preferences);

            // Customize the custom gallery
            var packageSourcesViewModel = new PackageSourcesViewModel(new PackageSourcesModel(feedSource, feedSourceStore));

            var viewModel = new NuGetViewModel(
                descriptor,
                this.Host,
                packageSourcesViewModel,
                (sourceUrl, siteRoot) => new NuGetPackageManager(
                    sourceUrl,
                    siteRoot,
                    this.Host),
                installRoot,
                GetCurrentTaskScheduler());

            viewModel.ShouldShowPrereleaseFilter = true;

            return(Task.Factory.StartNew <bool?>(() =>
            {
                var view = new NuGetView(descriptor.DialogTitle);

                // show the gallery view
                view.DataContext = viewModel;

                return this.Host.ShowDialog(null, view);
            },
                                                 CancellationToken.None,
                                                 TaskCreationOptions.None,
                                                 GetCurrentTaskScheduler()));
        }
예제 #5
0
        /// <summary>
        /// Shows a custom NuGet-style gallery.
        /// </summary>
        /// <param name="galleryId">A gallery descriptor for the gallery</param>
        /// <param name="installRoot">Root path for installing packages.</param>
        /// <returns>Task that shows the gallery.</returns>
        public Task<bool?> ShowGallery(
            INuGetGalleryDescriptor descriptor,
            string installRoot)
        {
            var feedSource = new FeedSource(descriptor.FeedUri, descriptor.FeedName)
            {
                IsBuiltIn = true,
                FilterTag = descriptor.FilterTag,
            };

            var preferences = this.Host.GetExtensionSpecificPreferences(descriptor.PreferencesStore);
            IFeedSourceStore feedSourceStore;

            // we special case the NuGet gallery to use the system-wide NuGet store
            feedSourceStore = new NuGetFeedSourceStore(preferences);

            // Customize the custom gallery
            var packageSourcesViewModel = new PackageSourcesViewModel(new PackageSourcesModel(feedSource, feedSourceStore));

            var viewModel = new NuGetViewModel(
                descriptor,
                this.Host,
                packageSourcesViewModel,
                (sourceUrl, siteRoot) => new NuGetPackageManager(
                        sourceUrl,
                        siteRoot,
                        this.Host),
                installRoot,
                GetCurrentTaskScheduler());

            viewModel.ShouldShowPrereleaseFilter = true;

            return Task.Factory.StartNew<bool?>(() =>
            {
                var view = new NuGetView(descriptor.DialogTitle);

                // show the gallery view
                view.DataContext = viewModel;

                return this.Host.ShowDialog(null, view);
            },
            CancellationToken.None,
            TaskCreationOptions.None,
            GetCurrentTaskScheduler());
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:NuGetModel"/> class.
        /// <remarks>This is internal for tests. Callers inside of the NuGet module should used NuGetDataCache::GetModel to
        /// take advantage of cachein</remarks>
        /// </summary>
        internal NuGetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost host, FeedSource remoteSource, string destination, INuGetPackageManager packageManager, TaskScheduler scheduler)
        {
            Debug.Assert(host != null, "webMatrixHost must not be null");
            Debug.Assert(remoteSource != null, "remoteSource must not be null");
            Debug.Assert(remoteSource.SourceUrl != null, "remoteSource.SourceUrl must not be null");

            this.Descriptor = descriptor;
            this.Scheduler  = scheduler;

            FeedSource     = remoteSource;
            _webMatrixHost = host;
            _packageKind   = descriptor.PackageKind;
            _galleryId     = descriptor.GalleryId;

            this.PackageManager = packageManager;

            this.FilterManager = new FilterManager(this, this.Scheduler, descriptor);
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:FilterManager"/> class.
        /// </summary>
        internal FilterManager(NuGetModel model, TaskScheduler scheduler, INuGetGalleryDescriptor descriptor)
        {
            Debug.Assert(model != null, "Model must not be null");
            Debug.Assert(scheduler != null, "TaskScheduler must not be null");
            this.Model = model;

            Filters = new ObservableCollection<IListViewFilter>();

            _installedFilter = new ListViewFilter(Resources.Filter_Installed, string.Format(Resources.Filter_InstalledDescription, descriptor.PackageKind), supportsPrerelease: false);
            _installedFilter.FilteredItems.SortDescriptions.Clear();

            _updatesFilter = new ListViewFilter(Resources.Filter_Updated, string.Format(Resources.Filter_UpdatedDescription, descriptor.PackageKind), supportsPrerelease: true);
            _updatesFilter.FilteredItems.SortDescriptions.Clear();

            _disabledFilter = new ListViewFilter(Resources.Filter_Disabled, string.Format(Resources.Filter_DisabledDescription, descriptor.PackageKind), supportsPrerelease: false);
            _disabledFilter.FilteredItems.SortDescriptions.Clear();

            _scheduler = scheduler;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:FilterManager"/> class.
        /// </summary>
        internal FilterManager(NuGetModel model, TaskScheduler scheduler, INuGetGalleryDescriptor descriptor)
        {
            Debug.Assert(model != null, "Model must not be null");
            Debug.Assert(scheduler != null, "TaskScheduler must not be null");
            this.Model = model;

            Filters = new ObservableCollection <IListViewFilter>();

            _installedFilter = new ListViewFilter(Resources.Filter_Installed, string.Format(Resources.Filter_InstalledDescription, descriptor.PackageKind), supportsPrerelease: false);
            _installedFilter.FilteredItems.SortDescriptions.Clear();

            _updatesFilter = new ListViewFilter(Resources.Filter_Updated, string.Format(Resources.Filter_UpdatedDescription, descriptor.PackageKind), supportsPrerelease: true);
            _updatesFilter.FilteredItems.SortDescriptions.Clear();

            _disabledFilter = new ListViewFilter(Resources.Filter_Disabled, string.Format(Resources.Filter_DisabledDescription, descriptor.PackageKind), supportsPrerelease: false);
            _disabledFilter.FilteredItems.SortDescriptions.Clear();

            _scheduler = scheduler;
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:NuGetViewModel"/> class.
        /// </summary>
        public NuGetViewModel(
            INuGetGalleryDescriptor descriptor,
            IWebMatrixHost host,
            PackageSourcesViewModel packageSourcesViewModel,
            Func <Uri, string, INuGetPackageManager> packageManagerCreator,
            string destination,
            TaskScheduler scheduler)
        {
            this.Descriptor = descriptor;
            this.Host       = host;
            this.Scheduler  = scheduler;

            _packageManagerCreator        = packageManagerCreator;
            _destination                  = destination;
            _preferences                  = this.Host.GetExtensionSpecificPreferences(this.Descriptor.PreferencesStore);
            _selectedPrereleaseFilter     = LoadPrereleaseFilter();
            _includePrerelease            = (_selectedPrereleaseFilter == Resources.Prerelease_Filter_IncludePrerelease);
            PackagesToDisplayForUpdateAll = new List <PackageViewModel>();

            this.ShowDetailsPageCommand   = new RelayCommand(this.ShowDetailsPage, this.CanShowDetailsPage);
            this.ShowLicensePageCommand   = new RelayCommand(this.ShowLicensePage, this.CanShowLicensePage);
            this.ShowUninstallPageCommand = new RelayCommand(this.ShowUninstallPage, this.CanShowUninstallPage);

            this.ShowListCommand = new RelayCommand(this.ShowList, this.CanShowList);

            this.InstallCommand   = new RelayCommand(this.Install, this.CanInstall);
            this.UpdateCommand    = new RelayCommand(this.Update, this.CanUpdate);
            this.UninstallCommand = new RelayCommand(this.Uninstall, this.CanUninstall);

            this.UpdateAllCommand             = new RelayCommand(this.UpdateAll, this.CanUpdateAll);
            this.ShowLicensePageForAllCommand = new RelayCommand(this.ShowLicensePageForAll, this.CanShowLicensePageForAll);

            this.DisableCommand = new RelayCommand(this.Disable, this.CanDisable);
            this.EnableCommand  = new RelayCommand(this.Enable, this.CanEnable);

            this.DefaultActionCommand = new RelayCommand(this.DefaultAction, this.CanDefaultAction);

            // Initialize the Package Sources
            InitializePackageSources(packageSourcesViewModel);
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:NuGetViewModel"/> class.
        /// </summary>
        public NuGetViewModel(
            INuGetGalleryDescriptor descriptor,
            IWebMatrixHost host,
            PackageSourcesViewModel packageSourcesViewModel, 
            Func<Uri, string, INuGetPackageManager> packageManagerCreator, 
            string destination,
            TaskScheduler scheduler)
        {
            this.Descriptor = descriptor;
            this.Host = host;
            this.Scheduler = scheduler;

            _packageManagerCreator = packageManagerCreator;
            _destination = destination;
            _preferences = this.Host.GetExtensionSpecificPreferences(this.Descriptor.PreferencesStore);
            _selectedPrereleaseFilter = LoadPrereleaseFilter();
            _includePrerelease = (_selectedPrereleaseFilter == Resources.Prerelease_Filter_IncludePrerelease);
            PackagesToDisplayForUpdateAll = new List<PackageViewModel>();

            this.ShowDetailsPageCommand = new RelayCommand(this.ShowDetailsPage, this.CanShowDetailsPage);
            this.ShowLicensePageCommand = new RelayCommand(this.ShowLicensePage, this.CanShowLicensePage);
            this.ShowUninstallPageCommand = new RelayCommand(this.ShowUninstallPage, this.CanShowUninstallPage);

            this.ShowListCommand = new RelayCommand(this.ShowList, this.CanShowList);

            this.InstallCommand = new RelayCommand(this.Install, this.CanInstall);
            this.UpdateCommand = new RelayCommand(this.Update, this.CanUpdate);
            this.UninstallCommand = new RelayCommand(this.Uninstall, this.CanUninstall);

            this.UpdateAllCommand = new RelayCommand(this.UpdateAll, this.CanUpdateAll);
            this.ShowLicensePageForAllCommand = new RelayCommand(this.ShowLicensePageForAll, this.CanShowLicensePageForAll);

            this.DisableCommand = new RelayCommand(this.Disable, this.CanDisable);
            this.EnableCommand = new RelayCommand(this.Enable, this.CanEnable);

            this.DefaultActionCommand = new RelayCommand(this.DefaultAction, this.CanDefaultAction);

            // Initialize the Package Sources
            InitializePackageSources(packageSourcesViewModel);
        }
예제 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:NuGetModel"/> class.
        /// <remarks>This is internal for tests. Callers inside of the NuGet module should used NuGetDataCache::GetModel to 
        /// take advantage of cachein</remarks>
        /// </summary>
        internal NuGetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost host, FeedSource remoteSource, string destination, INuGetPackageManager packageManager, TaskScheduler scheduler)
        {
            Debug.Assert(host != null, "webMatrixHost must not be null");
            Debug.Assert(remoteSource != null, "remoteSource must not be null");
            Debug.Assert(remoteSource.SourceUrl != null, "remoteSource.SourceUrl must not be null");

            this.Descriptor = descriptor;
            this.Scheduler = scheduler;

            FeedSource = remoteSource;
            _webMatrixHost = host;
            _packageKind = descriptor.PackageKind;
            _galleryId = descriptor.GalleryId;

            this.PackageManager = packageManager;

            this.FilterManager = new FilterManager(this, this.Scheduler, descriptor);
        }
예제 #12
0
 public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, bool includePrerelease = false)
 {
     return GetModel(descriptor, webMatrixHost, remoteSource, null, null, TaskScheduler.Default);
 }
예제 #13
0
 public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, bool includePrerelease = false)
 {
     return(GetModel(descriptor, webMatrixHost, remoteSource, null, null, TaskScheduler.Default));
 }