예제 #1
0
        /// <summary>
        /// Adds a new derived class to each of the given domain classes.
        /// </summary>
        /// <param name="sources">DomainClasses to add a derived from.</param>
        public static void AddNewInheritanceRelationshipNewDerivedClass(List <DomainClass> sources)
        {
            if (sources.Count == 0)
            {
                return;
            }

            using (Transaction transaction = sources[0].Store.TransactionManager.BeginTransaction("Create new inheritance rs"))
            {
                foreach (DomainClass source in sources)
                {
                    // Create new domain class to act as the derived class
                    DomainClass target = source.Store.ElementFactory.CreateElement(DomainClass.DomainClassId) as DomainClass;
                    Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(source.Store as IServiceProvider, source.Store.DefaultPartition);
                    Microsoft.VisualStudio.Modeling.ElementGroup      elementGroup      = new Microsoft.VisualStudio.Modeling.ElementGroup(source.Store.DefaultPartition);
                    elementGroup.Add(target);
                    elementGroup.MarkAsRoot(target);
                    elementOperations.MergeElementGroup(source.ModelContext, elementGroup);
                    target.Name = NameHelper.GetUniqueName(source.Store, DomainClass.DomainClassId);

                    // create a new embedding relationship
                    AddNewInheritanceRelationship(target, source, true);
                }
                transaction.Commit();
            }
        }
예제 #2
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            ModelContext modelContext = e.ModelElement as ModelContext;

            if (modelContext != null)
            {
                if (modelContext.ViewContext == null)
                {
                    ViewContext viewContext = new ViewContext(modelContext.Store);
                    viewContext.DomainModelTreeView = new DomainModelTreeView(modelContext.Store);
                    viewContext.DiagramView         = new DiagramView(modelContext.Store);
                    modelContext.ViewContext        = viewContext;
                    modelContext.MetaModel.View.ViewContexts.Add(viewContext);
                }

                if (modelContext.DiagramClasses.Count == 0)
                {
                    DesignerDiagramClass ddC = new DesignerDiagramClass(modelContext.Store);
                    //ddC.Name = "DesignerDiagram";
                    ddC.Name  = NameHelper.GetUniqueName(modelContext.Store, DesignerDiagramClass.DomainClassId);
                    ddC.Title = "Designer";
                    modelContext.DiagramClasses.Add(ddC);

                    DiagramClassView vm = new DiagramClassView(modelContext.Store);
                    vm.IsExpanded   = true;
                    vm.DiagramClass = ddC;
                    modelContext.ViewContext.DiagramView.DiagramClassViews.Add(vm);
                }

                DomainClass domainClass = modelContext.Store.ElementFactory.CreateElement(DomainClass.DomainClassId) as DomainClass;
                domainClass.IsDomainModel = true;
                Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(modelContext.Store as IServiceProvider, modelContext.Store.DefaultPartition);
                Microsoft.VisualStudio.Modeling.ElementGroup      elementGroup      = new Microsoft.VisualStudio.Modeling.ElementGroup(modelContext.Store.DefaultPartition);
                elementGroup.Add(domainClass);
                elementGroup.MarkAsRoot(domainClass);
                elementOperations.MergeElementGroup(modelContext, elementGroup);
                domainClass.Name = NameHelper.GetUniqueName(modelContext.Store, DomainClass.DomainClassId);

                SerializedDomainModel child = new SerializedDomainModel(domainClass.Store);
                child.DomainClass       = domainClass;
                child.SerializationName = domainClass.SerializationName;

                if (modelContext.SerializationModel == null)
                {
                    modelContext.SerializationModel = new SerializationModel(modelContext.Store);
                }

                modelContext.SerializationModel.SerializedDomainModel = child;
                SerializationHelper.AddSerializationDomainProperties(domainClass.Store, domainClass);
            }
        }