Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PackageViewModel"/> class.
 /// </summary>
 public PackageViewModel(
     NuGetModel model,
     IPackage package,
     PackageViewModelAction packageAction)
     : this(model, package, false, packageAction)
 {
 }
Ejemplo n.º 2
0
        private void BeginUpdateModel(FeedSource source, bool includePrerelease)
        {
            if (source == null)
            {
                Debug.Fail("We should always have a feed source selected");
                return;
            }

            // Set the loading message and set Loading to true
            Loading        = true;
            LoadingMessage = this.Descriptor.LoadingMessage;

            _nuGetModel = NuGetModel.GetModel(
                this.Descriptor,
                this.Host,
                source,
                _destination ?? this.Host.WebSite.Path,
                _packageManagerCreator,
                this.Scheduler,
                includePrerelease);

            this.Filters = _nuGetModel.FilterManager.Filters;

            // we're using attached to parent here to prevent a race condition in tests for install/uninstall/update actions
            // we don't want the task set by 'EndInstall' to complete until after we've reloaded
            var updateModelTask = Task.Factory.StartNew(() => _nuGetModel.FilterManager.UpdateFilters(), CancellationToken.None, TaskCreationOptions.AttachedToParent, TaskScheduler.Default);

            _primaryTask = updateModelTask.ContinueWith(EndUpdateModel, CancellationToken.None, TaskContinuationOptions.AttachedToParent, this.Scheduler);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PackageViewModel"/> class.
 /// </summary>
 public PackageViewModel(
     NuGetModel model,
     IPackage package,
     PackageViewModelAction packageAction)
     : this(model, package, false, packageAction)
 {
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:PackageViewModel"/> class for an installed package
        /// </summary>
        public PackageViewModel(
            NuGetModel model,
            IPackage package,
            bool shouldPullRemotePackage,
            PackageViewModelAction packageAction)
        {
            Debug.Assert(package != null, "package parameter should not be null");

            this.Model = model;
            _package = package;
            _shouldPullRemotePackage = shouldPullRemotePackage;
            this.PackageAction = packageAction;

            this.LaunchUrlCommand = new RelayCommand(url => this.OpenUrl(url as Uri));

            SetName();
            SetSearchtext();
            _authors = new Lazy<string>(GetAuthors);
            SetDependencies();
            SetIconSource();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:PackageViewModel"/> class for an installed package
        /// </summary>
        public PackageViewModel(
            NuGetModel model,
            IPackage package,
            bool shouldPullRemotePackage,
            PackageViewModelAction packageAction)
        {
            Debug.Assert(package != null, "package parameter should not be null");

            this.Model = model;
            _package   = package;
            _shouldPullRemotePackage = shouldPullRemotePackage;
            this.PackageAction       = packageAction;

            this.LaunchUrlCommand = new RelayCommand(url => this.OpenUrl(url as Uri));

            SetName();
            SetSearchtext();
            _authors = new Lazy <string>(GetAuthors);
            SetDependencies();
            SetIconSource();
        }
Ejemplo n.º 10
0
 private void Host_WebSiteChanged(object sender, EventArgs e)
 {
     NuGetModel.ClearCache();
 }
Ejemplo n.º 11
0
        private void BeginUpdateModel(FeedSource source, bool includePrerelease)
        {
            if (source == null)
            {
                Debug.Fail("We should always have a feed source selected");
                return;
            }

            // Set the loading message and set Loading to true
            Loading = true;
            LoadingMessage = this.Descriptor.LoadingMessage;

            _nuGetModel = NuGetModel.GetModel(
                this.Descriptor, 
                this.Host, 
                source, 
                _destination ?? this.Host.WebSite.Path, 
                _packageManagerCreator,
                this.Scheduler,
                includePrerelease);

            this.Filters = _nuGetModel.FilterManager.Filters;

            // we're using attached to parent here to prevent a race condition in tests for install/uninstall/update actions
            // we don't want the task set by 'EndInstall' to complete until after we've reloaded
            var updateModelTask = Task.Factory.StartNew(() => _nuGetModel.FilterManager.UpdateFilters(), CancellationToken.None, TaskCreationOptions.AttachedToParent, TaskScheduler.Default);
            _primaryTask = updateModelTask.ContinueWith(EndUpdateModel, CancellationToken.None, TaskContinuationOptions.AttachedToParent, this.Scheduler);
        }