コード例 #1
0
        public TypeSelectorViewModel(IResourceServiceModel resourceServiceModel, ResourceTreeItemViewModel resource)
        {
            _resourceServiceModel = resourceServiceModel;

            var rootType   = _resourceServiceModel.TypeTree;
            var constraint = new[] { rootType.Name };

            // Extract children constraint
            if (resource != null)
            {
                var resourceType = _resourceServiceModel.TypeTree.DerivedTypes
                                   .Flatten(t => t.DerivedTypes).First(t => t.Name == resource.Resource.TypeName);
                constraint = resourceType.References.First(r => r.Name == "Children").SupportedTypes;
            }

            var matches = FilterTypes(rootType, constraint);

            // If there is a single, abstract root node, we can skip it
            if (matches.Count == 1 && !matches[0].Creatable)
            {
                matches = matches[0].DerivedTypes;
            }

            TypeTree = matches.Select(type => new ResourceTypeViewModel(type));

            CreateCmd = new AsyncCommand(Create, CanCreate);
            CancelCmd = new RelayCommand(Cancel, CanCancel);
        }
コード例 #2
0
        /// <summary>
        /// Select <see cref="ResourceTreeItemViewModel"/> and load the details
        /// </summary>
        private async Task SelectResource(ResourceTreeItemViewModel treeItem)
        {
            SelectedResource = treeItem;

            if (treeItem == null)
            {
                ShowEmpty();
                return;
            }

            //Select view model for the right resource type
            var detailsVm = DetailsFactory.Create(treeItem.Resource.TypeName);

            await LoadDetails(() => detailsVm.Load(treeItem.Resource.Id));

            ActivateItem(detailsVm);
        }