示例#1
0
 public Endpoint(Configuration.ISettings configurationSettings, Common.Connection.IFactory connectionFactory, Common.Routing.IKey routingKey, Common.Queue.IName queueName)
 {
     _configurationSettings = configurationSettings;
     _connectionFactory = connectionFactory;
     _routingKey = routingKey;
     _queueName = queueName;
 }
        public void Setup()
        {
            _sparkCoreSettings = A.Fake<Configuration.ISparkCore>();
            A.CallTo(() => _sparkCoreSettings.AccessToken).Returns("0123456789abcdef123456");
            A.CallTo(() => _sparkCoreSettings.DefaultIndexName).Returns("CoreIndex");
            A.CallTo(() => _sparkCoreSettings.DefaultInterval).Returns(TimeSpan.FromSeconds(100));
            A.CallTo(() => _sparkCoreSettings.DefaultType).Returns("CoreType");
            A.CallTo(() => _sparkCoreSettings.Devices).Returns(new[] { _deviceA, _deviceB });

            _elasticSearchSettings = A.Fake<Configuration.IElasticSearch>();
            A.CallTo(() => _elasticSearchSettings.Host).Returns("http://localhost:9220");
            A.CallTo(() => _elasticSearchSettings.Indexes).Returns(new[] { _tempIndex, _humidityIndex, _lightIndex });

            _settings = A.Fake<Configuration.ISettings>();
            A.CallTo(() => _settings.SparkCore).Returns(_sparkCoreSettings);
            A.CallTo(() => _settings.ElasticSearch).Returns(_elasticSearchSettings);

            _sparkApi = A.Fake<Io.Spark.IApi>();
            _documentFactory = A.Fake<Document.IFactory>();
            _schedulerProvider = A.Fake<ISchedulerProvider>();
            _testScheduler = new TestScheduler();
            A.CallTo(() => _schedulerProvider.AsyncScheduler).Returns(_testScheduler);

            _subject = new SparkSource(_settings, _sparkApi, _documentFactory, _schedulerProvider);
        }
示例#3
0
        public Connector(Configuration.ISettings configurationSettings, Event.IProvider eventProvider, Messaging.Component.IEndpoint endpoint)
        {
            _configurationSettings = configurationSettings;
            _eventProvider = eventProvider;
            _endpoint = endpoint;

            _messages = new Subject<Message.IMessage>();
        }
示例#4
0
        public QueryEndpoint(Configuration.IProvider configurationProvider)
        {
            _settings = configurationProvider.GetSettings();
            _instructionNumber = new InstructionNumber();

            _ipAddress = string.IsNullOrWhiteSpace(_settings.LocalIpAddress)
              ? Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork)
              : IPAddress.Parse(_settings.LocalIpAddress);
        }
        public void Setup()
        {
            _elasticSearchSettings = A.Fake<Configuration.IElasticSearch>();
            A.CallTo(() => _elasticSearchSettings.Host).Returns("http://localhost:9220");
            A.CallTo(() => _elasticSearchSettings.Indexes).Returns(new[] { _tempIndex, _humidityIndex, _lightIndex });

            _settings = A.Fake<Configuration.ISettings>();
            A.CallTo(() => _settings.SparkCore).Returns(A.Fake<Configuration.ISparkCore>());
            A.CallTo(() => _settings.ElasticSearch).Returns(_elasticSearchSettings);

            _clock = A.Fake<IClock>();
            A.CallTo(() => _clock.UtcNow).Returns(DateTime.UtcNow);
        }
示例#6
0
 public Instance(Configuration.ISettings configurationSettings, Common.IConnectionFactory connectionFactory, With.Message.ISerializer messageSerializer)
 {
     _configurationSettings = configurationSettings;
     _connectionFactory = connectionFactory;
     _messageSerializer = messageSerializer;
 }
示例#7
0
        protected IReadOnlyCollection <Configuration.PackageSource> GetPackageSources(Configuration.ISettings settings)
        {
            var availableSources = SourceProvider.LoadPackageSources().Where(source => source.IsEnabled);
            var packageSources   = new List <Configuration.PackageSource>();

            if (!NoCache && !ExcludeCacheAsSource)
            {
                // Add the v3 global packages folder
                var globalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(settings);

                if (!string.IsNullOrEmpty(globalPackageFolder) && Directory.Exists(globalPackageFolder))
                {
                    packageSources.Add(new FeedTypePackageSource(globalPackageFolder, FeedType.FileSystemV3));
                }
            }

            foreach (var source in Source)
            {
                packageSources.Add(Common.PackageSourceProviderExtensions.ResolveSource(availableSources, source));
            }

            if (Source.Count == 0)
            {
                packageSources.AddRange(availableSources);
            }

            foreach (var source in FallbackSource)
            {
                packageSources.Add(Common.PackageSourceProviderExtensions.ResolveSource(packageSources, source));
            }

            return(packageSources);
        }
示例#8
0
 internal static Configuration.PackageSourceProvider CreateSourceProvider(Configuration.ISettings settings)
 {
     return(new Configuration.PackageSourceProvider(settings));
 }
示例#9
0
 public BaseController()
 {
     this.Settings = DiContainer.container.Resolve <ISettings>();
 }
        /// <summary>
        /// Get the view of installed packages. Use for Get-Package command.
        /// </summary>
        internal static List <PowerShellInstalledPackage> GetPowerShellPackageView(
            Dictionary <NuGetProject, IEnumerable <PackageReference> > dictionary,
            ISolutionManager SolutionManager,
            Configuration.ISettings settings)
        {
            var views = new List <PowerShellInstalledPackage>();

            foreach (var entry in dictionary)
            {
                var nugetProject = entry.Key;
                var projectName  = entry.Key.GetMetadata <string>(NuGetProjectMetadataKeys.Name);

                FolderNuGetProject          packageFolderProject = null;
                FallbackPackagePathResolver fallbackResolver     = null;

                // Build a project-specific strategy for resolving a package .nupkg path.
                if (nugetProject is INuGetIntegratedProject) // This is technically incorrect for DNX projects,
                                                             // however since that experience is deprecated we don't
                                                             // care.
                {
                    var pathContext = NuGetPathContext.Create(settings);
                    fallbackResolver = new FallbackPackagePathResolver(pathContext);
                }
                else
                {
                    var project = nugetProject as MSBuildNuGetProject;

                    if (project != null)
                    {
                        packageFolderProject = project.FolderNuGetProject;
                    }
                }

                // entry.Value is an empty list if no packages are installed.
                foreach (var package in entry.Value)
                {
                    string installPackagePath = null;
                    string licenseUrl         = null;

                    // Try to get the path to the package .nupkg on disk.
                    if (fallbackResolver != null)
                    {
                        var packageInfo = fallbackResolver.GetPackageInfo(
                            package.PackageIdentity.Id,
                            package.PackageIdentity.Version);

                        installPackagePath = packageInfo?.PathResolver.GetPackageFilePath(
                            package.PackageIdentity.Id,
                            package.PackageIdentity.Version);
                    }
                    else if (packageFolderProject != null)
                    {
                        installPackagePath = packageFolderProject.GetInstalledPackageFilePath(package.PackageIdentity);
                    }

                    // Try to read out the license URL.
                    using (var reader = GetPackageReader(installPackagePath))
                        using (var nuspecStream = reader?.GetNuspec())
                        {
                            if (nuspecStream != null)
                            {
                                var nuspecReader = new NuspecReader(nuspecStream);
                                licenseUrl = nuspecReader.GetLicenseUrl();
                            }
                        }

                    var view = new PowerShellInstalledPackage
                    {
                        Id = package.PackageIdentity.Id,
                        AsyncLazyVersions = new AsyncLazy <IEnumerable <NuGetVersion> >(
                            () => Task.FromResult <IEnumerable <NuGetVersion> >(new[] { package.PackageIdentity.Version }),
                            NuGetUIThreadHelper.JoinableTaskFactory),
                        ProjectName = projectName,
                        LicenseUrl  = licenseUrl
                    };

                    views.Add(view);
                }
            }

            return(views);
        }
示例#11
0
 public Instance(Configuration.ISettings configurationSettings, Common.IConnectionFactory connectionFactory, With.Message.ISerializer messageSerializer)
 {
     _configurationSettings = configurationSettings;
     _connectionFactory     = connectionFactory;
     _messageSerializer     = messageSerializer;
 }
示例#12
0
 public Factory(Configuration.ISettings settings)
 {
     _settings = settings;
 }
        /// <summary>
        /// Returns the <see cref="DownloadResourceResult"/> for a given <paramref name="packageIdentity" />
        /// from the given <paramref name="sources" />.
        /// </summary>
        public static async Task <DownloadResourceResult> GetDownloadResourceResultAsync(IEnumerable <SourceRepository> sources,
                                                                                         PackageIdentity packageIdentity,
                                                                                         Configuration.ISettings settings,
                                                                                         Common.ILogger logger,
                                                                                         CancellationToken token)
        {
            if (sources == null)
            {
                throw new ArgumentNullException(nameof(sources));
            }

            if (packageIdentity == null)
            {
                throw new ArgumentNullException(nameof(packageIdentity));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var failedTasks = new List <Task <DownloadResourceResult> >();
            var tasksLookup = new Dictionary <Task <DownloadResourceResult>, SourceRepository>();

            var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);

            try
            {
                // Create a group of local sources that will go first, then everything else.
                var groups     = new Queue <List <SourceRepository> >();
                var localGroup = new List <SourceRepository>();
                var otherGroup = new List <SourceRepository>();

                foreach (var source in sources)
                {
                    if (source.PackageSource.IsLocal)
                    {
                        localGroup.Add(source);
                    }
                    else
                    {
                        otherGroup.Add(source);
                    }
                }

                groups.Enqueue(localGroup);
                groups.Enqueue(otherGroup);

                while (groups.Count > 0)
                {
                    token.ThrowIfCancellationRequested();

                    var sourceGroup = groups.Dequeue();
                    var tasks       = new List <Task <DownloadResourceResult> >();

                    foreach (var source in sourceGroup)
                    {
                        var task = GetDownloadResourceResultAsync(source, packageIdentity, settings, logger, linkedTokenSource.Token);
                        tasksLookup.Add(task, source);
                        tasks.Add(task);
                    }

                    while (tasks.Any())
                    {
                        var completedTask = await Task.WhenAny(tasks);

                        if (completedTask.Status == TaskStatus.RanToCompletion)
                        {
                            tasks.Remove(completedTask);

                            // Cancel the other tasks, since, they may still be running
                            linkedTokenSource.Cancel();

                            if (tasks.Any())
                            {
                                // NOTE: Create a Task out of remainingTasks which waits for all the tasks to complete
                                // and disposes the linked token source safely. One of the tasks could try to access
                                // its incoming CancellationToken to register a callback. If the linkedTokenSource was
                                // disposed before being accessed, it will throw an ObjectDisposedException.
                                // At the same time, we do not want to wait for all the tasks to complete before
                                // before this method returns with a DownloadResourceResult.
                                var remainingTasks = Task.Run(async() =>
                                {
                                    try
                                    {
                                        await Task.WhenAll(tasks);
                                    }
                                    catch
                                    {
                                        // Any exception from one of the remaining tasks is not actionable.
                                        // And, this code is running on the threadpool and the task is not awaited on.
                                        // Catch all and do nothing.
                                    }
                                    finally
                                    {
                                        linkedTokenSource.Dispose();
                                    }
                                });
                            }

                            return(completedTask.Result);
                        }
                        else
                        {
                            token.ThrowIfCancellationRequested();

                            // In this case, completedTask did not run to completion.
                            // That is, it faulted or got canceled. Remove it, and try Task.WhenAny again
                            tasks.Remove(completedTask);
                            failedTasks.Add(completedTask);
                        }
                    }
                }

                // no matches were found
                var errors = new StringBuilder();

                errors.AppendLine(string.Format(CultureInfo.CurrentCulture,
                                                Strings.UnknownPackageSpecificVersion, packageIdentity.Id,
                                                packageIdentity.Version.ToNormalizedString()));

                foreach (var task in failedTasks)
                {
                    var message = ExceptionUtilities.DisplayMessage(task.Exception);

                    errors.AppendLine($"  {tasksLookup[task].PackageSource.Source}: {message}");
                }

                throw new FatalProtocolException(errors.ToString());
            }
            catch
            {
                linkedTokenSource.Dispose();
                throw;
            }
        }
        /// <summary>
        /// Returns the <see cref="DownloadResourceResult"/> for a given <paramref name="packageIdentity" /> from the given
        /// <paramref name="sourceRepository" />.
        /// </summary>
        public static async Task <DownloadResourceResult> GetDownloadResourceResultAsync(SourceRepository sourceRepository,
                                                                                         PackageIdentity packageIdentity,
                                                                                         Configuration.ISettings settings,
                                                                                         Common.ILogger logger,
                                                                                         CancellationToken token)
        {
            if (sourceRepository == null)
            {
                throw new ArgumentNullException(nameof(sourceRepository));
            }

            if (packageIdentity == null)
            {
                throw new ArgumentNullException(nameof(packageIdentity));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var downloadResource = await sourceRepository.GetResourceAsync <DownloadResource>(token);

            if (downloadResource == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.DownloadResourceNotFound, sourceRepository.PackageSource.Source));
            }

            token.ThrowIfCancellationRequested();

            DownloadResourceResult result;

            try
            {
                result = await downloadResource.GetDownloadResourceResultAsync(
                    packageIdentity,
                    settings,
                    logger,
                    token);
            }
            catch (OperationCanceledException)
            {
                result = new DownloadResourceResult(DownloadResourceResultStatus.Cancelled);
            }

            if (result == null)
            {
                throw new FatalProtocolException(string.Format(
                                                     CultureInfo.CurrentCulture,
                                                     Strings.DownloadStreamNotAvailable,
                                                     packageIdentity,
                                                     sourceRepository.PackageSource.Source));
            }

            if (result.Status == DownloadResourceResultStatus.Cancelled)
            {
                throw new RetriableProtocolException(string.Format(
                                                         CultureInfo.CurrentCulture,
                                                         Strings.PackageCancelledFromSource,
                                                         packageIdentity,
                                                         sourceRepository.PackageSource.Source));
            }

            if (result.Status == DownloadResourceResultStatus.NotFound)
            {
                throw new FatalProtocolException(string.Format(
                                                     CultureInfo.CurrentCulture,
                                                     Strings.PackageNotFoundOnSource,
                                                     packageIdentity,
                                                     sourceRepository.PackageSource.Source));
            }

            if (result.PackageReader == null)
            {
                result.PackageStream.Seek(0, SeekOrigin.Begin);
                var packageReader = new PackageArchiveReader(result.PackageStream);
                result.PackageStream.Seek(0, SeekOrigin.Begin);
                result = new DownloadResourceResult(result.PackageStream, packageReader);
            }

            return(result);
        }
示例#15
0
 public Connector(With.Messaging.Client.IEndpoint clientEndpoint, Configuration.ISettings configurationSettings, Gateway.IFactory gatewayFactory)
 {
     _clientEndpoint        = clientEndpoint;
     _configurationSettings = configurationSettings;
     _gatewayFactory        = gatewayFactory;
 }
        public PackageManagerControl(
            PackageManagerModel model,
            Configuration.ISettings nugetSettings,
            IVsWindowSearchHostFactory searchFactory,
            IVsShell4 vsShell,
            INuGetUILogger uiLogger = null)
        {
            _uiDispatcher = Dispatcher.CurrentDispatcher;
            _uiLogger     = uiLogger;
            Model         = model;
            Settings      = nugetSettings;
            if (!Model.IsSolution)
            {
                _detailModel = new PackageDetailControlModel(Model.Context.SolutionManager, Model.Context.Projects);
            }
            else
            {
                _detailModel = new PackageSolutionDetailControlModel(
                    Model.Context.SolutionManager,
                    Model.Context.Projects,
                    Model.Context.PackageManagerProviders);
            }

            InitializeComponent();

            _windowSearchHostFactory = searchFactory;
            if (_windowSearchHostFactory != null)
            {
                _windowSearchHost = _windowSearchHostFactory.CreateWindowSearchHost(
                    _topPanel.SearchControlParent);
                _windowSearchHost.SetupSearch(this);
                _windowSearchHost.IsVisible = true;
            }

            AddRestoreBar();

            AddRestartRequestBar(vsShell);

            _packageDetail.Control    = this;
            _packageDetail.Visibility = Visibility.Hidden;

            SetTitle();

            _topPanel.IsSolution = Model.IsSolution;
            var settings = LoadSettings();

            InitializeFilterList(settings);
            InitSourceRepoList(settings);
            ApplySettings(settings, nugetSettings);
            _initialized = true;

            // UI is initialized. Start the first search
            _packageList.CheckBoxesEnabled = _topPanel.Filter == ItemFilter.UpdatesAvailable;
            _packageList.IsSolution        = this.Model.IsSolution;

            Loaded += (_, __) =>
            {
                SearchPackagesAndRefreshUpdateCount(_windowSearchHost.SearchQuery.SearchString, useCache: false);
                RefreshConsolidatablePackagesCount();
            };

            // register with the UI controller
            var controller = model.UIController as NuGetUI;

            if (controller != null)
            {
                controller.PackageManagerControl = this;
            }

            var solutionManager = Model.Context.SolutionManager;

            solutionManager.NuGetProjectAdded      += SolutionManager_ProjectsChanged;
            solutionManager.NuGetProjectRemoved    += SolutionManager_ProjectsChanged;
            solutionManager.NuGetProjectUpdated    += SolutionManager_ProjectsUpdated;
            solutionManager.NuGetProjectRenamed    += SolutionManager_ProjectRenamed;
            solutionManager.ActionsExecuted        += SolutionManager_ActionsExecuted;
            solutionManager.AfterNuGetCacheUpdated += SolutionManager_CacheUpdated;

            Model.Context.SourceProvider.PackageSourceProvider.PackageSourcesChanged += Sources_PackageSourcesChanged;

            if (IsUILegalDisclaimerSuppressed())
            {
                _legalDisclaimer.Visibility = Visibility.Collapsed;
            }

            _missingPackageStatus = false;
        }
 public PackageRestoreConsent(Configuration.ISettings settings)
     : this(settings, EnvironmentVariableWrapper.Instance)
 {
 }
示例#18
0
 public Factory(Configuration.ISettings settings)
 {
     _settings = settings;
 }
示例#19
0
 public Connector(With.Messaging.Client.IEndpoint clientEndpoint, Configuration.ISettings configurationSettings, Gateway.IFactory gatewayFactory)
 {
     _clientEndpoint = clientEndpoint;
     _configurationSettings = configurationSettings;
     _gatewayFactory = gatewayFactory;
 }
示例#20
0
 public VsPackageRestorer(Configuration.ISettings settings, ISolutionManager solutionManager, IPackageRestoreManager restoreManager)
 {
     _settings        = settings;
     _solutionManager = solutionManager;
     _restoreManager  = restoreManager;
 }
 public PackageRestoreConsent(Configuration.ISettings settings)
     : this(settings, new EnvironmentVariableWrapper())
 {
 }
示例#22
0
 public BaseController(ISettings settings)
 {
     Settings = settings;
 }
 public PackageRestoreConsent(Configuration.ISettings settings, Common.IEnvironmentVariableReader environmentReader)
     : this(settings, environmentReader, ConfigurationDefaults.Instance)
 {
 }
 public ExtensibleSourceRepositoryProvider([ImportMany] IEnumerable <Lazy <INuGetResourceProvider> > resourceProviders, [Import] Configuration.ISettings settings)
     : this(new Configuration.PackageSourceProvider(settings, DefaultPrimarySources, DefaultSecondarySources, migratePackageSources : null), resourceProviders)
 {
 }
 public PackageRestoreConsent(Configuration.ISettings settings, Common.IEnvironmentVariableReader environmentReader, ConfigurationDefaults configurationDefaults)
 {
     _settings              = settings ?? throw new ArgumentNullException(nameof(settings));
     _environmentReader     = environmentReader ?? throw new ArgumentNullException(nameof(environmentReader));
     _configurationDefaults = configurationDefaults ?? throw new ArgumentNullException(nameof(configurationDefaults));
 }
 public PluginCredentialProviderBuilder(IExtensionLocator extensionLocator, Configuration.ISettings settings)
     : this(extensionLocator, settings, new EnvironmentVariableWrapper())
 {
 }
 public VsSourceControlTracker(ISolutionManager solutionManager, ISourceControlManagerProvider sourceControlManagerProvider, Configuration.ISettings vsSettings)
     :
     this(solutionManager, sourceControlManagerProvider, ServiceLocator.GetGlobalService <SVsTrackProjectDocuments, IVsTrackProjectDocuments2>(), vsSettings)
 {
 }