internal static ModelToExplorerModelXRef GetModelToBrowserModelXRef(EditingContext context)
        {
            Type modelToExplorerModelXRefType;

            if (
                !_modelManagerType2XRefType.TryGetValue(
                    context.GetEFArtifactService().Artifact.ModelManager.GetType(), out modelToExplorerModelXRefType))
            {
                Debug.Fail(
                    "Could not find a ModelToExplorerModelXRef type for the ModelManager of type '"
                    + context.GetEFArtifactService().Artifact.ModelManager.GetType()
                    + "'.  Make sure to call AddModelManager2XRefType before calling GetModelToBrowserModelXRef.");
                return(null);
            }

            // Update EFElement to BrowserEFElement cross reference so that Search Results can later access it
            var xref = (ModelToExplorerModelXRef)context.Items.GetValue(modelToExplorerModelXRefType);

            if (xref == null)
            {
                xref = (ModelToExplorerModelXRef)Activator.CreateInstance(modelToExplorerModelXRefType);
                context.Items.SetValue(xref);
            }
            return(xref);
        }
Exemplo n.º 2
0
        internal Uri GetCurrentUri(FrameWrapper frame)
        {
            EditingContext context = null;

            if (!_mapFrameToUri.TryGetValue(frame, out context))
            {
                if (context == null)
                {
                    SetCurrentUri(frame, frame.Uri);
                    return(frame.Uri);
                }
            }

            var artifactService = context.GetEFArtifactService();

            Debug.Assert(
                artifactService != null && artifactService.Artifact != null,
                "There is no artifact service/artifact tied to this editing context!");
            if (artifactService != null &&
                artifactService.Artifact != null)
            {
                return(artifactService.Artifact.Uri);
            }
            return(null);
        }
Exemplo n.º 3
0
        public override void CreateViewModel(EditingContext ctx)
        {
            var service = ctx.GetEFArtifactService();

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

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

            var xref = ModelToExplorerModelXRef.GetModelToBrowserModelXRef(ctx);

            xref.Clear();

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

            var designerInfo = artifact.DesignerInfo();

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

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

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

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

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

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

            base.ViewModel = new ExplorerViewModel(ctx, edmRootNode);
        }
Exemplo n.º 4
0
        private static MicrosoftDataEntityDesignDocData GetDocData(EditingContext editingContext)
        {
            Debug.Assert(editingContext != null, "editingContext != null");

            var artifactService = editingContext.GetEFArtifactService();

            return((MicrosoftDataEntityDesignDocData)VSHelpers.GetDocData(ServiceProvider, artifactService.Artifact.Uri.LocalPath));
        }
Exemplo n.º 5
0
 internal static EFArtifact GetArtifact(EditingContext context)
 {
     if (context != null)
     {
         var service = context.GetEFArtifactService();
         if (service != null)
         {
             return(service.Artifact);
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        internal static void CreateDefaultDiagram(EditingContext context, EntityDesignerDiagram diagram)
        {
            var service  = context.GetEFArtifactService();
            var artifact = service.Artifact;

            Debug.Assert(artifact != null, "Artifact is null");

            var cpc = new CommandProcessorContext(
                context, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_CreateDiagram);
            var cmd = new DelegateCommand(
                () =>
            {
                EntityDesignerDiagramAdd.StaticInvoke(cpc, diagram);

                foreach (var shapeElement in diagram.NestedChildShapes)
                {
                    var entityShape = shapeElement as EntityTypeShape;
                    if (entityShape != null)
                    {
                        EntityTypeShapeAdd.StaticInvoke(cpc, entityShape);
                        EntityTypeShapeChange.StaticInvoke(
                            cpc, entityShape, ViewModelDiagram.NodeShape.AbsoluteBoundsDomainPropertyId);
                        EntityTypeShapeChange.StaticInvoke(cpc, entityShape, ViewModelDiagram.NodeShape.IsExpandedDomainPropertyId);
                        continue;
                    }

                    var associationConnector = shapeElement as AssociationConnector;
                    if (associationConnector != null)
                    {
                        AssociationConnectorAdd.StaticInvoke(cpc, associationConnector);
                        AssociationConnectorChange.StaticInvoke(
                            cpc, associationConnector, ViewModelDiagram.LinkShape.EdgePointsDomainPropertyId);
                        AssociationConnectorChange.StaticInvoke(
                            cpc, associationConnector, ViewModelDiagram.LinkShape.ManuallyRoutedDomainPropertyId);
                        continue;
                    }

                    var inheritanceConnector = shapeElement as InheritanceConnector;
                    if (inheritanceConnector != null)
                    {
                        InheritanceConnectorAdd.StaticInvoke(cpc, inheritanceConnector);
                        InheritanceConnectorChange.StaticInvoke(
                            cpc, inheritanceConnector, ViewModelDiagram.LinkShape.EdgePointsDomainPropertyId);
                        InheritanceConnectorChange.StaticInvoke(
                            cpc, inheritanceConnector, ViewModelDiagram.LinkShape.ManuallyRoutedDomainPropertyId);
                        continue;
                    }
                }
            });

            CommandProcessor.InvokeSingleCommand(cpc, cmd);
        }
Exemplo n.º 7
0
        /// <summary>
        ///     Returns the current active artifacts.
        ///     Assumption in here is that a view can span multiple artifacts..
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected virtual HashSet <EFArtifact> GetCurrentArtifactsInView(EditingContext context)
        {
            var serviceFromContext = context.GetEFArtifactService();

            Debug.Assert(
                serviceFromContext != null, "Null service in EditingContext for ExplorerViewModelHelper.ProcessModelChangesCommitted()");

            var artifacts = new HashSet <EFArtifact>();

            artifacts.Add(serviceFromContext.Artifact);

            return(artifacts);
        }
        internal PropertyExtensionContextImpl(
            EditingContext editingContext, ProjectItem projectItem, Version targetSchemaVersion, byte[] extensionToken)
        {
            Debug.Assert(editingContext != null, "editingContext should not be null");
            Debug.Assert(editingContext.GetEFArtifactService().Artifact != null, "editingContext should not have null artifact");
            Debug.Assert(projectItem != null, "projectItem should not be null");
            Debug.Assert(extensionToken != null, "extensionToken should not be null");

            _editingContext      = editingContext;
            _projectItem         = projectItem;
            _targetSchemaVersion = targetSchemaVersion;
            _extensionToken      = extensionToken;
        }
        public override EntityDesignerChangeScope CreateChangeScope(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("name should not be null.");
            }

            if (_scope != null)
            {
                throw new InvalidOperationException(Resources.Extensibility_StartChangeScopeFailed);
            }

            var txn = new EfiTransaction(_editingContext.GetEFArtifactService().Artifact, PROPERTY_EXTENSION_ORIGINATOR_ID, name);

            _scope = new ChangeScopeImpl(txn, _editingContext, _extensionToken, this);
            return(_scope);
        }
Exemplo n.º 10
0
        // <summary>
        //     Show the dialog to create a new enum type.
        // </summary>
        public static EnumType AddNewEnumType(
            string selectedUnderlyingType, EditingContext editingContext, string originatingId, EventHandler onDialogActivated = null)
        {
            if (editingContext == null)
            {
                throw new ArgumentNullException("editingContext");
            }

            var artifactService      = editingContext.GetEFArtifactService();
            var entityDesignArtifact = artifactService.Artifact as EntityDesignArtifact;

            Debug.Assert(
                entityDesignArtifact != null,
                typeof(EntityDesignViewModelHelper).Name
                + ".AddEnumType: Unable to find Entity Design Artifact from the passed in editing context.");

            if (entityDesignArtifact != null)
            {
                var vm = new EnumTypeViewModel(entityDesignArtifact, selectedUnderlyingType);

                var result = ShowEnumTypeDialog(vm, onDialogActivated);

                if (result == true &&
                    vm.IsValid)
                {
                    var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_CreateEnumType);
                    var createEnumTypeCommand = new CreateEnumTypeCommand(
                        vm.Name, vm.SelectedUnderlyingType
                        , (vm.IsReferenceExternalType ? vm.ExternalTypeName : String.Empty), vm.IsFlag, false);

                    cp.EnqueueCommand(createEnumTypeCommand);

                    foreach (var member in vm.Members)
                    {
                        if (String.IsNullOrWhiteSpace(member.Name) == false)
                        {
                            cp.EnqueueCommand(new CreateEnumTypeMemberCommand(createEnumTypeCommand, member.Name, member.Value));
                        }
                    }
                    cp.Invoke();
                    return(createEnumTypeCommand.EnumType);
                }
            }
            return(null);
        }
Exemplo n.º 11
0
 public override void Complete()
 {
     _editingContext.GetEFArtifactService().Artifact.XmlModelProvider.BeginUndoScope(_efiTransaction.Name);
     try
     {
         _efiTransaction.Commit(true);
         _isComplete = true;
     }
     finally
     {
         _editingContext.GetEFArtifactService().Artifact.XmlModelProvider.EndUndoScope();
     }
 }
Exemplo n.º 12
0
        protected override HashSet <EFArtifact> GetCurrentArtifactsInView(EditingContext context)
        {
            var artifacts            = new HashSet <EFArtifact>();
            var service              = context.GetEFArtifactService();
            var entityDesignArtifact = service.Artifact as EntityDesignArtifact;

            Debug.Assert(
                entityDesignArtifact != null,
                "The active artifact is not type of: " + typeof(EntityDesignArtifact) + ", Actual:" + service.Artifact.GetType());
            if (entityDesignArtifact != null)
            {
                artifacts.Add(entityDesignArtifact);

                if (entityDesignArtifact.DiagramArtifact != null)
                {
                    artifacts.Add(entityDesignArtifact.DiagramArtifact);
                }
            }
            return(artifacts);
        }
Exemplo n.º 13
0
        protected override void OnDocumentReloading(EventArgs e)
        {
            base.OnDocumentReloading(e);

            // When document is about to be reloaded, we need to close the artifact since the underlying vs text buffer will be destroyed.
            // During document reloading, LoadDocData and LoadView methods will be called which recreate a new vs text buffer, the Escher model and the DSL model elements.
            if (EditingContext != null)
            {
                var artifactService = EditingContext.GetEFArtifactService();

                Debug.Assert(artifactService != null && artifactService.Artifact != null, "Why there is no active artifact?");
                if (artifactService != null &&
                    artifactService.Artifact != null)
                {
                    var contextManager = EditingContextManager;
                    if (contextManager != null)
                    {
                        contextManager.CloseArtifact(artifactService.Artifact.Uri);
                    }
                }
            }
        }
Exemplo n.º 14
0
        protected override void OnBeforeShowContextMenu()
        {
            // Creating commands for adding scalar and complex properties to complex types (one for each complex type from the model).
            // Since the scalar types can change dependent on the schemaVersion and since complex types can be added or deleted
            // we need to compute these commands each time a context menu is requested

            // only need to do this if selected is ExplorerComplexType
            var selectedElement = CurrentExplorerInfo._explorerFrame.GetSelectedExplorerEFElement();

            if (selectedElement is ExplorerComplexType)
            {
                var service = EditingContext.GetEFArtifactService();
                Debug.Assert(service != null && service.Artifact != null, "service and service.Artifact must both be non-null");
                if (service != null &&
                    service.Artifact != null)
                {
                    // Creating commands for adding scalar properties to complex types (one for each primitive type)
                    var i = 0;
                    foreach (var type in ModelHelper.AllPrimitiveTypesSorted(service.Artifact.SchemaVersion))
                    {
                        var cmdId = new CommandID(
                            PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddScalarPropertyBase + i);
                        var cmd = MenuCommandService.FindCommand(cmdId);
                        if (cmd == null)
                        {
                            cmd = new DynamicStatusMenuCommand(OnStatusAddComplexTypeProperty, OnMenuAddComplexTypeProperty, cmdId);
                            cmd.Properties[PackageConstants.guidEscherCmdSet] = type;
                            MenuCommandService.AddCommand(cmd);
                        }
                        else
                        {
                            cmd.Properties[PackageConstants.guidEscherCmdSet] = type;
                        }
                        i++;
                    }

                    // set up commands for complex types
                    var conceptualModel = service.Artifact.ConceptualModel();
                    Debug.Assert(conceptualModel != null, "service.Artifact.ConceptualModel() should not be null");
                    if (conceptualModel != null)
                    {
                        var complexTypes = new List <ComplexType>(conceptualModel.ComplexTypes());
                        complexTypes.Sort(EFElement.EFElementDisplayNameComparison);

                        i = 0;
                        foreach (var complexType in complexTypes)
                        {
                            // don't add an item for a ComplexType that is same as currently selected one
                            if (selectedElement.ModelItem == complexType)
                            {
                                continue;
                            }

                            // if we find an old command with the same cmdId remove it and replace
                            // with the new one to force VS to refresh the text
                            var cmdId = new CommandID(
                                PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddComplexPropertyBase + i);
                            var cmd = MenuCommandService.FindCommand(cmdId);
                            if (cmd != null)
                            {
                                MenuCommandService.RemoveCommand(cmd);
                            }
                            cmd = new DynamicStatusMenuCommand(OnStatusAddComplexTypeProperty, OnMenuAddComplexTypeProperty, cmdId);
                            cmd.Properties[PackageConstants.guidEscherCmdSet] = complexType;
                            MenuCommandService.AddCommand(cmd);

                            i++;
                            if (i >= AddComplexPropertyCommandMaxCount)
                            {
                                // break after adding 10 ComplexTypes
                                break;
                            }
                        }

                        // if some of the complex types were removed, we need to remove unnecessary commands
                        var cmd2 =
                            MenuCommandService.FindCommand(
                                new CommandID(PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddComplexPropertyBase + i));
                        while (i < AddComplexPropertyCommandMaxCount &&
                               cmd2 != null)
                        {
                            MenuCommandService.RemoveCommand(cmd2);
                            i++;
                            cmd2 =
                                MenuCommandService.FindCommand(
                                    new CommandID(
                                        PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddComplexPropertyBase + i));
                        }
                    }
                }
            }
        }