public RepositoryEditorViewModel()
        {
            Mediator.Subscribe <EditRepositoryEvent>(repo =>
            {
                AcceptText = "Commit";
                Repository = repo as Repository;
                _isNewRepo = false;
                if (Repository != null)
                {
                    Repository.BlockUpdates = true;
                }

                _repoBeforeEdit = Repository != null ? new Repository()
                {
                    Password = Repository.Password,
                    Name     = Repository.Name,
                    Path     = Repository.Path,
                    Type     = Repository.Type,
                    UserName = Repository.UserName
                } : null;

                // Make sure to get the details view in place for this repo type
                if (Repository != null)
                {
                    Mediator.NotifyColleaguesAsync <RepositoryTypeSelectedInEditEvent>(this.Repository.Type);
                }
            });

            Mediator.Subscribe <AddRepositoryEvent>(repo =>
            {
                AcceptText = "Add";
                Repository = new Repository();
                _isNewRepo = true;
            });

            // When a user selects a different repo type from the combobox, we update the repository object with that type,
            // then publish that new type so the corresponding dataservice can provide a details view for that type
            RepositoryServices = CollectionViewSource.GetDefaultView(DataServiceLocator.GetSharedServices());
            RepositoryServices.CurrentChanged += (s, e) =>
            {
                var current = RepositoryServices.CurrentItem as ISourceControlDataService;
                if (current != null)
                {
                    this.Repository.Type = current.RepositoryType;
                    Mediator.NotifyColleaguesAsync <RepositoryTypeSelectedInEditEvent>((RepositoryServices.CurrentItem as ISourceControlDataService).RepositoryType);
                }
            };

            // this is the response from the data service providing a custom details view for the seleted repo type
            Mediator.Subscribe <ShowRepositoryDetailsInEditorEvent>(repoDetailsView =>
            {
                RepositoryDetailsView = repoDetailsView;
                var match             = (from r in RepositoryServices.Cast <ISourceControlDataService>()
                                         where r.RepositoryType == Repository.Type
                                         select r).FirstOrDefault();
                RepositoryServices.MoveCurrentTo(match);
            });
        }
Beispiel #2
0
        public void Initialize()
        {
            BlockUpdates = false;

            if (CommitItems == null)
            {
                _items  = new ObservableCollectionEx <ICommitItem>();
                _locker = new object();

                // Apparently, not only must CommitItems be set on the UI thread, but the ICollectionView object
                // must also be created on it!
                UiDispatcherService.Invoke(() =>
                {
                    CommitItems            = CollectionViewSource.GetDefaultView(_items);
                    var listCollectionView = CommitItems as ListCollectionView;
                    if (listCollectionView != null)
                    {
                        listCollectionView.CustomSort = new CommitItemSorter()
                        {
                            Direction = ListSortDirection.Descending
                        };
                    }
                });
            }

            if (_historyChecker != null)
            {
                _historyChecker.Stop();
                _historyChecker = null;
            }

            _dataService = (from d in DataServiceLocator.GetSharedServices()
                            where this.Type == d.RepositoryType
                            select d).FirstOrDefault();

            this.RefreshCommitHistory();

            _historyChecker = new DispatcherTimer()
            {
                IsEnabled = false, Interval = new TimeSpan(0, 0, UpdateInterval ?? 3, 0)
            };
            _historyChecker.Tick     += (s, e) => RefreshCommitHistory();
            _historyChecker.IsEnabled = true;
            _historyChecker.Start();
        }