Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Merges the configure.
        /// </summary>
        /// <param name="elementGroup">The element group.</param>
        protected override void MergeConfigure(Microsoft.VisualStudio.Modeling.ElementGroup elementGroup)
        {
            base.MergeConfigure(elementGroup);

            DomainClassInfo.SetUniqueName(this, StrategyManager.GetInstance(this.Store).NamingStrategy.CreateLayerName(null, this, this.Name));
            Namespace = StrategyManager.GetInstance(this.Store).NamingStrategy.CreateNamespace(Component.Namespace, Name, this);
        }
Ejemplo n.º 3
0
        protected override void MergeConfigure(Microsoft.VisualStudio.Modeling.ElementGroup elementGroup)
        {
            base.MergeConfigure(elementGroup);

            foreach (ElementLink link in elementGroup.ElementLinks)
            {
                if (link is DomainPropertyReferencesType)
                {
                    DomainType targeType = (link as DomainPropertyReferencesType).DomainType;
                }
            }
        }
Ejemplo n.º 4
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);
            }
        }
        /// <summary>
        /// Add new domain class command executed.
        /// </summary>
        private void AddNewDomainClassCommand_Executed()
        {
            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Create new domain class + Root node"))
            {
                // create new domain class
                DomainClass domainClass = this.Store.ElementFactory.CreateElement(DomainClass.DomainClassId) as DomainClass;
                Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(this.Store as IServiceProvider, this.Store.DefaultPartition);
                Microsoft.VisualStudio.Modeling.ElementGroup elementGroup = new Microsoft.VisualStudio.Modeling.ElementGroup(this.Store.DefaultPartition);
                elementGroup.Add(domainClass);
                elementGroup.MarkAsRoot(domainClass);
                elementOperations.MergeElementGroup(this.modelTreeView.ViewContext.ModelContext, elementGroup);
                domainClass.Name = NameHelper.GetUniqueName(Store, DomainClass.DomainClassId);

                transaction.Commit();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Lors de l'ajout d'un layer, on crée automatiquement le packageLayer qui le contient
        /// </summary>
        /// <param name="sourceElement">The source element.</param>
        /// <param name="elementGroup">The element group.</param>
        private void MergeRelateLayer(Microsoft.VisualStudio.Modeling.ModelElement sourceElement, Microsoft.VisualStudio.Modeling.ElementGroup elementGroup)
        {
            Layer sourceLayer = sourceElement as Layer;

            if (sourceLayer != null)
            {
                // Un Layer est toujours dans un LayerPackage
                if (this.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.IsSerializing || this.Store.InUndoRedoOrRollback)
                {
                    return;
                }

                // Recherche du package layer associé et si il n'existe pas on le crée
                LayerPackage parentPackage = null;
                foreach (LayerPackage package in this.LayerPackages)
                {
                    if (package.Level == sourceLayer.Level)
                    {
                        parentPackage = package;
                        break;
                    }
                }

                // Transaction pour forcer la création du package avant l'ajout du layer
                // cf LayerPackageInsertRule
                using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Add layer package"))
                {
                    if (parentPackage == null)
                    {
                        parentPackage       = new LayerPackage(this.Store);
                        parentPackage.Level = (short)sourceLayer.Level;
                        MergeRelateLayerPackage(parentPackage, null);
                    }

                    // Ajout
                    parentPackage.Layers.Add(sourceLayer);
                    transaction.Commit();
                }
            }

            this.Layers.Add(sourceElement as SoftwareLayer);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// A la création d'un package, on ajoute sa couche d'interface
        /// </summary>
        /// <param name="sourceElement">The source element.</param>
        /// <param name="elementGroup">The element group.</param>
        private void MergeRelateLayerPackage(Microsoft.VisualStudio.Modeling.ModelElement sourceElement, Microsoft.VisualStudio.Modeling.ElementGroup elementGroup)
        {
            // Ajout du package
            LayerPackage layerPackage = sourceElement as LayerPackage;

            this.LayerPackages.Add(layerPackage);

            if (this.Store.TransactionManager.CurrentTransaction.IsSerializing || this.Store.InUndoRedoOrRollback)
            {
                return;
            }

            // Recherche si il existe une couche d'interface de ce niveau
            short newLevel = (short)(layerPackage.Level + 1);

            // Pas d'interface pour la couche UI
            if (layerPackage.InterfaceLayer == null)  //&& layerPackage.Level != 100) // UIWorkflowLayer.Level
            {
                InterfaceLayer il = new InterfaceLayer(layerPackage.Store);
                il.Level = layerPackage.LayerLevel;
                layerPackage.InterfaceLayer = il;
                this.Layers.Add(il);
            }
        }
        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);
            }
        }
        /// <summary>
        /// Add new diagram class command executed.
        /// </summary>
        private void AddNewDiagramClassCommand_Executed()
        {
            using (Transaction transaction = Store.TransactionManager.BeginTransaction("Create new diagram class + vm"))
            {
                // create new diagram class
                DiagramClass diagramClass = Store.ElementFactory.CreateElement(DiagramClass.DomainClassId) as DiagramClass;
                Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(Store as IServiceProvider, Store.DefaultPartition);
                Microsoft.VisualStudio.Modeling.ElementGroup elementGroup = new Microsoft.VisualStudio.Modeling.ElementGroup(Store.DefaultPartition);
                elementGroup.Add(diagramClass);
                elementGroup.MarkAsRoot(diagramClass);
                elementOperations.MergeElementGroup(this.diagramView.ViewContext.ModelContext, elementGroup);
                diagramClass.Name = NameHelper.GetUniqueName(Store, DiagramClass.DomainClassId);

                diagramClass.Title = diagramClass.Name;

                DiagramClassView view = new DiagramClassView(this.Store);
                view.DiagramClass = diagramClass;
                this.diagramView.DiagramClassViews.Add(view);

                transaction.Commit();
            }
        }
        /// <summary>
        /// Add new diagram class from template command executed.
        /// </summary>
        private void AddNewDiagramClassFromTemplateCommand_Executed()
        {
            DiagramClassTemplateSelectorViewModel vm = new DiagramClassTemplateSelectorViewModel(this.ViewModelStore);
            bool? result = this.GlobalServiceProvider.Resolve<IUIVisualizerService>().ShowDialog("DiagramClassTemplateSelector", vm);
            if (result == true)
            {
                using (Transaction transaction = Store.TransactionManager.BeginTransaction("Create new templated diagram class + vm"))
                {
                    // create new diagram class
                    DiagramClass diagramClass;

                    if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.GeneralGraphicalDependencyTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(DependencyDiagram.DomainClassId) as DependencyDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.SpecificGraphicalDependencyTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(SpecificDependencyDiagram.DomainClassId) as SpecificDependencyDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.ModalDiagramTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(ModalDiagram.DomainClassId) as ModalDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.SpecificElementsDiagramTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(SpecificElementsDiagram.DomainClassId) as SpecificElementsDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.DesignerSurfaceDiagramTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(DesignerSurfaceDiagram.DomainClassId) as DesignerSurfaceDiagram;
                    else
                    {
                        throw new NotSupportedException();
                    }

                    (diagramClass as TemplatedDiagramClass).UniqueId = vm.SelectedTemplateVM.UniqueId;
                    (diagramClass as TemplatedDiagramClass).Name = vm.SelectedTemplateVM.Name;
                    (diagramClass as TemplatedDiagramClass).Title = vm.SelectedTemplateVM.DisplayName;
                    (diagramClass as TemplatedDiagramClass).Description = vm.SelectedTemplateVM.Description;
                    diagramClass.IsCustom = true;

                    Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(Store as IServiceProvider, Store.DefaultPartition);
                    Microsoft.VisualStudio.Modeling.ElementGroup elementGroup = new Microsoft.VisualStudio.Modeling.ElementGroup(Store.DefaultPartition);
                    elementGroup.Add(diagramClass);
                    elementGroup.MarkAsRoot(diagramClass);
                    elementOperations.MergeElementGroup(this.diagramView.ViewContext.ModelContext, elementGroup);

                    DiagramClassView view = new DiagramClassView(this.Store);
                    view.DiagramClass = diagramClass;
                    this.diagramView.DiagramClassViews.Add(view);

                    transaction.Commit();
                }
            }
        }