コード例 #1
0
        /// <summary>
        /// Suppression des ports externes qui ne sont plus dans le modèle de référence
        /// </summary>
        /// <param name="modelPorts">The model ports.</param>
        protected void RemoveUnusedPorts(List <Guid> modelPorts)
        {
            // Suppression des inutiles
            IList <ExternalPublicPort> ports = Ports;

            while (true)
            {
                ExternalPublicPort portToDelete = null;
                foreach (ExternalPublicPort publicPort in ports)
                {
                    if (!modelPorts.Contains(publicPort.ComponentPortMoniker))
                    {
                        portToDelete = publicPort;
                        break;
                    }
                }
                if (portToDelete != null)
                {
                    // Recherche du port qui le remplace
                    ExternalPublicPort remplacant = null;
                    foreach (ExternalPublicPort newPort in Ports)
                    {
                        if (newPort.Name == portToDelete.Name && newPort != portToDelete)
                        {
                            remplacant = newPort;
                            break;
                        }
                    }
                    IList <ClassUsesOperations>      classReferences = null;
                    IList <ExternalServiceReference> layerReferences = null;

                    if (remplacant != null)
                    {
                        // Si ce port avait un lien, on essaye de le recréer sur le nouveau port du même nom
                        classReferences = ClassUsesOperations.GetLinksToSources(portToDelete);
                        layerReferences = ExternalServiceReference.GetLinksToClients(portToDelete);

                        // Suppression de l'ancien port
                        portToDelete.Delete();

                        // Re création des liens
                        if (layerReferences != null)
                        {
                            foreach (ExternalServiceReference link in layerReferences)
                            {
                                if (ReferencedModel != null)
                                {
                                    ((SoftwareLayer)link.Client).AddReferenceToService(ReferencedModel.Id,
                                                                                       ReferencedModel.Name,
                                                                                       ReferencedModel.Version,
                                                                                       portToDelete.Name);
                                }
                            }
                        }

                        if (classReferences != null)
                        {
                            foreach (ClassUsesOperations link in classReferences)
                            {
                                new ClassUsesOperations(link.Source, remplacant);
                            }
                        }
                    }
                    else
                    {
                        portToDelete.Delete();
                    }
                }
                else
                {
                    break;
                }
            }
        }
コード例 #2
0
        public static bool CanAcceptSourceAndTarget(DslModeling::ModelElement candidateSource, DslModeling::ModelElement candidateTarget)
        {
            if (candidateSource == candidateTarget)
            {
                return(false);
            }

            if (candidateSource == null)
            {
                if (candidateTarget != null)
                {
                    throw new global::System.ArgumentNullException("candidateSource");
                }
                else // Both null
                {
                    return(false);
                }
            }

            bool acceptSource = CanAcceptSource(candidateSource);

            // If the source wasn't accepted then there's no point checking targets.
            // If there is no target then the source controls the accept.
            if (!acceptSource || candidateTarget == null)
            {
                return(acceptSource);
            }

            if (!CanAcceptTarget(candidateTarget))
            {
                return(false);
            }

            if (candidateTarget is ExternalComponent)
            {
                if (candidateSource is DataLayer)
                {
                    return(DataLayerReferencesExternalComponent.GetLink((DataLayer)candidateSource, (ExternalComponent)candidateTarget) == null);
                }
                return(false);
            }

            //     Assembly    ->      Assembly                AssemblyReferencesAssemblies
            //     Assembly    ->      Model                   DotnetPublication
            if (candidateSource is DotNetAssembly)
            {
                if (candidateTarget is DotNetAssembly)
                {
                    return(AssemblyReferencesAssemblies.GetLink((DotNetAssembly)candidateSource, (DotNetAssembly)candidateTarget) == null);
                }

                if (candidateTarget is ExternalPublicPort)
                {
                    return(ExternalServiceReference.GetLink((AbstractLayer)candidateSource, (ExternalPublicPort)candidateTarget) == null);
                }
            }

            // Important - Comme ExternalServiceContract hérite de ExternalPublicPort, il faut faire ce test avant
            if (candidateSource is ExternalServiceContract || candidateTarget is ExternalServiceContract)
            {
                if (!(candidateSource is ExternalServiceContract))
                {
                    Utils.Swap <ModelElement>(ref candidateSource, ref candidateTarget);
                }

                if (candidateTarget is ClassImplementation || candidateTarget is Scenario)
                {
                    return(ClassUsesOperations.GetLinks((TypeWithOperations)candidateTarget, (ExternalServiceContract)candidateSource).Count == 0);
                }

                return(candidateTarget is SoftwareLayer);
            }

            if (candidateSource is ExternalPublicPort || candidateTarget is ExternalPublicPort)
            {
                // Contract tjs en temps que source
                if (!(candidateSource is ExternalPublicPort))
                {
                    Utils.Swap <ModelElement>(ref candidateSource, ref candidateTarget);
                }

                if (candidateTarget is AbstractLayer)
                {
                    return(ExternalServiceReference.GetLink((AbstractLayer)candidateTarget, (ExternalPublicPort)candidateSource) == null);
                }
            }

            if (candidateSource is ServiceContract || candidateTarget is ServiceContract)
            {
                // Contract tjs en temps que source
                if (!(candidateSource is ServiceContract))
                {
                    Utils.Swap <ModelElement>(ref candidateSource, ref candidateTarget);
                }

                ServiceContract contract = candidateSource as ServiceContract;
                if (candidateTarget is ClassImplementation)
                {
                    ClassImplementation clazz = candidateTarget as ClassImplementation;
                    if (contract.Layer.Level > clazz.Layer.Level)
                    {
                        return(clazz.Contract == null);
                    }
                    else
                    {
                        return(ClassUsesOperations.GetLinks(clazz, contract).Count == 0);
                    }
                }

                if (candidateTarget is Scenario)
                {
                    SoftwareLayer iLayer = GetDownestLayer(((Scenario)candidateTarget).Layer, null);
                    return(((ServiceContract)candidateSource).Layer == iLayer && ScenarioUsesContracts.GetLinks((Scenario)candidateTarget, (ServiceContract)candidateSource).Count == 0);
                }

                if (candidateTarget is SoftwareLayer)
                {
                    int layerLevel;
                    if (candidateTarget is Layer)
                    {
                        layerLevel = ((Layer)candidateTarget).Level;
                    }
                    else if (candidateTarget is InterfaceLayer)
                    {
                        layerLevel = ((InterfaceLayer)candidateTarget).Level;
                    }
                    else
                    {
                        return(false);
                    }

                    // Implementation
                    if (contract.Layer.Level > layerLevel)
                    {
                        // Est ce qu'il y a dèjà une implémentation avec cette couche ?
                        foreach (Implementation impl in Implementation.GetLinksToImplementations(contract))
                        {
                            if (impl.ClassImplementation.Layer == ((SoftwareLayer)candidateTarget))
                            {
                                return(false); // Si oui, c'est pas bon
                            }
                        }
                        return(true);
                    }
                    // Utilise service
                    else if (contract.Layer.Level < layerLevel)
                    {
                        foreach (ClassUsesOperations link in ClassUsesOperations.GetLinksToSources(contract))
                        {
                            // if (link.Source.Layer == (Layer)candidateTarget)
                            return(false);
                        }
                        return(true);
                    }
                }
            }

            if (candidateSource is ClassImplementation)
            {
                if (candidateTarget is ClassImplementation)
                {
                    //// Dans le même layer
                    //Layer sourceLayer = ((ClassImplementation)candidateSource).Layer;
                    //Layer targetLayer = ((ClassImplementation)candidateTarget).Layer;
                    //if (targetLayer.LayerPackage  == sourceLayer.LayerPackage)
                    //{
                    //    return true;
                    //}

                    //// Sinon il faut que ce soit la couche immédiatement en dessous
                    //SoftwareLayer downestLayer=null;
                    //if (sourceLayer.Level > targetLayer.Level)
                    //{
                    //    downestLayer = GetDownestLayer(sourceLayer, null);
                    //    return downestLayer == targetLayer;
                    //}
                    //else
                    //{
                    //    downestLayer = GetDownestLayer(targetLayer, null);
                    //    return downestLayer == sourceLayer;
                    //}
                    return(true);
                }

                //if (candidateTarget is Scenario)
                //{
                //    SoftwareLayer iLayer = GetDownestLayer(((Scenario)candidateTarget).Layer, null);
                //    return ((ServiceContract)candidateSource).Layer == iLayer && ScenarioUsesContracts.GetLinks((Scenario)candidateTarget, (ClassImplementation)candidateSource).Count == 0;
                //}

                return(candidateTarget is InterfaceLayer);
            }

            return(false);
        }