Ejemplo n.º 1
0
        /// <summary>
        ///     Selection helper method.  This takes the existing selection in the
        ///     context and creates a new selection that contains the toggled
        ///     state of the item.  If the item is to be
        ///     added to the selection, it is added as the primary selection.
        /// </summary>
        /// <param name="context">The editing context to apply this selection change to.</param>
        /// <param name="itemToToggle">The item to toggle selection for.</param>
        /// <returns>A Selection object that contains the new selection.</returns>
        /// <exception cref="ArgumentNullException">If context or itemToToggle is null.</exception>
        internal static T Toggle <T>(EditingContext context, EFObject itemToToggle) where T : Selection
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (itemToToggle == null)
            {
                throw new ArgumentNullException("itemToToggle");
            }

            var existing = context.Items.GetValue <T>();

            // Is the item already in the selection?  If so, remove it.
            // If not, add it to the beginning.

            var list = new List <EFObject>(existing.SelectedObjects);

            if (list.Contains(itemToToggle))
            {
                list.Remove(itemToToggle);
            }
            else
            {
                list.Insert(0, itemToToggle);
            }

            var selection = Activator.CreateInstance <T>();

            selection.SetSelectedObjects(list);
            context.Items.SetValue(selection);
            return(selection);
        }
        internal ModelElement GetExisting(EFObject obj)
        {
            ModelElement result;

            _modelToViewModel.TryGetValue(obj, out result);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Retrieve the root "Schema" node for current node.  If there is no root mapping node, this will return null.
        /// </summary>
        /// <returns></returns>
        internal static XNamespace GetRootNamespace(EFObject node)
        {
            var currNode = node;
            EFRuntimeModelRoot runtimeModel = null;
            EFDesignerInfoRoot designerInfo = null;
            XNamespace ns = null;

            while (currNode != null)
            {
                runtimeModel = currNode as EFRuntimeModelRoot;
                designerInfo = currNode as EFDesignerInfoRoot;
                if (runtimeModel != null)
                {
                    ns = runtimeModel.XNamespace;
                    break;
                }
                else if (designerInfo != null)
                {
                    ns = designerInfo.XNamespace;
                    break;
                }
                else
                {
                    currNode = currNode.Parent;
                }
            }

            return ns;
        }
Ejemplo n.º 4
0
 internal void RecordModelChange(
     EfiChange.EfiChangeType changeType, EFObject changed,
     string property, object oldValue, object newValue)
 {
     switch (changeType)
     {
         case EfiChange.EfiChangeType.Create:
             _creates.Add(new EfiChange(changeType, changed));
             break;
         case EfiChange.EfiChangeType.Delete:
             _deletes.Add(new EfiChange(changeType, changed));
             break;
         case EfiChange.EfiChangeType.Update:
             EfiChange change = null;
             if (_updates.ContainsKey(changed))
             {
                 change = _updates[changed];
             }
             else
             {
                 change = new EfiChange(changeType, changed);
                 _updates[changed] = change;
             }
             change.RecordModelChange(property, oldValue, newValue);
             break;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        ///     Selection helper method.  This takes the existing selection in the
        ///     context and creates a new selection that contains the original
        ///     selection and the itemToAdd.  If itemToAdd is already in the
        ///     original selection it is promoted to the primary selection.
        /// </summary>
        /// <param name="context">The editing context to apply this selection change to.</param>
        /// <param name="itemToAdd">The item to add to the selection.</param>
        /// <returns>A Selection object that contains the new selection.</returns>
        /// <exception cref="ArgumentNullException">If context or itemToAdd is null.</exception>
        internal static T Union <T>(EditingContext context, EFObject itemToAdd) where T : Selection
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (itemToAdd == null)
            {
                throw new ArgumentNullException("itemToAdd");
            }

            var existing = context.Items.GetValue <T>();

            // short cut if we're already in the right state.
            if (existing.PrimarySelection == itemToAdd)
            {
                return(existing);
            }

            // Is the item already in the selection?  If not, add it.
            var list = new List <EFObject>(existing.SelectedObjects);

            if (list.Contains(itemToAdd))
            {
                list.Remove(itemToAdd);
            }

            list.Insert(0, itemToAdd);
            var selection = Activator.CreateInstance <T>();

            selection.SetSelectedObjects(list);
            context.Items.SetValue(selection);
            return(selection);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Selection helper method.  This sets itemToSelect into the selection.
        ///     Any existing items are deselected.
        /// </summary>
        /// <param name="context">The editing context to apply this selection change to.</param>
        /// <param name="itemToSelect">The item to select.</param>
        /// <returns>A Selection object that contains the new selection.</returns>
        /// <exception cref="ArgumentNullException">If context or itemToSelect is null.</exception>
        internal static T SelectOnly <T>(EditingContext context, EFObject itemToSelect) where T : Selection
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (itemToSelect == null)
            {
                throw new ArgumentNullException("itemToSelect");
            }

            // Check to see if only this object is selected.  If so, bail.
            var existing = context.Items.GetValue <T>();

            if (existing.PrimarySelection == itemToSelect)
            {
                var en = existing.SelectedObjects.GetEnumerator();
                en.MoveNext();
                if (!en.MoveNext())
                {
                    return(existing);
                }
            }

            var selection = Activator.CreateInstance <T>();

            selection.SetSelectedObjects(itemToSelect);
            context.Items.SetValue(selection);
            return(selection);
        }
 internal static void ScheduleChildAntiDependenciesForRebinding(CommandProcessorContext cpc, EFObject efObject)
 {
     // identify any binding that was referencing this symbol, and add it to the list of things to rebind.
     var visitor = new AntiDependencyCollectorVisitor();
     visitor.Traverse(efObject);
     ScheduleBindingsForRebind(cpc, visitor.AntiDependencyBindings);
 }
        /// <summary>
        ///     This method makes sure that:
        ///     1. Any given item is not duplicated in the list
        ///     2. If the newDeleted item's parent is already in the list, don't add it
        ///     3. If any children of newDeleted are already in the list, remove the child item
        ///     This greatly optimizes the actually CleanUp() process.
        /// </summary>
        /// <param name="newDeleted"></param>
        private void AddToDeleteList(EFObject newDeleted)
        {
            // if newDeleted is already there, just return
            if (_itemsToDelete.Contains(newDeleted))
            {
                return;
            }

            // don't add newDeleted if any of its parents are already being deleted
            var container = newDeleted.Parent;

            while (container != null)
            {
                if (_itemsToDelete.Contains(container))
                {
                    return;
                }
                container = container.Parent;
            }

            // if the newDeleted item is the parent of an existing item
            // remove the child item and just add the parent below
            RemoveChildrenOfNewDeleted(newDeleted as EFContainer);

            // add the item
            _itemsToDelete.Add(newDeleted);
        }
Ejemplo n.º 9
0
        internal void RecordModelChange(
            EfiChange.EfiChangeType changeType, EFObject changed,
            string property, object oldValue, object newValue)
        {
            switch (changeType)
            {
            case EfiChange.EfiChangeType.Create:
                _creates.Add(new EfiChange(changeType, changed));
                break;

            case EfiChange.EfiChangeType.Delete:
                _deletes.Add(new EfiChange(changeType, changed));
                break;

            case EfiChange.EfiChangeType.Update:
                EfiChange change = null;
                if (_updates.ContainsKey(changed))
                {
                    change = _updates[changed];
                }
                else
                {
                    change            = new EfiChange(changeType, changed);
                    _updates[changed] = change;
                }
                change.RecordModelChange(property, oldValue, newValue);
                break;
            }
        }
Ejemplo n.º 10
0
 private void CheckAll(EFObject obj)
 {
     CheckEntityType(obj);
     CheckAssociation(obj);
     CheckEntityModel(obj);
     CheckComplexType(obj);
 }
        /// <summary>
        ///     This method will make an AttributePath for a given an EFObject.
        /// </summary>
        private static AttributePath MakeAttributePathFromEFObject(EFObject efobject)
        {
            var attributePath = new AttributePath();
            var curr          = efobject.XObject;

            while (curr != null)
            {
                if (curr.NodeType == XmlNodeType.Document)
                {
                    var doc = (XDocument)curr;
                    attributePath.PushFront(doc.Root.Name.LocalName, doc.Root.Name.Namespace.NamespaceName, true);
                }
                else if (curr.NodeType == XmlNodeType.Attribute)
                {
                    var attr = (XAttribute)curr;
                    attributePath.PushFront(attr.Name.LocalName, attr.Name.Namespace.NamespaceName, false);
                }
                else if (curr.NodeType == XmlNodeType.Element)
                {
                    var el = (XElement)curr;
                    attributePath.PushFront(el.Name.LocalName, el.Name.Namespace.NamespaceName, true);
                }
                else
                {
                    Debug.Fail("Unexpected XObject type is neither an attribute nor an element");
                    return(null);
                }

                curr = curr.Parent;
            }
            return(attributePath);
        }
        internal static MappingViewModel CreateViewModel(EditingContext ctx, EFObject selection)
        {
            // clear out the xref so its clean for this new view model
            var xref = ModelToMappingModelXRef.GetModelToMappingModelXRef(ctx);
            xref.Clear();

            // we might be creating a view model for an entity or an association or a FunctionImport
            var entityType = selection as EntityType;
            var association = selection as Association;
            var fim = selection as FunctionImportMapping;

            // create the view model root
            MappingEFElement root = null;
            if (entityType != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, entityType, null);
            }
            else if (association != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, association, null);
            }
            else if (fim != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, fim, null);
            }
            else
            {
                throw new ArgumentException("selection");
            }

            return new MappingViewModel(ctx, root);
        }
Ejemplo n.º 13
0
        internal static void RefactorRenameElement(EFObject objectToRefactor, string newName = null, bool showPreview = true)
        {
            if (objectToRefactor != null &&
                objectToRefactor.Artifact != null)
            {
                var namedObject = objectToRefactor as EFNormalizableItem;
                if (namedObject != null)
                {
                    // If the API call did not supply a new name for the object, bring up the dialog for the user to input a name
                    if (newName == null)
                    {
                        var dialog = new RefactorRenameDialog(namedObject);
                        if (dialog.ShowModal() == true)
                        {
                            newName = dialog.NewName;

                            if (dialog.ShowPreview.HasValue)
                            {
                                showPreview = dialog.ShowPreview.Value;
                            }
                        }
                    }

                    if (newName != null)
                    {
                        RefactorRenameElementInDesignerOnly(namedObject, newName, showPreview);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private bool CheckForMissingAnnotations(EFObject efObject)
        {
            if (_checkAnnotations)
            {
                var miaEFobject = ModelItemAnnotation.GetModelItem(efObject.XObject);
                var isArtifact  = efObject is EFArtifact;
                if (miaEFobject == null &&
                    !isArtifact)
                {
                    if (!_noMIAList.Contains(efObject.XObject))
                    {
                        _noMIAList.Add(efObject.XObject);
                    }
                    return(true);
                }

                // Check for incorrect/stale annotations
                if (miaEFobject != efObject &&
                    !isArtifact &&
                    !IsValidGhostNode(efObject))
                {
                    if (!_incorrectMIAList.ContainsKey(efObject.XObject))
                    {
                        _incorrectMIAList.Add(efObject.XObject, miaEFobject);
                    }
                    return(true);
                }
            }

            return(false);
        }
        internal static MappingViewModel CreateViewModel(EditingContext ctx, EFObject selection)
        {
            // clear out the xref so its clean for this new view model
            var xref = ModelToMappingModelXRef.GetModelToMappingModelXRef(ctx);

            xref.Clear();

            // we might be creating a view model for an entity or an association or a FunctionImport
            var entityType  = selection as EntityType;
            var association = selection as Association;
            var fim         = selection as FunctionImportMapping;

            // create the view model root
            MappingEFElement root = null;

            if (entityType != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, entityType, null);
            }
            else if (association != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, association, null);
            }
            else if (fim != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, fim, null);
            }
            else
            {
                throw new ArgumentException("selection");
            }

            return(new MappingViewModel(ctx, root));
        }
Ejemplo n.º 16
0
        private bool CheckForNoXObject(EFObject efObject)
        {
            if (_checkXObject && efObject.XObject == null)
            {
                // some EFAttributes are not tied to XAttributes
                var efAttribute   = efObject as EFAttribute;
                var parentElement = efObject.Parent as EFElement;
                if (efAttribute != null &&
                    parentElement != null)
                {
                    var xattr = efAttribute.Namespace != null
                                    ? parentElement.GetAttribute(efObject.EFTypeName, efAttribute.Namespace.NamespaceName)
                                    : parentElement.GetAttribute(efObject.EFTypeName);

                    if (xattr == null)
                    {
                        return(true);
                    }
                }

                if (!_noXObjectList.Contains(efObject))
                {
                    _noXObjectList.Add(efObject);
                }
                return(true);
            }

            return(false);
        }
        private static ModelElement CreateModelElementForEFObjectType(EFObject obj, Partition partition)
        {
            ModelElement modelElement = null;
            var t = obj.GetType();
            if (t == typeof(ConceptualEntityModel))
            {
                modelElement = new EntityDesignerViewModel(partition);
            }
            else if (t == typeof(ConceptualEntityType))
            {
                modelElement = new EntityType(partition);
            }
            else if (t == typeof(ConceptualProperty))
            {
                modelElement = new ScalarProperty(partition);
            }
            else if (t == typeof(ComplexConceptualProperty))
            {
                modelElement = new ComplexProperty(partition);
            }
            else if (t == typeof(Association))
            {
                modelElement = new ViewModel.Association(partition);
            }
            else if (t == typeof(EntityTypeBaseType))
            {
                modelElement = new Inheritance(partition);
            }
            else if (t == typeof(NavigationProperty))
            {
                modelElement = new ViewModel.NavigationProperty(partition);
            }

            return modelElement;
        }
Ejemplo n.º 18
0
        internal static void RefactorRenameElement(EFObject objectToRefactor, string newName = null, bool showPreview = true)
        {
            if (objectToRefactor != null
                && objectToRefactor.Artifact != null)
            {
                var namedObject = objectToRefactor as EFNormalizableItem;
                if (namedObject != null)
                {
                    // If the API call did not supply a new name for the object, bring up the dialog for the user to input a name
                    if (newName == null)
                    {
                        var dialog = new RefactorRenameDialog(namedObject);
                        if (dialog.ShowModal() == true)
                        {
                            newName = dialog.NewName;

                            if (dialog.ShowPreview.HasValue)
                            {
                                showPreview = dialog.ShowPreview.Value;
                            }
                        }
                    }

                    if (newName != null)
                    {
                        RefactorRenameElementInDesignerOnly(namedObject, newName, showPreview);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        internal override DslModeling.ModelElement SynchronizeSingleDslModelElement(
            DslModeling.ModelElement parentViewModel, EFObject modelElement)
        {
            var t = modelElement.GetType();

            if (t == typeof(ConceptualEntityType))
            {
                return(TranslateEntityType(parentViewModel as EntityDesignerViewModel, modelElement as ConceptualEntityType));
            }
            else if (t == typeof(EntityTypeBaseType))
            {
                return(TranslateBaseType(parentViewModel as EntityDesignerViewModel, (modelElement).Parent as ConceptualEntityType));
            }
            else if (t == typeof(ModelNavigationProperty))
            {
                return(TranslateNavigationProperty(parentViewModel as ViewModelEntityType, modelElement as ModelNavigationProperty));
            }
            else if (t == typeof(ComplexConceptualProperty) ||
                     t == typeof(ConceptualProperty))
            {
                return(TranslateProperty(parentViewModel as ViewModelEntityType, modelElement as ModelProperty));
            }
            else if (t == typeof(ModelAssociation))
            {
                return(TranslateAssociation(parentViewModel as EntityDesignerViewModel, modelElement as ModelAssociation));
            }
            else if (t == typeof(DesignerModel.Diagram))
            {
                return(TranslateDiagramValues(parentViewModel as EntityDesignerViewModel, modelElement as DesignerModel.Diagram));
            }

            Debug.Assert(false, "modelElement with type= " + t.Name + " is not supported");

            return(null);
        }
        internal static void NavigateTo(EFObject efobject)
        {
            if (efobject.RuntimeModelRoot() == null)
            {
                // nothing to navigate to, so just return;
                return;
            }

            if (efobject.RuntimeModelRoot() is StorageEntityModel)
            {
                // s-space object, so just return;
                return;
            }

            var selectionService = Services.DslMonitorSelectionService;
            Debug.Assert(selectionService != null, "Could not retrieve IMonitorSelectionService from Escher package.");
            var foundDSLElementMatchInDiagram = false;
            if (selectionService != null)
            {
                var singleDiagramDocView = selectionService.CurrentDocumentView as SingleDiagramDocView;

                if (singleDiagramDocView != null)
                {
                    foundDSLElementMatchInDiagram = NavigateToDSLNodeInDiagram(
                        singleDiagramDocView.Diagram as EntityDesignerDiagram, efobject);
                    if (foundDSLElementMatchInDiagram)
                    {
                        // The code below is added to ensure that the right doc-view is shown and activated.
                        singleDiagramDocView.Frame.Show();
                        return;
                    }
                }
            }

            // Retrieves the doc data for the efobject.
            var docdata = VSHelpers.GetDocData(Services.ServiceProvider, efobject.Uri.LocalPath) as ModelingDocData;
            Debug.Assert(docdata != null, "Could not find get doc data for artifact with URI:" + efobject.Uri.LocalPath);
            if (docdata != null)
            {
                foreach (var docView in docdata.DocViews)
                {
                    var singleDiagramDocView = docView as SingleDiagramDocView;
                    Debug.Assert(
                        singleDiagramDocView != null,
                        "Why the doc view is not type of SingleDiagramDocView? Actual type:" + docView.GetType().Name);
                    if (docView != null)
                    {
                        foundDSLElementMatchInDiagram = NavigateToDSLNodeInDiagram(
                            singleDiagramDocView.Diagram as EntityDesignerDiagram, efobject);
                        if (foundDSLElementMatchInDiagram)
                        {
                            // The code below is added to ensure that the right doc-view is shown and activated.
                            singleDiagramDocView.Frame.Show();
                            return;
                        }
                    }
                }
            }
        }
 internal void Add(EFObject obj, ModelElement viewElement, EditingContext context)
 {
     if (_globalMapModelAndViewModel.ContainsKey(viewElement.Partition) == false)
     {
         _globalMapModelAndViewModel[viewElement.Partition] = new ModelToDesignerModelXRefItem();
     }
     _globalMapModelAndViewModel[viewElement.Partition].Add(obj, viewElement, context);
 }
 internal ModelElement GetExisting(EFObject obj, Partition partition)
 {
     if (_globalMapModelAndViewModel.ContainsKey(partition))
     {
         return(_globalMapModelAndViewModel[partition].GetExisting(obj));
     }
     return(null);
 }
Ejemplo n.º 23
0
 internal override void Initialize(EFObject obj, EditingContext editingContext, bool runningInVS)
 {
     base.Initialize(obj, editingContext, runningInVS);
     if (obj != null)
     {
         LoadDesignerInfoAndDescriptors(editingContext, obj.Artifact);
     }
 }
 internal void Remove(EFObject obj, ModelElement viewElement)
 {
     Debug.Assert(
         _globalMapModelAndViewModel.ContainsKey(viewElement.Partition), "There is no modelToViewModel map for the partition");
     if (_globalMapModelAndViewModel.ContainsKey(viewElement.Partition))
     {
         _globalMapModelAndViewModel[viewElement.Partition].Remove(obj, viewElement);
     }
 }
        internal void Remove(EFObject efObject)
        {
            ModelElement viewElement;

            if (_modelToViewModel.TryGetValue(efObject, out viewElement))
            {
                Remove(efObject, viewElement);
            }
        }
Ejemplo n.º 26
0
        internal override void Initialize(EFObject obj, EditingContext editingContext, bool runningInVS)
        {
            _attribute      = obj as TEFAttribute;
            _editingContext = editingContext;
            _runningInVS    = runningInVS;

            // now perform any initialization on derived types
            OnTypeDescriptorInitialize();
        }
        internal void Remove(EFObject efObject)
        {
            ModelElement viewElement;

            if (_modelToViewModel.TryGetValue(efObject, out viewElement))
            {
                Remove(efObject, viewElement);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        ///     Returns the top most ComplexProperty that this ScalarProperty lives in (null if the parent isn't a ComplexProperty)
        /// </summary>
        /// <returns></returns>
        internal ComplexProperty GetTopMostComplexProperty()
        {
            EFObject efObject = this;

            while (efObject.Parent is ComplexProperty)
            {
                efObject = efObject.Parent;
            }
            return(efObject as ComplexProperty);
        }
Ejemplo n.º 29
0
 private static void Main(string[] args)
 {
     Mapper.CreateMap <EFObject, DTOObject>().
     ForMember(dtoo => dtoo.DS, opt => opt.MapFrom(efo => efo.D.ToString("g")));
     var fromDB = new EFObject()
     {
         D = DateTime.Now
     };
     var toDTO = Mapper.Map <EFObject, DTOObject>(fromDB);
 }
        internal EFRenameContributorInput(EFObject objectToBeRenamed, string newName, string oldName)
        {
            ArgumentValidation.CheckForNullReference(objectToBeRenamed, "objectToBeRenamed");
            ArgumentValidation.CheckForNullReference(newName, "newName");
            ArgumentValidation.CheckForNullReference(oldName, "oldName");

            _objectToBeRenamed = objectToBeRenamed;
            _oldName = oldName;
            _newName = newName;
        }
Ejemplo n.º 31
0
            private void CheckComplexType(EFObject obj)
            {
                var complexType = obj as ComplexType;

                if (complexType != null)
                {
                    CheckForCircularComplexTypeDefinition(complexType);
                    CheckForEnumPropertiesWithStoreGeneratedPattern(complexType);
                }
            }
Ejemplo n.º 32
0
        internal EFRenameContributorInput(EFObject objectToBeRenamed, string newName, string oldName)
        {
            ArgumentValidation.CheckForNullReference(objectToBeRenamed, "objectToBeRenamed");
            ArgumentValidation.CheckForNullReference(newName, "newName");
            ArgumentValidation.CheckForNullReference(oldName, "oldName");

            _objectToBeRenamed = objectToBeRenamed;
            _oldName           = oldName;
            _newName           = newName;
        }
Ejemplo n.º 33
0
            private void CheckAssociation(EFObject obj)
            {
                var a = obj as Association;

                if (a != null)
                {
                    CheckForAssociationWithoutAssociationSet(a);
                    CheckForUnmappedAssociation(a);
                    CheckAssociationForUnmappedEntityTypeKeys(a);
                }
            }
Ejemplo n.º 34
0
            private void CheckEntityType(EFObject obj)
            {
                var et = obj as EntityType;

                if (et != null)
                {
                    CheckForEntityTypesWithoutEntitySets(et);
                    CheckForMultipleEntitySetsPerType(et);
                    CheckConceptualEntityType(et);
                }
            }
        internal static IList <ModelElement> GetExisting(EditingContext context, EFObject obj)
        {
            IList <ModelElement> result;

            var xref = GetModelToDesignerModelXRef(context);

            result = xref.GetExisting(obj);

            Debug.Assert(result != null);
            return(result);
        }
Ejemplo n.º 36
0
        internal ErrorInfo(Severity severity, string message, EFObject item, int errorCode, ErrorClass errorClass)
        {
            Debug.Assert(item != null, "item != null");
            _severity = severity;

            // prefix the error code in front of the error message.  This is here to help identify runtime errors that cause safe-mode
            _message    = String.Format(CultureInfo.CurrentCulture, Resources.Error_Message_With_Error_Code_Prefix, errorCode, message);
            _item       = item;
            _errorCode  = errorCode;
            _errorClass = errorClass;
        }
Ejemplo n.º 37
0
 internal static void SetModelItem(XObject xobject, EFObject efobject)
 {
     if (xobject.Annotation <EFObject>() == null)
     {
         xobject.AddAnnotation(efobject);
     }
     else
     {
         xobject.RemoveAnnotations <EFObject>();
         xobject.AddAnnotation(efobject);
     }
 }
Ejemplo n.º 38
0
 internal static void SetModelItem(XObject xobject, EFObject efobject)
 {
     if (xobject.Annotation<EFObject>() == null)
     {
         xobject.AddAnnotation(efobject);
     }
     else
     {
         xobject.RemoveAnnotations<EFObject>();
         xobject.AddAnnotation(efobject);
     }
 }
Ejemplo n.º 39
0
        internal void UpdateSelection()
        {
            var newSelection = new HashSet <EFObject>();

            if (SelectedModelItem != null &&
                TreeControl.CurrentColumn < TreeControl.Columns.Length &&
                TreeControl.Columns[TreeControl.CurrentColumn] != null)
            {
                // use the current column index to find what type of column we have
                var currentColumnType = TreeControl.Columns[TreeControl.CurrentColumn].GetType();

                // we have to find the "descriptable" EFElements for the MappingEFElements here
                EFObject modelItemForDescriptor = null;
                if (SelectedModelItem is ScalarProperty)
                {
                    var scalarProperty = SelectedModelItem as ScalarProperty;
                    if (currentColumnType.IsAssignableFrom(typeof(ValueColumn)) ||
                        currentColumnType.IsAssignableFrom(typeof(PropertyColumn)))
                    {
                        modelItemForDescriptor = scalarProperty.Name.Target;
                    }
                    else if (currentColumnType.IsAssignableFrom(typeof(ColumnNameColumn)))
                    {
                        modelItemForDescriptor = scalarProperty.ColumnName.Target;
                    }
                }
                else if (SelectedModelItem is FunctionScalarProperty)
                {
                    var functionScalarProperty = SelectedModelItem as FunctionScalarProperty;
                    if (currentColumnType.IsAssignableFrom(typeof(PropertyColumn)))
                    {
                        modelItemForDescriptor = functionScalarProperty.Name.Target;
                    }
                    else if (currentColumnType.IsAssignableFrom(typeof(ParameterColumn)))
                    {
                        modelItemForDescriptor = functionScalarProperty.ParameterName.Target;
                    }
                }

                // if we were able to find a corresponding descriptable EFElement (if we allow the property window to
                // display the properties) then add the EFElement to a new MappingDetailsSelection and update the context
                if (modelItemForDescriptor != null)
                {
                    newSelection.Add(modelItemForDescriptor);
                }
            }
            if (_editingContext != null &&
                _editingContext.Items != null)
            {
                _editingContext.Items.SetValue(new MappingDetailsSelection(newSelection));
            }
        }
Ejemplo n.º 40
0
            private static T GetFirstAntiDependencyOfType <T>(EFObject obj) where T : EFObject
            {
                var antiDeps = obj.GetAntiDependenciesOfType <T>();

                if (antiDeps != null)
                {
                    foreach (var t in antiDeps)
                    {
                        return(t);
                    }
                }
                return(null);
            }
Ejemplo n.º 41
0
        private ErrorInfo(Severity severity, string message, EFObject item, string itemPath, int errorCode, ErrorClass errorClass)
        {
            Debug.Assert(item == null ^ itemPath == null, "item and itemPath are mutually exclusive");

            _severity = severity;
            _item = item;
            _itemPath = itemPath;
            // prefix the error code in front of the error message.  This is here to help identify runtime errors that cause safe-mode
            _message = String.Format(CultureInfo.CurrentCulture, Resources.Error_Message_With_Error_Code_Prefix, errorCode, message);
            _item = item;
            _errorCode = errorCode;
            _errorClass = errorClass;
        }
        internal void Add(EFObject obj, ModelElement viewElement, EditingContext context)
        {
            var viewModel = viewElement as EntityDesignerViewModel;
            if (viewModel != null)
            {
                viewModel.EditingContext = context;
            }

            Remove(obj);
            Remove(viewElement);

            _modelToViewModel.Add(obj, viewElement);
            _viewModelToModel.Add(viewElement, obj);
        }
        internal override void Initialize(EFObject obj, EditingContext editingContext, bool runningInVS)
        {
            _entityTypeShape = obj as EntityTypeShape;

            Debug.Assert(_entityTypeShape != null, "EFObject is null or is not a type of EntityTypeShape.");

            if (_entityTypeShape != null)
            {
                var entityType = _entityTypeShape.EntityType.Target;
                Debug.Assert(entityType != null, "EntityTypeShape does not contain instance of an entity type.");
                if (entityType != null)
                {
                    base.Initialize(entityType, editingContext, runningInVS);
                }
            }
        }
 private static ExplorerTreeViewItem GetTreeViewItemForEFObject(EFObject efobject, ExplorerFrame explorerFrame)
 {
     var treeViewItem = explorerFrame.ExplorerTreeRoot;
     if (null != efobject
         && !(efobject is EFArtifact))
     {
         var entityDesignArtifact = efobject.Artifact.ArtifactSet.GetEntityDesignArtifact();
         var editingContext =
             PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(entityDesignArtifact.Uri);
         var element = explorerFrame.ExplorerViewModelHelper.GetExplorerEFElementForEFObject(editingContext, efobject);
         Debug.Assert(element != null, "Unable to find ExplorerEFElement for efobject of type " + efobject.GetType());
         if (element != null)
         {
             treeViewItem = explorerFrame.GetTreeViewItem(element, true);
         }
     }
     return treeViewItem;
 }
        internal static ModelElement CreateConnectorModelElementForEFObjectType(EFObject obj, ModelElement end1, ModelElement end2)
        {
            ModelElement modelElement = null;
            var t = obj.GetType();
            var et1 = end1 as EntityType;
            var et2 = end2 as EntityType;
            if (t == typeof(Association))
            {
                Debug.Assert(et1 != null && et2 != null, "Unexpected end type for Association model element");
                modelElement = new ViewModel.Association(et1, et2);
            }
            else if (t == typeof(EntityTypeBaseType))
            {
                Debug.Assert(et1 != null && et2 != null, "Unexpected end type for Inheritance model element");
                modelElement = new Inheritance(et1, et2);
            }

            return modelElement;
        }
Ejemplo n.º 46
0
        internal static XNamespace GetRootNamespace(EFObject node)
        {
            var currNode = node;
            EFDesignerInfoRoot model = null;
            XNamespace ns = null;

            while (currNode != null)
            {
                model = currNode as EFDesignerInfoRoot;
                if (model != null)
                {
                    ns = model.XNamespace;
                    break;
                }
                else
                {
                    currNode = currNode.Parent;
                }
            }

            return ns;
        }
Ejemplo n.º 47
0
 internal EfiChange(EfiChangeType changeType, EFObject changed)
 {
     _changeType = changeType;
     _changed = changed;
     _properties = new Dictionary<string, OldNewPair>();
 }
        private bool CheckForMissingAnnotations(EFObject efObject)
        {
            if (_checkAnnotations)
            {
                var miaEFobject = ModelItemAnnotation.GetModelItem(efObject.XObject);
                var isArtifact = efObject is EFArtifact;
                if (miaEFobject == null
                    && !isArtifact)
                {
                    if (!_noMIAList.Contains(efObject.XObject))
                    {
                        _noMIAList.Add(efObject.XObject);
                    }
                    return true;
                }

                // Check for incorrect/stale annotations
                if (miaEFobject != efObject
                    && !isArtifact
                    && !IsValidGhostNode(efObject))
                {
                    if (!_incorrectMIAList.ContainsKey(efObject.XObject))
                    {
                        _incorrectMIAList.Add(efObject.XObject, miaEFobject);
                    }
                    return true;
                }
            }

            return false;
        }
        private bool CheckForNoXObject(EFObject efObject)
        {
            if (_checkXObject && efObject.XObject == null)
            {
                // some EFAttributes are not tied to XAttributes
                var efAttribute = efObject as EFAttribute;
                var parentElement = efObject.Parent as EFElement;
                if (efAttribute != null
                    && parentElement != null)
                {
                    var xattr = efAttribute.Namespace != null
                                    ? parentElement.GetAttribute(efObject.EFTypeName, efAttribute.Namespace.NamespaceName)
                                    : parentElement.GetAttribute(efObject.EFTypeName);
                    if (xattr == null)
                    {
                        return true;
                    }
                }

                if (!_noXObjectList.Contains(efObject))
                {
                    _noXObjectList.Add(efObject);
                }
                return true;
            }

            return false;
        }
        private bool CheckForUnresolved(EFObject efObject)
        {
            var efElement = efObject as EFElement;
            var itemBinding = efObject as ItemBinding;
            var parentElement = efObject.Parent as EFElement;
            if (_checkUnresolved)
            {
                if (efElement != null)
                {
                    if (!(efElement.State == EFElementState.Resolved || efElement.State == EFElementState.ResolveAttempted))
                    {
                        if (!_unresolvedList.Contains(efObject))
                        {
                            _unresolvedList.Add(efObject);
                        }
                        return true;
                    }
                }
                else if (itemBinding != null)
                {
                    if (itemBinding.Parent.State == EFElementState.Resolved
                        && (itemBinding.Resolved == false || itemBinding.IsStatusUnknown))
                    {
                        var xattr = parentElement.GetAttribute(efObject.EFTypeName);
                        if (xattr == null)
                        {
                            return true;
                        }

                        if (!_unresolvedList.Contains(efObject))
                        {
                            _unresolvedList.Add(efObject);
                        }
                        return true;
                    }
                }
            }

            return false;
        }
        private bool CheckForDisposed(EFObject efObject)
        {
            if (_checkDisposed && efObject.IsDisposed)
            {
                if (!_disposedList.Contains(efObject))
                {
                    _disposedList.Add(efObject);
                }
                return true;
            }

            return false;
        }
        // <summary>
        //     Returns a wrapper for the specified EFObject. The wrapper is the type descriptor
        //     that describes the properties that should be displayed for the EFObject.
        //     The returned wrapper should be handed to a property window control
        // </summary>
        public static ObjectDescriptor GetObjectDescriptor(EFObject obj, EditingContext editingContext, bool runningInVS)
        {
            if (obj != null)
            {
                Type objectDescriptorType;

                if (ObjectDescriptorTypes.TryGetValue(obj.GetType(), out objectDescriptorType))
                {
                    // create the descriptor wrapper for the EFObject object
                    var descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, objectDescriptorType, null, null);
                    descriptor.Initialize(obj, editingContext, runningInVS);
                    return descriptor;
                }
                else
                {
                    // special case for Property
                    var property = obj as Property;
                    if (property != null)
                    {
                        ObjectDescriptor descriptor = null;
                        if (property is ComplexConceptualProperty)
                        {
                            descriptor =
                                (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFComplexPropertyDescriptor), null, null);
                        }
                        else if (property.EntityModel.IsCSDL)
                        {
                            descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFPropertyDescriptor), null, null);
                        }
                        else
                        {
                            descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSPropertyDescriptor), null, null);
                        }
                        descriptor.Initialize(obj, editingContext, runningInVS);
                        return descriptor;
                    }

                    // special case for Parameter
                    var parameter = obj as Parameter;
                    if (parameter != null)
                    {
                        ObjectDescriptor descriptor = null;
                        if (parameter.Parent is FunctionImport)
                        {
                            descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFParameterDescriptor), null, null);
                            descriptor.Initialize(obj, editingContext, runningInVS);
                            return descriptor;
                        }
                        else if (parameter.Parent is Function)
                        {
                            //Stored procedure parameter descriptor (EFSParameterDescriptor)
                            descriptor = (ObjectDescriptor)TypeDescriptor.CreateInstance(null, typeof(EFSParameterDescriptor), null, null);
                            descriptor.Initialize(obj, editingContext, runningInVS);
                            return descriptor;
                        }
                    }
                }
            }

            return null;
        }
 /// <summary>
 /// </summary>
 /// <param name="efObject"></param>
 /// <returns></returns>
 protected abstract EFElement GetNavigationTarget(EFObject efObject);
        internal ExplorerEFElement GetExplorerEFElementForEFObject(EditingContext editingContext, EFObject targetEFObject)
        {
            if (targetEFObject == null)
            {
                return null;
            }

            // 
            //  Find the EFObject we want to navigate to for the given EFObject
            //
            var targetEFElement = GetNavigationTarget(targetEFObject);

            //
            // get all EFElement nodes on the path from our target node to the root.
            //
            var elementStack = new LinkedList<EFElement>();
            var e = targetEFElement;
            while (e != null)
            {
                elementStack.AddLast(e);
                e = e.Parent as EFElement;
            }

            //
            // unwind the stack, making sure that each element's explorer model node exists. 
            //
            var explorerElement = ViewModel.RootNode;
            while (elementStack.Count > 0)
            {
                var e2 = elementStack.Last.Value;
                elementStack.RemoveLast();
                var viewModelType = ModelToExplorerModelXRef.GetViewModelTypeForEFlement(editingContext, e2);
                // if viewModelType is null then that kind of EFElement is not displayed
                // in the Explorer (e.g. S-side StorageEntityContainer and children)
                if (null != viewModelType)
                {
                    var nextElement = ModelToExplorerModelXRef.GetNewOrExisting(editingContext, e2, explorerElement, viewModelType);

                    // There are "dummy-nodes" in the view-model that don't correspond to a node in the model.  
                    // We need to skip over them here. 
                    if (nextElement != null
                        && elementStack.Count > 0)
                    {
                        nextElement = nextElement.GetParentNodeForElement(elementStack.Last.Value);
                        Debug.Assert(nextElement != null, "GetParentNodeForElement returned null");
                    }

                    if (nextElement != null)
                    {
                        explorerElement = nextElement;
                    }
                }
            }
            Debug.Assert(explorerElement != null, "no explorer element found for targetEFObject");

            if (explorerElement != null)
            {
                //
                // now make sure that our target node in the explorer tree is visible.
                //
                explorerElement.ExpandTreeViewToMe();
            }

            return explorerElement;
        }
Ejemplo n.º 55
0
 internal ICollection<EFObject> GetAntiDependenciesClosure(EFObject item)
 {
     return _dependencyGraph.GetAntiDependenciesClosure(item);
 }
Ejemplo n.º 56
0
        internal void RemoveErrorsForEFObject(EFObject efobject, ErrorClass errorClass, int errorCodeToRemove)
        {
            Dictionary<ErrorClass, ICollection<ErrorInfo>> errorClass2ErrorInfo = null;
            _artifacts2Errors.TryGetValue(efobject.Artifact, out errorClass2ErrorInfo);
            if (errorClass2ErrorInfo != null)
            {
                foreach (var errors in GetErrorInfosUsingMask(errorClass2ErrorInfo, errorClass))
                {
                    var errorsToRemove = new List<ErrorInfo>();
                    foreach (var errorInfo in errors)
                    {
                        if (errorInfo.ErrorCode == errorCodeToRemove)
                        {
                            errorsToRemove.Add(errorInfo);
                        }
                    }

                    foreach (var errorInfo in errorsToRemove)
                    {
                        errors.Remove(errorInfo);
                    }
                }
            }
        }
 /// <summary>
 ///     Gets a value indicating whether the EFObject should be visited.
 /// </summary>
 protected virtual bool ShouldVisit(EFObject efObject)
 {
     return true;
 }
 /// <summary>
 ///     Gets a value indicating whether the EFObject is a valid ghost node.
 /// </summary>
 /// <remarks>
 ///     A valid ghost node will not cause an error if it has an incorrect or stale xlinq annotation.
 /// </remarks>
 protected virtual bool IsValidGhostNode(EFObject efObject)
 {
     return false;
 }
        /// <summary>
        ///     This method makes sure that:
        ///     1. Any given item is not duplicated in the list
        ///     2. If the newDeleted item's parent is already in the list, don't add it
        ///     3. If any children of newDeleted are already in the list, remove the child item
        ///     This greatly optimizes the actually CleanUp() process.
        /// </summary>
        /// <param name="newDeleted"></param>
        private void AddToDeleteList(EFObject newDeleted)
        {
            // if newDeleted is already there, just return
            if (_itemsToDelete.Contains(newDeleted))
            {
                return;
            }

            // don't add newDeleted if any of its parents are already being deleted
            var container = newDeleted.Parent;
            while (container != null)
            {
                if (_itemsToDelete.Contains(container))
                {
                    return;
                }
                container = container.Parent;
            }

            // if the newDeleted item is the parent of an existing item
            // remove the child item and just add the parent below
            RemoveChildrenOfNewDeleted(newDeleted as EFContainer);

            // add the item
            _itemsToDelete.Add(newDeleted);
        }
Ejemplo n.º 60
0
 internal abstract XNamespace GetRootNamespace(EFObject node);