private void DeleteFeedSource(FeedSource feedSource)
 {
     if (this.FeedSources.Contains(feedSource))
     {
         this.FeedSources.Remove(feedSource);
     }
 }
Exemplo 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);
        }
Exemplo n.º 3
0
 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;
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 7
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));
     }
 }
Exemplo n.º 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());
        }
Exemplo n.º 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()));
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 13
0
        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;
        }
Exemplo n.º 14
0
 internal static PackageSource ToNuGetPackageSource(this FeedSource feedSource)
 {
     return(new PackageSource(feedSource.SourceUrl.AbsoluteUri, feedSource.Name));
 }
Exemplo n.º 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);
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 18
0
 public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, bool includePrerelease = false)
 {
     return GetModel(descriptor, webMatrixHost, remoteSource, null, null, TaskScheduler.Default);
 }
Exemplo n.º 19
0
 public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, bool includePrerelease = false)
 {
     return(GetModel(descriptor, webMatrixHost, remoteSource, null, null, TaskScheduler.Default));
 }
Exemplo n.º 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;
 }
Exemplo n.º 22
0
 public PackageSourcesModel(FeedSource feedSource, IFeedSourceStore feedSourceStore)
 {
     _feedSource = feedSource;
     _feedSourceStore = feedSourceStore;
 }