コード例 #1
0
        private void ReplaceChildren(ObservableCollection <AppViewModel> freshApps)
        {
            UiDispatcherService.RunOnUiThread(() => Children.Clear());
            foreach (TreeViewItemViewModel avm in freshApps)
            {
                UiDispatcherService.RunOnUiThread(() => Children.Add(avm));
            }

            if (Children.Count == 0)
            {
                UiDispatcherService.RunOnUiThread(() => Children.Add(EmptyPlaceholder));
            }
            else if (Children.Count > 1 && HasEmptyPlaceholder)
            {
                UiDispatcherService.RunOnUiThread(() => Children.Remove(EmptyPlaceholder));
            }
        }
        /// <summary>
        /// add any ovms to cfivm.Children which are in currentOrgs but not in cfivm.Children.
        /// </summary>
        /// <param name="cfivm"></param>
        /// <param name="freshOrgs"></param>
        private void AddNewOrgs(ObservableCollection <OrgViewModel> freshOrgs)
        {
            foreach (OrgViewModel newOVM in freshOrgs)
            {
                if (newOVM != null)
                {
                    bool orgInChildren = Children.Any(ovm =>
                    {
                        var oldOVM = ovm as OrgViewModel;
                        return(oldOVM != null && oldOVM.Org.OrgId == newOVM.Org.OrgId);
                    });

                    if (!orgInChildren)
                    {
                        UiDispatcherService.RunOnUiThread(() => Children.Add(newOVM));
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Add any svms to Children which are in freshSpaces but not in Children.
        /// </summary>
        /// <param name="ovm"></param>
        /// <param name="freshSpaces"></param>
        private void AddNewSpaces(ObservableCollection <SpaceViewModel> freshSpaces)
        {
            foreach (SpaceViewModel newSVM in freshSpaces)
            {
                if (newSVM != null)
                {
                    bool spaceInChildren = Children.Any(svm =>
                    {
                        var oldSVM = svm as SpaceViewModel;
                        return(oldSVM != null && oldSVM.Space.SpaceId == newSVM.Space.SpaceId);
                    });

                    if (!spaceInChildren)
                    {
                        UiDispatcherService.RunOnUiThread(() => Children.Add(newSVM));
                    }
                }
            }
        }
        /// <summary>
        /// remove all ovms from cfivm.Children which don't appear in currentOrgs.
        /// </summary>
        /// <param name="cfivm"></param>
        /// <param name="freshOrgs"></param>
        private void RemoveNonexistentOrgs(ObservableCollection <OrgViewModel> freshOrgs)
        {
            var orgsToRemove = new ObservableCollection <OrgViewModel>();

            foreach (TreeViewItemViewModel priorChild in Children)
            {
                if (priorChild is OrgViewModel oldOVM)
                {
                    bool orgStillExists = freshOrgs.Any(ovm => ovm != null && ovm.Org.OrgId == oldOVM.Org.OrgId);

                    if (!orgStillExists)
                    {
                        orgsToRemove.Add(oldOVM);
                    }
                }
            }

            foreach (OrgViewModel ovm in orgsToRemove)
            {
                UiDispatcherService.RunOnUiThread(() => Children.Remove(ovm));
            }
        }
コード例 #5
0
        /// <summary>
        /// Remove all svms from Children which don't appear in freshSpaces.
        /// </summary>
        /// <param name="ovm"></param>
        /// <param name="freshSpaces"></param>
        private void RemoveNonexistentSpaces(ObservableCollection <SpaceViewModel> freshSpaces)
        {
            var spacesToRemove = new ObservableCollection <SpaceViewModel>();

            foreach (TreeViewItemViewModel priorChild in Children)
            {
                if (priorChild is SpaceViewModel oldSVM)
                {
                    bool spaceStillExists = freshSpaces.Any(svm => svm != null && svm.Space.SpaceId == oldSVM.Space.SpaceId);

                    if (!spaceStillExists)
                    {
                        spacesToRemove.Add(oldSVM);
                    }
                }
            }

            foreach (SpaceViewModel svm in spacesToRemove)
            {
                UiDispatcherService.RunOnUiThread(() => Children.Remove(svm));
            }
        }
        public override async Task RefreshChildren()
        {
            if (!IsRefreshing)
            {
                IsRefreshing = true;

                var freshOrgs = await FetchChildren();

                RemoveNonexistentOrgs(freshOrgs);
                AddNewOrgs(freshOrgs);

                if (Children.Count == 0)
                {
                    UiDispatcherService.RunOnUiThread(() => Children.Add(EmptyPlaceholder));
                }
                else if (Children.Count > 1 && HasEmptyPlaceholder)
                {
                    UiDispatcherService.RunOnUiThread(() => Children.Remove(EmptyPlaceholder));
                }

                IsRefreshing = false;
            }
        }