Exemplo n.º 1
0
        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.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();
            ShowReview   = ReactiveCommand.Create().OnExecuteCompleted(DoShowReview);
        }
Exemplo n.º 2
0
        public GistCreationViewModel(
            IModelServiceFactory modelServiceFactory,
            ISelectedTextProvider selectedTextProvider,
            IGistPublishService gistPublishService,
            INotificationService notificationService,
            IUsageTracker usageTracker)
        {
            Guard.ArgumentNotNull(selectedTextProvider, nameof(selectedTextProvider));
            Guard.ArgumentNotNull(gistPublishService, nameof(gistPublishService));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.modelServiceFactory = modelServiceFactory;
            this.gistPublishService  = gistPublishService;
            this.notificationService = notificationService;
            this.usageTracker        = usageTracker;

            FileName     = VisualStudio.Services.GetFileNameFromActiveDocument() ?? Resources.DefaultGistFileName;
            SelectedText = selectedTextProvider.GetSelectedText();

            var canCreateGist = this.WhenAny(
                x => x.FileName,
                fileName => !String.IsNullOrEmpty(fileName.Value));

            CreateGist = ReactiveCommand.CreateFromObservable(OnCreateGist, canCreateGist);
        }
Exemplo n.º 3
0
        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;
            initialized = new TaskCompletionSource <object>(null);

            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());
        }
Exemplo n.º 4
0
        public RepositoryCreationViewModel(
            IModelServiceFactory modelServiceFactory,
            IOperatingSystem operatingSystem,
            IRepositoryCreationService repositoryCreationService,
            IUsageTracker usageTracker)
        {
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem));
            Guard.ArgumentNotNull(repositoryCreationService, nameof(repositoryCreationService));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.modelServiceFactory       = modelServiceFactory;
            this.operatingSystem           = operatingSystem;
            this.repositoryCreationService = repositoryCreationService;
            this.usageTracker = usageTracker;

            SelectedGitIgnoreTemplate = GitIgnoreItem.None;
            SelectedLicense           = LicenseItem.None;

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(this.WhenAny(x => x.BaseRepositoryPath, x => x.Value))
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid);

            var nonNullRepositoryName = this.WhenAny(
                x => x.RepositoryName,
                x => x.BaseRepositoryPath,
                (x, y) => x.Value)
                                        .WhereNotNull();

            RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                      .IfNullOrEmpty(Resources.RepositoryNameValidatorEmpty)
                                      .IfTrue(x => x.Length > 100, Resources.RepositoryNameValidatorTooLong)
                                      .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                                 .Add(repoName =>
            {
                var parsedReference = GetSafeRepositoryName(repoName);
                return(parsedReference != repoName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null);
            });

            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();

            CreateRepository = InitializeCreateRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(CreateRepository.IsExecuting,
                                                                    (canKeep, publishing) => canKeep && !publishing)
                             .ToProperty(this, x => x.CanKeepPrivate);

            isCreating = CreateRepository.IsExecuting
                         .ToProperty(this, x => x.IsCreating);

            BaseRepositoryPath = repositoryCreationService.DefaultClonePath;
        }
Exemplo n.º 5
0
 public RepositoryCloneViewModel(
     IGlobalConnection connection,
     IModelServiceFactory modelServiceFactory,
     IRepositoryCloneService cloneService,
     IOperatingSystem operatingSystem)
     : this(connection.Get(), modelServiceFactory, cloneService, operatingSystem)
 {
 }
 public PullRequestCreationViewModel(
     IModelServiceFactory modelServiceFactory,
     IPullRequestService service,
     INotificationService notifications,
     IMessageDraftStore draftStore)
     : this(modelServiceFactory, service, notifications, draftStore, DefaultScheduler.Instance)
 {
 }
 PullRequestCreationViewModel(
     IGlobalConnection connection,
     IModelServiceFactory modelServiceFactory,
     ITeamExplorerServiceHolder teservice,
     IPullRequestService service, INotificationService notifications)
     : this(connection.Get(), modelServiceFactory, teservice?.ActiveRepo, service, notifications)
 {
 }
        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();
        }
Exemplo n.º 9
0
        public static async Task <IModelService> GetModelService(
            this IConnectionManager cm,
            ILocalRepositoryModel repository,
            IModelServiceFactory factory)
        {
            var connection = await cm.LookupConnection(repository);

            return(connection != null ? await factory.CreateAsync(connection) : null);
        }
 public RepositoryCreationViewModel(
     IGlobalConnection connection,
     IModelServiceFactory modelServiceFactory,
     IOperatingSystem operatingSystem,
     IRepositoryCreationService repositoryCreationService,
     IUsageTracker usageTracker)
     : this(connection.Get(), modelServiceFactory, operatingSystem, repositoryCreationService, usageTracker)
 {
 }
Exemplo n.º 11
0
        public static async Task <IModelService> GetModelService(
            this IConnectionManager cm,
            LocalRepositoryModel repository,
            IModelServiceFactory factory)
        {
            var connection = await cm.GetConnection(repository);

            return(connection?.IsLoggedIn == true ? await factory.CreateAsync(connection) : null);
        }
Exemplo n.º 12
0
 public PullRequestCreationViewModel(
     IModelServiceFactory modelServiceFactory,
     IPullRequestService service,
     INotificationService notifications,
     IMessageDraftStore draftStore,
     IGitService gitService,
     IAutoCompleteAdvisor autoCompleteAdvisor)
     : this(modelServiceFactory, service, notifications, draftStore, gitService, autoCompleteAdvisor, DefaultScheduler.Instance)
 {
 }
 PullRequestListViewModel(
     IGlobalConnection connection,
     IModelServiceFactory modelServiceFactory,
     ITeamExplorerServiceHolder teservice,
     IPackageSettings settings,
     IVisualStudioBrowser visualStudioBrowser)
     : this(connection.Get(), modelServiceFactory, teservice.ActiveRepo, settings, visualStudioBrowser)
 {
     Guard.ArgumentNotNull(connection, nameof(connection));
     Guard.ArgumentNotNull(teservice, nameof(teservice));
     Guard.ArgumentNotNull(settings, nameof(settings));
 }
 public RoslynVisualizationService(
     IModelServiceFactory modelServiceFactory,
     IDiagramServiceFactory diagramServiceFactory,
     IUiServiceFactory uiServiceFactory,
     IDiagramPluginFactory diagramPluginFactory,
     IEnumerable <DiagramPluginId> diagramPluginIds)
     : base(modelServiceFactory,
            diagramServiceFactory,
            uiServiceFactory,
            diagramPluginFactory,
            diagramPluginIds)
 {
 }
        PullRequestUserReviewsViewModel CreateTarget(
            IPullRequestEditorService editorService   = null,
            IPullRequestSessionManager sessionManager = null,
            IModelServiceFactory modelServiceFactory  = null)
        {
            editorService       = editorService ?? Substitute.For <IPullRequestEditorService>();
            sessionManager      = sessionManager ?? Substitute.For <IPullRequestSessionManager>();
            modelServiceFactory = modelServiceFactory ?? Substitute.For <IModelServiceFactory>();

            return(new PullRequestUserReviewsViewModel(
                       editorService,
                       sessionManager,
                       modelServiceFactory));
        }
 PullRequestDetailViewModel(
     IGlobalConnection connection,
     IModelServiceFactory modelServiceFactory,
     ITeamExplorerServiceHolder teservice,
     IPullRequestService pullRequestsService,
     IPullRequestSessionManager sessionManager,
     IUsageTracker usageTracker)
     : this(teservice.ActiveRepo,
            modelServiceFactory.CreateBlocking(connection.Get()),
            pullRequestsService,
            sessionManager,
            usageTracker)
 {
 }
Exemplo n.º 17
0
        public static IRepositoryPublishViewModel GetViewModel(
            IRepositoryPublishService service        = null,
            INotificationService notificationService = null,
            IConnectionManager connectionManager     = null,
            IModelServiceFactory factory             = null)
        {
            service             = service ?? Substitute.For <IRepositoryPublishService>();
            notificationService = notificationService ?? Substitute.For <INotificationService>();
            connectionManager   = connectionManager ?? Substitutes.ConnectionManager;
            factory             = factory ?? Substitute.For <IModelServiceFactory>();

            return(new RepositoryPublishViewModel(service, notificationService, connectionManager,
                                                  factory, Substitute.For <IDialogService>(), Substitute.For <IUsageTracker>()));
        }
Exemplo n.º 18
0
        public ForkRepositoryExecuteViewModel(
            IModelServiceFactory modelServiceFactory,
            IRepositoryForkService repositoryForkService
            )
        {
            this.modelServiceFactory   = modelServiceFactory;
            this.repositoryForkService = repositoryForkService;

            this.WhenAnyValue(model => model.UpdateOrigin)
            .Subscribe(value => CanAddUpstream = value);

            this.WhenAnyValue(model => model.UpdateOrigin, model => model.AddUpstream)
            .Subscribe(tuple => CanResetMasterTracking = tuple.Item1 && tuple.Item2);

            CreateFork = ReactiveCommand.CreateAsyncObservable(OnCreateFork);
        }
        public PullRequestUserReviewsViewModel(
            IPullRequestEditorService editorService,
            IPullRequestSessionManager sessionManager,
            IModelServiceFactory modelServiceFactory)
        {
            Guard.ArgumentNotNull(editorService, nameof(editorService));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));

            this.editorService       = editorService;
            this.sessionManager      = sessionManager;
            this.modelServiceFactory = modelServiceFactory;

            NavigateToPullRequest = ReactiveCommand.Create().OnExecuteCompleted(_ =>
                                                                                NavigateTo(Invariant($"{LocalRepository.Owner}/{LocalRepository.Name}/pull/{PullRequestNumber}")));
        }
        static PullRequestReviewAuthoringViewModel CreateTarget(
            IPullRequestEditorService editorService   = null,
            IPullRequestSessionManager sessionManager = null,
            IModelServiceFactory modelServiceFactory  = null,
            IPullRequestFilesViewModel files          = null)
        {
            editorService       = editorService ?? Substitute.For <IPullRequestEditorService>();
            sessionManager      = sessionManager ?? CreateSessionManager();
            modelServiceFactory = modelServiceFactory ?? CreateModelServiceFactory();
            files = files ?? Substitute.For <IPullRequestFilesViewModel>();

            return(new PullRequestReviewAuthoringViewModel(
                       editorService,
                       sessionManager,
                       modelServiceFactory,
                       files));
        }
        public PullRequestDetailViewModel(
            IPullRequestService pullRequestsService,
            IPullRequestSessionManager sessionManager,
            IModelServiceFactory modelServiceFactory,
            IUsageTracker usageTracker,
            IVSGitExt vsGitExt)
        {
            Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.pullRequestsService = pullRequestsService;
            this.sessionManager      = sessionManager;
            this.modelServiceFactory = modelServiceFactory;
            this.usageTracker        = usageTracker;
            this.vsGitExt            = vsGitExt;

            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);

            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();
        }
Exemplo n.º 22
0
        GistCreationViewModel(
            IGlobalConnection connection,
            IModelServiceFactory modelServiceFactory,
            ISelectedTextProvider selectedTextProvider,
            IGistPublishService gistPublishService,
            INotificationService notificationService,
            IUsageTracker usageTracker)
            : this(connection.Get(), modelServiceFactory, selectedTextProvider, gistPublishService, usageTracker)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(selectedTextProvider, nameof(selectedTextProvider));
            Guard.ArgumentNotNull(gistPublishService, nameof(gistPublishService));
            Guard.ArgumentNotNull(notificationService, nameof(notificationService));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.notificationService = notificationService;
        }
Exemplo n.º 23
0
        public VisualizationService(
            IModelServiceFactory modelServiceFactory,
            IDiagramServiceFactory diagramServiceFactory,
            IUiServiceFactory uiServiceFactory,
            IDiagramPluginFactory diagramPluginFactory,
            IEnumerable <DiagramPluginId> diagramPluginIds)
        {
            ModelServiceFactory   = modelServiceFactory;
            DiagramServiceFactory = diagramServiceFactory;
            UiServiceFactory      = uiServiceFactory;
            DiagramPluginFactory  = diagramPluginFactory;
            DiagramPluginIds      = diagramPluginIds;

            ModelService     = ModelServiceFactory.Create();
            _diagramServices = new Dictionary <DiagramId, IDiagramService>();
            _diagramUis      = new Dictionary <DiagramId, IUiService>();
            _diagramPlugins  = new Dictionary <DiagramId, List <IDiagramPlugin> >();
        }
Exemplo n.º 24
0
        public PullRequestSessionManager(
            IPullRequestService service,
            IPullRequestSessionService sessionService,
            IConnectionManager connectionManager,
            IModelServiceFactory modelServiceFactory,
            ITeamExplorerServiceHolder teamExplorerService)
        {
            Guard.ArgumentNotNull(service, nameof(service));
            Guard.ArgumentNotNull(sessionService, nameof(sessionService));
            Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(teamExplorerService, nameof(teamExplorerService));

            this.service             = service;
            this.sessionService      = sessionService;
            this.connectionManager   = connectionManager;
            this.modelServiceFactory = modelServiceFactory;
            teamExplorerService.Subscribe(this, x => RepoChanged(x).Forget());
        }
        PullRequestSessionManager CreateTarget(
            IPullRequestService service = null,
            IPullRequestSessionService sessionService = null,
            IConnectionManager connectionManager      = null,
            IModelServiceFactory modelServiceFactory  = null,
            ITeamExplorerContext teamExplorerContext  = null)
        {
            service             = service ?? CreatePullRequestService();
            sessionService      = sessionService ?? CreateSessionService();
            connectionManager   = connectionManager ?? CreateConnectionManager();
            modelServiceFactory = modelServiceFactory ?? CreateModelServiceFactory();
            teamExplorerContext = teamExplorerContext ?? CreateTeamExplorerContext(CreateRepositoryModel());

            return(new PullRequestSessionManager(
                       service,
                       sessionService,
                       connectionManager,
                       modelServiceFactory,
                       teamExplorerContext));
        }
        public PullRequestReviewAuthoringViewModel(
            IPullRequestEditorService editorService,
            IPullRequestSessionManager sessionManager,
            IModelServiceFactory modelServiceFactory,
            IPullRequestFilesViewModel files)
        {
            Guard.ArgumentNotNull(editorService, nameof(editorService));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(files, nameof(files));

            this.editorService       = editorService;
            this.sessionManager      = sessionManager;
            this.modelServiceFactory = modelServiceFactory;

            canApproveRequestChanges = this.WhenAnyValue(
                x => x.Model,
                x => x.PullRequestModel,
                (review, pr) => review != null && pr != null && review.User.Login != pr.Author.Login)
                                       .ToProperty(this, x => x.CanApproveRequestChanges);

            Files = files;

            var hasBodyOrComments = this.WhenAnyValue(
                x => x.Body,
                x => x.FileComments.Count,
                (body, comments) => !string.IsNullOrWhiteSpace(body) || comments > 0);

            Approve = ReactiveCommand.CreateAsyncTask(_ => DoSubmit(Octokit.PullRequestReviewEvent.Approve));
            Comment = ReactiveCommand.CreateAsyncTask(
                hasBodyOrComments,
                _ => DoSubmit(Octokit.PullRequestReviewEvent.Comment));
            RequestChanges = ReactiveCommand.CreateAsyncTask(
                hasBodyOrComments,
                _ => DoSubmit(Octokit.PullRequestReviewEvent.RequestChanges));
            Cancel = ReactiveCommand.CreateAsyncTask(DoCancel);
            NavigateToPullRequest = ReactiveCommand.Create().OnExecuteCompleted(_ =>
                                                                                NavigateTo(Invariant($"{LocalRepository.Owner}/{LocalRepository.Name}/pull/{PullRequestModel.Number}")));
        }
Exemplo n.º 27
0
        public GistCreationViewModel(
            IConnection connection,
            IModelServiceFactory modelServiceFactory,
            ISelectedTextProvider selectedTextProvider,
            IGistPublishService gistPublishService,
            IUsageTracker usageTracker)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(selectedTextProvider, nameof(selectedTextProvider));
            Guard.ArgumentNotNull(gistPublishService, nameof(gistPublishService));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            Title = Resources.CreateGistTitle;
            this.gistPublishService = gistPublishService;
            this.usageTracker       = usageTracker;

            FileName     = VisualStudio.Services.GetFileNameFromActiveDocument() ?? Resources.DefaultGistFileName;
            SelectedText = selectedTextProvider.GetSelectedText();

            var modelService = modelServiceFactory.CreateBlocking(connection);

            apiClient = modelService.ApiClient;

            // This class is only instantiated after we are logged into to a github account, so we should be safe to grab the first one here as the defaut.
            account = modelService.GetAccounts()
                      .FirstAsync()
                      .Select(a => a.First())
                      .ObserveOn(RxApp.MainThreadScheduler)
                      .ToProperty(this, vm => vm.Account);

            var canCreateGist = this.WhenAny(
                x => x.FileName,
                fileName => !String.IsNullOrEmpty(fileName.Value));

            CreateGist = ReactiveCommand.CreateAsyncObservable(canCreateGist, OnCreateGist);
        }
Exemplo n.º 28
0
        public PullRequestDetailViewModel(
            IPullRequestService pullRequestsService,
            IPullRequestSessionManager sessionManager,
            IModelServiceFactory modelServiceFactory,
            IUsageTracker usageTracker,
            ITeamExplorerContext teamExplorerContext,
            IPullRequestFilesViewModel files,
            ISyncSubmodulesCommand syncSubmodulesCommand,
            IViewViewModelFactory viewViewModelFactory,
            IGitService gitService,
            IOpenIssueishDocumentCommand openDocumentCommand,
            [Import(AllowDefault = true)] JoinableTaskContext joinableTaskContext)
        {
            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));
            Guard.ArgumentNotNull(gitService, nameof(gitService));
            Guard.ArgumentNotNull(openDocumentCommand, nameof(openDocumentCommand));

            this.pullRequestsService   = pullRequestsService;
            this.sessionManager        = sessionManager;
            this.modelServiceFactory   = modelServiceFactory;
            this.usageTracker          = usageTracker;
            this.teamExplorerContext   = teamExplorerContext;
            this.syncSubmodulesCommand = syncSubmodulesCommand;
            this.viewViewModelFactory  = viewViewModelFactory;
            this.gitService            = gitService;
            this.openDocumentCommand   = openDocumentCommand;
            JoinableTaskContext        = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;

            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);

            OpenConversation = ReactiveCommand.Create(DoOpenConversation);

            OpenOnGitHub = ReactiveCommand.Create(DoOpenDetailsUrl);

            ShowReview = ReactiveCommand.Create <IPullRequestReviewSummaryViewModel>(DoShowReview);

            ShowAnnotations = ReactiveCommand.Create <IPullRequestCheckViewModel>(DoShowAnnotations);
        }
        public RepositoryCreationViewModel(
            IConnection connection,
            IModelServiceFactory modelServiceFactory,
            IOperatingSystem operatingSystem,
            IRepositoryCreationService repositoryCreationService,
            IUsageTracker usageTracker)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem));
            Guard.ArgumentNotNull(repositoryCreationService, nameof(repositoryCreationService));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.operatingSystem           = operatingSystem;
            this.repositoryCreationService = repositoryCreationService;
            this.usageTracker = usageTracker;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title);
            SelectedGitIgnoreTemplate = GitIgnoreItem.None;
            SelectedLicense           = LicenseItem.None;

            modelService = modelServiceFactory.CreateBlocking(connection);

            accounts = modelService.GetAccounts()
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
            .Select(accts => accts?.FirstOrDefault())
            .WhereNotNull()
            .Subscribe(a => SelectedAccount = a);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(this.WhenAny(x => x.BaseRepositoryPath, x => x.Value))
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid);

            var nonNullRepositoryName = this.WhenAny(
                x => x.RepositoryName,
                x => x.BaseRepositoryPath,
                (x, y) => x.Value)
                                        .WhereNotNull();

            RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                      .IfNullOrEmpty(Resources.RepositoryNameValidatorEmpty)
                                      .IfTrue(x => x.Length > 100, Resources.RepositoryNameValidatorTooLong)
                                      .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                                 .Add(repoName =>
            {
                var parsedReference = GetSafeRepositoryName(repoName);
                return(parsedReference != repoName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null);
            });

            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();

            CreateRepository = InitializeCreateRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(CreateRepository.IsExecuting,
                                                                    (canKeep, publishing) => canKeep && !publishing)
                             .ToProperty(this, x => x.CanKeepPrivate);

            isCreating = CreateRepository.IsExecuting
                         .ToProperty(this, x => x.IsCreating);

            GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetGitIgnoreTemplates(),
                new[] { GitIgnoreItem.None },
                OrderedComparer <GitIgnoreItem> .OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare,
                x =>
            {
                if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase))
                {
                    SelectedGitIgnoreTemplate = x;
                }
            });

            Licenses = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetLicenses(),
                new[] { LicenseItem.None },
                OrderedComparer <LicenseItem> .OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare);

            BaseRepositoryPath = repositoryCreationService.DefaultClonePath;
        }
Exemplo n.º 30
0
        public RepositoryCloneViewModel(
            IConnection connection,
            IModelServiceFactory modelServiceFactory,
            IRepositoryCloneService cloneService,
            IOperatingSystem operatingSystem)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(cloneService, nameof(cloneService));
            Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem));

            this.connection          = connection;
            this.modelServiceFactory = modelServiceFactory;
            this.operatingSystem     = operatingSystem;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, connection.HostAddress.Title);

            Repositories = new TrackingCollection <IRemoteRepositoryModel>();
            repositories.ProcessingDelay = TimeSpan.Zero;
            repositories.Comparer        = OrderedComparer <IRemoteRepositoryModel> .OrderBy(x => x.Owner).ThenBy(x => x.Name).Compare;

            repositories.Filter        = FilterRepository;
            repositories.NewerComparer = OrderedComparer <IRemoteRepositoryModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            filterTextIsEnabled = this.WhenAny(x => x.IsBusy,
                                               loading => loading.Value || repositories.UnfilteredCount > 0 && !LoadingFailed)
                                  .ToProperty(this, x => x.FilterTextIsEnabled);

            this.WhenAny(
                x => x.repositories.UnfilteredCount,
                x => x.IsBusy,
                x => x.LoadingFailed,
                (unfilteredCount, loading, failed) =>
            {
                if (loading.Value)
                {
                    return(false);
                }

                if (failed.Value)
                {
                    return(false);
                }

                return(unfilteredCount.Value == 0);
            })
            .Subscribe(x =>
            {
                NoRepositoriesFound = x;
            });

            this.WhenAny(x => x.FilterText, x => x.Value)
            .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Subscribe(_ => repositories.Filter = FilterRepository);

            var baseRepositoryPath = this.WhenAny(
                x => x.BaseRepositoryPath,
                x => x.SelectedRepository,
                (x, y) => x.Value);

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(baseRepositoryPath)
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid)
                                          .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            var canCloneObservable = this.WhenAny(
                x => x.SelectedRepository,
                x => x.BaseRepositoryPathValidator.ValidationResult.IsValid,
                (x, y) => x.Value != null && y.Value);

            canClone     = canCloneObservable.ToProperty(this, x => x.CanClone);
            CloneCommand = ReactiveCommand.Create(canCloneObservable);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());
            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();
            BaseRepositoryPath  = cloneService.DefaultClonePath;
            NoRepositoriesFound = true;
        }