Ejemplo n.º 1
0
        /// <summary>
        /// Traverses the specified visitor.
        /// </summary>
        /// <param name="visitor">The visitor.</param>
        /// <param name="element">The element.</param>
        public void Traverse(IReferenceVisitor visitor, ModelElement element)
        {
            if (visitor == null)
            {
                throw new ArgumentNullException("visitor");
            }
            if (element == null)
            {
                return;
            }

            _visitor = visitor;

            // Il faut toujours commencer par un modèle pour initialiser le contexte
            CandleModel model = null;

            if (!(element is CandleModel))
            {
                model = CandleModel.GetInstance(element.Store);
                visitor.Accept(new ReferenceItem(null, model, false)); // Initialisation du contexte
            }

            // Parcours de l'élément choisi
            Traverse(new ReferenceItem(null, element, false));

            if (model != null)
            {
                visitor.ExitElement(new ReferenceItem(null, model, false));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Contextual dependency properties filter
        /// </summary>
        /// <param name="modelElement"></param>
        /// <returns></returns>
        public override PropertyDescriptorCollection GetCustomProperties(ModelElement modelElement)
        {
            PropertyDescriptorCollection collections = base.GetCustomProperties(modelElement);

            _appName = CandleModel.GetInstance(modelElement.Store).Name;

            if (modelElement is ServiceContract || modelElement is ClassImplementation ||
                modelElement is Operation || modelElement is Layer)
            {
                collections.Add(LogCallHandlerProperty.Register(modelElement));
                collections.Add(CacheCallHandlerProperty.Register(modelElement));
                collections.Add(PerformanceCounterCallHandlerProperty.Register(modelElement));
            }

            return(collections);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="e">Provides data for the ElementDeleted event.</param>
        public override void ElementDeleted(ElementDeletedEventArgs e)
        {
            CandleElement elem = e.ModelElement as CandleElement;

            if (elem == null)
            {
                return;
            }

            if (elem.Store.InUndoRedoOrRollback)
            {
                return;
            }

            CandleModel.GetInstance(elem.Store).RegisterElementPendingDelete(elem);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="e">Provides data for the ElementDeleted event.</param>
        public override void ElementDeleted(ElementDeletedEventArgs e)
        {
            LayerPackage layerPackage = e.ModelElement as LayerPackage;

            if (layerPackage == null)
            {
                return;
            }

            if (layerPackage.Store.InUndoRedoOrRollback)
            {
                return;
            }

            SoftwareComponent component = CandleModel.GetInstance(layerPackage.Store).SoftwareComponent;

            if (component != null)
            {
                // Suppression de la couche d'interface
                AbstractLayer interfaceLayer = null;
                foreach (AbstractLayer al in component.Layers)
                {
                    ISortedLayer sl = al as ISortedLayer;
                    if (sl != null && sl.Level == layerPackage.LayerLevel)
                    {
                        interfaceLayer = al;
                        break;
                    }
                }
                if (interfaceLayer != null)
                {
                    interfaceLayer.Delete();
                }
                IList <PresentationViewsSubject> shapes = PresentationViewsSubject.GetLinksToPresentation(component);
                foreach (PresentationViewsSubject link in shapes)
                {
                    ((SoftwareComponentShape)link.Presentation).ArrangeShapes();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Récupère les stratégies du modèle courant.
        /// </summary>
        /// <param name="store"></param>
        /// <remarks>
        /// Si un autre modèle est ouvert dans la solution, on retourne un manager ne contenant aucune strategie.
        /// </remarks>
        /// <returns></returns>
        public static IStrategyManager GetInstance(Store store)
        {
            // Modèle correspondant au store
            CandleModel model = CandleModel.GetInstance(store);

            if (model == null) // On a pas trouvé le modèle, on retourne un strategyManager vide
            {
                return(new StrategyManager());
            }

            // Si on a dèja chargé les stratégies, on les retourne
            if (s_currentModelId != Guid.Empty && s_currentModelId == model.Id)
            {
                return(s_currentStrategyManager);
            }

            // Est ce que c'est le modèle courant
            CandleModel currentModel = CandleModel.GetModelFromCurrentSolution();

            if (currentModel == null || currentModel.Id != model.Id)
            {
                return(new StrategyManager());
            }

            // Sinon on va créer les stratégies
            SuspendWatcher(false);

            // Flag indiquant si on peut persister les stratégies ou seulement les initialiser.
            // On ne peut pas persister si on est dans le cas d'une initialisation du modèle puisqu'on ne connait pas
            // encore le nom du modèle
            bool   canPersist       = true;
            string strategyFileName = null;

            try
            {
                // Création d'un nouveau fichier de strategies ayant le même nom que le modèle mais avec
                // l'extension .strategies
                string modelFileName = model.FileName;

                // Dans le cas d'une création d'un modèle, on ne peut pas récupérer le filepath du modèle car
                // il n'y a pas encore de vue active. Dans ce cas, on essaye de le déduire.
                if (modelFileName == null)
                {
                    string name = model.Name;

                    // On est dans le cas d'une initialisation de modèle, on ne va crèer le fichier des stratégies tout de suite
                    // on attend que le modèle soit initialisé
                    if (name.Contains("?"))
                    {
                        canPersist       = false;
                        strategyFileName = Path.GetTempFileName();  // Fichier temporaire pour récupèrer les stratégies pré-initialisées
                        Utils.DeleteFile(strategyFileName);         // Obligé car GetTempFileName crée le fichier
                    }
                    else
                    {
                        IShellHelper shell = ServiceLocator.Instance.GetService <IShellHelper>();
                        if (shell != null)
                        {
                            string tmp = Path.GetFileNameWithoutExtension(shell.GetSolutionAssociatedModelName());
                            if (!String.IsNullOrEmpty(tmp))
                            {
                                name = tmp;
                            }
                            else
                            {
                                tmp = shell.Solution.FullName;
                                if (!String.IsNullOrEmpty(tmp))
                                {
                                    name = Path.GetFileNameWithoutExtension(tmp);
                                }
                            }
                        }

                        strategyFileName = String.Concat(Path.Combine(ServiceLocator.Instance.ShellHelper.SolutionFolder, name), DefaultStrategiesFileNameExtension);
                    }
                }
                else
                {
                    strategyFileName = Path.ChangeExtension(modelFileName, DefaultStrategiesFileNameExtension);
                }

                // Initialisation du fichier de stratégies à partir d'un modèle
                if (!String.IsNullOrEmpty(model.StrategyTemplate))
                {
                    EnsureStrategiesFileExists(strategyFileName, model.StrategyTemplate, canPersist);
                }

                StrategyManager manager = null;
                if (File.Exists(strategyFileName))
                {
                    manager = Load(store, strategyFileName);
                }
                else
                {
                    manager = new StrategyManager();
                }

                if (canPersist)
                {
                    manager.FileName = strategyFileName;
                    // Cache pour éviter de le relire
                    s_currentModelId         = model.Id;
                    s_currentStrategyManager = manager;
                }

                return(manager);
            }
            finally
            {
                SuspendWatcher(true);

                // Suppression du fichier temporaire
                if (!canPersist)
                {
                    Utils.DeleteFile(strategyFileName);
                }
            }
        }
Ejemplo n.º 6
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider sp, object value)
        {
            ModelElement model = context.Instance as ModelElement;

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

            _edSvc = (IWindowsFormsEditorService)sp.GetService(typeof(IWindowsFormsEditorService));
            if (_edSvc != null)
            {
                _comboBox = new ComboBox();
                _comboBox.DropDownStyle = ComboBoxStyle.Simple;

                int num1 = 0;
                SoftwareComponent component = CandleModel.GetInstance(model.Store).SoftwareComponent;
                string            item1     = PopulateListBoxItems(component.GetDefinedTypeNames(), out num1);
                _comboBox.Size         = new Size(num1 + 10, 120);
                _comboBox.KeyDown     += KeyDown;
                _comboBox.Leave       += ValueChanged;
                _comboBox.DoubleClick += ValueChanged;
                _comboBox.Click       += ValueChanged;
                _edSvc.DropDownControl(_comboBox);
                if (_comboBox.Text.Length == 0)
                {
                    return(value);
                }
                string item2 = _comboBox.Text;
                if ((item2 == null) || (item1 == item2))
                {
                    return(value);
                }

                if (!String.IsNullOrEmpty(item2))
                {
                    bool shouldCreateModel = false;
                    ClrTypeParser.Parse(item2, delegate(string typeName)
                    {
                        shouldCreateModel = true;
                        return(typeName);
                    });

                    // Si il y a des types à créer, il faut que la couche modèle existe
                    if (shouldCreateModel && component.DataLayer == null)
                    {
                        IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                        if (ide != null)
                        {
                            ide.ShowMessage(
                                String.Format("Can't create user type '{0}' because the models layer does not exist.",
                                              item2));
                        }
                    }
                    else
                    {
                        return(item2);
                    }
                }
            }
            return(value);
        }