示例#1
0
        /// <summary>
        /// Ajout d'une référence sur une couche. Cette action ne peut se faire qu'avec un composant binaire.
        /// </summary>
        /// <param name="modelId">The model id.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="modelVersion">The model version.</param>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        public ExternalServiceReference AddReferenceToService(Guid modelId, string displayName, VersionInfo modelVersion, string serviceName, ReferenceScope scope, string mode)
        {
            ExternalComponent externalComponent = this.AddExternalModel(modelId, displayName, modelVersion);

            if (externalComponent != null && externalComponent.MetaData.ComponentType == ComponentType.Library)
            {
                foreach (ExternalPublicPort port in externalComponent.Ports)
                {
                    if (Utils.StringCompareEquals(serviceName, port.Name))
                    {
                        ExternalServiceReference link = ExternalServiceReference.GetLink(this, port);
                        if (link == null)
                        {
                            using (Transaction transaction = port.Store.TransactionManager.BeginTransaction("Create external service reference"))
                            {
                                link = new ExternalServiceReference(this, port);
                                transaction.Commit();
                            }
                            link.Scope = scope;
                            if (!port.IsInGac)
                            {
                                link.Scope |= ReferenceScope.Runtime;
                            }
                            link.ConfigurationMode = mode;
                        }
                        return(link);
                    }
                }
            }
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (logger != null)
            {
                logger.Write("Add reference to service", String.Format("Can not create a link between {0} and {1} because the port {2} doesn't exist", this.Name, displayName, serviceName), LogType.Error);
            }
            return(null);
        }
示例#2
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;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Permet lors de l'import d'une assembly de récupérer la liste des assemblies
        /// référencées par celle-ci
        /// </summary>
        /// <param name="asm">The asm.</param>
        /// <returns></returns>
        private List <AssemblyName> GetAssemblyListToCreate(Assembly asm)
        {
            List <AssemblyName> referencedAssemblies = new List <AssemblyName>();

            // Parcours de la liste des assemblies CLR
            foreach (AssemblyName an in asm.GetReferencedAssemblies())
            {
                // On ignore les assemblies systèmes
                if (Utils.StringCompareEquals(an.Name, "mscorlib") ||
                    an.Name.StartsWith("System", StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                // On regarde si cette assembly existe déjà dans le modèle
                DotNetAssembly eam = Component.FindDotNetAssemblyModelFromAssembly(an);
                if (eam != null)
                {
                    // Recherche si ce lien existe dèjà
                    bool notFound = AssemblyReferencesAssemblies.GetLink(this, eam) == null &&
                                    AssemblyReferencesAssemblies.GetLink(eam, this) == null;

                    if (notFound)
                    {
                        // Création du lien
                        AssemblyReferencesAssemblies ara = new AssemblyReferencesAssemblies(this, eam);
                        ara.Scope = ReferenceScope.Publish;
                        if (eam.IsInGac)
                        {
                            ara.Scope |= ReferenceScope.Runtime;
                        }
                        if (eam.Visibility == Visibility.Public)
                        {
                            ara.Scope |= ReferenceScope.Compilation;
                        }
                        //this.InternalAssemblyReferences.Add( eam );
                    }
                    continue;
                }

                // Idem si c'est une référence externe (binaire)
                ExternalComponent esm = Component.Model.FindExternalComponentByName(an.Name);
                if (esm != null && esm.MetaData != null && esm.MetaData.ComponentType == ComponentType.Library)
                {
                    foreach (ExternalPublicPort port in esm.Ports)
                    {
                        if (Utils.StringCompareEquals(an.Name, port.Name))
                        {
                            if (ExternalServiceReference.GetLink(this, port) == null)
                            {
                                ExternalServiceReferences.Add(port);
                            }
                        }
                        break;
                    }
                }

                // Liste des références externes à créer
                referencedAssemblies.Add(an);
            }
            return(referencedAssemblies);
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Création d'une dépendance avec une assembly importée
        /// </summary>
        /// <param name="asm">The asm.</param>
        internal void InsertDependencies(Assembly asm)
        {
            // Gestion des dépendances
            List <AssemblyName> referencedAssemblies = GetAssemblyListToCreate(asm);

            if (referencedAssemblies.Count == 0)
            {
                return;
            }

            // On va demander de faire le mapping entre l'assembly et les modèles
            // Fenetre permettant de trouver le lien entre une assembly et son modèle
            ReferencedAssembliesForm form = new ReferencedAssembliesForm(this, referencedAssemblies.ToArray());

            if (form.ShowDialog() == DialogResult.OK)
            {
                // Création des composants externes
                List <ExternalComponent> externalComponents = new List <ExternalComponent>();
                foreach (ComponentMetadataMap map in form.SelectedAssemblyBindings)
                {
                    if (!map.AlreadyExists)
                    {
                        externalComponents.Add(map.CreateComponent(Component.Model));
                    }
                }

                // Puis création des relations avec eux
                foreach (ExternalComponent externalComponent in externalComponents)
                {
                    // Pour l'instant, on ne crée des références qu'avec des composants binaires
                    if (externalComponent == null || externalComponent.MetaData == null ||
                        externalComponent.MetaData.ComponentType != ComponentType.Library)
                    {
                        continue;
                    }

                    if (externalComponent.Ports.Count == 1)
                    {
                        if (ExternalServiceReference.GetLink(this, externalComponent.Ports[0]) == null)
                        {
                            ExternalServiceReference esr =
                                new ExternalServiceReference(this, externalComponent.Ports[0]);
                            esr.Scope = ReferenceScope.Runtime;
                        }
                    }
                    else if (externalComponent.Ports.Count > 1)
                    {
                        string assemblyName = asm.GetName().Name;
                        foreach (ExternalPublicPort port in externalComponent.Ports)
                        {
                            if (Utils.StringCompareEquals(port.Name, assemblyName) ||
                                Utils.StringCompareEquals(port.Parent.Name, assemblyName))
                            {
                                if (ExternalServiceReference.GetLink(this, port) == null)
                                {
                                    ExternalServiceReference esr = new ExternalServiceReference(this, port);
                                    esr.Scope = ReferenceScope.Runtime;
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                        ide.LogError(false, String.Format("Can not create relationship between {0} and {1}", this.Name, externalComponent.Name), 0, 0, "Import");
                    }
                }
            }
        }