/// <summary>
        /// Loads the list of favourite local git repositories from a persistent storage.
        /// </summary>
        /// <returns>The list of favourite local git repositories.</returns>
        public async Task <IList <Repository> > LoadFavouriteHistoryAsync()
        {
            await TaskScheduler.Default;

            var history = _repositoryStorage.Load(KeyFavouriteHistory) ?? Array.Empty <Repository>();

            // backwards compatibility - port the existing user's categorised repositories
            var(migrated, changed) = await _repositoryHistoryMigrator.MigrateAsync(history);

            if (changed)
            {
                _repositoryStorage.Save(KeyFavouriteHistory, migrated);
            }

            return(migrated ?? new List <Repository>());
        }
        /// <summary>
        /// Loads the history of local git repositories from a persistent storage.
        /// </summary>
        /// <returns>The history of local git repositories.</returns>
        public async Task <IList <Repository> > LoadHistoryAsync()
        {
            await TaskScheduler.Default;

            int size = AppSettings.RecentRepositoriesHistorySize;

            var history = _repositoryStorage.Load(KeyRecentHistory);

            if (history == null)
            {
                return(Array.Empty <Repository>());
            }

            return(AdjustHistorySize(history, size).ToList());
        }
        /// <summary>
        /// Loads the list of recently used remote git repositories from a persistent storage.
        /// </summary>
        /// <returns>The list of recently used remote git repositories.</returns>
        public async Task <IList <Repository> > LoadRecentHistoryAsync()
        {
            await TaskScheduler.Default;

            // BUG: this must be a separate settings
            // TODO: to be addressed separately
            int size    = AppSettings.RecentRepositoriesHistorySize;
            var history = _repositoryStorage.Load(KeyRemoteHistory);

            if (history == null)
            {
                return(Array.Empty <Repository>());
            }

            return(AdjustHistorySize(history, size).ToList());
        }
Example #4
0
        public async Task MigrateSettings_should_migrate_old_categorised_settings()
        {
            var xml = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.CategorisedRepositories02.xml");

            if (string.IsNullOrWhiteSpace(xml))
            {
                throw new FileFormatException("Unexpected data");
            }

            _repositoryStorage.Load().Returns(x => new RepositoryCategoryXmlSerialiser().Deserialize(xml));

            var(currentHistory, migrated) = await _historyMigrator.MigrateAsync(new List <Current.Repository>());

            currentHistory.Count.Should().Be(8);
            currentHistory.Count(r => r.Category == "Git Extensions").Should().Be(1);
            currentHistory.Count(r => r.Category == "3rd Party").Should().Be(2);
            currentHistory.Count(r => r.Category == "Tests").Should().Be(5);

            migrated.Should().BeTrue();
        }
Example #5
0
        public async Task AddAsMostRecentAsync_should_add_new_path_as_top_entry()
        {
            const string repoToAdd = "https://path.to/add";
            var          history   = new List <Repository>
            {
                new Repository("http://path1/"),
                new Repository("http://path3/"),
                new Repository("http://path4/"),
                new Repository("http://path5/"),
            };

            _repositoryStorage.Load(Key).Returns(x => history);

            var newHistory = await _manager.AddAsMostRecentAsync(repoToAdd);

            newHistory.Count.Should().Be(5);
            newHistory[0].Path.Should().Be(repoToAdd);
        }
        /// <summary>
        /// Migrates settings from the old legacy format into the new structure.
        /// </summary>
        /// <param name="currentHistory">The current list of favourite local git repositories.</param>
        /// <returns>
        /// The list of favourite local git repositories enriched with the legacy categorised git repositories.
        /// <c>changed</c> is <see langword="true"/>, if the migration has taken place; otherwise <see langword="false"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="currentHistory"/> is <see langword="null"/>.</exception>
        public async Task <(IList <Current.Repository> history, bool changed)> MigrateAsync(IEnumerable <Current.Repository> currentHistory)
        {
            if (currentHistory is null)
            {
                throw new ArgumentNullException(nameof(currentHistory));
            }

            var history = currentHistory.ToList();

            await TaskScheduler.Default;
            var categorised = _repositoryStorage.Load();

            if (categorised.Count < 1)
            {
                return(history, false);
            }

            var changed = MigrateSettings(history, categorised);

            // settings have been migrated, clear the old setting
            _repositoryStorage.Save();

            return(history, changed);
        }