Пример #1
0
        /// <summary>
        ///     Removes the passed in symbol.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="item"></param>
        internal void RemoveSymbol(Symbol symbol, EFElement item)
        {
            if (_symbolTable.ContainsKey(symbol))
            {
                var items = _symbolTable[symbol];
                if (items.Count == 1)
                {
                    _symbolTable.Remove(symbol);
                }
                else
                {
                    items.Remove(item);

                    if (items.Count == 1)
                    {
                        // remove any duplicate symbol errors on the last remaining item with this symbol
                        var otherItem = items[0];
                        RemoveErrorsForEFObject(otherItem, ErrorClass.ResolveError, ErrorCodes.NORMALIZE_DUPLICATE_SYMBOL_DEFINED);
                    }
                }

                // remove any existing duplicate symbol errors on this item
                RemoveErrorsForEFObject(item, ErrorClass.ResolveError, ErrorCodes.NORMALIZE_DUPLICATE_SYMBOL_DEFINED);
            }
        }
Пример #2
0
        /// <summary>
        ///     Add a symbol to the global symbol table that maps to the passed in item.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="item"></param>
        internal void AddSymbol(Symbol symbol, EFElement item)
        {
            if (!_symbolTable.ContainsKey(symbol))
            {
                var list = new List <EFElement>(1);
                list.Add(item);
                _symbolTable.Add(symbol, list);
            }
            else
            {
                var current = LookupSymbol(symbol);
                if (current.Identity != item.Identity)
                {
                    // duplicate symbol.  Add the new item to the list
                    _symbolTable[symbol].Add(item);

                    // make it ready to display to the user
                    var displayableSymbol = EFNormalizableItem.ConvertSymbolToExternal(symbol);

                    // add an duplicate symbol error
                    var msg       = String.Format(CultureInfo.CurrentCulture, Resources.NORMALIZE_DUPLICATE_SYMBOL_DEFINED, displayableSymbol);
                    var errorInfo = new ErrorInfo(
                        ErrorInfo.Severity.ERROR, msg, item, ErrorCodes.NORMALIZE_DUPLICATE_SYMBOL_DEFINED, ErrorClass.ResolveError);
                    AddError(errorInfo);
                }
            }
        }
Пример #3
0
 internal MultiItemBinding(EFElement parent, string attributeName, char delimiter, NameNormalizer nameNormalizer)
     : base(parent, parent.XElement.Attribute(attributeName))
 {
     _attributeName  = attributeName;
     _delimiter      = delimiter;
     _nameNormalizer = nameNormalizer;
 }
 internal override ExplorerEFElement GetParentNodeForElement(EFElement childElement)
 {
     Debug.Assert(childElement != null, "on ExplorerEFElement with name " + Name + " received null child");
     var childElementType = childElement.GetType();
     if (typeof(StorageEntityType) == childElementType)
     {
         return _typesGhostNode;
     }
     else if (typeof(Association) == childElementType)
     {
         return _assocsGhostNode;
     }
     else if (typeof(Function) == childElementType)
     {
         return _funcsGhostNode;
     }
     else if (typeof(StorageEntityContainer) == childElementType)
     {
         return this;
     }
     else
     {
         Debug.Fail(
             string.Format(
                 CultureInfo.CurrentCulture,
                 Resources.BadChildForParentException, GetType().FullName, childElementType.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 InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
         //     Resources.BadChildForParentException, this.GetType().FullName, childElementType.FullName));
     }
 }
        // TODO - make this private, and remove the need to pass in the type to GetNew()/GetNewOrExisting().
        protected override Type GetViewModelTypeForEFlement(EFElement efElement)
        {
            if (!IsDisplayedInExplorer(efElement))
            {
                return null;
            }

            var efElementType = efElement.GetType();

            Type explorerType = null;
            _modelType2ExplorerViewModelType.TryGetValue(efElementType, out explorerType);

            // Get correct view-model type for a c-side or s-side entity type.  
            if (explorerType == null)
            {
                var assoc = efElement as Association;
                if (assoc != null)
                {
                    if (assoc.EntityModel.IsCSDL)
                    {
                        explorerType = typeof(ExplorerConceptualAssociation);
                    }
                    else
                    {
                        explorerType = typeof(ExplorerStorageAssociation);
                    }
                }
            }

            Debug.Assert(explorerType != null, "Unable to find explorer type for efobject type " + efElementType);

            return explorerType;
        }
 internal override ExplorerEFElement GetParentNodeForElement(EFElement childElement)
 {
     Debug.Assert(childElement != null, "GetParentNodeForElement on ExplorerEFElement with name " + Name + " received null child");
     Debug.Assert(
         ModelItem == childElement.Parent, "GetParentNodeForElement - underlying model element with identity " +
                                           ModelItem.Identity + " is not the same as the child element's parent, which has identity "
                                           + childElement.Parent.Identity);
     var childElementType = childElement.GetType();
     if (typeof(ConceptualEntitySet) == childElementType)
     {
         return _entitySetsGhostNode;
     }
     else if (typeof(AssociationSet) == childElementType)
     {
         return _assocSetsGhostNode;
     }
     else if (typeof(FunctionImport) == childElementType)
     {
         // if asked what FunctionImport parent node is redirect to the parent (i.e. the ConceptulaEntityModel)
         // This is because, for FunctionImports, we are not using the same parent-child relationship in the 
         // View-Model that we are in the Model
         return Parent.GetParentNodeForElement(childElement);
     }
     else
     {
         throw new InvalidOperationException(
             string.Format(
                 CultureInfo.CurrentCulture,
                 Resources.BadChildForParentException, GetType().FullName, childElementType.FullName));
     }
 }
Пример #7
0
        /// <summary>
        ///     Add a symbol to the global symbol table that maps to the passed in item.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="item"></param>
        internal void AddSymbol(Symbol symbol, EFElement item)
        {
            if (!_symbolTable.ContainsKey(symbol))
            {
                var list = new List<EFElement>(1);
                list.Add(item);
                _symbolTable.Add(symbol, list);
            }
            else
            {
                var current = LookupSymbol(symbol);
                if (current.Identity != item.Identity)
                {
                    // duplicate symbol.  Add the new item to the list 
                    _symbolTable[symbol].Add(item);

                    // make it ready to display to the user
                    var displayableSymbol = EFNormalizableItem.ConvertSymbolToExternal(symbol);

                    // add an duplicate symbol error
                    var msg = String.Format(CultureInfo.CurrentCulture, Resources.NORMALIZE_DUPLICATE_SYMBOL_DEFINED, displayableSymbol);
                    var errorInfo = new ErrorInfo(
                        ErrorInfo.Severity.ERROR, msg, item, ErrorCodes.NORMALIZE_DUPLICATE_SYMBOL_DEFINED, ErrorClass.ResolveError);
                    AddError(errorInfo);
                }
            }
        }
        internal MappingLovEFElement(EFElement modelElement, string displayName)
        {
            Debug.Assert(modelElement != null, "null modelElement");
            Debug.Assert(displayName != null, "null displayName");

            _object = modelElement;
            _displayName = displayName;
        }
Пример #9
0
 protected override void InsertChild(EFElement efElementToInsert)
 {
     var entityTypeShape = efElementToInsert as EntityTypeShape;
     if (entityTypeShape != null)
     {
         var explorerEntityTypeShape = AddEntityTypeShape(entityTypeShape);
         var index = _explorerEntityTypeShapes.IndexOf(explorerEntityTypeShape);
         _children.Insert(index, explorerEntityTypeShape);
     }
 }
        internal EFElementClipboardFormat(EFElement efElement)
        {
            var normalizableItem = efElement as EFNormalizableItem;

            NormalizedName = null;
            if (normalizableItem != null)
            {
                NormalizedName = normalizableItem.NormalizedName;
            }
        }
Пример #11
0
        internal EFElementClipboardFormat(EFElement efElement)
        {
            var normalizableItem = efElement as EFNormalizableItem;

            NormalizedName = null;
            if (normalizableItem != null)
            {
                NormalizedName = normalizableItem.NormalizedName;
            }
        }
        protected override void InsertChild(EFElement efElementToInsert)
        {
            if (efElementToInsert is Documentation)
            {
                // the ViewModel does not keep track of Documentation
                // elements for any ExplorerEFElement but it is not 
                // an error - so just return
                return;
            }

            base.InsertChild(efElementToInsert);
        }
        protected override void InsertChild(EFElement efElementToInsert)
        {
            var prop = efElementToInsert as Property;
            if (prop != null)
            {
                var explorerProp = AddProperty(prop);
                var index = _properties.IndexOf(explorerProp);
                _children.Insert(index, explorerProp);
                return;
            }

            base.InsertChild(efElementToInsert);
        }
 protected override void InsertChild(EFElement efElementToInsert)
 {
     var funcImport = efElementToInsert as FunctionImport;
     if (funcImport != null)
     {
         var explorerFuncImport = AddFunctionImport(funcImport);
         var index = _functionImports.IndexOf(explorerFuncImport);
         _children.Insert(index, explorerFuncImport);
     }
     else
     {
         base.InsertChild(efElementToInsert);
     }
 }
Пример #15
0
 protected override void InsertChild(EFElement efElementToInsert)
 {
     var diagram = efElementToInsert as Diagram;
     if (diagram != null)
     {
         var explorerDiagram = AddDiagram(diagram);
         var index = _diagrams.IndexOf(explorerDiagram);
         _children.Insert(index, explorerDiagram);
     }
     else
     {
         base.InsertChild(efElementToInsert);
     }
 }
 protected override void InsertChild(EFElement efElementToInsert)
 {
     var param = efElementToInsert as Parameter;
     if (param != null)
     {
         var explorerParam = AddParameter(param);
         var index = _parameters.IndexOf(explorerParam);
         _children.Insert(index, explorerParam);
     }
     else
     {
         base.InsertChild(efElementToInsert);
     }
 }
 protected override void InsertChild(EFElement efElementToInsert)
 {
     var assoc = efElementToInsert as Association;
     if (assoc != null)
     {
         var explorerAssociation = AddAssociation(assoc);
         var index = _associations.IndexOf(explorerAssociation);
         _children.Insert(index, explorerAssociation);
     }
     else
     {
         base.InsertChild(efElementToInsert);
     }
 }
 protected override void InsertChild(EFElement efElementToInsert)
 {
     var complexType = efElementToInsert as ComplexType;
     if (complexType != null)
     {
         var explorerComplexType = AddComplexType(complexType);
         var index = _complexTypes.IndexOf(explorerComplexType);
         _children.Insert(index, explorerComplexType);
     }
     else
     {
         base.InsertChild(efElementToInsert);
     }
 }
 protected override void InsertChild(EFElement efElementToInsert)
 {
     var entitySet = efElementToInsert as EntitySet;
     if (entitySet != null)
     {
         var explorerEntitySet = AddEntitySet(entitySet);
         var index = _entitySets.IndexOf(explorerEntitySet);
         _children.Insert(index, explorerEntitySet);
     }
     else
     {
         base.InsertChild(efElementToInsert);
     }
 }
Пример #20
0
        internal static NormalizedName DefaultNameNormalizerForEDM(EFElement parent, string refName)
        {
            var            model          = ModelHelper.GetBaseModelRoot(parent);
            NormalizedName normalizedName = null;

            if (model != null)
            {
                string potentialAliasOrNamespacePart = null;
                string nonAliasOrNamespacePart       = null;
                SeparateRefNameIntoParts(refName, out potentialAliasOrNamespacePart, out nonAliasOrNamespacePart);

                // does the name start with the schema's namespace or alias?
                if (!string.IsNullOrEmpty(potentialAliasOrNamespacePart))
                {
                    refName = nonAliasOrNamespacePart;
                    var symbol = new Symbol(model.NamespaceValue, refName);

                    if (potentialAliasOrNamespacePart.Equals(model.NamespaceValue, StringComparison.CurrentCultureIgnoreCase))
                    {
                        // it starts with the namespace
                        normalizedName = new NormalizedName(symbol, null, model.NamespaceValue, refName);
                    }
                    else if (potentialAliasOrNamespacePart.Equals(model.AliasValue, StringComparison.CurrentCultureIgnoreCase))
                    {
                        // it starts with the alias
                        normalizedName = new NormalizedName(symbol, model.AliasValue, null, refName);
                    }
                }
                else
                {
                    // now, the name doesn't start with the alias or the namespace, so tack on the namespace
                    var symbol = new Symbol(model.NamespaceValue, refName);
                    normalizedName = new NormalizedName(symbol, null, null, refName);
                }
            }
            else
            {
                var symbol = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }
            return(normalizedName);
        }
        protected override void InsertChild(EFElement efElementToInsert)
        {
            var assocEnd = efElementToInsert as AssociationEnd;
            if (assocEnd != null)
            {
                // the ViewModel does not keep track of AssociationEnd elements 
                // but it is not an error - so just return
                return;
            }

            var refConstraint = efElementToInsert as ReferentialConstraint;
            if (refConstraint != null)
            {
                // the ViewModel does not keep track of ReferentialConstraint elements 
                // but it is not an error - so just return
                return;
            }

            base.InsertChild(efElementToInsert);
        }
        internal static NormalizedName DefaultNameNormalizerForEDM(EFElement parent, string refName)
        {
            var model = ModelHelper.GetBaseModelRoot(parent);
            NormalizedName normalizedName = null;
            if (model != null)
            {
                string potentialAliasOrNamespacePart = null;
                string nonAliasOrNamespacePart = null;
                SeparateRefNameIntoParts(refName, out potentialAliasOrNamespacePart, out nonAliasOrNamespacePart);

                // does the name start with the schema's namespace or alias?
                if (!string.IsNullOrEmpty(potentialAliasOrNamespacePart))
                {
                    refName = nonAliasOrNamespacePart;
                    var symbol = new Symbol(model.NamespaceValue, refName);

                    if (potentialAliasOrNamespacePart.Equals(model.NamespaceValue, StringComparison.CurrentCultureIgnoreCase))
                    {
                        // it starts with the namespace
                        normalizedName = new NormalizedName(symbol, null, model.NamespaceValue, refName);
                    }
                    else if (potentialAliasOrNamespacePart.Equals(model.AliasValue, StringComparison.CurrentCultureIgnoreCase))
                    {
                        // it starts with the alias
                        normalizedName = new NormalizedName(symbol, model.AliasValue, null, refName);
                    }
                }
                else
                {
                    // now, the name doesn't start with the alias or the namespace, so tack on the namespace
                    var symbol = new Symbol(model.NamespaceValue, refName);
                    normalizedName = new NormalizedName(symbol, null, null, refName);
                }
            }
            else
            {
                var symbol = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }
            return normalizedName;
        }
        // <summary>
        //     Helper method that determine whether an EFElement is represented in model browser.
        // </summary>
        internal static bool IsDisplayedInExplorer(EFElement efElement)
        {
            // If efElement type is StorageEntityContainer or EFDesignerInfoRoot, don't display it in Model Browser.
            // Note: GetParentOfType() will also return true if self is of passed-in type.
            if (null != efElement.GetParentOfType(typeof(StorageEntityContainer)))
            {
                return false;
            }
                // We do not display Enum type members
            else if (efElement is EnumTypeMember)
            {
                return false;
            }
                // For any Designer objects, check whether the map between the EFElement and ExplorerEFElement exists.
            else if (null != efElement.GetParentOfType(typeof(EFDesignerInfoRoot)))
            {
                return _modelType2ExplorerViewModelType.ContainsKey(efElement.GetType());
            }

            return true;
        }
 internal MappingEFElement GetExistingOrParent(EFElement modelElement)
 {
     MappingEFElement result = null;
     while (result == null
            && modelElement != null)
     {
         if (!_dict.TryGetValue(modelElement, out result))
         {
             modelElement = modelElement.Parent as EFElement;
         }
     }
     return result;
 }
Пример #25
0
 protected override void InsertChild(EFElement efElementToInsert)
 {
     // do nothing
 }
Пример #26
0
 internal LocalNameDefaultableValue(EFElement parent)
     :
     base(parent, EFNameableItem.AttributeName)
 {
 }
Пример #27
0
 internal static NormalizedName DefaultNameNormalizerForDesigner(EFElement parent, string refName)
 {
     return(DefaultNameNormalizerForEDM(parent.Artifact.ConceptualModel(), refName));
 }
Пример #28
0
 // <summary>
 //     Creates a new item.
 // </summary>
 // <param name="context">The current EditingContext; can be null</param>
 // <param name="modelItem">The underlying model item; can be null for view model items that don't have an underlying model item yet.</param>
 // <param name="parent">This item's parent; this should only be null for root level items</param>
 protected MappingEFElement(EditingContext context, EFElement modelItem, MappingEFElement parent)
 {
     _context = context;
     _modelItem = modelItem;
     _parent = parent;
 }
Пример #29
0
 internal virtual void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
 {
 }
Пример #30
0
 // This will be called from the child EFObject's constructor, so not all of the member variables may be hooked up yet.
 // be careful.  De-referencing certain fields may trigger NREs.  Default implementation will append new child elements as the last
 // element.
 internal virtual void GetXLinqInsertPosition(EFElement child, out XNode insertAt, out bool insertBefore)
 {
     insertAt     = XContainer.Elements().LastOrDefault();
     insertBefore = false;
 }
 public MappingFunctionMappingRoot(EditingContext context, EFElement modelItem, MappingEFElement parent)
     : base(context, modelItem, parent)
 {
 }
 internal static NormalizedName DefaultNameNormalizerForDesigner(EFElement parent, string refName)
 {
     return DefaultNameNormalizerForEDM(parent.Artifact.ConceptualModel(), refName);
 }
Пример #33
0
 internal static int EFElementDisplayNameComparison(EFElement elem1, EFElement elem2)
 {
     return(String.Compare(elem1.DisplayName, elem2.DisplayName, StringComparison.CurrentCulture));
 }
        internal static NormalizedName DefaultNameNormalizerForMSL(EFElement parent, string refName)
        {
            var model = MappingModel.GetMappingRoot(parent);

            string potentialAliasOrNamespacePart = null;
            string nonAliasOrNamespacePart = null;
            SeparateRefNameIntoParts(refName, out potentialAliasOrNamespacePart, out nonAliasOrNamespacePart);

            Symbol symbol = null;
            NormalizedName normalizedName = null;

            if (!string.IsNullOrEmpty(potentialAliasOrNamespacePart))
            {
                // see if our type name starts with any of the defined aliases
                var startsWithAlias = false;

                foreach (var a in model.Aliases())
                {
                    if (potentialAliasOrNamespacePart.Equals(a.Key.Value, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (a.State == EFElementState.Parsed)
                        {
                            // alias is only in a parsed state, skip for now and don't add an error
                            // we'll end up looping around again later once its been resolved
                            return new NormalizedName(new Symbol(refName), null, null, refName);
                        }

                        if (a.State != EFElementState.Resolved
                            || a.Value.Status != BindingStatus.Known)
                        {
                            var msg = string.Format(CultureInfo.CurrentCulture, Resources.RESOLVE_UNRESOLVED_ALIAS, refName);
                            var artifactSet = parent.Artifact.ModelManager.GetArtifactSet(parent.Artifact.Uri);
                            var errorInfo = new ErrorInfo(
                                ErrorInfo.Severity.ERROR, msg, parent, ErrorCodes.RESOLVE_UNRESOLVED_ALIAS, ErrorClass.ResolveError);
                            artifactSet.AddError(errorInfo);
                            return new NormalizedName(new Symbol(String.Empty), null, null, refName);
                        }

                        // in the symbol replace alias with the full namespace
                        symbol = new Symbol(a.Value.Target.Namespace.Value, nonAliasOrNamespacePart);
                        normalizedName = new NormalizedName(symbol, a.Key.Value, null, nonAliasOrNamespacePart);

                        startsWithAlias = true;
                        break;
                    }
                }

                if (startsWithAlias == false
                    && model.Artifact.ConceptualModel() != null
                    && model.Artifact.StorageModel() != null)
                {
                    var conceptualNamespace = model.Artifact.ConceptualModel().Namespace.Value;
                    var storageNamespace = model.Artifact.StorageModel().Namespace.Value;
                    var currentNamespace = string.Empty;

                    var convertIt = false;

                    var startsWithConceptualNamespace = false;
                    var startsWithStorageNamespace = false;

                    if (potentialAliasOrNamespacePart.Equals(conceptualNamespace, StringComparison.CurrentCultureIgnoreCase))
                    {
                        startsWithConceptualNamespace = true;
                    }

                    if (potentialAliasOrNamespacePart.Equals(storageNamespace, StringComparison.CurrentCultureIgnoreCase))
                    {
                        startsWithStorageNamespace = true;
                    }

                    if (startsWithConceptualNamespace && startsWithStorageNamespace)
                    {
                        // in this case, the two namespaces start with the same thing and we got a match
                        // on both; for example if there is pubsModel & pubsModel.Store and we are checking
                        // on a string 'pubsModel.Store.Customer'; whichever is longer is the real one
                        if (conceptualNamespace.Length > storageNamespace.Length)
                        {
                            currentNamespace = conceptualNamespace;
                            convertIt = true;
                        }
                        else
                        {
                            currentNamespace = storageNamespace;
                            convertIt = true;
                        }
                    }
                    else if (startsWithConceptualNamespace)
                    {
                        currentNamespace = conceptualNamespace;
                        convertIt = true;
                    }
                    else if (startsWithStorageNamespace)
                    {
                        currentNamespace = storageNamespace;
                        convertIt = true;
                    }

                    if (convertIt)
                    {
                        // convert to our normalized name format
                        symbol = new Symbol(currentNamespace, nonAliasOrNamespacePart);
                        normalizedName = new NormalizedName(symbol, null, currentNamespace, nonAliasOrNamespacePart);
                    }
                }
            }

            if (symbol == null)
            {
                // either there was no Alias or Namespace part or it didn't
                // match any of the known Aliases or Namespaces
                symbol = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }

            return normalizedName;
        }
Пример #35
0
 internal SingleItemBinding(EFElement parent, string attributeName, NameNormalizer nameNormalizer)
     : base(parent, parent.GetAttribute(attributeName))
 {
     _attributeName  = attributeName;
     _nameNormalizer = nameNormalizer;
 }
Пример #36
0
 /// <summary>
 ///     Creates a new DefaultableValue that wraps an XAttribute
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="xattribute"></param>
 protected DefaultableValue(EFElement parent, XAttribute xattribute)
     : base(parent, xattribute)
 {
 }
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "The context argument cannot be null");
            Debug.Assert(StorageEntityType == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(MappingConceptualEntityType.ConceptualEntityType != null, "The parent item isn't set up correctly");
            Debug.Assert(underlyingModelItem != null, "The underlyingModelItem cannot be null");
            var storeEntityType = underlyingModelItem as EntityType;
            Debug.Assert(
                storeEntityType != null,
                "underlyingModelItem must be of type EntityType, actual type = " + underlyingModelItem.GetType().FullName);
            Debug.Assert(storeEntityType.EntityModel.IsCSDL == false, "The storageEntityType must not be a CSDL EntityType");

            Context = context;
            ColumnMappings.Context = context;

            // create a context if we weren't passed one
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateMappingFragment);
            }

            // create the MappingFragment - if we already have a default EntityTypeMapping then just add
            // the MappingFragment to that mapping, otherwise if we already have an IsTypeOf
            // EntityTypeMapping then add the MappingFragment to that, otherwise create an IsTypeOf
            // EntityTypeMapping and add the MappingFragment to that
            var cet = MappingConceptualEntityType.ConceptualEntityType;
            var defaultEtm = ModelHelper.FindEntityTypeMapping(cpc, cet, EntityTypeMappingKind.Default, false);
            var etmKind = (defaultEtm == null ? EntityTypeMappingKind.IsTypeOf : EntityTypeMappingKind.Default);
            var cmd = new CreateMappingFragmentCommand(cet, storeEntityType, etmKind);

            // add post-invoke event to fix up our view model
            cmd.PostInvokeEvent += (o, eventsArgs) =>
                {
                    // fix up our view model
                    ModelItem = storeEntityType;
                    Parent.AddChild(this);

                    // assign the table to our container node as well
                    ColumnMappings.ModelItem = storeEntityType;

                    // now try and do some match ups between the entity and the table
                    var mappingStrategy = ModelHelper.DetermineCurrentInheritanceStrategy(cet);
                    var topMostBaseType = cet.ResolvableTopMostBaseType;
                    foreach (var child in ColumnMappings.Children)
                    {
                        var msp = child as MappingScalarProperty;
                        if (msp != null)
                        {
                            List<Property> properties;
                            if (ModelHelper.FindScalarPropertyPathByLocalName(cet, msp.ColumnName, out properties))
                            {
                                msp.CreateModelItem(cpc, _context, properties);
                            }
                            else if (InheritanceMappingStrategy.TablePerType == mappingStrategy
                                     &&
                                     ModelHelper.FindScalarPropertyPathByLocalName(topMostBaseType, msp.ColumnName, out properties))
                            {
                                msp.CreateModelItem(cpc, _context, properties);
                            }
                        }
                    }
                };

            try
            {
                // now update the model
                var cp = new CommandProcessor(cpc);
                cp.EnqueueCommand(cmd);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                ColumnMappings.ModelItem = null;
                Parent.RemoveChild(this);
                throw;
            }
        }
Пример #38
0
 internal DefaultableValue(EFElement parent, string attributeName, string attributeNamespace)
     : base(parent, parent.GetAttribute(attributeName, attributeNamespace))
 {
     _namespace = attributeNamespace;
     Debug.Assert(parent != null && parent.XElement != null, "Unexpected parent == null or parent.Element == null");
 }
 internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
 {
     var entityProperty = underlyingModelItem as Property;
     Debug.Assert(entityProperty != null, "entityProperty argument cannot be null");
     var properties = new List<Property>(1);
     properties.Add(entityProperty);
     CreateModelItem(cpc, context, properties);
 }
Пример #40
0
        // <summary>
        //     This lets you switch the underlyingModelItem.
        // </summary>
        // <param name="cpc">The transaction to use for this entire process, cannot be null</param>
        // <param name="context">The current EditingContext</param>
        // <param name="newUnderlyingModelItem">The new model item to switch to</param>
        // <param name="deleteModelItemOnly">If 'true' then the MappingEFElement will just have its model item switched, if 'false' then a new MappingEFElement will be create and this one will be deleted</param>
        internal void SwitchModelItem(
            CommandProcessorContext cpc, EditingContext context, EFElement newUnderlyingModelItem, bool deleteModelItemOnly)
        {
            Debug.Assert(cpc != null, "You should send a cpc to this function so that the entire switch is in a single transaction");

            var cmd = new DelegateCommand(
                () =>
                    {
                        if (deleteModelItemOnly)
                        {
                            DeleteModelItemsRecursive(this, cpc);
                            CreateModelItem(cpc, context, newUnderlyingModelItem);
                        }
                        else
                        {
                            Delete(cpc);
                            var newElement = CreateCreatorNodeCopy();
                            newElement.CreateModelItem(cpc, context, newUnderlyingModelItem);
                        }
                    });

            var cp = new CommandProcessor(cpc, cmd);
            cp.Invoke();
        }
 private static bool IsCsdlElement(EFElement element)
 {
     var entityModel = element.GetParentOfType(typeof(BaseEntityModel)) as BaseEntityModel;
     if (entityModel != null
         && entityModel.IsCSDL)
     {
         return false;
     }
     return true;
 }
        internal static MappingEFElement GetNewOrExisting(EditingContext context, EFElement modelElement, MappingEFElement parent)
        {
            MappingEFElement result;

            var xref = GetModelToMappingModelXRef(context);
            result = xref.GetExisting(modelElement);
            if (result != null)
            {
                result.Parent = parent;
            }
            else
            {
                Type viewModelType;
                ModelTypeToViewModelType.TryGetValue(modelElement.GetType(), out viewModelType);
                if (viewModelType == null)
                {
                    // try the base class type
                    ModelTypeToViewModelType.TryGetValue(modelElement.GetType().BaseType, out viewModelType);
                }

                if (viewModelType != null)
                {
                    result = Activator.CreateInstance(viewModelType, context, modelElement, parent) as MappingEFElement;
                    xref.Add(modelElement, result);
                }
                else
                {
                    // implement a special case for entity type
                    // create the correct C- or S-space entity type in our view model
                    var entityType = modelElement as EntityType;
                    if (entityType != null)
                    {
                        var mappingDetailsInfo = context.Items.GetValue<MappingDetailsInfo>();
                        if (mappingDetailsInfo.EntityMappingMode == EntityMappingModes.Tables)
                        {
                            var entityModel = entityType.Parent as BaseEntityModel;
                            Debug.Assert(
                                entityModel != null,
                                "entityType's parent should be an EntityModel but received type "
                                + (entityType.Parent == null ? "NULL" : entityType.Parent.GetType().FullName));

                            if (entityModel.IsCSDL)
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingConceptualEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                            else
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingStorageEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingFunctionEntityType), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }

                    // special case for scalar properties
                    var scalarProperty = modelElement as ScalarProperty;
                    if (scalarProperty != null)
                    {
                        if (scalarProperty.Parent is MappingFragment
                            || scalarProperty.Parent is ComplexProperty)
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingScalarProperty), context, modelElement, parent) as MappingEFElement;
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingEndScalarProperty), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }
                }
            }

            return result;
        }
Пример #43
0
        internal static NormalizedName DefaultNameNormalizerForMSL(EFElement parent, string refName)
        {
            var model = MappingModel.GetMappingRoot(parent);

            string potentialAliasOrNamespacePart = null;
            string nonAliasOrNamespacePart       = null;

            SeparateRefNameIntoParts(refName, out potentialAliasOrNamespacePart, out nonAliasOrNamespacePart);

            Symbol         symbol         = null;
            NormalizedName normalizedName = null;

            if (!string.IsNullOrEmpty(potentialAliasOrNamespacePart))
            {
                // see if our type name starts with any of the defined aliases
                var startsWithAlias = false;

                foreach (var a in model.Aliases())
                {
                    if (potentialAliasOrNamespacePart.Equals(a.Key.Value, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (a.State == EFElementState.Parsed)
                        {
                            // alias is only in a parsed state, skip for now and don't add an error
                            // we'll end up looping around again later once its been resolved
                            return(new NormalizedName(new Symbol(refName), null, null, refName));
                        }

                        if (a.State != EFElementState.Resolved ||
                            a.Value.Status != BindingStatus.Known)
                        {
                            var msg         = string.Format(CultureInfo.CurrentCulture, Resources.RESOLVE_UNRESOLVED_ALIAS, refName);
                            var artifactSet = parent.Artifact.ModelManager.GetArtifactSet(parent.Artifact.Uri);
                            var errorInfo   = new ErrorInfo(
                                ErrorInfo.Severity.ERROR, msg, parent, ErrorCodes.RESOLVE_UNRESOLVED_ALIAS, ErrorClass.ResolveError);
                            artifactSet.AddError(errorInfo);
                            return(new NormalizedName(new Symbol(String.Empty), null, null, refName));
                        }

                        // in the symbol replace alias with the full namespace
                        symbol         = new Symbol(a.Value.Target.Namespace.Value, nonAliasOrNamespacePart);
                        normalizedName = new NormalizedName(symbol, a.Key.Value, null, nonAliasOrNamespacePart);

                        startsWithAlias = true;
                        break;
                    }
                }

                if (startsWithAlias == false &&
                    model.Artifact.ConceptualModel() != null &&
                    model.Artifact.StorageModel() != null)
                {
                    var conceptualNamespace = model.Artifact.ConceptualModel().Namespace.Value;
                    var storageNamespace    = model.Artifact.StorageModel().Namespace.Value;
                    var currentNamespace    = string.Empty;

                    var convertIt = false;

                    var startsWithConceptualNamespace = false;
                    var startsWithStorageNamespace    = false;

                    if (potentialAliasOrNamespacePart.Equals(conceptualNamespace, StringComparison.CurrentCultureIgnoreCase))
                    {
                        startsWithConceptualNamespace = true;
                    }

                    if (potentialAliasOrNamespacePart.Equals(storageNamespace, StringComparison.CurrentCultureIgnoreCase))
                    {
                        startsWithStorageNamespace = true;
                    }

                    if (startsWithConceptualNamespace && startsWithStorageNamespace)
                    {
                        // in this case, the two namespaces start with the same thing and we got a match
                        // on both; for example if there is pubsModel & pubsModel.Store and we are checking
                        // on a string 'pubsModel.Store.Customer'; whichever is longer is the real one
                        if (conceptualNamespace.Length > storageNamespace.Length)
                        {
                            currentNamespace = conceptualNamespace;
                            convertIt        = true;
                        }
                        else
                        {
                            currentNamespace = storageNamespace;
                            convertIt        = true;
                        }
                    }
                    else if (startsWithConceptualNamespace)
                    {
                        currentNamespace = conceptualNamespace;
                        convertIt        = true;
                    }
                    else if (startsWithStorageNamespace)
                    {
                        currentNamespace = storageNamespace;
                        convertIt        = true;
                    }

                    if (convertIt)
                    {
                        // convert to our normalized name format
                        symbol         = new Symbol(currentNamespace, nonAliasOrNamespacePart);
                        normalizedName = new NormalizedName(symbol, null, currentNamespace, nonAliasOrNamespacePart);
                    }
                }
            }

            if (symbol == null)
            {
                // either there was no Alias or Namespace part or it didn't
                // match any of the known Aliases or Namespaces
                symbol         = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }

            return(normalizedName);
        }