Example #1
0
 public CmdUtility([NotNull] IProcessUtility processUtility, [NotNull] IMessageHub messageHub, [NotNull] ICancellationTokenSourceProvider cancellationTokenSourceProvider)
 {
     _processUtility = processUtility ?? throw new ArgumentNullException(nameof(processUtility));
     _messageHub     = messageHub ?? throw new ArgumentNullException(nameof(messageHub));
     _cancellationTokenSourceProvider = cancellationTokenSourceProvider;
 }
        public MainViewModel(
            [NotNull] SynchronizationContext synchronizationContext,
            [NotNull] IProcessUtility processUtility,
            [NotNull] IMessageHub messageHub,
            [NotNull] ICmdUtility cmdUtility,
            [NotNull] IGitUtility gitUtility,
            [NotNull] Func <string, GitInfo, TfsInfo, ShelveViewModel> shelveViewModelFactory,
            [NotNull] Func <string, GitInfo, TfsInfo, UnshelveViewModel> unshelveViewModelFactory,
            [NotNull] Func <string, TfsInfo, PullViewModel> pullViewModelFactory,
            [NotNull] IGitTfsUtility gitTfsUtility,
            [NotNull] ITfsUtility tfsUtility,
            [NotNull] ICancellationTokenSourceProvider cancellationTokenSourceProvider,
            [NotNull] Func <string, bool, ConfirmationViewModel> confirmationViewModelFactory,
            [NotNull] Func <ConfirmationViewModel, IConfirmationWindow> confirmationWindowFactory,
            [NotNull] ICommandManager commandManager,
            [NotNull] IRateLimiter rateLimiter)
            : base(commandManager)
        {
            _           = rateLimiter ?? throw new ArgumentNullException(nameof(rateLimiter));
            _tfsUtility = tfsUtility;
            _cancellationTokenSourceProvider = cancellationTokenSourceProvider ?? throw new ArgumentNullException(nameof(cancellationTokenSourceProvider));
            _confirmationViewModelFactory    = confirmationViewModelFactory ?? throw new ArgumentNullException(nameof(confirmationViewModelFactory));
            _confirmationWindowFactory       = confirmationWindowFactory ?? throw new ArgumentNullException(nameof(confirmationWindowFactory));
            _rateLimiter              = rateLimiter;
            _pullViewModelFactory     = pullViewModelFactory ?? throw new ArgumentNullException(nameof(pullViewModelFactory));
            _synchronizationContext   = synchronizationContext ?? throw new ArgumentNullException(nameof(synchronizationContext));
            processUtility            = processUtility ?? throw new ArgumentNullException(nameof(processUtility));
            _messageHub               = messageHub ?? throw new ArgumentNullException(nameof(messageHub));
            _cmdUtility               = cmdUtility ?? throw new ArgumentNullException(nameof(cmdUtility));
            _gitUtility               = gitUtility ?? throw new ArgumentNullException(nameof(gitUtility));
            _gitTfsUtility            = gitTfsUtility ?? throw new ArgumentNullException(nameof(gitTfsUtility));
            _shelveViewModelFactory   = shelveViewModelFactory ?? throw new ArgumentNullException(nameof(shelveViewModelFactory));
            _unshelveViewModelFactory = unshelveViewModelFactory ?? throw new ArgumentNullException(nameof(unshelveViewModelFactory));

            processUtility.ProcessMessageFired += ProcessUtility_ProcessMessageFired;
            processUtility.ProcessErrorFired   += ProcessUtility_ProcessErrorFired;

            ChooseDirectoryCommand          = AddCommand(ChooseDirectoryAsync, () => CanBrowse);
            SetDirectoryCommand             = AddCommand <string>(SetDirectoryAsync, directory => CanBrowse);
            PullCommand                     = AddCommand(GitTfsPull, () => CanExecuteGitTfsAction);
            OpenShelveDialogCommand         = AddCommand(OpenShelveDialogAsync, () => CanExecuteGitTfsAction);
            OpenUnshelveDialogCommand       = AddCommand(OpenUnshelveDialogAsync, () => CanExecuteGitTfsAction);
            WindowClosingCommand            = AddCommand(WindowClosing);
            CancelCommand                   = AddCommand(Cancel, () => CanCancel);
            CopyShelvesetToClipboardCommand = AddCommand(CopyShelvesetToClipboard, () => CreatedShelvesetName != null);
            OpenShelvesetInBrowserCommand   = AddCommand(OpenShelvesetInBrowser, () => _createdShelvesetUrl != null);
            ShowLogsCommand                 = AddCommand(ProcessCommands.ViewLogs);
            _dialog = new CommonOpenFileDialog
            {
                IsFolderPicker   = true,
                InitialDirectory = DirectoryPath
            };
            var savedUsedPaths = Settings.Default.UsedDirectoryPaths;

            UsedPaths = string.IsNullOrEmpty(savedUsedPaths)
                ? new ObservableCollection <string>()
                : new ObservableCollection <string>(savedUsedPaths.Split(UsedPathsSeparator).Select(x => x.Trim()).Where(x => x != string.Empty));
            if (!string.IsNullOrWhiteSpace(Settings.Default.DirectoryPath))
            {
                _ = SetDirectoryAsync(Settings.Default.DirectoryPath);
            }

            _subscriptionTokens.Add(messageHub.Subscribe <Message>(OnNewMessage));
            _subscriptionTokens.Add(messageHub.Subscribe <TaskState>(OnTaskAction));
            _subscriptionTokens.Add(messageHub.Subscribe <CancellationState>(OnCancellationStateChange));
            _subscriptionTokens.Add(messageHub.Subscribe <DialogType>(OnDialogChanged));
            _subscriptionTokens.Add(messageHub.Subscribe <GitInfo>(OnGitInfoChanged));
            _subscriptionTokens.Add(messageHub.Subscribe <TfsInfo>(OnTfsInfoChanged));
            _subscriptionTokens.Add(messageHub.Subscribe <ShelvesetData>(OnShelvesetEvent));
            _fileSystemWatcher = new FileSystemWatcher
            {
                Filter = "HEAD.lock",
                IncludeSubdirectories = true,
                InternalBufferSize    = 64 * 1024
            };
            _fileSystemWatcher.Changed += FileSystemWatcher_Changed;

            Version = GetProgramVersion();
        }