Exemplo n.º 1
0
        /// <summary>
        /// Execute the command
        /// </summary>
        public void Exec()
        {
            CandleModel system = _shape.ModelElement as CandleModel;

            // Si la commande a été lancé sur le composant, on référence le modèle
            if (system == null)
            {
                BinaryComponent component = _shape.ModelElement as BinaryComponent;
                if (component != null)
                {
                    system = component.Model;
                }
            }

            // Peut etre à null si le composant n'est pas de type Binary
            if (system != null)
            {
                // Affiche la fenetre de dialogue permettant de choisir les assemblies
                IAssemblySelectorDialog selector = ServiceLocator.Instance.GetService <IAssemblySelectorDialog>();
                if (selector.ShowDialog(0))
                {
                    ImportAssemblies(system, selector.SelectedAssemblies);

                    // On arrange les shapes du composant
                    IList <PresentationElement> componentShapes = PresentationViewsSubject.GetPresentation(system.Component);
                    ArrangeShapesCommand        cmd             = new ArrangeShapesCommand((NodeShape)componentShapes[0]);
                    cmd.Exec();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"></see> method.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that can be used to gain additional context information.</param>
        /// <param name="provider">An <see cref="T:System.IServiceProvider"></see> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>
        /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed.
        /// </returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            PresentationElement shape = context.Instance as PresentationElement;

            if (shape == null)
            {
                return(value);
            }

            _externalAssembly = shape.ModelElement as DotNetAssembly;
            if (_externalAssembly == null)
            {
                return(value);
            }

            using (
                Transaction transaction =
                    _externalAssembly.Store.TransactionManager.BeginTransaction("Retrieve assembly infos"))
            {
                IAssemblySelectorDialog selector = ServiceLocator.Instance.GetService <IAssemblySelectorDialog>();
                if (selector.ShowDialog(1))
                {
                    _externalAssembly.InitFromAssembly(selector.SelectedAssemblies[0], true);

                    // Vérification si il n'y a pas des relations orphelines
                    // TODO
                    transaction.Commit();
                }
            }

            return(value);
        }
        // Ajout de l'élément
        /// <summary>
        /// Alerts listeners that a rule has been used.
        /// </summary>
        /// <param name="e">An ElementAddedEventArgs that contains the event data.</param>
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            #region Condition

            // Test the element
            DotnetAssemblyShape shape = e.ModelElement as DotnetAssemblyShape;
            if (shape == null)
            {
                return;
            }

            // Teste qu'elle est la source qui a générée l'événement
            if (shape.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.IsSerializing ||
                shape.Store.InUndoRedoOrRollback)
            {
                return;
            }

            #endregion

            #region Traitement

            DotNetAssembly externalAssembly = shape.ModelElement as DotNetAssembly;
            if (externalAssembly != null && !String.IsNullOrEmpty(externalAssembly.FullName))
            {
                return;
            }

            using (
                Transaction transaction =
                    externalAssembly.Store.TransactionManager.BeginTransaction("Retrieve assembly infos"))
            {
                try
                {
                    IAssemblySelectorDialog selector = ServiceLocator.Instance.GetService <IAssemblySelectorDialog>();
                    if (selector.ShowDialog(1))
                    {
                        externalAssembly.InitFromAssembly(selector.SelectedAssemblies[0], true);
                        transaction.Commit();
                    }
                }
                catch (Exception ex)
                {
                    ILogger logger = ServiceLocator.Instance.GetService <ILogger>();
                    if (logger != null)
                    {
                        logger.WriteError("Import assembly", "Reflection error", ex);
                    }
                    transaction.Rollback();
                }
            }

            #endregion
        }
Exemplo n.º 4
0
        /// <summary>
        /// Execute the command
        /// </summary>
        public void Exec()
        {
            // Affiche la fenetre de dialogue permettant de choisir les assemblies
            IAssemblySelectorDialog selector = ServiceLocator.Instance.GetService <IAssemblySelectorDialog>();

            if (selector.ShowDialog(1)) // Une seule sélection possible
            {
                Assembly asm = selector.SelectedAssemblies[0];
                using (Transaction transaction = _element.Store.TransactionManager.BeginTransaction("Update model version"))
                {
                    // Mise à jour de la version du composant et son emplacement initial
                    // et création des nouvelles dépendances (les dépendances actuelles ne seront pas touchées
                    // mais il faudra s'assurer qu'elles soient bien à jour car la procédure ne vérifie que le nom
                    // et ignore la version)
                    _element.InitFromAssembly(asm, true /* creation des nouvelles dépendances*/);
                    transaction.Commit();
                }

                // Vérification si les assemblies existantes possédent la bonne version
                foreach (AssemblyName assemblyName in asm.GetReferencedAssemblies())
                {
                    // On ignore les assemblies systèmes
                    if (Utils.StringCompareEquals(assemblyName.Name, "mscorlib") ||
                        assemblyName.Name.StartsWith("System", StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    // On regarde si cette assembly existe déjà dans le modèle
                    DotNetAssembly eam = _element.Component.FindDotNetAssemblyModelFromAssembly(assemblyName);
                    if (eam != null)
                    {
                        if (!assemblyName.Version.Equals((Version)eam.Version))
                        {
                            using (Transaction transaction = _element.Store.TransactionManager.BeginTransaction("Update assembly version"))
                            {
                                eam.Version = new VersionInfo(assemblyName.Version);
                                transaction.Commit();
                            }
                        }
                    }
                    else
                    {
                        // Idem pour les composants externes
                        ExternalComponent esm = _element.Component.Model.FindExternalComponentByName(assemblyName.Name);
                        if (esm != null && esm.MetaData != null && esm.MetaData.ComponentType == ComponentType.Library)
                        {
                            if (!assemblyName.Version.Equals((Version)esm.Version))
                            {
                                // Recherche si il existe un modèle avec la bonne version
                                List <ComponentModelMetadata> versions = RepositoryManager.Instance.ModelsMetadata.Metadatas.GetAllVersions(esm.Id);
                                ComponentModelMetadata        metadata = versions.Find(delegate(ComponentModelMetadata m) { return(assemblyName.Version.Equals(m.Version)); });
                                using (Transaction transaction = _element.Store.TransactionManager.BeginTransaction("Update model version"))
                                {
                                    if (metadata != null)
                                    {
                                        // OK on met a jour
                                        esm.Version = metadata.Version;
                                    }
                                    else // erreur On a pas trouvé de modéle
                                    {
                                        // Sauvegarde de la bonne version
                                        esm.Version = new VersionInfo(assemblyName.Version);
                                        // On force à null pour obliger l'utilisateur à sélectionner un
                                        // modéle
                                        esm.ModelMoniker = Guid.Empty;
                                    }
                                    transaction.Commit();
                                }
                            }
                        }
                    }
                }

                // Demande si il faut aussi mettre à jour le n° de version du composant
                if (_element.Visibility == Visibility.Public)
                {
                    if (MessageBox.Show(String.Format("Do you want to change the current version of the component from {0} to {1}",
                                                      _element.Component.Model.Version, _element.Version), "Component version change", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        using (Transaction transaction = _element.Store.TransactionManager.BeginTransaction("Update model version"))
                        {
                            _element.Component.Model.Version = _element.Version;
                            transaction.Commit();
                        }
                    }
                }
            }
        }