Exemplo n.º 1
0
        private static IEnumerable <ExplorerEFElement> AncestorsFromNode(ExplorerEFElement startNode)
        {
            var e = startNode;

            while (e != null)
            {
                yield return(e);

                e = e.Parent;
            }
        }
        internal ExplorerEFElement GetExistingOrParent(EFElement efElement)
        {
            ExplorerEFElement result = null;

            while (result == null &&
                   efElement != null)
            {
                if (!_dict.TryGetValue(efElement, out result))
                {
                    efElement = efElement.Parent as EFElement;
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        protected override bool RemoveChild(ExplorerEFElement efElementToRemove)
        {
            var explorerProperty = efElementToRemove as ExplorerProperty;

            if (explorerProperty != null)
            {
                var indexOfRemovedChild = _properties.Remove(explorerProperty);
                return((indexOfRemovedChild < 0) ? false : true);
            }

            Debug.Fail(
                string.Format(
                    CultureInfo.CurrentCulture, Resources.BadRemoveBadChildType,
                    efElementToRemove.GetType().FullName, Name, GetType().FullName));
            return(false);
        }
        protected override bool RemoveChild(ExplorerEFElement efElementToRemove)
        {
            var explorerEntityContainer = efElementToRemove as ExplorerConceptualEntityContainer;

            if (explorerEntityContainer == null)
            {
                Debug.Fail(
                    string.Format(
                        CultureInfo.CurrentCulture, Resources.BadRemoveBadChildType,
                        efElementToRemove.GetType().FullName, Name, GetType().FullName));
                return(false);
            }

            var indexOfRemovedChild = _entityContainers.Remove(explorerEntityContainer);

            return((indexOfRemovedChild < 0) ? false : true);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     If the element being removed is part of the Search Results then
        ///     removes it from the Search Results list
        /// </summary>
        /// <param name="elementToBeRemoved">element to be removed</param>
        /// <returns>whether removal was successful</returns>
        internal bool RemoveElementFromSearchResults(ExplorerEFElement elementToBeRemoved)
        {
            if (null == elementToBeRemoved)
            {
                Debug.Fail(
                    typeof(ExplorerSearchResults).Name + ".RemoveElementFromSearchResults() received null elementToBeRemoved");
                return(false);
            }

            if (elementToBeRemoved.IsInSearchResults)
            {
                elementToBeRemoved.IsInSearchResults = false;
                return(_results.Remove(elementToBeRemoved));
            }

            return(false);
        }
        protected override bool RemoveChild(ExplorerEFElement efElementToRemove)
        {
            var explorerAssocSet = efElementToRemove as ExplorerAssociationSet;

            if (explorerAssocSet == null)
            {
                Debug.Fail(
                    string.Format(
                        CultureInfo.CurrentCulture, Resources.BadRemoveBadChildType,
                        efElementToRemove.GetType().FullName, Name, GetType().FullName));
                return(false);
            }

            var indexOfRemovedChild = _associationSets.Remove(explorerAssocSet);

            return((indexOfRemovedChild < 0) ? false : true);
        }
Exemplo n.º 7
0
        protected override bool RemoveChild(ExplorerEFElement efElementToRemove)
        {
            var explorerEntityTypeShape = efElementToRemove as ExplorerEntityTypeShape;

            if (explorerEntityTypeShape == null)
            {
                Debug.Fail(
                    string.Format(
                        CultureInfo.CurrentCulture, Resources.BadRemoveBadChildType,
                        efElementToRemove.GetType().FullName, Name, GetType().FullName));
                return(false);
            }
            // We can't use TypedChildList's Remove to delete the entity-type-shape because the it will fail if the underlying entity-type has been deleted.
            // When the entity-type is deleted, the name of the entity-type-shape will change to an empty string and deletion will fail
            // until the list is re-sorted (see implementation of ExplorerEFElement's Remove).
            return(_explorerEntityTypeShapes.ChildList.Remove(explorerEntityTypeShape));
        }
Exemplo n.º 8
0
        // Must have public constructor to allow creation by reflection
        // in EditingContext.GetValue()

        internal void Reset()
        {
            if (null != _results)
            {
                foreach (var explorerElement in _results)
                {
                    explorerElement.IsInSearchResults = false;
                }
                _results.Clear();
            }
            _previousSearchResultItem      = null;
            _previousSearchResultItemIndex = -1;
            _nextSearchResultItem          = null;
            _nextSearchResultItemIndex     = -1;
            _currentSelectionIsInResults   = false;
            _targetString        = null;
            _elementTextToSearch = null;
        }
        private static ExplorerEFElement GetNewOrExisting(
            EditingContext context, EFElement efElement, ExplorerEFElement parent, Type viewModelType, bool mustNotExist)
        {
            var xref   = GetModelToBrowserModelXRef(context);
            var result = xref.GetExisting(efElement);

            if (result != null)
            {
                if (mustNotExist)
                {
                    Debug.Fail(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.BadInsertChildAlreadyExists, efElement.GetType().FullName, parent.GetType().FullName));
                    return(null);
                    // 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.BadInsertChildAlreadyExists, efElement.GetType().FullName, parent.GetType().FullName));
                }
                else
                {
                    result.Parent = parent;
                }
            }
            else
            {
                if (viewModelType != null)
                {
                    if (!xref.IsDisplayedInExplorerProtected(efElement))
                    {
                        Debug.Fail(
                            "Attempting to create an ExplorerEFElement of type " + viewModelType.FullName +
                            " based on an EFElement which is not displayed in the Explorer " + efElement.ToPrettyString());
                        return(null);
                    }

                    result = Activator.CreateInstance(viewModelType, context, efElement, parent) as ExplorerEFElement;
                    xref.Add(efElement, result);
                }
            }

            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Get previous Search Result and update Next and Previous pointers
        /// </summary>
        internal ExplorerEFElement SelectPreviousSearchResult()
        {
            var itemToBeReturned = _previousSearchResultItem;

            if (null != _previousSearchResultItem)
            {
                if (_currentSelectionIsInResults)
                {
                    if (null == _nextSearchResultItem)
                    {
                        // there was no next search item - make the next item the end of the list
                        _nextSearchResultItemIndex = _results.Count - 1;
                    }
                    else
                    {
                        _nextSearchResultItemIndex--;
                    }
                    _nextSearchResultItem = _results[_nextSearchResultItemIndex];
                }
                else
                {
                    // the currently selected item is now in the results
                    // but Next does not need to be updated
                    _currentSelectionIsInResults = true;
                }

                _previousSearchResultItemIndex--;
                if (_previousSearchResultItemIndex < 0)
                {
                    _previousSearchResultItem      = null;
                    _previousSearchResultItemIndex = -1;
                }
                else
                {
                    _previousSearchResultItem = _results[_previousSearchResultItemIndex];
                }
            }

            return(itemToBeReturned);
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Get next Search Result and update Next and Previous items
        /// </summary>
        internal ExplorerEFElement SelectNextSearchResult()
        {
            var itemToBeReturned = _nextSearchResultItem;

            if (null != _nextSearchResultItem)
            {
                if (_currentSelectionIsInResults)
                {
                    if (null == _previousSearchResultItem)
                    {
                        // there was no previous search item - make the previous item the start of the list
                        _previousSearchResultItemIndex = 0;
                    }
                    else
                    {
                        _previousSearchResultItemIndex++;
                    }
                    _previousSearchResultItem = _results[_previousSearchResultItemIndex];
                }
                else
                {
                    // the currently selected item is now in the results
                    // but Previous does not need to be updated
                    _currentSelectionIsInResults = true;
                }

                _nextSearchResultItemIndex++;
                if (_nextSearchResultItemIndex >= _results.Count)
                {
                    _nextSearchResultItem      = null;
                    _nextSearchResultItemIndex = -1;
                }
                else
                {
                    _nextSearchResultItem = _results[_nextSearchResultItemIndex];
                }
            }

            return(itemToBeReturned);
        }
        internal static ExplorerEFElement GetParentExplorerElement(EditingContext context, EFElement efElement)
        {
            // Finds the Explorer parent of the efElement
            // The explorer parent may not be the same as model parent

            ExplorerEFElement explorerParentItem = null;
            var parent = efElement.Parent as EFElement;

            if (parent != null)
            {
                var xref = GetModelToBrowserModelXRef(context);

                var currentItem = efElement;
                while (explorerParentItem == null &&
                       currentItem != null)
                {
                    currentItem        = currentItem.Parent as EFElement;
                    explorerParentItem = xref.GetExisting(currentItem);
                }
            }

            return(explorerParentItem);
        }
 public ExplorerConceptualEntityContainer(
     EditingContext context,
     ConceptualEntityContainer entityContainer, ExplorerEFElement parent)
     : base(context, entityContainer, parent)
 {
 }
Exemplo n.º 14
0
 public ExplorerAssociationSet(EditingContext context, AssociationSet assocSet, ExplorerEFElement parent)
     : base(context, assocSet, parent)
 {
     // do nothing
 }
Exemplo n.º 15
0
 public ExplorerParameter(EditingContext context, Parameter parameter, ExplorerEFElement parent)
     : base(context, parameter, parent)
 {
     // do nothing
 }
Exemplo n.º 16
0
 public ExplorerEntitySet(EditingContext context, EntitySet entitySet, ExplorerEFElement parent)
     : base(context, entitySet, parent)
 {
     // do nothing
 }
 internal static ExplorerEFElement GetNewOrExisting(
     EditingContext context, EFElement efElement, ExplorerEFElement parent, Type viewModelType)
 {
     return(GetNewOrExisting(context, efElement, parent, viewModelType, false));
 }
 private void Add(EFElement efElement, ExplorerEFElement explorerEFElement)
 {
     _dict.Add(efElement, explorerEFElement);
 }
Exemplo n.º 19
0
 public ExplorerEnumType(EditingContext context, EnumType enumType, ExplorerEFElement parent)
     : base(context, enumType, parent)
 {
     // do nothing
 }
Exemplo n.º 20
0
 public ExplorerNavigationProperty(EditingContext context, NavigationProperty navigationProperty, ExplorerEFElement parent)
     : base(context, navigationProperty, parent)
 {
     // do nothing
 }
Exemplo n.º 21
0
 /// <summary>
 ///     Removes a child element from this object
 /// </summary>
 /// <param name="explorerElement">the element to remove</param>
 /// <returns>true if element was successfully removed, false otherwise</returns>
 protected virtual bool RemoveChild(ExplorerEFElement explorerElement)
 {
     return(false);
 }
 public ExplorerConceptualProperty(EditingContext context, Property property, ExplorerEFElement parent)
     : base(context, property, parent)
 {
     // do nothing
 }
        public ExplorerConceptualEntityModel(EditingContext context, ConceptualEntityModel entityModel, ExplorerEFElement parent)
            : base(context, entityModel, parent)
        {
            _typesGhostNode = new ExplorerTypes(
                Resources.ConceptualTypesGhostNodeName, context, this);
            _complexTypesGhostNode = new ExplorerComplexTypes(Resources.ComplexTypesGhostNodeName, context, this);
            _assocsGhostNode       = new ExplorerAssociations(
                Resources.ConceptualAssociationsGhostNodeName, context, this);
            _funcImportsGhostNode = new ExplorerFunctionImports(
                Resources.FunctionImportsGhostNodeName, context, this);

            _enumTypesGhostNode = null;

            if (EdmFeatureManager.GetEnumTypeFeatureState(entityModel.Artifact).IsEnabled())
            {
                _enumTypesGhostNode = new ExplorerEnumTypes(
                    Resources.EnumTypesGhostNodeName, context, this);
            }
        }
Exemplo n.º 24
0
 public ExplorerStorageEntityModel(EditingContext context, StorageEntityModel entityModel, ExplorerEFElement parent)
     : base(context, entityModel, parent)
 {
     _typesGhostNode = new ExplorerTypes(
         Resources.StorageTypesGhostNodeName, context, this);
     _funcsGhostNode = new ExplorerFunctions(
         Resources.StorageFunctionsGhostNodeName, context, this);
     _assocsGhostNode = new ExplorerAssociations(
         Resources.StorageAssociationsGhostNodeName, context, this);
 }
 protected EntityDesignExplorerEFElement(EditingContext context, EFElement modelItem, ExplorerEFElement parent)
     : base(context, modelItem, parent)
 {
 }
 public ExplorerConceptualEntityType(EditingContext context, EntityType entityType, ExplorerEFElement parent)
     : base(context, entityType, parent)
 {
     // do nothing
 }
 public ExplorerEntityContainerAssociationSets(string name, EditingContext context, ExplorerEFElement parent)
     : base(context, null, parent)
 {
     if (name != null)
     {
         base.Name = name;
     }
 }
Exemplo n.º 28
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);
        }
 public ExplorerConceptualAssociation(EditingContext context, Association assoc, ExplorerEFElement parent)
     : base(context, assoc, parent)
 {
     // do nothing
 }
Exemplo n.º 30
0
        internal static int HierarchyCompare(ExplorerEFElement element1, ExplorerEFElement element2)
        {
            var element1PathFromRoot = element1.SelfAndAncestors().Reverse();
            var element2PathFromRoot = element2.SelfAndAncestors().Reverse();

            var element1PathFromRootEnumerator = element1PathFromRoot.GetEnumerator();
            var element2PathFromRootEnumerator = element2PathFromRoot.GetEnumerator();
            ExplorerEFElement jointParent      = null;
            ExplorerEFElement path1Child       = null;
            ExplorerEFElement path2Child       = null;

            while (true)
            {
                // Note: must update _both_ child elements so cannot use && operator in while loop
                if (element1PathFromRootEnumerator.MoveNext())
                {
                    path1Child = element1PathFromRootEnumerator.Current;
                }
                else
                {
                    path1Child = null;
                }
                if (element2PathFromRootEnumerator.MoveNext())
                {
                    path2Child = element2PathFromRootEnumerator.Current;
                }
                else
                {
                    path2Child = null;
                }

                if (null == path1Child ||
                    null == path2Child)
                {
                    // have reached end of at least one path
                    break;
                }

                if (path1Child == path2Child)
                {
                    // update joint parent
                    jointParent = path1Child;
                }
                else
                {
                    // have found point where trees differ
                    break;
                }
            }

            if (null == jointParent)
            {
                Debug.Assert(
                    false,
                    "efElement1PathFromRoot and efElement2PathFromRoot have no common ancestor - they should at least have the same root node");
                return(0);
            }

            // now compare
            if (null == path1Child &&
                null == path2Child)
            {
                // paths were the same - so ends were the same
                return(0);
            }
            else if (null == path1Child)
            {
                // element1 = jointParent, element2 = child of jointParent
                return(-1);
            }
            else if (null == path2Child)
            {
                // element1 = child of jointParent, element2 = jointParent
                return(1);
            }
            else
            {
                // comparing 2 children of jointParent
                return(jointParent.CompareChildren(path1Child, path2Child));
            }
        }