コード例 #1
0
        private ExplorerEnumType AddEnumType(EnumType enumType)
        {
            var explorerEnumType = ModelToExplorerModelXRef.GetNew(_context, enumType, this, typeof(ExplorerEnumType)) as ExplorerEnumType;

            _enumTypes.Insert(explorerEnumType);
            return(explorerEnumType);
        }
コード例 #2
0
        internal void ClearChildren()
        {
            if (_children != null)
            {
                var xref = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(_context);
                var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(_context);

                // remove children from xref recursively
                foreach (var child in _children)
                {
                    child.ClearChildren();
                    child.Parent = null;

                    // if in Search Results remove from them
                    explorerSearchResults.RemoveElementFromSearchResults(child);

                    if (child.ModelItem != null)
                    {
                        xref.Remove(child.ModelItem);
                    }
                }

                // clear the list
                _children.Clear();
            }
        }
コード例 #3
0
ファイル: ExplorerDiagrams.cs プロジェクト: dotnet/ef6tools
        private ExplorerDiagram AddDiagram(Diagram diagram)
        {
            var explorerDiagram = ModelToExplorerModelXRef.GetNew(_context, diagram, this, typeof(ExplorerDiagram)) as ExplorerDiagram;

            _diagrams.Insert(explorerDiagram);
            return(explorerDiagram);
        }
コード例 #4
0
        public override void CreateViewModel(EditingContext ctx)
        {
            var service = ctx.GetEFArtifactService();

            Debug.Assert(service != null, "Null service in ExplorerViewModelHelper.CreateViewModel()");
            var artifact = service.Artifact;

            Debug.Assert(artifact != null, "Null artifact in ExplorerViewModelHelper.CreateViewModel()");

            var xref = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(ctx);

            xref.Clear();

            var edmRootNode = new ExplorerRootNode(ctx, null, artifact.Uri);

            var designerInfo = artifact.DesignerInfo();

            if (designerInfo != null &&
                designerInfo.Diagrams != null)
            {
                var explorerDiagrams = (ExplorerDiagrams)
                                       ModelToExplorerModelXRef.GetNewOrExisting(
                    ctx, designerInfo.Diagrams, edmRootNode, typeof(ExplorerDiagrams));
                edmRootNode.Diagrams = explorerDiagrams;
            }

            if (artifact.ConceptualModel() != null)
            {
                var browserCsdlEntityModel = (ExplorerConceptualEntityModel)
                                             ModelToExplorerModelXRef.GetNewOrExisting(
                    ctx, artifact.ConceptualModel(), edmRootNode, typeof(ExplorerConceptualEntityModel));
                edmRootNode.ConceptualModel = browserCsdlEntityModel;
            }

            if (artifact.StorageModel() != null)
            {
                var browserSsdlEntityModel = (ExplorerStorageEntityModel)
                                             ModelToExplorerModelXRef.GetNewOrExisting(
                    ctx, artifact.StorageModel(), edmRootNode, typeof(ExplorerStorageEntityModel));
                edmRootNode.StorageModel = browserSsdlEntityModel;
            }

            // expand the tree view so that the Conceptual, Storage Models, and Diagram nodes are visible
            if (edmRootNode.Diagrams != null)
            {
                edmRootNode.Diagrams.Types.ExpandTreeViewToMe();
            }

            if (edmRootNode.ConceptualModel != null)
            {
                edmRootNode.ConceptualModel.Types.ExpandTreeViewToMe();
            }

            if (edmRootNode.StorageModel != null)
            {
                edmRootNode.StorageModel.Types.ExpandTreeViewToMe();
            }

            base.ViewModel = new ExplorerViewModel(ctx, edmRootNode);
        }
コード例 #5
0
ファイル: ExplorerEntityType.cs プロジェクト: dotnet/ef6tools
        private void LoadPropertiesFromModel()
        {
            // load Properties from model
            var entityType = ModelItem as EntityType;

            Debug.Assert(
                entityType != null, "Underlying EntityType is null calculating Properties for ExplorerEntityType with name " + Name);
            if (entityType != null)
            {
                foreach (var child in entityType.Properties())
                {
                    if (child.EntityModel.IsCSDL)
                    {
                        _properties.Insert(
                            (ExplorerConceptualProperty)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerConceptualProperty)));
                    }
                    else
                    {
                        _properties.Insert(
                            (ExplorerStorageProperty)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerStorageProperty)));
                    }
                }
            }
        }
コード例 #6
0
        private void LoadEntityTypesFromModel()
        {
            // load children from model
            // note: have to go to parent to get this as this is a dummy node
            var entityModel = Parent.ModelItem as BaseEntityModel;

            if (entityModel != null)
            {
                foreach (var child in entityModel.EntityTypes())
                {
                    if (_isConceptual)
                    {
                        _entityTypes.Insert(
                            (ExplorerConceptualEntityType)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerConceptualEntityType)));
                    }
                    else
                    {
                        _entityTypes.Insert(
                            (ExplorerStorageEntityType)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerStorageEntityType)));
                    }
                }
            }
        }
コード例 #7
0
        internal void RecalculateResults(EditingContext context, ModelSearchResults modelSearchResults)
        {
            // reset all old IsInSearchResults values
            foreach (var oldSearchResult in Results)
            {
                oldSearchResult.IsInSearchResults = false;
            }

            // now recalculate the results based on the new ModelSearchResults
            Reset();
            _targetString        = modelSearchResults.TargetString;
            _elementTextToSearch = modelSearchResults.ElementTextToSearch;
            var modelToExplorerModelXRef = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(context);

            if (null != modelToExplorerModelXRef)
            {
                // add all the ExplorerEFElements to _results
                foreach (var result in modelSearchResults.Results)
                {
                    var resultsExplorerElement = modelToExplorerModelXRef.GetExisting(result);
                    if (resultsExplorerElement != null)
                    {
                        resultsExplorerElement.IsInSearchResults = true;
                        _results.Add(resultsExplorerElement);
                    }
                }

                // now sort _results according to the order they appear in the Explorer
                SortResults();
            }
        }
コード例 #8
0
        private void LoadAssociationsFromModel()
        {
            // load children from model
            // note: have to go to parent to get this as this is a dummy node
            var entityModel = Parent.ModelItem as BaseEntityModel;

            if (entityModel != null)
            {
                foreach (var child in entityModel.Associations())
                {
                    if (child.EntityModel.IsCSDL)
                    {
                        _associations.Insert(
                            (ExplorerConceptualAssociation)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerConceptualAssociation)));
                    }
                    else
                    {
                        _associations.Insert(
                            (ExplorerStorageAssociation)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerStorageAssociation)));
                    }
                }
            }
        }
コード例 #9
0
        private ExplorerParameter AddParameter(Parameter param)
        {
            var explorerParam =
                ModelToExplorerModelXRef.GetNew(_context, param, this, typeof(ExplorerParameter)) as ExplorerParameter;

            _parameters.Insert(explorerParam);
            return(explorerParam);
        }
コード例 #10
0
ファイル: ExplorerEntityType.cs プロジェクト: dotnet/ef6tools
        private ExplorerNavigationProperty AddNavigationProperty(NavigationProperty navProp)
        {
            var explorerNavProp =
                ModelToExplorerModelXRef.GetNew(_context, navProp, this, typeof(ExplorerNavigationProperty)) as ExplorerNavigationProperty;

            _navigationProperties.Insert(explorerNavProp);
            return(explorerNavProp);
        }
コード例 #11
0
        private ExplorerComplexType AddComplexType(ComplexType complexType)
        {
            var explorerComplexType =
                ModelToExplorerModelXRef.GetNew(_context, complexType, this, typeof(ExplorerComplexType)) as ExplorerComplexType;

            _complexTypes.Insert(explorerComplexType);
            return(explorerComplexType);
        }
コード例 #12
0
        private ExplorerFunction AddFunction(Function function)
        {
            var explorerFunction =
                ModelToExplorerModelXRef.GetNew(_context, function, this, typeof(ExplorerFunction)) as ExplorerFunction;

            _functions.Insert(explorerFunction);
            return(explorerFunction);
        }
        private ExplorerAssociationSet AddAssociationSet(AssociationSet entityType)
        {
            var explorerAssocSet =
                ModelToExplorerModelXRef.GetNew(_context, entityType, this, typeof(ExplorerAssociationSet)) as ExplorerAssociationSet;

            _associationSets.Insert(explorerAssocSet);
            return(explorerAssocSet);
        }
コード例 #14
0
        private ExplorerEntitySet AddEntitySet(EntitySet entitySet)
        {
            var explorerEntitySet =
                ModelToExplorerModelXRef.GetNew(_context, entitySet, this, typeof(ExplorerEntitySet)) as ExplorerEntitySet;

            _entitySets.Insert(explorerEntitySet);
            return(explorerEntitySet);
        }
コード例 #15
0
        private ExplorerFunctionImport AddFunctionImport(FunctionImport funcImport)
        {
            var explorerFuncImport =
                ModelToExplorerModelXRef.GetNew(_context, funcImport, this, typeof(ExplorerFunctionImport)) as ExplorerFunctionImport;

            _functionImports.Insert(explorerFuncImport);
            return(explorerFuncImport);
        }
コード例 #16
0
        private ExplorerProperty AddProperty(Property prop)
        {
            ExplorerProperty explorerProp = null;

            explorerProp =
                ModelToExplorerModelXRef.GetNew(_context, prop, this, typeof(ExplorerConceptualProperty)) as ExplorerConceptualProperty;
            _properties.Insert(explorerProp);
            return(explorerProp);
        }
コード例 #17
0
        internal virtual void RemoveChildIfLoaded(EFElement efChildElementToRemove)
        {
            // only remove this child if we have already loaded from model
            // if we have not yet loaded then this child (or rather lack thereof)
            // will be picked up next time Children is called
            if (_hasLoadedFromModel)
            {
                var xref                  = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(_context);
                var explorerElement       = xref.GetExisting(efChildElementToRemove);
                var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(_context);

                if (explorerElement != null)
                {
                    if (RemoveChild(explorerElement))
                    {
                        if (_children.Contains(explorerElement))
                        {
                            explorerElement.ClearChildren();

                            // if in Search Results remove explorerElement from them
                            explorerSearchResults.RemoveElementFromSearchResults(explorerElement);

                            xref.Remove(efChildElementToRemove);
                            explorerElement.Parent = null;
                            _children.Remove(explorerElement);
                            return;
                        }
                    }

                    // this means efChildElementToRemove is a valid
                    // EFElement which we have mapped in our ViewModel
                    // but that we're trying to remove it when this
                    // ExplorerEFElement is not the child element's parent
                    Debug.Assert(
                        false, string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.BadRemoveChildNotParent, explorerElement.Name, Name));
                    return;
                    // TODO: we need to provide a general exception-handling mechanism and replace the above Assert()
                    // by e.g. the excepiton below
                    // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                    //     Resources.BadRemoveChildNotParent, explorerElement.Name, this.Name));
                }

                // otherwise the Model child element does not map to any
                // ViewModel element - this is valid as we do not display
                // all children
                return;
            }
        }
コード例 #18
0
ファイル: ExplorerDiagrams.cs プロジェクト: dotnet/ef6tools
        private void LoadDiagramsFromModel()
        {
            // load children from model
            var diagrams = ModelItem as Diagrams;

            if (diagrams != null)
            {
                foreach (var child in diagrams.Items)
                {
                    _diagrams.Insert(
                        (ExplorerDiagram)ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerDiagram)));
                }
            }
        }
コード例 #19
0
        private void LoadEntityContainersFromModel()
        {
            // load entity container children from model
            var em = ModelItem as ConceptualEntityModel;

            if (em != null)
            {
                foreach (ConceptualEntityContainer child in em.EntityContainers())
                {
                    _entityContainers.Insert(
                        (ExplorerConceptualEntityContainer)
                        ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerConceptualEntityContainer)));
                }
            }
        }
コード例 #20
0
        protected override void InsertChild(EFElement efElementToInsert)
        {
            var entityContainer = efElementToInsert as ConceptualEntityContainer;

            if (entityContainer != null)
            {
                _entityContainers.Insert(
                    (ExplorerConceptualEntityContainer)
                    ModelToExplorerModelXRef.GetNewOrExisting(_context, entityContainer, this, typeof(ExplorerConceptualEntityContainer)));
            }
            else
            {
                base.InsertChild(efElementToInsert);
            }
        }
        private void LoadAssociationSetsFromModel()
        {
            // load children from model
            // note: have to go to parent to get this as this is a dummy node
            var container = Parent.ModelItem as BaseEntityContainer;

            if (container != null)
            {
                foreach (var child in container.AssociationSets())
                {
                    _associationSets.Insert(
                        (ExplorerAssociationSet)
                        ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerAssociationSet)));
                }
            }
        }
コード例 #22
0
        private void LoadParametersFromModel()
        {
            // load children from model
            var functionImport = ModelItem as FunctionImport;

            Debug.Assert(functionImport != null, "Underlying FunctionImport is null for ExplorerFunctionImport with name " + Name);
            if (functionImport != null)
            {
                foreach (var child in functionImport.Parameters())
                {
                    _parameters.Insert(
                        (ExplorerParameter)
                        ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerParameter)));
                }
            }
        }
コード例 #23
0
        private void LoadFunctionsFromModel()
        {
            // load children from model
            // note: have to go to parent to get this as this is a dummy node
            var sem = Parent.ModelItem as StorageEntityModel;

            Debug.Assert(sem != null, "BrowserFunctions node should always have a StorageEntityModel as this.Parent.ModelItem");
            if (sem != null)
            {
                foreach (var child in sem.Functions())
                {
                    _functions.Insert(
                        (ExplorerFunction)
                        ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerFunction)));
                }
            }
        }
コード例 #24
0
        private void LoadPropertiesFromModel()
        {
            // load Properties from model
            var complexType = ModelItem as ComplexType;

            Debug.Assert(
                complexType != null, "Underlying ComplexType is null calculating Properties for ExplorerComplexType with name " + Name);
            if (complexType != null)
            {
                foreach (var child in complexType.Properties())
                {
                    _properties.Insert(
                        (ExplorerConceptualProperty)
                        ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerConceptualProperty)));
                }
            }
        }
コード例 #25
0
ファイル: ExplorerEntityType.cs プロジェクト: dotnet/ef6tools
        private ExplorerProperty AddProperty(Property prop)
        {
            ExplorerProperty explorerProp = null;

            if (prop.EntityModel.IsCSDL)
            {
                explorerProp =
                    ModelToExplorerModelXRef.GetNew(_context, prop, this, typeof(ExplorerConceptualProperty)) as ExplorerConceptualProperty;
            }
            else
            {
                explorerProp =
                    ModelToExplorerModelXRef.GetNew(_context, prop, this, typeof(ExplorerStorageProperty)) as ExplorerStorageProperty;
            }
            _properties.Insert(explorerProp);
            return(explorerProp);
        }
コード例 #26
0
        private ExplorerAssociation AddAssociation(Association assoc)
        {
            ExplorerAssociation explorerAssociation = null;

            if (assoc.EntityModel.IsCSDL)
            {
                explorerAssociation =
                    ModelToExplorerModelXRef.GetNew(_context, assoc, this, typeof(ExplorerConceptualAssociation)) as
                    ExplorerConceptualAssociation;
            }
            else
            {
                explorerAssociation =
                    ModelToExplorerModelXRef.GetNew(_context, assoc, this, typeof(ExplorerStorageAssociation)) as ExplorerStorageAssociation;
            }
            _associations.Insert(explorerAssociation);
            return(explorerAssociation);
        }
コード例 #27
0
        private ExplorerEntityType AddEntityType(EntityType entityType)
        {
            ExplorerEntityType explorerEntityType = null;

            if (_isConceptual)
            {
                explorerEntityType =
                    ModelToExplorerModelXRef.GetNew(_context, entityType, this, typeof(ExplorerConceptualEntityType)) as ExplorerEntityType;
            }
            else
            {
                explorerEntityType =
                    ModelToExplorerModelXRef.GetNew(_context, entityType, this, typeof(ExplorerStorageEntityType)) as ExplorerEntityType;
            }

            _entityTypes.Insert(explorerEntityType);
            return(explorerEntityType);
        }
コード例 #28
0
        protected override void LoadChildrenFromModel()
        {
            var diagram = ModelItem as Diagram;

            Debug.Assert(diagram != null, "Underlying diagram is null calculating EntityTypeShape for ExplorerDiagram with name " + Name);
            if (diagram != null)
            {
                foreach (var child in diagram.EntityTypeShapes)
                {
                    // only show the EntityTypeShape that contains a valid EntityType.
                    if (child.EntityType.Target != null)
                    {
                        _explorerEntityTypeShapes.Insert(
                            (ExplorerEntityTypeShape)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerEntityTypeShape)));
                    }
                }
            }
        }
コード例 #29
0
        private void LoadFunctionImportsFromModel()
        {
            // load children from model
            // note: have to go to parent to get this as this is a dummy node
            var entityModel = Parent.ModelItem as ConceptualEntityModel;

            if (entityModel != null)
            {
                var entityContainer = entityModel.FirstEntityContainer as ConceptualEntityContainer;
                if (entityContainer != null)
                {
                    foreach (var child in entityContainer.FunctionImports())
                    {
                        _functionImports.Insert(
                            (ExplorerFunctionImport)
                            ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerFunctionImport)));
                    }
                }
            }
        }
コード例 #30
0
ファイル: ExplorerEntityType.cs プロジェクト: dotnet/ef6tools
        private void LoadNavigationPropertiesFromModel()
        {
            // load NavigationProperties from model
            var entityType = ModelItem as EntityType;

            Debug.Assert(
                entityType != null,
                "Underlying EntityType is null calculating NavigationProperties for ExplorerEntityType with name " + Name);
            var cet = entityType as ConceptualEntityType;

            if (cet != null)
            {
                foreach (var child in cet.NavigationProperties())
                {
                    _navigationProperties.Insert(
                        (ExplorerNavigationProperty)
                        ModelToExplorerModelXRef.GetNewOrExisting(_context, child, this, typeof(ExplorerNavigationProperty)));
                }
            }
        }
コード例 #31
0
 /// <summary>
 ///     Processes a Create or Delete change.
 /// </summary>
 /// <returns>
 ///     true if more model changes should be processed; otherwise, false;
 /// </returns>
 protected abstract bool ProcessCreateOrDeleteChange(EditingContext ctx, ModelToExplorerModelXRef xref, EfiChange change);
コード例 #32
0
        protected override bool ProcessCreateOrDeleteChange(EditingContext ctx, ModelToExplorerModelXRef xref, EfiChange change)
        {
            var artifact = change.Changed as EFArtifact;

            var conceptualModel = change.Changed as ConceptualEntityModel;
            var storageModel = change.Changed as StorageEntityModel;
            var mappingModel = change.Changed as MappingModel;
            if (null != artifact
                ||
                null != conceptualModel
                ||
                null != storageModel
                ||
                null != mappingModel)
            {
                // reset the search results - they will no longer be valid
                // once the view model is recalculated below
                var explorerSearchResults = ExplorerSearchResults.GetExplorerSearchResults(ctx);
                explorerSearchResults.Reset();

                // reload the UI - the ExplorerViewModelChanged will be fired
                // allowing the frame to rebind
                CreateViewModel(ctx);

                // don't process any more
                return false;
            }

            var efElement = change.Changed as EFElement;
            // ExplorerViewModelHelper only needs to process EFElement changes
            // (others are DefaultableValue and SingleItemBinding - but
            // ExplorerViewModel does not currently need to map these latter)
            if (null != efElement)
            {
                var parent = efElement.Parent as EFElement;
                Debug.Assert(
                    null != parent,
                    "received changed element of type " + change.Changed.GetType().FullName + " with non-EFElement parent of type "
                    + (efElement.Parent == null ? "NULL" : efElement.Parent.GetType().FullName));
                if (null != parent)
                {
                    // special case changing of an entity's key
                    // If we are creating/deleting a Key PropertyRef then we need
                    // to update the underlying ExplorerProperty
                    var propRef = efElement as PropertyRef;
                    var keyElement = efElement as Key;
                    if (propRef != null)
                    {
                        keyElement = propRef.GetParentOfType(typeof(Key)) as Key;
                        if (keyElement != null
                            && null != propRef.Name
                            && null != propRef.Name.Target)
                        {
                            ExplorerEFElement explorerProp =
                                xref.GetExisting(propRef.Name.Target) as ExplorerProperty;
                            if (null != explorerProp)
                            {
                                explorerProp.OnModelPropertyChanged(ExplorerEFElement.IsKeyPropertyID);
                            }
                        }
                    }
                    else if (keyElement != null)
                    {
                        // key must be a child of an entity
                        var et = parent as EntityType;
                        if (et != null)
                        {
                            // the key is being created or completely removed, so sync up every property
                            foreach (var prop in et.Properties())
                            {
                                ExplorerEFElement explorerProp = xref.GetExisting(prop) as ExplorerProperty;
                                if (null != explorerProp)
                                {
                                    explorerProp.OnModelPropertyChanged(ExplorerEFElement.IsKeyPropertyID);
                                }
                            }
                        }
                    }
                    else
                    {
                        // find Explorer node which maps to the model's parent
                        // this can be null is the ViewModel does not map the
                        // parent object
                        if (typeof(FunctionImport) == efElement.GetType())
                        {
                            // the FunctionImport Explorer Parent node has been decided to be the ConceptualEntityModel ExplorerEFElement
                            // rather than the ConceptualEntityContainer one which we would more naturally use to match the model setup
                            parent = parent.Parent as EFElement;
                        }
                        var explorerParentItem = xref.GetExisting(parent);
                        if (null != explorerParentItem)
                        {
                            // now find the Explorer node which should be the new/deleted ViewModel element's parent
                            // (may not be the same as above due to Explorer ghost nodes)
                            explorerParentItem = explorerParentItem.GetParentNodeForElement(efElement);

                            if (EfiChange.EfiChangeType.Create == change.Type)
                            {
                                // It's possible that between the Create of a parent and its child
                                // the Children property is called on the parent which loads the
                                // child into the parent, even though the child is being added with 
                                // change.Type = Create. For safety, we should remove the existing
                                // child (if it exists) so as to ensure any changes in the child change 
                                // are reflected.
                                var explorerEFElement = xref.GetExisting(efElement);
                                if (explorerEFElement != null)
                                {
                                    explorerParentItem.RemoveChildIfLoaded(efElement);
                                }
                                explorerParentItem.InsertChildIfLoaded(efElement);
                            }
                            else
                            {
                                explorerParentItem.RemoveChildIfLoaded(efElement);
                            }
                        }
                    }
                }
            }

            return true;
        }