2016-08-20 9 views
0

element Atarget element BEnterprise Architectに特定の関連付けコネクタCを使用して接続しています。c#addinを通じてエンタープライズアーキテクト図のコネクタを削除する方法

ユーザーが別の送信元と宛先の要素の間、このコネクタを使用している場合、私は警告メッセージを表示し、c#を使用してコネクタを削除するには、アドインコード:

次のことを私が使用するコードです。コネクタを削除できません。

public void ToDeleteConnectorByID(int connectorID) 
     { 
      try 
      { 

       EA.Connector addedConnector = Session.Repository.GetConnectorByID(Convert.ToInt32(connectorID)); 
       EA.Element cuurentobjectconnectorele = Session.Repository.GetElementByID(addedConnector.ClientID); 

         for (short m = 0; m < cuurentobjectconnectorele.Connectors.Count - 1; m++) 
         { 
          cuurentobjectconnectorele.Connectors.Delete(m); 
          cuurentobjectconnectorele.Update(); 
         } 

        } 

      catch (Exception ex) 
      { 
       MessageBox.Show("no connector deleted-exception"); 
      } 

     } 

答えて

0

以下の方法は、条件に基づいて要素間にコネクタを追加するために使用できます。ユーザーがツールボックスまたはリソースウィンドウから新しいコネクタを図にドラッグすると、トリガされます。通知は、コネクタが作成される直前に提供されるため、アドインでコネクタの追加を無効にすることができます。

/// <summary> 
    /// EA_OnPreNewConnector notifies Add-Ins that a new connector is about to be created on a diagram. 
    /// It enables Add-Ins to permit or deny creation of a new connector. 
    /// </summary> 
    /// <param name="Repository"></param> 
    /// <param name="Info"></param> 
    /// <returns>Return True to enable addition of the new connector to the model. Return False to disable addition of the new connector.</returns> 

public bool EA_OnPreNewConnector(EA.Repository Repository, EA.EventProperties Info) 
{ 
    try 
    { 
      //To get added Connector Type 
      string connectorType = ""; 
      EA.EventProperty connectorTypePropID; 
      connectorTypePropID = Info.Get(0); 
      connectorType = connectorTypePropID.Value; 

      //To get added Connector stereotype 
      string connectorStereotype = ""; 
      EA.EventProperty connectorStereotypePropID; 
      connectorStereotypePropID = Info.Get(2); 
      connectorStereotype = connectorStereotypePropID.Value; 

      //To get added Connector client ID 
      int clientID = 0; 
      EA.EventProperty clientIDPropID; 
      clientIDPropID = Info.Get(3); 
      clientID = Convert.ToInt32(clientIDPropID.Value); 

      //To get added Connector Supplier ID 
      int supplierID = 0; 
      EA.EventProperty supplierIDPropID; 
      supplierIDPropID = Info.Get(4); 
      supplierID = Convert.ToInt32(supplierIDPropID.Value); 

      //To get added Connector diagram 
      int diagramID = 0; 
      EA.EventProperty diagramIDPropID; 
      diagramIDPropID = Info.Get(5); 
      diagramID = Convert.ToInt32(diagramIDPropID.Value); 

      EA.Element sourceElemnet = Session.Repository.GetElementByID(clientID); 
      EA.Element destinationElemnet = Session.Repository.GetElementByID(supplierID); 

      if (sourceElemnet != null && destinationElemnet != null) 
      { 
       //Your condition based on when the connector needs to be created. 



       return true; 
      } 

      MessageBox.Show("This connection is not possible."); 
      return false; 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("This connection is not possible."); 
      return false; 
     } 
    } 

Returninbg TRUE、コネクタが作成されます。 FALSEを返すと、コネクタは作成されません。

作成中にコネクタを削除することをお勧めします。

+0

ありがとうございます。 .itは正常に動作しています... – rashmi

+0

@rashmi解決したら回答として受け入れてください – Arshad

1

コードのこの部分を試してみてください:

public void ToDeleteConnectorByID(int connectorID) { 
    try { 
    EA.Connector addedConnector = Session.Repository.GetConnectorByID(Convert.ToInt32(connectorID)); 
    EA.Element currentobjectconnectorele = Session.Repository.GetElementByID(addedConnector.ClientID); 

    for (short m = 0; m < currentobjectconnectorele.Connectors.Count; m++) { 
     if (addConnector.ConnectorID == currentobjectconnectorele.ConnectorID) { 
     currentobjectconnectorele.Connectors.Delete(m); 
     } 
    } 
    } 

    catch (Exception ex) { 
    MessageBox.Show("no connector deleted-exception"); 
    } 
} 

あなたUpdateはちょうど余分であり、あなたはすべてのコネクタではなく、あなたが探しているだけのものを削除しています。さらに、あなたのループは短すぎます。

N.B:C#はわかりませんが、ifの中にループを残すことができます。私はbreakがキーワードだと思います。

+0

このコードを試しましたが、コネクターが自動的に削除されないようにしてください。 – rashmi

+1

connectorIDが正しいかどうかを確認してください:SQLウィンドウを印刷して見つけてください: 'SELECT * FROM t_connector WHERE connector_id = ' –

関連する問題