/// <summary> /// Execute the command /// </summary> public void Exec() { PropagatesOperationsDialog dlg = new PropagatesOperationsDialog(_targets, _sources); if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } // On récupère les roles TypeWithOperations source = dlg.Source; TypeWithOperations target = dlg.Target; using (Transaction transaction = target.Store.TransactionManager.BeginTransaction("Model affectation")) { // Suppression avant copie if (dlg.ClearTargetOperations) { using (Transaction clearTransaction = target.Store.TransactionManager.BeginTransaction("Clear operations")) { target.Operations.Clear(); clearTransaction.Commit(); } } // Copie foreach (Operation op in dlg.SelectedOperations) { target.Operations.Add(Operation.CopyOperation(target.Store, op)); } transaction.Commit(); } }
/// <summary> /// Finds the operation. /// </summary> /// <param name="port">The port.</param> /// <param name="func">The func.</param> /// <returns></returns> private static Operation FindOperation(TypeWithOperations port, CodeFunction func) { foreach (Operation op in port.Operations) { if (op.Name == func.Name && op.Type == func.Type.AsString && func.Parameters.Count == op.Arguments.Count) { bool ok = true; int i = 0; foreach (CodeParameter param in func.Parameters) { Argument arg = op.Arguments[i]; if (arg.Name != param.Name || arg.Type != param.Type.AsString) { ok = false; break; } } if (ok) { return(op); } } } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="OperationSelectorDlg"/> class. /// </summary> /// <param name="type">The type.</param> public OperationSelectorDlg(TypeWithOperations type) { InitializeComponent(); foreach (Operation op in type.Operations) { lstOperations.Items.Add(op); } }
/// <summary> /// Sélection dans la combobox de la source /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void cbSource_SelectedIndexChanged(object sender, EventArgs e) { source = ((ListItem)cbSource.SelectedItem).Value; lstOperations.Items.Clear(); foreach (Operation oper in source.Operations) { lstOperations.Items.Add(oper, true); } }
/// <summary> /// Permutation de la source et de la cible /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnSwitch_Click(object sender, EventArgs e) { source = target = null; List <TypeWithOperations> tmp = sources; sources = targets; targets = tmp; Populate(); }
/// <summary> /// Constructeur prenant le shape courant /// </summary> /// <param name="obj">The obj.</param> public PropagatesOperationsCommand(object obj) { LinkShape shape = obj as LinkShape; if (shape != null && shape.ModelElement is ClassUsesOperations) { ClassImplementation clazz = ((ClassUsesOperations)shape.ModelElement).Source as ClassImplementation; if (clazz == null) { return; } _sources.Add(clazz); if (clazz.Contract != null) { _sources.Add(clazz.Contract); } TypeWithOperations target = (TypeWithOperations)((ClassUsesOperations)shape.ModelElement).TargetService; if (target == null) { Debug.Assert(((ClassUsesOperations)shape.ModelElement).ExternalTargetService != null); _targets.Add(((ClassUsesOperations)shape.ModelElement).ExternalTargetService.ReferencedServiceContract); } else { _targets.Add(target); } } if (shape != null && shape.ModelElement is Implementation) { _sources.Add(((Implementation)shape.ModelElement).Contract); ClassImplementation clazz = ((Implementation)shape.ModelElement).ClassImplementation; _targets.Add(clazz); if (clazz.Contract != null) { _targets.Add(clazz.Contract); } } }
/// <summary> /// Retrieves the operations. /// </summary> /// <param name="port">The port.</param> /// <param name="members">The members.</param> /// <param name="checkPublic">if set to <c>true</c> [check public].</param> private static void RetrieveOperations(TypeWithOperations port, CodeElements members, bool checkPublic) { foreach (CodeElement codeElement in members) { CodeFunction func = codeElement as CodeFunction; if (func == null) { continue; } if (checkPublic && func.Access != vsCMAccess.vsCMAccessPublic) { continue; } // Operation Operation op = FindOperation(port, func); if (op == null) { op = new Operation(port.Store); op.Name = func.Name; op.Comment = NormalizeComment(func.DocComment); op.Type = func.Type.AsString; //if( Utils.StringStartsWith( op.Type, "system." ) ) // op.Type = op.Type.Substring( 7 ); port.Operations.Add(op); foreach (CodeParameter param in func.Parameters) { // Argument Argument arg = new Argument(port.Store); arg.Name = param.Name; arg.Comment = NormalizeComment(param.DocComment); arg.Type = param.Type.AsString; //if( Utils.StringStartsWith( arg.Type, "system." ) ) // arg.Type = arg.Type.Substring( 7 ); op.Arguments.Add(arg); } } } }
/// <summary> /// Sélection dans la combobox de la cible /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void cbTarget_SelectedIndexChanged(object sender, EventArgs e) { target = ((ListItem)cbTarget.SelectedItem).Value; btnOK.Enabled = target != null; }
/// <summary> /// Imports the operations. /// </summary> /// <param name="layer">The layer.</param> /// <param name="port">The port.</param> /// <param name="fileName">Name of the file.</param> /// <returns>true if the import is ok</returns> public bool ImportOperations(SoftwareLayer layer, TypeWithOperations port, string fileName) { FileCodeModel fcm = ServiceLocator.Instance.ShellHelper.GetFileCodeModel(fileName); if (fcm == null) { return(false); } foreach (CodeElement cn in fcm.CodeElements) { if (cn is CodeNamespace) { foreach (CodeElement ci in ((CodeNamespace)cn).Members) { if ((ci is CodeInterface || ci is CodeClass) && layer is InterfaceLayer) { CodeElements members; string comment; if (ci is CodeInterface) { comment = ((CodeInterface)ci).DocComment; members = ((CodeInterface)ci).Members; } else { comment = ((CodeClass)ci).DocComment; members = ((CodeClass)ci).Members; } if (port == null) { port = new ServiceContract(layer.Store); port.Name = ci.Name; port.RootName = ci.Name; port.Comment = NormalizeComment(comment); ((InterfaceLayer)layer).ServiceContracts.Add((ServiceContract)port); } RetrieveOperations(port, members, false); } else if (ci is CodeClass && layer is Layer) { CodeClass cc = ci as CodeClass; ClassImplementation clazz = port as ClassImplementation; //if (cc.Access == vsCMAccess.vsCMAccessPublic) { if (clazz == null) { clazz = new ClassImplementation(layer.Store); clazz.Name = ci.Name; clazz.RootName = ci.Name; clazz.Comment = NormalizeComment(cc.DocComment); ((Layer)layer).Classes.Add(clazz); } InterfaceLayer iLayer = clazz.Layer.LayerPackage.InterfaceLayer; // Si il y a plusieurs interfaces, on ne fait rien car on ne sait pas laquelle prendre if (iLayer != null && cc.ImplementedInterfaces.Count == 1) { ServiceContract contract = clazz.Contract; if (contract == null) { string iName = cc.ImplementedInterfaces.Item(1).Name; contract = iLayer.ServiceContracts.Find(delegate(ServiceContract c) { return(c.Name == iName); }); if (contract == null) { contract = new ServiceContract(layer.Store); contract.Name = StrategyManager.GetInstance(clazz.Store).NamingStrategy.CreateElementName(iLayer, cc.Name); contract.RootName = cc.Name; contract.Comment = NormalizeComment(cc.DocComment); iLayer.ServiceContracts.Add(contract); RetrieveOperations(contract, cc.Members, true); } clazz.Contract = contract; } } } } } } } return(true); }
/// <summary> /// Execution du wizard /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="DSLFactory.Candle.SystemModel.Strategies.StrategyElementElementAddedEventArgs"/> instance containing the event data.</param> public void RunWizard(ModelElement sender, StrategyElementElementAddedEventArgs e) { CandleElement elem = e.ModelElement as CandleElement; txtRootName.Text = elem.RootName; if (elem is ServiceContract) // Ce cas est désactivé (voir selection du wizard) { _layer = ((ServiceContract)e.ModelElement).Layer; txtName.Text = StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_layer, elem.RootName); } else { _layer = ((ClassImplementation)e.ModelElement).Layer; _iLayer = ((ClassImplementation)e.ModelElement).Layer.LayerPackage.InterfaceLayer; txtName.Text = StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_layer, elem.RootName); if (_iLayer == null) { txtContractName.Visible = false; } else { txtContractName.Text = StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_iLayer, txtName.Text); } } if (elem is ServiceContract || ((ClassImplementation)elem).Layer.LayerPackage.InterfaceLayer == null) { lblContractName.Visible = false; txtContractName.Visible = false; txtContractName.Text = null; } lblHeader.Text = String.Format(lblHeader.Text, _layer.Name); groupBox1.Text = _layer.Namespace; if (!s_dontShow) { e.UserCancel = (ShowDialog() == DialogResult.Cancel); if (e.UserCancel) { return; } s_dontShow = ckDontShow.Checked; } // Ici on force les noms des classes donc on ne veut pas que la régle basée sur la modification // du RootName s'execute. On l'indique dans le contexte de la transaction if ( !elem.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.ContainsKey( "CustomizableElementChangeRule_Enabled")) { elem.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.Add( "CustomizableElementChangeRule_Enabled", false); } elem.Name = txtName.Text; using (Transaction transaction = elem.Store.TransactionManager.BeginTransaction("Set root name")) { // Force la transaction pour que la règle s'execute tout de suite et qu'on puisse // forcer le nom ensuite elem.RootName = txtRootName.Text; transaction.Commit(); } // Si c'est une classe, on essaye de créer son interface ClassImplementation clazz = elem as ClassImplementation; if (clazz != null && _iLayer != null && !String.IsNullOrEmpty(txtContractName.Text)) { if (clazz.Contract == null) { // On regarde si l'interface n'existe pas clazz.Contract = _iLayer.ServiceContracts.Find( delegate(ServiceContract c) { return(c.Name == txtContractName.Text); }); if (clazz.Contract == null) { clazz.Contract = new ServiceContract(clazz.Store); clazz.Contract.RootName = txtRootName.Text; clazz.Layer.LayerPackage.InterfaceLayer.ServiceContracts.Add(clazz.Contract); UnplacedModelHelper.RegisterNewModel(clazz.Store, clazz.Contract); // Si la classe courante utilise un seul contract, on le recopie IList <ClassUsesOperations> links = ClassUsesOperations.GetLinksToServicesUsed(clazz); if (links.Count == 1) { ServiceContract contract = links[0].TargetService as ServiceContract; if (contract != null) { TypeWithOperations.CopyOperations(contract, clazz.Contract); } else { ExternalServiceContract externalContract = links[0].TargetService as ExternalServiceContract; if (externalContract != null) { TypeWithOperations.CopyOperations(externalContract.ReferencedServiceContract, clazz.Contract); } } } } } using (Transaction transaction = elem.Store.TransactionManager.BeginTransaction("Set root name")) { // Force la transaction pour que la règle s'execute tout de suite et qu'on puisse // forcer le nom ensuite clazz.Contract.RootName = elem.RootName; transaction.Commit(); } if (clazz.Contract.Name != txtContractName.Text) { clazz.Contract.Name = txtContractName.Text; } } e.CancelBubble = true; }