示例#1
0
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            NormalizedName normalizedName = null;

            if (refName == null)
            {
                return(null);
            }

            var modfunc = parent as ModificationFunction;

            if (modfunc != null)
            {
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(modfunc, refName);
            }
            else
            {
                var parentItem = parent;
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentItem, refName);
            }

            if (normalizedName == null)
            {
                var symbol = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }

            return(normalizedName);
        }
示例#2
0
        /// <summary>
        ///     We override this method because we need to do some extra things before
        ///     the normal PreInvoke gets called and our antiDeps are removed
        /// </summary>
        /// <param name="cpc"></param>
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            // remove the type of all related complex properties (so they won't get deleted)
            foreach (var property in EFElement.GetAntiDependenciesOfType <ComplexConceptualProperty>())
            {
                foreach (var cp in property.GetAntiDependenciesOfType <ComplexProperty>())
                {
                    // also delete all related ComplexProperty mappings
                    DeleteInTransaction(cpc, cp);
                }

                // rebind property.ComplexType to what it is bound to now. This adds a change to that SingleItemBinding
                // to the list of actions that this command takes (but note that its RefValue does not change).
                // This is important so that if Undo is called on this command that SingleItemBinding will be rebound back
                // to the re-added ComplexType. It is likely that this command will also delete ComplexProperty mappings (see just above).
                // If an Undo happens the resolve step for the ScalarProperty children of those mappings will fail if at
                // that time the property.ComplexType SingleItemBinding is not resolved.
                if (property.ComplexType.Target != null)
                {
                    // have to set to null and then reset because just setting to the existing value is shortcircuited out
                    property.ComplexType.SetRefName(null);
                    property.ComplexType.SetRefName(property.ComplexType.Target);
                    property.ComplexType.Rebind();
                }

                // unbind the property.ComplexType but leave the reference pointing to the soon to be non-existent ComplexType
                // so that the error message tells the user what has happened (and what they can do to fix it)
                property.ComplexType.Unbind();
                _complexPropertiesToResolve.Add(property);
            }

            base.PreInvoke(cpc);
        }
 /// <summary>
 ///     Allow the construction of a complex property at a specified position.
 /// </summary>
 /// <param name="parent">Property's Parent</param>
 /// <param name="element">Property's XElement</param>
 /// <param name="insertPosition">Information where the property should be inserted to. If the parameter is null, the property will be placed as the last property of the entity.</param>
 internal ComplexConceptualProperty(EFElement parent, XElement element, InsertPropertyPosition insertPosition)
     : base(parent, element, insertPosition)
 {
     Debug.Assert(
         parent is ConceptualEntityType || parent is ComplexType || parent == null,
         "Parent of ConceptualProperty should be either ConceptualEntityType or ComplexType (or null for testing)");
 }
示例#4
0
 /// <summary>
 ///     used to create normal nodes in the ViewModel tree
 /// </summary>
 /// <param name="modelItem">corresponding item in the Model</param>
 /// <param name="parent">parent item in the ViewModel tree</param>
 protected ExplorerEFElement(EditingContext context, EFElement modelItem, ExplorerEFElement parent)
 {
     _context            = context;
     _modelItem          = modelItem;
     _parent             = parent;
     _hasLoadedFromModel = false;
 }
示例#5
0
 internal DiagramIdDefaultableValue(EFElement parent)
     : base(parent, AttributeId)
 {
     // TODO: this is a temporary fix so that the old edmx file (doesn't contain diagramid) could still be loaded.
     // This should be go away once we implement upgrade/diagram fixup logic.
     _defaultValue = Guid.NewGuid().ToString("N");
 }
        protected virtual void AddAnnotations(AnnotatableElementClipboardFormat clipboardFormat, EFElement element)
        {
            foreach (var t in clipboardFormat.AdditionalAttributes)
            {
                var name = t.Item1;
                var value = t.Item2;
                var xn = XName.Get(name);
                var xa = new XAttribute(xn, value);
                element.XElement.Add(xa);
            }

            foreach (var s in clipboardFormat.AdditionalElements)
            {
                try
                {
                    var d = XDocument.Parse(s, LoadOptions.PreserveWhitespace);
                    var xe = d.Root;
                    xe.Remove();
                    element.XElement.Add(xe);
                }
                catch (XmlException)
                {
                    // ignore an XmlException.  There was probalby a problem parsing.
                }
            }
        }
示例#7
0
 /// <summary>
 ///     Create a Conceptual property at a specified position.
 /// </summary>
 /// <param name="parent">Property's Parent. The value is either ConceptualEntityTYpe or a ComplexType.</param>
 /// <param name="element">Property's XElement</param>
 /// <param name="insertPosition">Information where the property should be inserted to. If the parameter is null, the property will be placed as the last property of the entity.</param>
 public ConceptualProperty(EFElement parent, XElement element, InsertPropertyPosition insertPosition)
     : base(parent, element, insertPosition)
 {
     Debug.Assert(
         parent is ConceptualEntityType || parent is ComplexType,
         "Parent of ConceptualProperty should be either ConceptualEntityType or ComplexType");
 }
示例#8
0
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return(null);
            }

            var pr         = parent as PropertyRef;
            var key        = pr.Parent as Key;
            var entityType = key.Parent as EntityType;

            var    em     = entityType.Parent as BaseEntityModel;
            Symbol symbol = null;

            if (em != null)
            {
                symbol = new Symbol(em.NamespaceValue, entityType.LocalName.Value, refName);
            }

            if (symbol == null)
            {
                symbol = new Symbol(refName);
            }

            var normalizedName = new NormalizedName(symbol, null, null, refName);

            return(normalizedName);
        }
        internal ExplorerEFElement GetExisting(EFElement efElement)
        {
            ExplorerEFElement result;

            _dict.TryGetValue(efElement, out result);
            return(result);
        }
示例#10
0
 internal QueryView(EFElement parent, XElement element)
     : base(parent, element)
 {
     Debug.Assert(
         parent is EntitySetMapping || parent is AssociationSetMapping,
         "parent should be an EntitySetMapping or an AssociationSetMapping");
 }
示例#11
0
        internal MappingEFElement GetExisting(EFElement modelElement)
        {
            MappingEFElement result;

            _dict.TryGetValue(modelElement, out result);
            return(result);
        }
        /// <summary>
        ///     this will always return the preceding sibling that appears before the first sibling with a different namespace.
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        private static XElement GetLastSiblingOfMyNamespace(EFElement parent)
        {
            string expectedNamespace;

            if (ModelHelper.GetBaseModelRoot(parent).IsCSDL)
            {
                expectedNamespace = SchemaManager.GetCSDLNamespaceName(parent.Artifact.SchemaVersion);
            }
            else
            {
                expectedNamespace = SchemaManager.GetSSDLNamespaceName(parent.Artifact.SchemaVersion);
            }

            var      c          = parent.XContainer;
            XElement predecesor = null;

            foreach (var e in c.Elements())
            {
                if (e.Name.NamespaceName.Equals(expectedNamespace, StringComparison.OrdinalIgnoreCase))
                {
                    predecesor = e;
                }
                else
                {
                    break;
                }
            }
            return(predecesor);
        }
示例#13
0
 protected virtual void InsertChild(EFElement efElementToInsert)
 {
     throw new InvalidOperationException(
               string.Format(
                   CultureInfo.CurrentCulture,
                   Resources.BadInsertBadChildType, efElementToInsert.GetType().FullName, GetType().FullName));
 }
示例#14
0
        // 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 static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return(null);
            }

            Symbol symbol = null;

            var fi      = parent as FunctionImport;
            var func    = parent as Function;
            var fsp     = parent as FunctionScalarProperty;
            var modFunc = parent as ModificationFunction;

            if (fi != null)
            {
                // if we are in the CSDL, build it's normalized name based on the EC name
                // FunctionImports live in the entity container
                var ec = fi.Parent as BaseEntityContainer;
                if (ec != null)
                {
                    symbol = new Symbol(ec.EntityContainerName, fi.LocalName.Value, refName);
                }
            }
            else if (func != null)
            {
                // if we are in the SSDL, then build the name based on the namespace
                // Functions are top level types like EntityType and Association
                symbol = new Symbol(((BaseEntityModel)func.Parent).NamespaceValue, func.LocalName.Value, refName);
            }
            else if (fsp != null)
            {
                // this FunctionScalarProperty could be right under the function, nested inside an AssociationEnd,
                // or N levels deep inside a complex type hierarchy
                var mod = fsp.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction;
                Debug.Assert(mod != null, "Failed to get a pointer to the ModificationFunction");

                if (mod != null)
                {
                    // there is a reference to this param in a function mapping, these always
                    // point back to a parameter in a function, i.e., something in the SSDL
                    symbol = GetSymbolBasedOnModificationFunction(parent.Artifact.ArtifactSet, mod, refName);
                }
            }
            else if (null != modFunc)
            {
                symbol = GetSymbolBasedOnModificationFunction(parent.Artifact.ArtifactSet, modFunc, refName);
            }

            if (symbol == null)
            {
                symbol = new Symbol(refName);
            }

            var normalizedName = new NormalizedName(symbol, null, null, refName);

            return(normalizedName);
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            NormalizedName normalizedName = null;

            if (refName == null)
            {
                return null;
            }

            var parentEndProperty = parent as EndProperty;
            if (parentEndProperty != null)
            {
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parentEndProperty, refName);
            }
            else
            {
                var parentItem = parent;
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentItem, refName);
            }

            if (normalizedName == null)
            {
                normalizedName = new NormalizedName(new Symbol(refName), null, null, refName);
            }

            return normalizedName;
        }
示例#17
0
 /// <summary>
 ///     Allow the construction of a complex property at a specified position.
 /// </summary>
 /// <param name="parent">Property's Parent</param>
 /// <param name="element">Property's XElement</param>
 /// <param name="insertPosition">Information where the property should be inserted to. If the parameter is null, the property will be placed as the last property of the entity.</param>
 internal ComplexConceptualProperty(EFElement parent, XElement element, InsertPropertyPosition insertPosition)
     : base(parent, element, insertPosition)
 {
     Debug.Assert(
         parent is ConceptualEntityType || parent is ComplexType || parent == null,
         "Parent of ConceptualProperty should be either ConceptualEntityType or ComplexType (or null for testing)");
 }
示例#18
0
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            NormalizedName normalizedName = null;

            if (refName == null)
            {
                return(null);
            }

            var parentEndProperty = parent as EndProperty;

            if (parentEndProperty != null)
            {
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parentEndProperty, refName);
            }
            else
            {
                var parentItem = parent;
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentItem, refName);
            }

            if (normalizedName == null)
            {
                normalizedName = new NormalizedName(new Symbol(refName), null, null, refName);
            }

            return(normalizedName);
        }
示例#19
0
        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));
            }
        }
示例#20
0
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var pr = parent as PropertyRef;
            var key = pr.Parent as Key;
            var entityType = key.Parent as EntityType;

            var em = entityType.Parent as BaseEntityModel;
            Symbol symbol = null;
            if (em != null)
            {
                symbol = new Symbol(em.NamespaceValue, entityType.LocalName.Value, refName);
            }

            if (symbol == null)
            {
                symbol = new Symbol(refName);
            }

            var normalizedName = new NormalizedName(symbol, null, null, refName);

            return normalizedName;
        }
示例#21
0
 internal Condition(EFElement parent, XElement element)
     : base(parent, element)
 {
     Debug.Assert(
         parent is MappingFragment || parent is AssociationSetMapping || parent is ComplexProperty || parent == null,
         "parent should be a MappingFragment or an AssociationSetMapping or a ComplexProperty (or null for testing)");
 }
        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));
            }
        }
示例#23
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();
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            NormalizedName normalizedName = null;

            if (refName == null)
            {
                return null;
            }

            var modfunc = parent as ModificationFunction;
            if (modfunc != null)
            {
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(modfunc, refName);
            }
            else
            {
                var parentItem = parent;
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentItem, refName);
            }

            if (normalizedName == null)
            {
                var symbol = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }

            return normalizedName;
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            // cast the parameter to what this really is
            var end = parent as AssociationSetEnd;
            Debug.Assert(end != null, "parent should be an AssociationSetEnd");

            // get the assoc set
            var set = end.Parent as AssociationSet;
            Debug.Assert(set != null, "association set end parent should be an AssociationSet");

            // get the entity container name
            string entityContainerName = null;
            var ec = set.Parent as BaseEntityContainer;
            if (ec != null)
            {
                entityContainerName = ec.EntityContainerName;
            }

            Debug.Assert(ec != null, "AssociationSet parent should be a subclass of BaseEntityContainer");

            // the normalized name for an EnitySet is 'EntityContainerName + # + EntitySetName'
            var symbol = new Symbol(entityContainerName, refName);

            var normalizedName = new NormalizedName(symbol, null, null, refName);
            return normalizedName;
        }
示例#26
0
        private static FunctionComplexProperty CreateNewFunctionComplexProperty(EFElement parent, ComplexConceptualProperty property)
        {
            Debug.Assert(property != null,
                         "CreateFunctionComplexPropertyCommand.CreateNewFunctionComplexProperty() received null property");
            Debug.Assert
                (property.ComplexType.Target != null,
                typeof(CreateFunctionComplexPropertyCommand).Name
                + ".CreateNewFunctionComplexProperty() received property with null ComplexType.Target");

            // actually create it in the XLinq tree
            var fcp = new FunctionComplexProperty(parent, null);

            fcp.Name.SetRefName(property);
            fcp.TypeName.SetRefName(property.ComplexType.Target);

            XmlModelHelper.NormalizeAndResolve(fcp);

            if (fcp == null)
            {
                throw new ItemCreationFailureException();
            }

            Debug.Assert(
                fcp.Name.Target != null && fcp.Name.Target.LocalName.Value == fcp.Name.RefName,
                (fcp.Name.Target == null
                     ? "Broken property resolution for FunctionComplexProperty " + fcp.ToPrettyString() + ": null Target"
                     : "Broken property resolution for FunctionComplexProperty " + fcp.ToPrettyString() + ": Target.LocalName = "
                 + fcp.Name.Target.LocalName.Value + ", RefName = " + fcp.Name.RefName));

            return(fcp);
        }
 /// <summary>
 ///     Create a Conceptual property at a specified position.
 /// </summary>
 /// <param name="parent">Property's Parent. The value is either ConceptualEntityTYpe or a ComplexType.</param>
 /// <param name="element">Property's XElement</param>
 /// <param name="insertPosition">Information where the property should be inserted to. If the parameter is null, the property will be placed as the last property of the entity.</param>
 public ConceptualProperty(EFElement parent, XElement element, InsertPropertyPosition insertPosition)
     : base(parent, element, insertPosition)
 {
     Debug.Assert(
         parent is ConceptualEntityType || parent is ComplexType,
         "Parent of ConceptualProperty should be either ConceptualEntityType or ComplexType");
 }
示例#28
0
 internal QueryView(EFElement parent, XElement element)
     : base(parent, element)
 {
     Debug.Assert(
         parent is EntitySetMapping || parent is AssociationSetMapping,
         "parent should be an EntitySetMapping or an AssociationSetMapping");
 }
        /// <summary>
        ///     this will always return the preceding sibling that appears before the first sibling with a different namespace.
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        private static XElement GetLastSiblingOfMyNamespace(EFElement parent)
        {
            string expectedNamespace;
            if (ModelHelper.GetBaseModelRoot(parent).IsCSDL)
            {
                expectedNamespace = SchemaManager.GetCSDLNamespaceName(parent.Artifact.SchemaVersion);
            }
            else
            {
                expectedNamespace = SchemaManager.GetSSDLNamespaceName(parent.Artifact.SchemaVersion);
            }

            var c = parent.XContainer;
            XElement predecesor = null;
            foreach (var e in c.Elements())
            {
                if (e.Name.NamespaceName.Equals(expectedNamespace, StringComparison.OrdinalIgnoreCase))
                {
                    predecesor = e;
                }
                else
                {
                    break;
                }
            }
            return predecesor;
        }
示例#30
0
文件: Program.cs 项目: unibihac/bhmke
        private static List <EFElement> Problem1(List <ElasticNode> nodes, ref double E, ref double nu, ref double t)
        {
            //material property
            E  = 2.0e+11;
            nu = 0.3;
            t  = 0.01;

            var e  = new List <EFElement>();
            var e1 = new EFElement(1, MKEElementType.triangle, MKEPlaneType.stress);
            var e2 = new EFElement(2, MKEElementType.triangle, MKEPlaneType.stress);


            var n1 = new ElasticNode();

            n1.id = 1;
            n1.x1 = 0;
            n1.x2 = 0;
            //BC
            n1.u = 0;
            n1.v = 0;
            nodes.Add(n1);

            var n2 = new ElasticNode();

            n2.id = 2;
            n2.x1 = 0;
            n2.x2 = 0.10;
            //BC
            n2.u = 0;
            n2.v = 0;
            nodes.Add(n2);

            var n3 = new ElasticNode();

            n3.id = 3;
            n3.x1 = 0.20;
            n3.x2 = 0.10;
            //BC
            n3.fx = 5000; //BC
            n3.fy = 0;    //BC
            nodes.Add(n3);

            var n4 = new ElasticNode();

            n4.id = 4;
            n4.x1 = 0.20;
            n4.x2 = 0;
            //BC
            n4.fx = 5000; //BC
            n4.fy = 0;    //BC
            nodes.Add(n4);

            e1.nodes.Add(n1); e1.nodes.Add(n3); e1.nodes.Add(n2);
            e2.nodes.Add(n1); e2.nodes.Add(n4); e2.nodes.Add(n3);
            //
            e.Add(e1);
            e.Add(e2);
            return(e);
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            Symbol symbol = null;

            var fi = parent as FunctionImport;
            var func = parent as Function;
            var fsp = parent as FunctionScalarProperty;
            var modFunc = parent as ModificationFunction;

            if (fi != null)
            {
                // if we are in the CSDL, build it's normalized name based on the EC name
                // FunctionImports live in the entity container
                var ec = fi.Parent as BaseEntityContainer;
                if (ec != null)
                {
                    symbol = new Symbol(ec.EntityContainerName, fi.LocalName.Value, refName);
                }
            }
            else if (func != null)
            {
                // if we are in the SSDL, then build the name based on the namespace
                // Functions are top level types like EntityType and Association
                symbol = new Symbol(((BaseEntityModel)func.Parent).NamespaceValue, func.LocalName.Value, refName);
            }
            else if (fsp != null)
            {
                // this FunctionScalarProperty could be right under the function, nested inside an AssociationEnd, 
                // or N levels deep inside a complex type hierarchy
                var mod = fsp.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction;
                Debug.Assert(mod != null, "Failed to get a pointer to the ModificationFunction");

                if (mod != null)
                {
                    // there is a reference to this param in a function mapping, these always
                    // point back to a parameter in a function, i.e., something in the SSDL
                    symbol = GetSymbolBasedOnModificationFunction(parent.Artifact.ArtifactSet, mod, refName);
                }
            }
            else if (null != modFunc)
            {
                symbol = GetSymbolBasedOnModificationFunction(parent.Artifact.ArtifactSet, modFunc, refName);
            }

            if (symbol == null)
            {
                symbol = new Symbol(refName);
            }

            var normalizedName = new NormalizedName(symbol, null, null, refName);
            return normalizedName;
        }
示例#32
0
        internal MappingLovEFElement(EFElement modelElement, string displayName)
        {
            Debug.Assert(modelElement != null, "null modelElement");
            Debug.Assert(displayName != null, "null displayName");

            _object      = modelElement;
            _displayName = displayName;
        }
示例#33
0
 internal FunctionScalarProperty(EFElement parent, XElement element)
     : base(parent, element)
 {
     Debug.Assert(
         (parent as ModificationFunction) != null || parent is FunctionAssociationEnd || parent is FunctionComplexProperty,
         "parent should be a " + typeof(ModificationFunction).Name +
         " or a FunctionAssociationEnd or a FunctionComplexProperty");
 }
示例#34
0
 internal ScalarProperty(EFElement parent, XElement element)
     : base(parent, element)
 {
     Debug.Assert(
         parent is MappingFragment || parent is EndProperty || parent is ComplexProperty,
         "parent should be a " + typeof(MappingFragment).Name +
         " or an EndProperty or a ComplexProperty");
 }
示例#35
0
 private static void ValidateEFElement(EFElement element)
 {
     Debug.Assert(element != null, string.Format(CultureInfo.CurrentCulture, "You must pass in an {0}.", typeof(EFElement).Name));
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
 }
示例#36
0
 internal ScalarProperty(EFElement parent, XElement element)
     : base(parent, element)
 {
     Debug.Assert(
         parent is MappingFragment || parent is EndProperty || parent is ComplexProperty,
         "parent should be a " + typeof(MappingFragment).Name +
         " or an EndProperty or a ComplexProperty");
 }
示例#37
0
 internal void InsertChildIfLoaded(EFElement efElementToInsert)
 {
     // only insert this child if we have already loaded from model
     // if we have not yet loaded then this child will be picked up
     // next time Children is called
     if (_hasLoadedFromModel)
     {
         InsertChild(efElementToInsert);
     }
 }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return(null);
            }

            var parentItem = parent.Parent as EFElement;

            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            // some asserts to verify we're using this name normalizer in the correct context

            Debug.Assert(
                parentItem.GetParentOfType(typeof(ComplexProperty)) == null,
                "Use the PropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionComplexProperty)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(EntityTypeMapping)) == null,
                "Use the PropertyMappingNameNormalizer or FunctionPropertyMappingNameNormalizer to normalize children of "
                + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(AssociationSetMapping)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);
            Debug.Assert(
                parentItem.GetParentOfType(typeof(EndProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            //
            // try to normalize for a FunctionImportTypeMapping
            //
            var fitm = parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) as FunctionImportTypeMapping;

            if (fitm != null)
            {
                if (fitm.TypeName.Status == BindingStatus.Known)
                {
                    var symbol = new Symbol(fitm.TypeName.Target.NormalizedName, refName);
                    return(new NormalizedName(symbol, null, null, refName));
                }
            }

            return(new NormalizedName(new Symbol(refName), null, null, refName));
        }
示例#39
0
        // <summary>
        //     Does the work of actually showing the view model in the Trid.
        // </summary>
        private void DoShowMappingDetailsForElement(EFElement element)
        {
            Debug.Assert(element != null, "A null element was passed to DoShowMappingDetailsForElement()");
            if (element != null)
            {
                var xref           = Context.Items.GetValue <ModelToMappingModelXRef>();
                var mappingElement = xref.GetExisting(element);

                Debug.Assert(mappingElement != null, "Failed to get ViewModel element for the passed in Model element");
                if (mappingElement != null)
                {
                    TreeControl.BatchDrawItem = true;
                    try
                    {
                        var invalidate = DoSelectionChanged(mappingElement);
                        if (invalidate)
                        {
                            // local shortcuts
                            var tree       = TreeProvider;
                            var rootBranch = tree.Root;

                            if (rootBranch != null &&
                                !WatermarkVisible)
                            {
                                // expand all nodes
                                for (var i = 0; i < tree.VisibleItemCount; i++)
                                {
                                    if (tree.IsExpandable(i, 0) &&
                                        !tree.IsExpanded(i, 0))
                                    {
                                        tree.ToggleExpansion(i, 0);
                                    }
                                }

                                // scroll tree to top
                                TreeControl.CurrentIndex = 0;

                                UpdateTitleBar(mappingElement.Name);
                            }
                        }

                        // if the watermark is showing and selection changed, update the title bar
                        if (WatermarkVisible && invalidate)
                        {
                            UpdateTitleBar(null);
                        }
                    }
                    finally
                    {
                        TreeControl.BatchDrawItem = false;
                    }
                }
            }
        }
        private static bool IsCsdlElement(EFElement element)
        {
            var entityModel = element.GetParentOfType(typeof(BaseEntityModel)) as BaseEntityModel;

            if (entityModel != null &&
                entityModel.IsCSDL)
            {
                return(false);
            }
            return(true);
        }
示例#41
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);
            }
        }
 // This will be called from the child EFObject's constructor, so not all of the member variables may be hooked up yet. 
 // be careful.  referencing certain fields may cause null-reference exceptions 
 internal override void GetXLinqInsertPosition(EFElement child, out XNode insertAt, out bool insertBefore)
 {
     if (child is Documentation)
     {
         // base class will return correct position to insert the Documentation element - these always need to go first
         base.GetXLinqInsertPosition(child, out insertAt, out insertBefore);
     }
     else
     {
         AnnotatableElement.GetInsertPointForAnnotatableElements(this, out insertAt, out insertBefore);
     }
 }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var parentItem = parent.Parent as EFElement;
            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            // some asserts to verify we're using this name normalizer in the correct context

            Debug.Assert(
                parentItem.GetParentOfType(typeof(ComplexProperty)) == null,
                "Use the PropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionComplexProperty)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(EntityTypeMapping)) == null,
                "Use the PropertyMappingNameNormalizer or FunctionPropertyMappingNameNormalizer to normalize children of "
                + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(AssociationSetMapping)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);
            Debug.Assert(
                parentItem.GetParentOfType(typeof(EndProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            //
            // try to normalize for a FunctionImportTypeMapping
            //
            var fitm = parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) as FunctionImportTypeMapping;
            if (fitm != null)
            {
                if (fitm.TypeName.Status == BindingStatus.Known)
                {
                    var symbol = new Symbol(fitm.TypeName.Target.NormalizedName, refName);
                    return new NormalizedName(symbol, null, null, refName);
                }
            }

            return new NormalizedName(new Symbol(refName), null, null, refName);
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var entityContainerName = string.Empty;

            var parentAssociationSet = parent as AssociationSet;
            var parentAssociationSetMapping = parent as AssociationSetMapping;
            var parentFunctionAssociationEnd = parent as FunctionAssociationEnd;

            if (parentAssociationSet != null)
            {
                // are we trying to normalize the name of actual association set in the EC?
                var ec = parentAssociationSet.Parent as BaseEntityContainer;
                if (ec != null)
                {
                    entityContainerName = ec.LocalName.Value;
                }
            }
            else if (parentAssociationSetMapping != null
                     || parentFunctionAssociationEnd != null)
            {
                // we need to resolve a reference from the MSL to the AssociationSet
                var ecm = parent.GetParentOfType(typeof(EntityContainerMapping)) as EntityContainerMapping;
                if (ecm != null)
                {
                    entityContainerName = ecm.CdmEntityContainer.RefName;
                }
            }

            Symbol symbol = null;
            if (!string.IsNullOrEmpty(entityContainerName))
            {
                symbol = new Symbol(entityContainerName, refName);
            }

            if (symbol == null)
            {
                symbol = new Symbol(refName);
            }

            var normalizedName = new NormalizedName(symbol, null, null, refName);
            return normalizedName;
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var parentAssociationSetEnd = parent as AssociationSetEnd;
            var parentEndProperty = parent as EndProperty;
            var parentFunctionAssociationEnd = parent as FunctionAssociationEnd;

            var symbol = new Symbol();

            if (parentAssociationSetEnd != null)
            {
                // we are coming up with the object's name for the first time
                var assocSet = parentAssociationSetEnd.Parent as AssociationSet;
                if (assocSet != null)
                {
                    var ec = assocSet.Parent as BaseEntityContainer;
                    if (ec != null)
                    {
                        symbol = new Symbol(ec.EntityContainerName, assocSet.LocalName.Value, refName);
                    }
                }
            }
            else if (parentEndProperty != null)
            {
                // this end is inside an AssociationSetMapping, so we derive the end's name based on the set's name
                var asm = parentEndProperty.Parent as AssociationSetMapping;
                if (asm.Name.Status == BindingStatus.Known)
                {
                    symbol = new Symbol(asm.Name.Target.NormalizedName, refName);
                }
            }
            else if (parentFunctionAssociationEnd != null)
            {
                // this end is inside of a function mapping
                if (parentFunctionAssociationEnd.AssociationSet.Status == BindingStatus.Known)
                {
                    symbol = new Symbol(parentFunctionAssociationEnd.AssociationSet.Target.NormalizedName, refName);
                }
            }

            var normalizedName = new NormalizedName(symbol, null, null, refName);
            return normalizedName;
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            NormalizedName normalizedName = null;

            var parentAssociation = parent as Association;
            var parentAssociationSet = parent as AssociationSet;
            var parentAssociationSetMapping = parent as AssociationSetMapping;
            var parentNavigationProperty = parent as NavigationProperty;

            if (parentAssociation != null)
            {
                var model = parentAssociation.Parent as BaseEntityModel;
                if (model != null)
                {
                    // we are coming up with the object's name for the first time
                    var symbol = new Symbol(model.NamespaceValue, parentAssociation.LocalName.Value);
                    normalizedName = new NormalizedName(symbol, null, null, parentAssociation.LocalName.Value);
                }
            }
            else if (parentAssociationSet != null)
            {
                // we are wanting to resolve a reference from an Association Set that may or may not
                // use the alias defined in the EntityModel
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentAssociationSet, refName);
            }
            else if (parentAssociationSetMapping != null)
            {
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parentAssociationSetMapping, refName);
            }
            else if (parentNavigationProperty != null)
            {
                normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentNavigationProperty, refName);
            }

            if (normalizedName == null)
            {
                var symbol = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }

            return normalizedName;
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var entityContainerName = string.Empty;

            var parentFunctionImport = parent as FunctionImport;
            var parentFunctionImportMapping = parent as FunctionImportMapping;

            Symbol symbol = null;

            // are we trying to normalize the name of actual FunctionImport in the EC?
            if (parentFunctionImport != null)
            {
                var ec = parentFunctionImport.Parent as BaseEntityContainer;
                if (ec != null)
                {
                    entityContainerName = ec.EntityContainerName;
                }
            }
            else if (parentFunctionImportMapping != null)
            {
                var ecm = parentFunctionImportMapping.Parent as EntityContainerMapping;
                if (ecm != null)
                {
                    entityContainerName = ecm.CdmEntityContainer.RefName;
                }
            }

            if (!string.IsNullOrEmpty(entityContainerName))
            {
                symbol = new Symbol(entityContainerName, refName);
            }

            if (symbol == null)
            {
                symbol = new Symbol(refName);
            }

            var normalizedName = new NormalizedName(symbol, null, null, refName);
            return normalizedName;
        }
 internal static void GetInsertPointForAnnotatableElements(EFElement parent, out XNode insertPosition, out bool insertBefore)
 {
     if (parent.XContainer.Elements().Count() == 0)
     {
         insertPosition = null;
         insertBefore = false;
     }
     else
     {
         insertPosition = GetLastSiblingOfMyNamespace(parent);
         insertBefore = false;
         if (insertPosition == null)
         {
             insertPosition = parent.XContainer.Elements().First();
             insertBefore = true;
         }
     }
 }
        // an example use of an alias in a typename
        //
        //  <Alias cdm:Key="CNorthwind" cdm:Value="Test.Simple.Model" />
        //  ...
        //    <EntityTypeMapping cdm:TypeName="CNorthwind.CCategory">
        //      ...
        // 
        // we need to resolve CNorthwind.CCategory to Test.Simple.Model.CCategory so we
        // can look it up in the symbol table
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            // go get the needed parent objects
            var parentItem = parent;
            Debug.Assert(parentItem != null, "parent should not be an EFElement");

            refName = refName.Trim();
            refName = EntityTypeMapping.StripOffIsTypeOf(refName);

            return EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parentItem, refName);
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            NormalizedName normalizedName = null;

            // cast the parameter to what this really is
            var end = parent as AssociationSetEnd;
            Debug.Assert(end != null, "parent should be an AssociationSetEnd");

            // get the assoc set
            var set = end.Parent as AssociationSet;
            Debug.Assert(set != null, "end.Parent should be an AssociationSet");

            // the "Role" attribute points to a "Role" attribute in an Association End.  The trick
            // is that this attribute is optional and defaults to the raw name of the Entity pointed
            // to by the "Type" attribute of the Association End, and that might not be fully resolved
            // yet.  So, lets just get the Normalized Name for the assocation from the assocation set 
            //and tack on the Role name.
            if (set.Association.Status == BindingStatus.Known)
            {
                var assocNameRef = AssociationNameNormalizer.NameNormalizer(set.Association.Target, set.Association.RefName);
                var assocSymbol = assocNameRef.Symbol;
                var assocSetEndRoleSymbol = new Symbol(assocSymbol, refName);
                normalizedName = new NormalizedName(assocSetEndRoleSymbol, null, null, refName);
            }

            if (normalizedName == null)
            {
                var symbol = new Symbol(refName);
                normalizedName = new NormalizedName(symbol, null, null, refName);
            }

            return normalizedName;
        }
 internal AnnotatableElementClipboardFormat(EFElement efElement)
     : base(efElement)
 {
     // scan through the XML and identify any "extra" attributes we want to include in the copy
     foreach (var xo in ModelHelper.GetStructuredAnnotationsForElement(efElement))
     {
         var xa = xo as XAttribute;
         var xe = xo as XElement;
         if (xa != null)
         {
             var t = new Tuple<string, string>(xa.Name.ToString(), xa.Value);
             _additionalAttributes.Add(t);
         }
         else if (xe != null)
         {
             _additionalElements.Add(xe.ToString(SaveOptions.None));
         }
         else
         {
             Debug.Fail("unexepected type of XObject returned from GetAnnotationsForElement()");
         }
     }
 }
 /// <summary>
 ///     Deletes the passed in EFElement
 /// </summary>
 /// <param name="element">You can pass NULL to this, but if you do you must set the EFElement before calling InvokeInternal (or override it for specific functionality)</param>
 /// <param name="rebindAllBindings">Passing true (the default) causes all bindings in the artifact to rebind</param>
 /// <param name="removeAntiDeps">Passing true (the default) causes anti-dependencies to be deleted</param>
 internal DeleteEFElementCommand(EFElement element, bool rebindAllBindings, bool removeAntiDeps)
 {
     _element = element;
     _rebindAllBindings = rebindAllBindings;
     _removeAntiDeps = removeAntiDeps;
 }
 /// <summary>
 ///     Deletes the passed in EFElement
 /// </summary>
 /// <param name="element">You can pass NULL to this, but if you do you must set the EFElement before calling InvokeInternal (or override it for specific functionality)</param>
 /// <param name="rebindAllBindings">Passing true (the default) causes all bindings in the artifact to rebind</param>
 internal DeleteEFElementCommand(EFElement element, bool rebindAllBindings)
 {
     _element = element;
     _rebindAllBindings = rebindAllBindings;
 }
 /// <summary>
 ///     Deletes the passed in EFElement
 /// </summary>
 /// <param name="element">You can pass NULL to this, but if you do you must set the EFElement before calling InvokeInternal (or override it for specific functionality)</param>
 internal DeleteEFElementCommand(EFElement element)
 {
     _element = element;
 }
 /// <summary>
 ///     This will create a transaction if there isn't one already.  If the CommandProcessorContext is already
 ///     tracking a transaction, then a new one is NOT created.
 /// </summary>
 /// <param name="cpc"></param>
 /// <param name="element">The EFElement to delete</param>
 internal static void DeleteInTransaction(CommandProcessorContext cpc, EFElement element)
 {
     var cmd = element.GetDeleteCommand();
     DeleteInTransaction(cpc, cmd, true);
 }
        private static ComplexProperty CreateNewComplexProperty(EFElement parent, ComplexConceptualProperty property)
        {
            // actually create it in the XLinq tree
            var cp = new ComplexProperty(parent, null);
            cp.Name.SetRefName(property);

            XmlModelHelper.NormalizeAndResolve(cp);

            if (cp == null)
            {
                throw new ItemCreationFailureException();
            }

            Debug.Assert(cp.Name.Target != null && cp.Name.Target.LocalName.Value == cp.Name.RefName, "Broken property resolution");

            return cp;
        }
示例#57
0
 internal UpdateFunction(EFElement parent, XElement element)
     : base(parent, element)
 {
     Debug.Assert(parent is ModificationFunctionMapping, "parent should be a ModificationFunctionMapping");
     _functionType = ModificationFunctionType.Update;
 }
 internal ConceptualEntityContainer(EFElement parent, XElement element)
     : base(parent, element)
 {
 }
 internal ComplexConceptualProperty(EFElement parent, XElement element)
     : this(parent, element, null)
 {
 }
示例#60
0
 internal Association(EFElement parent, XElement element)
     : base(parent, element)
 {
 }