/// <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>());
        }
예제 #2
0
        /// <summary>
        /// Loads the history of remote git repositories to a persistent storage.
        /// </summary>
        /// <param name="repositoryHistory">A collection of remote git repositories.</param>
        /// <returns>An awaitable task.</returns>
        /// <remarks>The size of the history will be adjusted as per <see cref="AppSettings.RecentRepositoriesHistorySize"/> setting.</remarks>
        public async Task SaveHistoryAsync(IEnumerable <Repository> repositoryHistory)
        {
            await TaskScheduler.Default;

            // BUG: this must be a separate settings
            // TODO: to be addressed separately
            _repositoryStorage.Save(KeyRemoteHistory, AdjustHistorySize(repositoryHistory, AppSettings.RecentRepositoriesHistorySize));
        }
        public async Task SaveRecentHistoryAsync(IEnumerable <Repository> repositoryHistory)
        {
            if (repositoryHistory == null)
            {
                throw new ArgumentNullException(nameof(repositoryHistory));
            }

            await TaskScheduler.Default;

            // BUG: this must be a separate settings
            // TODO: to be addressed separately
            _repositoryStorage.Save(KeyRemoteHistory, AdjustHistorySize(repositoryHistory, AppSettings.RecentRepositoriesHistorySize));
        }
        /// <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);
        }
        /// <summary>
        /// Loads the history of local git repositories to a persistent storage.
        /// </summary>
        /// <param name="repositoryHistory">A collection of local git repositories.</param>
        /// <returns>An awaitable task.</returns>
        /// <remarks>The size of the history will be adjusted as per <see cref="AppSettings.RecentRepositoriesHistorySize"/> setting.</remarks>
        public async Task SaveHistoryAsync(IEnumerable <Repository> repositoryHistory)
        {
            await TaskScheduler.Default;

            _repositoryStorage.Save(KeyRecentHistory, AdjustHistorySize(repositoryHistory, AppSettings.RecentRepositoriesHistorySize));
        }