This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Removed IConnection.Repositories
.
#1279
Merged
grokys
merged 4 commits into
refactor/connections-master
from
refactor/connections/local-repositories
Nov 8, 2017
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
470ea13
Removed `IConnection.Repositories`.
grokys 213a7fc
Moved LocalRepositories to GitHub.VisualStudio.
grokys 01aad33
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys 8f6d218
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.ComponentModel.Composition; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using GitHub.Extensions; | ||
using GitHub.Helpers; | ||
using GitHub.Models; | ||
using GitHub.Services; | ||
|
||
namespace GitHub.App.Services | ||
{ | ||
/// <summary> | ||
/// Stores a collection of known local repositories. | ||
/// </summary> | ||
/// <remarks> | ||
/// The list of repositories exposed here is the list of local repositories known to Team | ||
/// Explorer. | ||
/// </remarks> | ||
[Export(typeof(ILocalRepositories))] | ||
public class LocalRepositories : ILocalRepositories | ||
{ | ||
readonly IVSGitServices vsGitServices; | ||
|
||
[ImportingConstructor] | ||
public LocalRepositories(IVSGitServices vsGitServices) | ||
{ | ||
this.vsGitServices = vsGitServices; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task Refresh() | ||
{ | ||
await ThreadingHelper.SwitchToPoolThreadAsync(); | ||
var list = vsGitServices.GetKnownRepositories(); | ||
await ThreadingHelper.SwitchToMainThreadAsync(); | ||
|
||
repositories.Except(list).ToList().ForEach(x => repositories.Remove(x)); | ||
list.Except(repositories).ToList().ForEach(x => repositories.Add(x)); | ||
} | ||
|
||
readonly ObservableCollectionEx<ILocalRepositoryModel> repositories | ||
= new ObservableCollectionEx<ILocalRepositoryModel>(); | ||
|
||
/// <inheritdoc/> | ||
public IReadOnlyObservableCollection<ILocalRepositoryModel> Repositories => repositories; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/GitHub.Exports.Reactive/Services/LocalRepositoriesExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using GitHub.Models; | ||
using GitHub.Primitives; | ||
using ReactiveUI; | ||
|
||
namespace GitHub.Services | ||
{ | ||
/// <summary> | ||
/// Implements extension methods for <see cref="ILocalRepositories"/>. | ||
/// </summary> | ||
public static class LocalRepositoriesExtensions | ||
{ | ||
/// <summary> | ||
/// Gets a derived collection that contains all known repositories with the specified | ||
/// clone URL, ordered by name. | ||
/// </summary> | ||
/// <param name="repos">The local repositories object.</param> | ||
/// <param name="address">The address.</param> | ||
public static IReactiveDerivedList<ILocalRepositoryModel> GetRepositoriesForAddress( | ||
this ILocalRepositories repos, | ||
HostAddress address) | ||
{ | ||
return repos.Repositories.CreateDerivedCollection( | ||
x => x, | ||
x => x.CloneUrl != null && address.Equals(HostAddress.Create(x.CloneUrl)), | ||
OrderedComparer<ILocalRepositoryModel>.OrderBy(x => x.Name).Compare); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using GitHub.Extensions; | ||
using GitHub.Models; | ||
|
||
namespace GitHub.Services | ||
{ | ||
/// <summary> | ||
/// Stores a collection of known local repositories. | ||
/// </summary> | ||
public interface ILocalRepositories | ||
{ | ||
/// <summary> | ||
/// Gets the currently known local repositories. | ||
/// </summary> | ||
IReadOnlyObservableCollection<ILocalRepositoryModel> Repositories { get; } | ||
|
||
/// <summary> | ||
/// Updates <see cref="Repositories"/>. | ||
/// </summary> | ||
Task Refresh(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Collections.Specialized; | ||
using System.ComponentModel; | ||
|
||
namespace GitHub.Extensions | ||
{ | ||
/// <summary> | ||
/// Represents a read-only interface to an <see cref="ObservableCollection{T}"/> | ||
/// </summary> | ||
/// <typeparam name="T">The type of elements in the collection.</typeparam> | ||
public interface IReadOnlyObservableCollection<T> : IReadOnlyList<T>, | ||
INotifyCollectionChanged, | ||
INotifyPropertyChanged | ||
{ | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
|
||
namespace GitHub.Extensions | ||
{ | ||
/// <summary> | ||
/// A non-braindead way to expose a read-only view on an <see cref="ObservableCollection{T}"/>. | ||
/// </summary> | ||
/// <typeparam name="T">The type of elements in the collection.</typeparam> | ||
/// <remarks> | ||
/// <see cref="ReadOnlyObservableCollection{T}"/> fails in its only purpose by Not. Freaking. | ||
/// Exposing. INotifyCollectionChanged. We define our own <see cref="IReadOnlyObservableCollection{T}"/> | ||
/// type and use this class to expose it. Seriously. | ||
/// </remarks> | ||
public class ObservableCollectionEx<T> : ObservableCollection<T>, IReadOnlyObservableCollection<T> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ObservableCollectionEx{T}"/> class. | ||
/// </summary> | ||
public ObservableCollectionEx() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ObservableCollectionEx{T}"/> class that | ||
/// contains elements copied from the specified list. | ||
/// </summary> | ||
public ObservableCollectionEx(List<T> list) | ||
: base(list) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ObservableCollectionEx{T}"/> class that | ||
/// contains elements copied from the specified collection. | ||
/// </summary> | ||
public ObservableCollectionEx(IEnumerable<T> collection) | ||
: base(collection) | ||
{ | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't this this implementation should be here, this will bring all the Rx dependencies in when there's no need for it. The reason this was in ConnectionManager to begin with was meant to be light weight and require minimal dependencies. Perhaps GitHub.Exports or some other place would be better? Maybe even GitHub.VisualStudio?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the fact that its export is in
GitHub.Exports
good enough? If you look at some of our models, e.g.PullRequestModel
- that is defined inGitHub.App
with its interface inGitHub.Exports
meaning that it's available to the non-rx parts of the extension. Rx shouldn't be loaded until a type that references rx is loaded, right?