public RemoteSourceViewModel(
            IChocolateyService chocolateyPackageService,
            IProgressService progressService,
            IConfigService configService,
            IEventAggregator eventAggregator,
            ChocolateySource source,
            IMapper mapper)
        {
            Source = source;
            _chocolateyPackageService = chocolateyPackageService;
            _progressService          = progressService;
            _configService            = configService;
            _eventAggregator          = eventAggregator;
            _mapper = mapper;

            ListViewMode = _configService.GetSettings().DefaultToTileViewForLocalSource ? ListViewMode.Tile : ListViewMode.Standard;

            Packages    = new ObservableCollection <IPackageViewModel>();
            DisplayName = source.Id;

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

            _eventAggregator.Subscribe(this);
        }
Example #2
0
        public RemoteSourceViewModel(
            IChocolateyService chocolateyPackageService,
            IDialogService dialogService,
            IProgressService progressService,
            IChocolateyGuiCacheService chocolateyGuiCacheService,
            IConfigService configService,
            IEventAggregator eventAggregator,
            ChocolateySource source,
            IMapper mapper)
        {
            Source = source;
            _chocolateyPackageService  = chocolateyPackageService;
            _dialogService             = dialogService;
            _progressService           = progressService;
            _chocolateyGuiCacheService = chocolateyGuiCacheService;
            _configService             = configService;
            _eventAggregator           = eventAggregator;
            _mapper = mapper;

            Packages    = new ObservableCollection <IPackageViewModel>();
            DisplayName = source.Id;

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

            _eventAggregator.Subscribe(this);
        }
Example #3
0
        private void InitializeTestDscResources()
        {
            chocolateySourceResource = new ChocolateySource
            {
                Ensure             = Ensure.Present,
                ResourceStepName   = "chocoSource",
                ChocoPackageSource = "https://chocolateySource"
            };

            dockerChocolateyResource = new ChocolateyPackage
            {
                ChocolateyPackageName = "docker-for-windows",
                ResourceStepName      = "dockerStep",
                DependsOn             = new List <DscResource> {
                    chocolateySourceResource
                },
                Ensure = Ensure.Present
            };

            visualStudioChocolateyResource = new ChocolateyPackage
            {
                ChocolateyPackageName = "visualstudio",
                Ensure    = Ensure.Present,
                DependsOn = new List <DscResource> {
                    dockerChocolateyResource
                },
                ResourceStepName = "visualStudioStep"
            };
        }
Example #4
0
        public void SourceSelectionChanged(object source)
        {
            var sourceItem = (ChocolateySource)source;

            SelectedSource = sourceItem;
            return;
        }
Example #5
0
        public ChocolateyFeed(ChocolateyFeedClient feedClient, ChocolateySource source, IInstalledPackagesManager installedPackages)
        {
            this._feedClient        = feedClient;
            this._installedPackages = installedPackages;
            this.Source             = source;

            this._packageCache = new List <ChocolateyPackage>();
        }
        private string CreateAddSourceCommand(ChocolateySource source)
        {
            const string addSourceCommandTemplate = @"choco sources add -name '{0}' -source '{1}'";

            var addSourceCommand = string.Format(addSourceCommandTemplate, source.Name, source.Location);

            return(addSourceCommand);
        }
Example #7
0
        public void RemoveSource(ChocolateySource source)
        {
            var config = XDocument.Load(ConfigurationLocation);

            config.Descendants("source").Where(e => e.Attribute("id").Value == source.Name).Remove();

            config.Save(ConfigurationLocation);
        }
Example #8
0
 private void GivenModelFilledWithValuesWithoutDependencies()
 {
     testChocolateySource = new ChocolateySource
     {
         ChocoPackageSource = "https://test123",
         Ensure             = Ensure.Present,
         ResourceStepName   = "dockerStep"
     };
 }
Example #9
0
 private void GivenModelFilledWithValues()
 {
     testChocolateySource = new ChocolateySource
     {
         ChocoPackageSource = "https://test123",
         Ensure             = Ensure.Present,
         ResourceStepName   = "dockerStep",
         DependsOn          = new List <DscResource> {
             testDependency
         }
     };
 }
Example #10
0
        public void AddSource(ChocolateySource source)
        {
            this.RemoveSource(source);

            var config = XDocument.Load(ConfigurationLocation);

            var newElement = new XElement("source", new XAttribute("id", source.Name), new XAttribute("value", source.Location.AbsoluteUri));

            config.Descendants("sources").FirstOrDefault().Add(newElement);

            config.Save(ConfigurationLocation);
        }
Example #11
0
        public void PopulateSources()
        {
            var sources = this._sourcesManager.GetSources();

            this.Sources = new ObservableCollection <ChocolateySource>(sources);

            this.RaisePropertyChanged(() => this.Sources);

            if (this.Sources.Any())
            {
                this.SelectedChocolateySource = this.Sources.First();
            }
        }
Example #12
0
        private void RemoveSource(ChocolateySource source)
        {
            if (this.SelectedChocolateySource == source)
            {
                if (this.SelectedSourceChanged != null)
                {
                    this.SelectedSourceChanged(null);
                }
            }

            this._sourcesManager.RemoveSource(source);

            this.Sources = new ObservableCollection <ChocolateySource>(this.Sources.Where(s => s.Name != source.Name));
            this.RaisePropertyChanged(() => this.Sources);
        }
        public RemoteSourceViewModel(
            IChocolateyService chocolateyPackageService,
            IDialogService dialogService,
            IProgressService progressService,
            IChocolateyGuiCacheService chocolateyGuiCacheService,
            IConfigService configService,
            IEventAggregator eventAggregator,
            ChocolateySource source,
            IMapper mapper,
            TranslationSource translator)
            : base(translator)
        {
            Source = source;
            _chocolateyPackageService  = chocolateyPackageService;
            _dialogService             = dialogService;
            _progressService           = progressService;
            _chocolateyGuiCacheService = chocolateyGuiCacheService;
            _configService             = configService;
            _eventAggregator           = eventAggregator;
            _mapper = mapper;

            Packages = new ObservableCollection <IPackageViewModel>();

            if (source.Id[0] == '[' && source.Id[source.Id.Length - 1] == ']')
            {
                _resourceId = source.Id.Trim('[', ']');
                DisplayName = translator[_resourceId];
                translator.PropertyChanged += (sender, e) =>
                {
                    DisplayName = translator[_resourceId];
                };
            }
            else
            {
                DisplayName = source.Id;
            }

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

            _eventAggregator.Subscribe(this);

            AddSortOptions();

            SortSelection = L(nameof(Resources.RemoteSourceViewModel_SortSelectionPopularity));
        }
Example #14
0
        private void AddSource()
        {
            var newSource = new ChocolateySource
            {
                Name     = this.NewSourceId,
                Location = this.NewSourceLocation
            };

            this.RemoveSource(newSource);

            this._sourcesManager.AddSource(newSource);

            this.Sources.Add(newSource);

            this.NewSourceId       = string.Empty;
            this.NewSourceLocation = null;
        }
Example #15
0
        private async Task HandleSelectedSourceChanged(ChocolateySource source)
        {
            this.Packages.Clear();
            this.HasSearchResults = false;
            this.SearchTerm       = string.Empty;

            this._feed = null;

            if (source != null)
            {
                this._feed = this._feedFactory.Create(source);
                await this.LoadPackages();
            }

            this.LoadMorePackagesCommand.RaiseCanExecuteChanged();
            this.SearchPackagesCommand.RaiseCanExecuteChanged();
            this.RaisePropertyChanged(() => this.CanSearchPackages);
        }
Example #16
0
        public IChocolateyFeed Create(ChocolateySource source)
        {
            if (this._feedCache.ContainsKey(source))
            {
                return(this._feedCache[source]);
            }

            var client = new ChocolateyFeedClient(source.Location)
            {
                IgnoreMissingProperties = true,
                MergeOption             = MergeOption.NoTracking
            };

            var feed = new ChocolateyFeed(client, source, this._installedPackages);

            this._feedCache.Add(source, feed);

            return(feed);
        }
Example #17
0
        private void GivenMergeResultAndModelWithSameSourceButDifferentEnsure()
        {
            mergeResultGiven = new MergeResult <DscResource>
            {
                Value = new ChocolateySource
                {
                    ResourceStepName   = "TestStep",
                    ChocoPackageSource = "Test.ch",
                    Ensure             = Ensure.Present
                }
            };

            modelGivenForMerge = new ChocolateySource
            {
                ResourceStepName   = "Step2",
                ChocoPackageSource = "Test.ch",
                Ensure             = Ensure.Absent
            };
        }
Example #18
0
        public async void Remove()
        {
            await _progressService.StartLoading(Resources.SettingsViewModel_RemovingSource);

            try
            {
                await _packageService.RemoveSource(_originalId);

                Sources.Remove(SelectedSource);
                SelectedSource = null;
                await _eventAggregator.PublishOnUIThreadAsync(new SourcesUpdatedMessage());
            }
            catch (UnauthorizedAccessException)
            {
                await _progressService.ShowMessageAsync(
                    Resources.General_UnauthorisedException_Title,
                    Resources.General_UnauthorisedException_Description);
            }
            finally
            {
                await _progressService.StopLoading();
            }
        }
Example #19
0
 public void New()
 {
     SelectedSource = new ChocolateySource();
 }
Example #20
0
 public void Cancel()
 {
     SelectedSource = null;
 }