static void SetActiveRepository(ITeamExplorerContext teamExplorerContext, ILocalRepositoryModel localRepositoryModel) { teamExplorerContext.ActiveRepository.Returns(localRepositoryModel); var eventArgs = new PropertyChangedEventArgs(nameof(teamExplorerContext.ActiveRepository)); teamExplorerContext.PropertyChanged += Raise.Event <PropertyChangedEventHandler>(teamExplorerContext, eventArgs); }
public PullRequestDetailViewModel( IPullRequestService pullRequestsService, IPullRequestSessionManager sessionManager, IModelServiceFactory modelServiceFactory, IUsageTracker usageTracker, ITeamExplorerContext teamExplorerContext, IPullRequestFilesViewModel files, ISyncSubmodulesCommand syncSubmodulesCommand, IViewViewModelFactory viewViewModelFactory) { Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService)); Guard.ArgumentNotNull(sessionManager, nameof(sessionManager)); Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory)); Guard.ArgumentNotNull(usageTracker, nameof(usageTracker)); Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); Guard.ArgumentNotNull(syncSubmodulesCommand, nameof(syncSubmodulesCommand)); Guard.ArgumentNotNull(viewViewModelFactory, nameof(viewViewModelFactory)); this.pullRequestsService = pullRequestsService; this.sessionManager = sessionManager; this.modelServiceFactory = modelServiceFactory; this.usageTracker = usageTracker; this.teamExplorerContext = teamExplorerContext; this.syncSubmodulesCommand = syncSubmodulesCommand; this.viewViewModelFactory = viewViewModelFactory; Files = files; Checkout = ReactiveCommand.CreateFromObservable( DoCheckout, this.WhenAnyValue(x => x.CheckoutState) .Cast <CheckoutCommandState>() .Select(x => x != null && x.IsEnabled)); Checkout.IsExecuting.Subscribe(x => isInCheckout = x); SubscribeOperationError(Checkout); Pull = ReactiveCommand.CreateFromObservable( DoPull, this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.PullEnabled)); SubscribeOperationError(Pull); Push = ReactiveCommand.CreateFromObservable( DoPush, this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.PushEnabled)); SubscribeOperationError(Push); SyncSubmodules = ReactiveCommand.CreateFromTask( DoSyncSubmodules, this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.SyncSubmodulesEnabled)); SyncSubmodules.Subscribe(_ => Refresh().ToObservable()); SubscribeOperationError(SyncSubmodules); OpenOnGitHub = ReactiveCommand.Create(DoOpenDetailsUrl); ShowReview = ReactiveCommand.Create <IPullRequestReviewSummaryViewModel>(DoShowReview); }
public PullRequestSessionManager( IPullRequestService service, IPullRequestSessionService sessionService, IConnectionManager connectionManager, IModelServiceFactory modelServiceFactory, ITeamExplorerContext teamExplorerContext) { Guard.ArgumentNotNull(service, nameof(service)); Guard.ArgumentNotNull(sessionService, nameof(sessionService)); Guard.ArgumentNotNull(connectionManager, nameof(connectionManager)); Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory)); Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); this.service = service; this.sessionService = sessionService; this.connectionManager = connectionManager; this.modelServiceFactory = modelServiceFactory; Observable.FromEventPattern(teamExplorerContext, nameof(teamExplorerContext.StatusChanged)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => StatusChanged().Forget()); teamExplorerContext.WhenAnyValue(x => x.ActiveRepository) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => RepoChanged(x).Forget()); }
/// <summary> /// This constructor can be used for unit testing. /// </summary> /// <param name="gitService">Used for monitoring the active repository.</param> /// <param name="joinableTaskContext">Used for switching to the Main thread.</param> public TeamExplorerServiceHolder(ITeamExplorerContext teamExplorerContext, JoinableTaskContext joinableTaskContext) { JoinableTaskCollection = joinableTaskContext.CreateCollection(); JoinableTaskCollection.DisplayName = nameof(TeamExplorerServiceHolder); JoinableTaskFactory = joinableTaskContext.CreateFactory(JoinableTaskCollection); TeamExplorerContext = teamExplorerContext; }
public IssuesAutoCompleteSource(ITeamExplorerContext teamExplorerContext, IGraphQLClientFactory graphqlFactory) { Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); Guard.ArgumentNotNull(graphqlFactory, nameof(graphqlFactory)); this.teamExplorerContext = teamExplorerContext; this.graphqlFactory = graphqlFactory; }
static GitHubPaneViewModel CreateTarget( IViewViewModelFactory viewModelFactory = null, ISimpleApiClientFactory apiClientFactory = null, IConnectionManager connectionManager = null, ITeamExplorerContext teamExplorerContext = null, IVisualStudioBrowser browser = null, IUsageTracker usageTracker = null, INavigationViewModel navigator = null, ILoggedOutViewModel loggedOut = null, INotAGitHubRepositoryViewModel notAGitHubRepository = null, INotAGitRepositoryViewModel notAGitRepository = null, ILoginFailedViewModel loginFailed = null) { viewModelFactory = viewModelFactory ?? Substitute.For <IViewViewModelFactory>(); connectionManager = connectionManager ?? Substitute.For <IConnectionManager>(); teamExplorerContext = teamExplorerContext ?? CreateTeamExplorerContext(ValidGitHubRepo); browser = browser ?? Substitute.For <IVisualStudioBrowser>(); usageTracker = usageTracker ?? Substitute.For <IUsageTracker>(); loggedOut = loggedOut ?? Substitute.For <ILoggedOutViewModel>(); notAGitHubRepository = notAGitHubRepository ?? Substitute.For <INotAGitHubRepositoryViewModel>(); notAGitRepository = notAGitRepository ?? Substitute.For <INotAGitRepositoryViewModel>(); loginFailed = loginFailed ?? Substitute.For <ILoginFailedViewModel>(); if (navigator == null) { navigator = CreateNavigator(); navigator.Content.Returns((IPanePageViewModel)null); } if (apiClientFactory == null) { var validGitHubRepoClient = Substitute.For <ISimpleApiClient>(); var validEnterpriseRepoClient = Substitute.For <ISimpleApiClient>(); var invalidRepoClient = Substitute.For <ISimpleApiClient>(); validGitHubRepoClient.GetRepository().Returns(new Octokit.Repository(1)); validEnterpriseRepoClient.GetRepository().Returns(new Octokit.Repository(1)); validEnterpriseRepoClient.IsEnterprise().Returns(true); apiClientFactory = Substitute.For <ISimpleApiClientFactory>(); apiClientFactory.Create(null).ReturnsForAnyArgs(invalidRepoClient); apiClientFactory.Create(ValidGitHubRepo).Returns(validGitHubRepoClient); apiClientFactory.Create(ValidEnterpriseRepo).Returns(validEnterpriseRepoClient); } return(new GitHubPaneViewModel( viewModelFactory, apiClientFactory, connectionManager, teamExplorerContext, browser, usageTracker, navigator, loggedOut, notAGitHubRepository, notAGitRepository, loginFailed)); }
public PullRequestDetailViewModel( IPullRequestService pullRequestsService, IPullRequestSessionManager sessionManager, IModelServiceFactory modelServiceFactory, IUsageTracker usageTracker, ITeamExplorerContext teamExplorerContext, IStatusBarNotificationService statusBarNotificationService) { Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService)); Guard.ArgumentNotNull(sessionManager, nameof(sessionManager)); Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory)); Guard.ArgumentNotNull(usageTracker, nameof(usageTracker)); Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); Guard.ArgumentNotNull(statusBarNotificationService, nameof(statusBarNotificationService)); this.pullRequestsService = pullRequestsService; this.sessionManager = sessionManager; this.modelServiceFactory = modelServiceFactory; this.usageTracker = usageTracker; this.teamExplorerContext = teamExplorerContext; this.statusBarNotificationService = statusBarNotificationService; Checkout = ReactiveCommand.CreateAsyncObservable( this.WhenAnyValue(x => x.CheckoutState) .Cast <CheckoutCommandState>() .Select(x => x != null && x.IsEnabled), DoCheckout); Checkout.IsExecuting.Subscribe(x => isInCheckout = x); SubscribeOperationError(Checkout); Pull = ReactiveCommand.CreateAsyncObservable( this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.PullEnabled), DoPull); SubscribeOperationError(Pull); Push = ReactiveCommand.CreateAsyncObservable( this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.PushEnabled), DoPush); SubscribeOperationError(Push); SyncSubmodules = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.SyncSubmodulesEnabled), DoSyncSubmodules); SyncSubmodules.Subscribe(_ => Refresh().ToObservable()); SubscribeOperationError(SyncSubmodules); OpenOnGitHub = ReactiveCommand.Create(); DiffFile = ReactiveCommand.Create(); DiffFileWithWorkingDirectory = ReactiveCommand.Create(this.WhenAnyValue(x => x.IsCheckedOut)); OpenFileInWorkingDirectory = ReactiveCommand.Create(this.WhenAnyValue(x => x.IsCheckedOut)); ViewFile = ReactiveCommand.Create(); }
static OpenFromClipboardCommand CreateOpenFromClipboardCommand( IGitHubContextService gitHubContextService = null, ITeamExplorerContext teamExplorerContext = null, IVSServices vsServices = null, GitHubContext contextFromClipboard = null, string repositoryDir = null, string repositoryName = null, string repositoryOwner = null, string currentBranch = null, (string, string, string)?resolveBlobResult = null,
public MentionsAutoCompleteSource( ITeamExplorerContext teamExplorerContext, IGraphQLClientFactory graphqlFactory, IAvatarProvider avatarProvider) { Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); Guard.ArgumentNotNull(graphqlFactory, nameof(graphqlFactory)); Guard.ArgumentNotNull(avatarProvider, nameof(avatarProvider)); this.teamExplorerContext = teamExplorerContext; this.graphqlFactory = graphqlFactory; this.avatarProvider = avatarProvider; }
PullRequestSessionManager CreateTarget( IPullRequestService service = null, IPullRequestSessionService sessionService = null, IConnectionManager connectionManager = null, ITeamExplorerContext teamExplorerContext = null) { service = service ?? CreatePullRequestService(); sessionService = sessionService ?? CreateSessionService(); connectionManager = connectionManager ?? CreateConnectionManager(); teamExplorerContext = teamExplorerContext ?? CreateTeamExplorerContext(CreateRepositoryModel()); return(new PullRequestSessionManager( service, sessionService, teamExplorerContext)); }
static OpenFromUrlCommand CreateOpenFromUrlCommand( IDialogService dialogService = null, IRepositoryCloneService repositoryCloneService = null, ITeamExplorerContext teamExplorerContext = null, IGitHubContextService gitHubContextService = null) { dialogService = dialogService ?? Substitute.For <IDialogService>(); repositoryCloneService = repositoryCloneService ?? Substitute.For <IRepositoryCloneService>(); teamExplorerContext = teamExplorerContext ?? Substitute.For <ITeamExplorerContext>(); gitHubContextService = gitHubContextService ?? Substitute.For <IGitHubContextService>(); return(new OpenFromUrlCommand( new Lazy <IDialogService>(() => dialogService), new Lazy <IRepositoryCloneService>(() => repositoryCloneService), new Lazy <ITeamExplorerContext>(() => teamExplorerContext), new Lazy <IGitHubContextService>(() => gitHubContextService))); }
public PullRequestSessionManager( IPullRequestService service, IPullRequestSessionService sessionService, ITeamExplorerContext teamExplorerContext) { Guard.ArgumentNotNull(service, nameof(service)); Guard.ArgumentNotNull(sessionService, nameof(sessionService)); Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); this.service = service; this.sessionService = sessionService; initialized = new TaskCompletionSource <object>(null); Observable.FromEventPattern(teamExplorerContext, nameof(teamExplorerContext.StatusChanged)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => StatusChanged().Forget(log)); teamExplorerContext.WhenAnyValue(x => x.ActiveRepository) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => RepoChanged(x).Forget(log)); }
public GitHubPaneViewModel( IViewViewModelFactory viewModelFactory, ISimpleApiClientFactory apiClientFactory, IConnectionManager connectionManager, ITeamExplorerContext teamExplorerContext, IVisualStudioBrowser browser, IUsageTracker usageTracker, INavigationViewModel navigator, ILoggedOutViewModel loggedOut, INotAGitHubRepositoryViewModel notAGitHubRepository, INotAGitRepositoryViewModel notAGitRepository, INoRemoteOriginViewModel noRemoteOrigin, ILoginFailedViewModel loginFailed) { Guard.ArgumentNotNull(viewModelFactory, nameof(viewModelFactory)); Guard.ArgumentNotNull(apiClientFactory, nameof(apiClientFactory)); Guard.ArgumentNotNull(connectionManager, nameof(connectionManager)); Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); Guard.ArgumentNotNull(browser, nameof(browser)); Guard.ArgumentNotNull(usageTracker, nameof(usageTracker)); Guard.ArgumentNotNull(navigator, nameof(navigator)); Guard.ArgumentNotNull(loggedOut, nameof(loggedOut)); Guard.ArgumentNotNull(notAGitHubRepository, nameof(notAGitHubRepository)); Guard.ArgumentNotNull(notAGitRepository, nameof(notAGitRepository)); Guard.ArgumentNotNull(noRemoteOrigin, nameof(noRemoteOrigin)); Guard.ArgumentNotNull(loginFailed, nameof(loginFailed)); this.viewModelFactory = viewModelFactory; this.apiClientFactory = apiClientFactory; this.connectionManager = connectionManager; this.teamExplorerContext = teamExplorerContext; this.navigator = navigator; this.loggedOut = loggedOut; this.notAGitHubRepository = notAGitHubRepository; this.notAGitRepository = notAGitRepository; this.noRemoteOrigin = noRemoteOrigin; this.loginFailed = loginFailed; var contentAndNavigatorContent = Observable.CombineLatest( this.WhenAnyValue(x => x.Content), navigator.WhenAnyValue(x => x.Content), (c, nc) => new { Content = c, NavigatorContent = nc }); contentOverride = contentAndNavigatorContent .SelectMany(x => { if (x.Content == null) { return(Observable.Return(ContentOverride.Spinner)); } else if (x.Content == navigator && x.NavigatorContent != null) { return(x.NavigatorContent.WhenAnyValue( y => y.IsLoading, y => y.Error, (l, e) => { if (l) { return ContentOverride.Spinner; } if (e != null) { return ContentOverride.Error; } else { return ContentOverride.None; } })); } else { return(Observable.Return(ContentOverride.None)); } }) .ToProperty(this, x => x.ContentOverride); // Returns navigator.Content if Content == navigator, otherwise null. var currentPage = contentAndNavigatorContent .Select(x => x.Content == navigator ? x.NavigatorContent : null); title = currentPage .SelectMany(x => x?.WhenAnyValue(y => y.Title) ?? Observable.Return <string>(null)) .Select(x => x ?? "GitHub") .ToProperty(this, x => x.Title); isSearchEnabled = currentPage .Select(x => x is ISearchablePageViewModel) .ToProperty(this, x => x.IsSearchEnabled); refresh = ReactiveCommand.CreateFromTask( () => navigator.Content.Refresh(), currentPage.SelectMany(x => x?.WhenAnyValue( y => y.IsLoading, y => y.IsBusy, (loading, busy) => !loading && !busy) ?? Observable.Return(false))); refresh.ThrownExceptions.Subscribe(); showPullRequests = ReactiveCommand.CreateFromTask( ShowPullRequests, this.WhenAny(x => x.Content, x => x.Value == navigator)); openInBrowser = ReactiveCommand.Create( () => { var url = ((IOpenInBrowser)navigator.Content).WebUrl; if (url != null) { browser.OpenUrl(url); } }, currentPage.Select(x => x is IOpenInBrowser)); BrowseRepository = ReactiveCommand.Create( () => { var url = LocalRepository.CloneUrl.ToRepositoryUrl(); if (url != null) { browser.OpenUrl(url); } }, currentPage.Select(x => x is IOpenInBrowser)); help = ReactiveCommand.Create(() => { }); help.Subscribe(_ => { browser.OpenUrl(new Uri(GitHubUrls.Documentation)); usageTracker.IncrementCounter(x => x.NumberOfGitHubPaneHelpClicks).Forget(); }); navigator.WhenAnyObservable(x => x.Content.NavigationRequested) .Subscribe(x => NavigateTo(x).Forget()); this.WhenAnyValue(x => x.SearchQuery) .Where(x => navigator.Content is ISearchablePageViewModel) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => ((ISearchablePageViewModel)navigator.Content).SearchQuery = x); }
TeamExplorerServiceHolder(ITeamExplorerContext teamExplorerContext) : this(teamExplorerContext, ThreadHelper.JoinableTaskContext) { }
public TeamExplorerServiceHolder(ITeamExplorerContext teamExplorerContext, [Import(AllowDefault = true)] JoinableTaskContext joinableTaskContext) { JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext; TeamExplorerContext = teamExplorerContext; }
static void SetActiveRepository(ITeamExplorerContext teamExplorerContext, ILocalRepositoryModel localRepositoryModel) { teamExplorerContext.ActiveRepository.Returns(localRepositoryModel); teamExplorerContext.StatusChanged += Raise.Event(); }