/// <summary> /// Creates the link. /// </summary> /// <param name="clazz">The clazz.</param> /// <param name="clazz2">The clazz2.</param> /// <returns></returns> private static ElementLink CreateLink(ClassImplementation clazz, ClassImplementation clazz2) { if (clazz.Layer.Level < clazz2.Layer.Level) { Utils.Swap <ClassImplementation>(ref clazz, ref clazz2); } if (clazz.Layer.LayerPackage == clazz2.Layer.LayerPackage) { return(new ClassUsesOperations(clazz, clazz2)); } SoftwareLayer nextLayer = GetDownestLayer(clazz.Layer, clazz2.Layer); if (nextLayer is InterfaceLayer) { ServiceContract contract = CreateContract(clazz2, (InterfaceLayer)nextLayer); new ClassUsesOperations(clazz, contract); return(CreateLink(contract, clazz2)); } ClassImplementation clazz3 = CreateClass(clazz2, (Layer)nextLayer); ClassUsesOperations link = new ClassUsesOperations(clazz, clazz3); link.Scope |= ReferenceScope.Compilation; if (nextLayer == clazz2.Layer) { return(link); } return(CreateLink(clazz3, clazz2)); }
/// <summary> /// Récupére la liste des services utilisés par cette couche. Cette méthode assure que les services sont uniques. /// </summary> /// <param name="mode">Mode à prendre en compte</param> /// <returns></returns> public List <ClassUsesOperations> GetServicesUsed(ConfigurationMode mode) { List <ClassUsesOperations> services = new List <ClassUsesOperations>(); List <TypeWithOperations> types = GetImplementations(); if (types == null || types.Count == 0) { return(services); } List <Guid> doublons = new List <Guid>(); foreach (TypeWithOperations clazz in types) { foreach (ClassUsesOperations service in ClassUsesOperations.GetLinksToServicesUsed(clazz)) { if (!mode.CheckConfigurationMode(service.ConfigurationMode) || doublons.Contains(service.TargetService.Id)) { continue; } doublons.Add(service.TargetService.Id); services.Add(service); } } return(services); }
/// <summary> /// Gets the service references. /// </summary> /// <param name="item">The item.</param> /// <param name="context">The context.</param> /// <param name="layers">The layers.</param> /// <returns></returns> protected IEnumerable <ReferenceItem> GetServiceReferences(TypeWithOperations item, ReferenceContext context, List <Guid> layers) { foreach (NamedElement service in item.ServicesUsed) { IList <ClassUsesOperations> externalServiceLinks = ClassUsesOperations.GetLinksToServicesUsed(item); foreach (ClassUsesOperations link in externalServiceLinks) { if (context.Mode.CheckConfigurationMode(link.ConfigurationMode) && context.CheckScope(link.Scope)) { if (service is ExternalServiceContract) { ExternalServiceContract contract = service as ExternalServiceContract; // Ici on part du principe qu'un composant ne publie qu'une couche donc // on ne prend en considèration que le 1er port rencontré. Si ce n'était pas le // cas, il faudrait d'abord créer un tableau global des ports rencontrés PUIS faire // un RetrieveReferencesForExternalComponent avec tous les ports. List <Guid> ports2 = new List <Guid>(); ports2.Add(contract.ComponentPortMoniker); yield return (new ReferenceItem(this, contract.Parent, link.Scope, ports2, context.IsExternal)); } else if (service is ServiceContract) { ServiceContract contract = service as ServiceContract; if (!layers.Contains(contract.Layer.Id)) { layers.Add(contract.Layer.Id); yield return(new ReferenceItem(this, contract.Layer, context.IsExternal)); } } else if (service is ClassImplementation) { ClassImplementation targetClazz = service as ClassImplementation; if (!layers.Contains(targetClazz.Layer.Id)) { layers.Add(targetClazz.Layer.Id); yield return(new ReferenceItem(this, targetClazz.Layer, context.IsExternal)); } } } } } }
/// <summary> /// Creates the link. /// </summary> /// <param name="clazz">The clazz.</param> /// <param name="layer">The layer.</param> /// <returns></returns> private static ElementLink CreateLink(ClassImplementation clazz, SoftwareLayer layer) { if (clazz.Layer.Level > ((ISortedLayer)layer).Level) { InterfaceLayer iLayer = (InterfaceLayer)GetDownestLayer(clazz.Layer, layer); ServiceContract contract = CreateContract(clazz, iLayer); ClassUsesOperations link = new ClassUsesOperations(clazz, contract); if (iLayer == layer) { return(link); } return(CreateLink(contract, layer)); } else // On monte { if (layer is InterfaceLayer) { ServiceContract contract = CreateContract(clazz, (InterfaceLayer)layer); return(CreateLink(contract, clazz)); } ClassImplementation clazz2 = CreateClass(clazz, (Layer)layer); return(CreateLink(clazz2, clazz)); } }
/// <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; } } }
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); }
/// <summary> /// Gets the parent for class uses operations. /// </summary> /// <param name="classUsesOperations">The class uses operations.</param> /// <returns></returns> private Microsoft.VisualStudio.Modeling.ModelElement GetParentForClassUsesOperations(ClassUsesOperations classUsesOperations) { ICustomizableElement clazz = classUsesOperations.Source as ICustomizableElement; System.Diagnostics.Debug.Assert(clazz != null); return(((SoftwareLayer)clazz.Owner).Component.Model); }