示例#1
0
        /// <summary>
        /// Drop d'un modèle à partir du repository tree
        /// </summary>
        /// <param name="e">The diagram drag event arguments.</param>
        public override void OnDragDrop(DiagramDragEventArgs e)
        {
            base.OnDragDrop(e);

            if (e.Data.GetDataPresent(typeof(RepositoryTreeControl.RepositoryDataDragDrop)))
            {
                RepositoryTreeControl.RepositoryDataDragDrop data = (RepositoryTreeControl.RepositoryDataDragDrop)e.Data.GetData(typeof(RepositoryTreeControl.RepositoryDataDragDrop));
                if (data != null && this.ModelElement is CandleModel)
                {
                    CandleModel model = ((CandleModel)this.ModelElement);

                    using (Transaction transaction = model.Store.TransactionManager.BeginTransaction("Drop a model"))
                    {
                        // On ne le met pas si il y est dèjà
                        if (model.Id == data.MetaData.Id)
                        {
                            ServiceLocator.Instance.IDEHelper.ShowMessage("You can not drag the current model.");
                            return;
                        }
                        if (model.FindExternalComponent(data.MetaData.Id) != null)
                        {
                            ServiceLocator.Instance.IDEHelper.ShowMessage("This model already exists in the designer.");
                            return;
                        }

                        ExternalComponent system = data.MetaData.CreateComponent(model);
                        transaction.Commit();
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            NodeShape shape = context.Instance as NodeShape;

            if (shape != null)
            {
                ExternalComponent element = shape.ModelElement as ExternalComponent;
                if (element != null)
                {
                    List <ComponentModelMetadata> versions =
                        RepositoryManager.Instance.ModelsMetadata.Metadatas.GetAllVersions(element.ModelMoniker);
                    ArrayList items = new ArrayList();
                    if (versions.Count == 0)
                    {
                        object value = context.PropertyDescriptor.GetValue(element);
                        if (value != null)
                        {
                            items.Add(value.ToString());
                        }
                    }
                    else
                    {
                        foreach (ComponentModelMetadata item in versions)
                        {
                            items.Add(item.Version.ToString());
                        }
                    }

                    return(new StandardValuesCollection(items.ToArray()));
                }
            }
            return(base.GetStandardValues(context));
        }
示例#3
0
        /// <summary>
        /// Chargement d'un modèle
        /// </summary>
        /// <param name="system"></param>
        /// <returns></returns>
        public static ModelLoader GetLoader(ExternalComponent system)
        {
            ComponentModelMetadata metaData = system.MetaData;
            ModelLoader            loader   = GetLoader(metaData);

            if (loader != null && loader.Model != null && loader.Model.SoftwareComponent != null)
            {
                loader.Model.SoftwareComponent.NamespaceResolver = new ExternalNamespaceProvider(system);
            }
            return(loader);
        }
示例#4
0
        /// <summary>
        /// Chargement et affichage du modèle
        /// </summary>
        /// <param name="e">The diagram point event arguments.</param>
        public override void OnDoubleClick(DiagramPointEventArgs e)
        {
            base.OnDoubleClick(e);

            ExternalComponent model = ModelElement as ExternalComponent;

            if (model != null)
            {
                ExternalComponentShapeHelper.TryToShow(model);
            }
        }
示例#5
0
        //private void ShowFromTemporaryFolder(string physicalModelFileName, string relativeModelFileName)
        //{
        //}

        /// <summary>
        /// Tries to show.
        /// </summary>
        /// <param name="model">The model.</param>
        public static void TryToShow(ExternalComponent model)
        {
            // Si le système n'est pas encore défini, on va demander à l'utilisateur d'en choisir un
            //  dans le référentiel ou d'en créer un nouveau.
            ComponentModelMetadata metaData = model.MetaData;

            if (metaData == null)
            {
                using (Transaction transaction = model.Store.TransactionManager.BeginTransaction("Select model"))
                {
                    if (RepositoryManager.Instance.ModelsMetadata.SelectModel(model, out metaData))
                    {
                        transaction.Commit();
                    }
                }
                return;
            }
            ShowModel(metaData);
        }
示例#6
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);
        }
示例#7
0
        /// <summary>
        /// Ajoute une référence sur un modèle externe.
        /// </summary>
        /// <param name="modelId">The model id.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="version">Version désirée ou null</param>
        /// <returns></returns>
        /// <remarks>
        /// Si la référence existe dans le référentiel avec le bon numèro de version,
        /// on rajoute la référence si le numéro de version n'est pas précisé ou n'est pas
        /// présent dans le référentiel, on affiche la boite de dialogue de sélection
        /// si ce n'est toujours pas bon, on rajoute la référence en tant que référence
        /// classique statique.
        /// </remarks>
        protected ExternalComponent AddExternalModel(Guid modelId, string displayName, VersionInfo version)
        {
            ExternalComponent externalComponent = this.Component.Model.FindExternalComponent(modelId);

            if (externalComponent != null)
            {
                return(externalComponent);
            }

            // Recherche le modèle dans le repository
            ComponentModelMetadata metadata = RepositoryManager.Instance.ModelsMetadata.Metadatas.Find(modelId, version);

            if (metadata != null)
            {
                // Ok on l'a trouvé
                using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Add external component"))
                {
                    externalComponent = metadata.CreateComponent(this.Component.Model);
                    transaction.Commit();
                    return(externalComponent);
                }
            }
            else
            {
                // Pas trouvé
                ReferencedAssembliesForm form = new ReferencedAssembliesForm(modelId, displayName, version, null);
                if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (form.SelectedAssemblyBindings.Count > 0)
                    {
                        return(form.SelectedAssemblyBindings[0].CreateComponent(this.Component.Model));
                    }
                }
            }

            return(null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExternalNamespaceProvider"/> class.
 /// </summary>
 /// <param name="externalComponent">The external component.</param>
 public ExternalNamespaceProvider(ExternalComponent externalComponent)
 {
     _externalComponent = externalComponent;
 }
示例#9
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);
        }