private void DeleteFeedSource(FeedSource feedSource)
 {
     if (this.FeedSources.Contains(feedSource))
     {
         this.FeedSources.Remove(feedSource);
     }
 }
Beispiel #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);
        }
 private void DeleteFeedSource(FeedSource feedSource)
 {
     if (this.FeedSources.Contains(feedSource))
     {
         this.FeedSources.Remove(feedSource);
     }
 }
        private void AddNewSource(object ignore)
        {
            FeedSource newSource = new FeedSource(new Uri(this.NewSourceUrl), this.NewSourceName);

            this.FeedSources.Add(newSource);

            this.NewSourceName = string.Empty;
            this.NewSourceUrl  = string.Empty;
        }
        public override bool Equals(object obj)
        {
            FeedSource fs = obj as FeedSource;

            if (fs == null)
            {
                return(false);
            }
            else
            {
                return(this.Name == fs.Name &&
                       this.SourceUrl == fs.SourceUrl &&
                       this.FilterTag == fs.FilterTag);
            }
        }
Beispiel #6
0
 private static bool Equals(FeedSource a, FeedSource b)
 {
     if (object.ReferenceEquals(a, b))
     {
         // If both are null, or both are same instance, return true.
         return true;
     }
     else if (object.ReferenceEquals(a, null) ^ object.ReferenceEquals(b, null))
     {
         // If one is null, but not both, return false.
         return false;
     }
     else
     {
         return a.Equals(b);
     }
 }
 private static bool Equals(FeedSource a, FeedSource b)
 {
     if (object.ReferenceEquals(a, b))
     {
         // If both are null, or both are same instance, return true.
         return(true);
     }
     else if (object.ReferenceEquals(a, null) ^ object.ReferenceEquals(b, null))
     {
         // If one is null, but not both, return false.
         return(false);
     }
     else
     {
         return(a.Equals(b));
     }
 }
Beispiel #8
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());
        }
Beispiel #9
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()));
        }
Beispiel #10
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;
        }
Beispiel #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);
        }
Beispiel #12
0
        private void OnSelectedFeedSourceChanged(FeedSource value)
        {
            try
            {
                // hide the details pane, the user selected a different feed
                this.IsDetailsPaneVisible = false;

                BeginUpdateModel(value, _includePrerelease);

                // this will save the change to the preferences store
                this.PackageSourcesViewModel.ActiveFeedSource = value;
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
            finally
            {
                OnPropertyChanged("SelectedFeedSource");
                OnPropertyChanged("SelectedFeedSourceItem");
            }
        }
        private void AddNewSource(object ignore)
        {
            FeedSource newSource = new FeedSource(new Uri(this.NewSourceUrl), this.NewSourceName);
            this.FeedSources.Add(newSource);

            this.NewSourceName = string.Empty;
            this.NewSourceUrl = string.Empty;
        }
Beispiel #14
0
 internal static PackageSource ToNuGetPackageSource(this FeedSource feedSource)
 {
     return(new PackageSource(feedSource.SourceUrl.AbsoluteUri, feedSource.Name));
 }
Beispiel #15
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);
        }
Beispiel #16
0
        private void OnSelectedFeedSourceChanged(FeedSource value)
        {
            try
            {
                // hide the details pane, the user selected a different feed
                this.IsDetailsPaneVisible = false;

                BeginUpdateModel(value, _includePrerelease);

                // this will save the change to the preferences store
                this.PackageSourcesViewModel.ActiveFeedSource = value;
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
            finally
            {
                OnPropertyChanged("SelectedFeedSource");
                OnPropertyChanged("SelectedFeedSourceItem");
            }
        }
Beispiel #17
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);
        }
Beispiel #18
0
 public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, bool includePrerelease = false)
 {
     return GetModel(descriptor, webMatrixHost, remoteSource, null, null, TaskScheduler.Default);
 }
Beispiel #19
0
 public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, bool includePrerelease = false)
 {
     return(GetModel(descriptor, webMatrixHost, remoteSource, null, null, TaskScheduler.Default));
 }
Beispiel #20
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);
        }
 public PackageSourcesModel(FeedSource feedSource, IFeedSourceStore feedSourceStore)
 {
     _feedSource      = feedSource;
     _feedSourceStore = feedSourceStore;
 }
Beispiel #22
0
 public PackageSourcesModel(FeedSource feedSource, IFeedSourceStore feedSourceStore)
 {
     _feedSource = feedSource;
     _feedSourceStore = feedSourceStore;
 }