Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Permet d'afficher les ports corresponds aux ports définis dans le modèle
        /// </summary>
        internal bool UpdateFromModel()
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            try
            {
                object flag;
                if (Store.TransactionManager.InTransaction &&
                    Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.TryGetValue(
                        "InModelLoader", out flag))
                {
                    return(false);
                }

                ComponentModelMetadata metaData = MetaData;
                CandleModel            model    = ReferencedModel;
                if (model == null || metaData == null) //|| metaData.Version.Equals(this.Version))
                {
                    return(false);
                }

                // Création des ports externes
                using (Transaction transaction = Store.TransactionManager.BeginTransaction("Populate external system"))
                {
                    // Mise à jour du numèro de version
                    if (!metaData.Version.Equals(Version))
                    {
                        Version = metaData.Version;
                    }

                    List <Guid> portsId = new List <Guid>();
                    if (model.BinaryComponent != null)
                    {
                        foreach (DotNetAssembly asm in model.BinaryComponent.Assemblies)
                        {
                            if (asm.Visibility == Visibility.Private)
                            {
                                continue;
                            }

                            portsId.Add(asm.Id);
                            ExternalPublicPort publicPort =
                                Ports.Find(
                                    delegate(ExternalPublicPort port) { return(port.ComponentPortMoniker == asm.Id); });
                            if (publicPort == null)
                            {
                                publicPort = new ExternalPublicPort(Store);
                                Ports.Add(publicPort);
                            }

                            publicPort.Name = asm.Name;
                            publicPort.ComponentPortMoniker = asm.Id;
                            publicPort.IsInGac = asm.IsInGac;
                        }
                    }
                    else if (model.SoftwareComponent != null)
                    {
                        if (model.IsLibrary)
                        {
                            foreach (TypeWithOperations pub in model.SoftwareComponent.PublicContracts)
                            {
                                portsId.Add(pub.Id);
                                ExternalPublicPort publicPort =
                                    Ports.Find(
                                        delegate(ExternalPublicPort port) { return(port.ComponentPortMoniker == pub.Id); });
                                if (publicPort == null)
                                {
                                    publicPort = new ExternalPublicPort(Store);
                                    Ports.Add(publicPort);
                                }
                                publicPort.Name = pub.Name;
                                publicPort.ComponentPortMoniker = pub.Id;
                            }
                        }
                        else
                        {
                            foreach (TypeWithOperations pub in model.SoftwareComponent.PublicContracts)
                            {
                                portsId.Add(pub.Id);
                                ExternalPublicPort publicPort =
                                    Ports.Find(
                                        delegate(ExternalPublicPort port) { return(port.ComponentPortMoniker == pub.Id); });
                                if (publicPort == null)
                                {
                                    publicPort = new ExternalServiceContract(Store);
                                    Ports.Add(publicPort);
                                }
                                publicPort.Name = pub.Name;
                                publicPort.ComponentPortMoniker = pub.Id;
                            }
                        }
                    }

                    RemoveUnusedPorts(portsId);
                    if (transaction.HasPendingChanges)
                    {
                        transaction.Commit();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.WriteError("Update from model", String.Format("Error in UpdateFromModel for {0}", Name), ex);
                }
            }
            return(false);
        }