Beispiel #1
0
 protected void NotifyPropertyChanged(string propertyName)
 {
     if (UiDispatcherService != null && PropertyChanged != null)
     {
         UiDispatcherService.InvokeAsync(() => PropertyChanged(this, new PropertyChangedEventArgs(propertyName)));
     }
 }
        public RepositoriesViewModel()
        {
            Repositories = new CollectionViewSource {
                Source = ApplicationSettings.Instance.Repositories
            };
            Repositories.View.CurrentChanged += (s, e) => Mediator.NotifyColleaguesAsync <RepositorySelectedEvent>(Repositories.View.CurrentItem as Repository);
            if (ApplicationSettings.Instance.Repositories.Count > 0)
            {
                Repositories.View.MoveCurrentToFirst();
                Mediator.NotifyColleaguesAsync <RepositorySelectedEvent>(Repositories.View.CurrentItem as Repository);
            }

            Mediator.Subscribe <DeleteRepositoryEvent>(r =>
            {
                var repo = r as Repository;
                if (repo != null && ApplicationSettings.Instance.Repositories.Contains(repo))
                {
                    UiDispatcherService.InvokeAsync(() =>
                    {
                        ApplicationSettings.Instance.Repositories.Remove(repo);
                        ApplicationSettings.Save();
                    });
                }
            });
        }
Beispiel #3
0
        public void RefreshCommitHistory()
        {
            if (BlockUpdates)
            {
                return;
            }

            Debug.WriteLine("Refreshing commit history for {0}", this.Name);

            var startRevision = this._items.OrderByDescending(item => item.Revision).Select(item => item.Revision).FirstOrDefault();

            if (!_alreadyUpdating && _dataService != null)
            {
                lock (_locker)
                {
                    _alreadyUpdating = true;
                    Status           = "Updating...";
                }

                _dataService.GetLogAsync(this, items =>
                {
                    if (items != null)
                    {
                        UiDispatcherService.InvokeAsync(() =>
                        {
                            var added = this._items.MergeAdd(items,
                                                             (item, collection) => collection.FirstOrDefault(c => c.Revision == item.Revision),
                                                             (itemOld, itemNew) =>
                            {
                                itemOld.Revision = itemNew.Revision;
                                itemOld.Author   = itemNew.Author;
                                itemOld.Date     = itemNew.Date;
                                itemOld.HasLocalEditsOnAnyFile = itemNew.HasLocalEditsOnAnyFile;
                                itemOld.LogMessage             = itemOld.LogMessage;
                                itemOld.ItemChanges            = itemNew.ItemChanges;
                            });
                            var list = new List <ICommitItem>();
                            if (added != null)
                            {
                                list.AddRange(added);
                            }

                            Mediator.NotifyColleaguesAsync <CommitsPublishedEvent>(list);
                        });
                    }

                    lock (_locker)
                    {
                        _alreadyUpdating = false;
                        Status           = string.Format("Last Update: {0}", DateTime.Now.ToShortTimeString());
                    }
                }, startRevision: startRevision);
            }
        }
        public ShellViewModel()
        {
            if (!Directory.Exists(ApplicationSettings.Instance.DiffDirectory))
            {
                Directory.CreateDirectory(ApplicationSettings.Instance.DiffDirectory);
            }
            var files = Directory.GetFiles(ApplicationSettings.Instance.DiffDirectory).ToList();

            files.ForEach(File.Delete);

            MenuView         = ViewLocator.GetSharedInstance <IMenuView>();
            MainView         = ViewLocator.GetSharedInstance <IRevisionHistoryView>();
            RepositoriesView = ViewLocator.GetSharedInstance <IRepositoriesView>();
            Container.RegisterInstance <ISourceControlController>();
            ChildWindowState = WindowState.Closed;

            Mediator.Subscribe <BeginBusyEvent>(text =>
            {
                IsBusy     = true;
                IsBusyText = (text ?? "").ToString();
            });
            Mediator.Subscribe <EndBusyEvent>(text => IsBusy = false);

            var showChildWindow = new Action <object>(repo =>
            {
                UiDispatcherService.InvokeAsync(() =>
                {
                    ChildWindowContent = ViewLocator.GetSharedInstance <IRepositoryEditorView>();
                    ChildWindowState   = WindowState.Open;
                });
            });

            Mediator.Subscribe <EditRepositoryEvent>(showChildWindow);
            Mediator.Subscribe <AddRepositoryEvent>(showChildWindow);

            Mediator.Subscribe <HideChildWindowEvent>(ignore => ChildWindowState = WindowState.Closed);
        }