/// <summary> /// Mise à jour des noms du package et de la couche d'interface /// </summary> /// <param name="slayer">The slayer.</param> private static void UpdateInterfaceAndLayerPackageName(SoftwareLayer slayer) { Layer layer = slayer as Layer; if (layer == null) { return; } LayerPackage package = layer.LayerPackage; if (String.IsNullOrEmpty(package.Name) && package.Name != "?") { package.Name = StrategyManager.GetInstance(layer.Store).NamingStrategy.GetLayerName(layer); } if (package.InterfaceLayer != null) { if (String.IsNullOrEmpty(package.InterfaceLayer.Name)) { package.InterfaceLayer.Name = StrategyManager.GetInstance(layer.Store).NamingStrategy.CreateLayerName(package, package.InterfaceLayer, layer.Name); } } }
/// <summary> /// Nom par défaut d'une couche /// </summary> /// <param name="layerPackage">The layer package.</param> /// <param name="element">Type de la couche</param> /// <param name="associatedName">Name of the associated.</param> /// <returns></returns> public virtual string CreateLayerName(LayerPackage layerPackage, SoftwareLayer element, string associatedName) { string typeName = element.GetType().Name; LayerNamingRule rule = FindRule(element); if (associatedName == null) { associatedName = rule.DefaultName; } return(string.Format(rule.FormatString, rule.DefaultName, element.Component.Name, element.Namespace, layerPackage != null ? layerPackage.Name : String.Empty, associatedName)); }
// 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) { // Test the element LayerPackage model = e.ModelElement as LayerPackage; if (model == null) { return; } Diagram.FixUpDiagram(model.Component, model); }
/// <summary> /// Creates the layer. /// </summary> /// <param name="component">The component.</param> /// <param name="package">The package.</param> /// <returns></returns> public SoftwareLayer CreateLayer(SoftwareComponent component, LayerPackage package) { SoftwareLayer layer = null; if (rbPres.Checked) { layer = new PresentationLayer(component.Store); } else if (rbUI.Checked) { layer = new UIWorkflowLayer(component.Store); } else if (rbDAL.Checked) { layer = new DataAccessLayer(component.Store); } else if (rbBLL.Checked) { layer = new BusinessLayer(component.Store); } else if (rbModels.Checked) { layer = new DataLayer(component.Store); } else if (rbInterface.Checked) { layer = new InterfaceLayer(component.Store); ((InterfaceLayer)layer).Level = (short)(package.Level + 1); package.InterfaceLayer = (InterfaceLayer)layer; } Layer tmp = layer as Layer; if (tmp != null) { package = component.LayerPackages.Find(delegate(LayerPackage p) { return(p.Level == tmp.Level); }); if (package == null) { package = new LayerPackage(component.Store); package.Level = tmp.Level; component.LayerPackages.Add(package); } package.Layers.Add(tmp); } component.Layers.Add(layer); return(layer); }
/// <summary> /// Ensures the interface layer. /// </summary> /// <returns></returns> private InterfaceLayer EnsureInterfaceLayer() { LayerPackage lp = new LayerPackage(_component.Store); lp.Name = "PublicContracts"; lp.Level = 100; _component.LayerPackages.Add(lp); InterfaceLayer iLayer = new InterfaceLayer(_component.Store); iLayer.Level = 101; _component.Layers.Add(iLayer); lp.InterfaceLayer = iLayer; iLayer.Name = StrategyManager.GetInstance(lp.Store).NamingStrategy.CreateLayerName(lp, iLayer, "PublicContracts"); iLayer.Namespace = StrategyManager.GetInstance(lp.Store).NamingStrategy.CreateNamespace(_component.Namespace, iLayer.Name, iLayer); return(iLayer); }
private static void OnNameChanged(ElementPropertyChangedEventArgs e, SoftwareComponent model) { string oldName = (string)e.OldValue; if (oldName != "?" && (model.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.IsSerializing || model.Store.InUndoRedoOrRollback)) { return; } string newName = (string)e.NewValue; foreach (SoftwareLayer layer in model.Layers) { if (oldName == "?") { if (layer.Name == "?") { LayerPackage lp = null; if (layer is Layer) { lp = ((Layer)layer).LayerPackage; } layer.Name = StrategyManager.GetInstance(layer.Store).NamingStrategy.CreateLayerName(lp, layer, null); // Le namespace sera mis à jour via la regle LayerNameChangeRule. } else { layer.Namespace = StrategyManager.GetInstance(model.Store).NamingStrategy.CreateNamespace(newName, layer.Name, layer); } } else if (layer.Namespace.StartsWith(oldName)) { layer.Namespace = newName + layer.Namespace.Substring(oldName.Length); } } }
/// <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(); } } }
/// <summary> /// Imports the specified obj. /// </summary> /// <param name="obj">The obj.</param> /// <param name="component">The component.</param> /// <param name="package">The package.</param> public static void Import(object obj, SoftwareComponent component, LayerPackage package) { MemoryStream ms = obj as MemoryStream; if (ms != null) { string projectInfo = String.Empty; String data = Encoding.Unicode.GetString(ms.ToArray()); StringBuilder sb = new StringBuilder(); for (int ix = 0; ix < data.Length; ix++) { char ch = data[ix]; if (ch == 0) { if (sb.Length > 2) { projectInfo = sb.ToString(); } if (sb.Length != 0) { sb = new StringBuilder(); } continue; } sb.Append(ch); } string[] infos = projectInfo.Split('|'); //// Comprend rien à la codification des noms de projet. //// //// Si contient un ., on prend le nom avant le / sinon c'est un site web, on //// prend le nom complet //string projectName = infos[1]; //if (projectName.IndexOf('.') > 0) //{ // int pos = projectName.LastIndexOf('\\'); // projectName = projectName.Substring(0, pos); //} Project prj = ServiceLocator.Instance.ShellHelper.FindProjectByName(infos[1]); if (prj != null) { using (Transaction transaction = component.Store.TransactionManager.BeginTransaction("Import layer")) { ImportProjectWizard wizard = new ImportProjectWizard(); if (wizard.ShowDialog() == DialogResult.OK) { SoftwareLayer layer = wizard.CreateLayer(component, package); string name = prj.Name; string[] parts = name.Split('\\'); if (parts.Length > 1) { name = parts[parts.Length - 2]; } layer.Name = name; layer.VSProjectName = name; // Récupération des propriétés for (int i = 0; i < prj.Properties.Count; i++) { EnvDTE.Property prop = prj.Properties.Item(i + 1); if (prop.Name == "RootNamespace") { layer.Namespace = prop.Value as string; } else if (prop.Name == "OutputFileName") { layer.AssemblyName = System.IO.Path.GetFileNameWithoutExtension(prop.Value as string); } } } transaction.Commit(); } } } }