Ejemplo n.º 1
0
        public string SaveState()
        {
            var state = new RepositoryViewModelState()
            {
                ActiveItemIndex = Items.IndexOf(ActiveItem)
            };

            if (null != _vmCommits.Commits)
            {
                state.Commits = _vmCommits.Commits.ToList();
            }
            if (null != _vmIssues.Issues)
            {
                state.Issues = _vmIssues.Issues.ToList();
            }

            if (null != _vmContents.PathTree)
            {
                state.PathTree = _vmContents.PathTree;
            }
            if (null != _vmContents.Breadcrumbs)
            {
                state.Breadcrumbs = _vmContents.Breadcrumbs.ToList();
            }
            if (null != _vmContents.Branches)
            {
                state.Branches = _vmContents.Branches;
            }
            if (null != _vmContents.SelectedBranch)
            {
                state.SelectedBranchName = _vmContents.SelectedBranch.Name;
            }

            return(JsonConvert.SerializeObject(state));
        }
Ejemplo n.º 2
0
        public void LoadState(string jsonState)
        {
            RepositoryViewModelState state = null;

            try
            {
                // Catch errors on deserializing state (ie vastly changed state object models between versions)
                state = JsonConvert.DeserializeObject <RepositoryViewModelState>(jsonState);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LoadState: " + ex.ToString());
                return;
            }

            // No state? Do nothing, get out of here
            if (null == state)
            {
                return;
            }

            if (null != state.Commits)
            {
                _vmCommits.Commits = new ObservableCollection <GhCommit>(state.Commits);
            }
            if (null != state.Issues)
            {
                _vmIssues.Issues = new ObservableCollection <GhIssue>(state.Issues);
            }

            if (null != state.PathTree)
            {
                _vmContents.PathTree = state.PathTree;
            }
            if (null != state.Breadcrumbs)
            {
                _vmContents.Breadcrumbs = new ObservableCollection <GhTreeItem>(state.Breadcrumbs);
            }
            if (null != state.Branches)
            {
                _vmContents.Branches = state.Branches;
            }
            if (!String.IsNullOrWhiteSpace(state.SelectedBranchName) && null != _vmContents.Branches)
            {
                _vmContents.SelectedBranch = _vmContents.Branches.FirstOrDefault(b => b.Name == state.SelectedBranchName);
            }

            // Do this last as this would call OnInitialize right away before restoring sub-state
            var activeItem = Items.ElementAtOrDefault(state.ActiveItemIndex);

            ActiveItem = activeItem;
        }