Exemple #1
0
        /// <summary>
        /// Recherche de la couche immédiatement en dessous
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="potentialLayer">The potential layer.</param>
        /// <returns></returns>
        private static SoftwareLayer GetDownestLayer(SoftwareLayer layer, SoftwareLayer potentialLayer)
        {
            // Recherche du layerPackage en dessous
            if (layer is InterfaceLayer)
            {
                LayerPackage layerPackage = null;
                foreach (LayerPackage lp in layer.SoftwareComponent.LayerPackages)
                {
                    if (lp.Level < ((InterfaceLayer)layer).Level)
                    {
                        if (layerPackage == null || layerPackage.Level < lp.Level)
                        {
                            layerPackage = lp;
                        }
                    }
                }

                if (layerPackage != null)
                {
                    List <SoftwareLayer> layers = new List <SoftwareLayer>();
                    foreach (SoftwareLayer sl in layerPackage.Layers)
                    {
                        layers.Add(sl);
                    }
                    // TODO a voir - On retourne tjs le 1er layer
                    if (layers.Count == 0)
                    {
                        return(null);
                    }
                    foreach (SoftwareLayer sl in layers)
                    {
                        if (sl == potentialLayer)
                        {
                            return(potentialLayer);
                        }
                    }
                    return(layers[0]);
                }
            }
            else
            {
                // Recherche de la couche d'interface
                ISortedLayer theLayer = null;
                foreach (AbstractLayer al in layer.SoftwareComponent.Layers)
                {
                    ISortedLayer sl = al as ISortedLayer;
                    if (sl != null && sl.Level < ((Layer)layer).Level)
                    {
                        if (theLayer == null || theLayer.Level < sl.Level)
                        {
                            theLayer = sl;
                        }
                    }
                }

                return(theLayer as SoftwareLayer);
            }

            return(null);
        }
Exemple #2
0
        /// <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));
        }
Exemple #3
0
        /// <summary>
        /// Liste de tous les types disponibles dans le modèle
        /// </summary>
        /// <param name="sourceLayer">Source à partir duquel on veut récupérer les types (null pour récupérer à partir du modelsLayer)</param>
        /// <param name="includeExternalTypes">Indique si on doit inclure les types externes</param>
        /// <returns></returns>
        public IList <DataType> GetAllTypes(SoftwareLayer sourceLayer, bool includeExternalTypes)
        {
            List <DataType> types = new List <DataType>();

            foreach (Package package in this.Packages)
            {
                foreach (DataType clazz in package.Types)
                {
                    types.Add(clazz);
                }
            }

            if (includeExternalTypes)
            {
                // Référence entre les couches modèles
                List <Guid> models = new List <Guid>();
                foreach (ExternalComponent sys in this.ReferencedExternalComponents)
                {
                    CandleModel model = sys.ReferencedModel;
                    if (model != null && model.DataLayer != null)
                    {
                        models.Add(model.Id);
                        types.AddRange(model.DataLayer.AllTypes);
                    }
                }

                if (sourceLayer != null)
                {
                    ExternalDataLayerVisitor visitor = new ExternalDataLayerVisitor(types, models);
                    ReferenceWalker          walker  = new ReferenceWalker(ReferenceScope.Compilation, new ConfigurationMode());
                    walker.Traverse(visitor, sourceLayer);
                }
            }
            return(types);
        }
Exemple #4
0
        /// <summary>
        /// Merges the disconnect layer.
        /// </summary>
        /// <param name="sourceElement">The source element.</param>
        private void MergeDisconnectLayer(Microsoft.VisualStudio.Modeling.ModelElement sourceElement)
        {
            SoftwareLayer layer = sourceElement as SoftwareLayer;

            if (layer != null)
            {
                foreach (ElementLink link in SoftwareComponentHasLayers.GetLinks(this, layer))
                {
                    // Delete the link, but without possible delete propagation to the element since it's moving to a new location.
                    link.Delete(SoftwareComponentHasLayers.SoftwareComponentDomainRoleId, SoftwareComponentHasLayers.SoftwareLayerDomainRoleId);
                }
            }
        }
Exemple #5
0
        protected void ValidateAssemblyNames(ValidationContext context)
        {
            string       msg         = "All the layers within the same Visual Studio project must have the same assembly name";
            bool         isValid     = true;
            ModelElement elemInError = this;

            try
            {
                // Tous les projets Visual Studio de même nom doivent avoir le même nom
                // d'assemblie
                Dictionary <string, string> names = new Dictionary <string, string>();
                foreach (AbstractLayer layer in Layers)
                {
                    SoftwareLayer slayer = layer as SoftwareLayer;
                    if (slayer == null)
                    {
                        continue;
                    }

                    if (names.ContainsKey(slayer.VSProjectName))
                    {
                        if (!Utils.StringCompareEquals(names[slayer.VSProjectName], slayer.AssemblyName))
                        {
                            isValid     = false;
                            elemInError = layer;
                            break;
                        }
                    }
                    else
                    {
                        names[slayer.VSProjectName] = slayer.AssemblyName;
                    }
                }
            }
            catch (Exception ex)
            {
                msg     = ex.Message;
                isValid = false;
            }

            if (!isValid)
            {
                context.LogError(
                    msg,
                    "NMS1", // Unique error number
                    elemInError);
            }
        }
Exemple #6
0
        /// <summary>
        /// Creates the link.
        /// </summary>
        /// <param name="contract">The contract.</param>
        /// <param name="targetLayer">The target layer.</param>
        /// <returns></returns>
        private static ElementLink CreateLink(ServiceContract contract, SoftwareLayer targetLayer)
        {
            InterfaceLayer iLayer = targetLayer as InterfaceLayer;
            Layer          layer  = targetLayer as Layer;

            Debug.Assert(iLayer != null || layer != null);
            int layerLevel = 0;

            if (layer != null)
            {
                layerLevel = layer.Level;
            }
            else if (iLayer != null)
            {
                layerLevel = iLayer.Level;
            }


            // On descend
            if (contract.Layer.Level > layerLevel)
            {
                // Implémentation
                Layer downLayer = GetDownestLayer(contract.Layer, targetLayer) as Layer;
                Debug.Assert(downLayer != null);
                ClassImplementation impl = CreateClass(contract, downLayer);
                Implementation      link = new Implementation(impl, contract);
                if (downLayer == targetLayer)
                {
                    return(link);
                }
                return(CreateLink(impl, targetLayer));
            }
            else
            {
                // On monte
                if (layer != null)
                {
                    ClassImplementation impl = CreateClass(contract, layer);
                    return(CreateLink(contract, impl));
                }
                // Sinon la couche destinatrice est une couche d'interface
                ServiceContract contract2 = CreateContract(contract, iLayer);
                return(CreateLink(contract, contract2));
            }
        }
Exemple #7
0
 /// <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));
     }
 }
Exemple #8
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);
        }