/// <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> /// 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); }