Example #1
0
        /// <summary>
        /// Wrapper to change DiagramObject style
        /// - Selected Diagramobjects
        /// - Package (Diagrams and their DiagramObjects in package and below Elements)
        /// - Element (Diagrams and their DiagramObjects below Elements)
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="type"></param>
        /// <param name="style"></param>
        /// <param name="property"></param>
        /// <param name="changeScope"></param>
        public static void DiagramObjectStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope)
        {
            EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: true);

            if (eaDia.Dia != null)
            {
                rep.SaveDiagram(eaDia.Dia.DiagramID);
                foreach (var diaObj in eaDia.SelObjects)
                {
                    var a           = new DiagramObjectStyle(rep, diaObj, type, style, property);
                    var objectStyle = new DiagramObjectStyle(rep, diaObj, type, style, property);
                    if (objectStyle.IsToProcess())
                    {
                        objectStyle.UpdateStyles();
                        objectStyle.SetProperties();
                        objectStyle.SetEaLayoutStyles();
                        objectStyle.SetCompleteNessMarker();
                    }
                }
                eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false);
            }
            else
            {
                var liParameter = new string[4];
                liParameter[0] = type;
                liParameter[1] = style;
                liParameter[2] = property;

                switch (rep.GetContextItemType())
                {
                case ObjectType.otPackage:
                    Package pkg = (Package)rep.GetContextObject();
                    RecursivePackages.DoRecursivePkg(rep, pkg, null, null,
                                                     SetDiagramObjectStyle,
                                                     liParameter,
                                                     changeScope);
                    break;

                case ObjectType.otElement:
                    Element el = (Element)rep.GetContextObject();
                    RecursivePackages.DoRecursiveEl(rep, el, null,
                                                    SetDiagramObjectStyle,
                                                    liParameter,
                                                    changeScope);
                    break;
                }
            }
        }
        /// <summary>
        /// Wrapper to change DiagramLink style
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="type"></param>
        /// <param name="style"></param>
        /// <param name="property"></param>
        /// <param name="changeScope"></param>
        public static void DiagramLinkStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope)
        {
            EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false);

            // Handle selected diagram and its selected items (connector/objects)
            if (eaDia.Dia != null)
            {
                rep.SaveDiagram(eaDia.Dia.DiagramID);
                // over all links
                foreach (var link in eaDia.GetSelectedLinks())
                {
                    var linkStyle = new DiagramLinkStyle(rep, link, type, style, property);
                    if (linkStyle.IsToProcess())
                    {
                        linkStyle.UpdateStyles();
                        linkStyle.SetProperties();
                        linkStyle.SetEaLayoutStyles();
                    }
                }
                eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false);
            }
            else
            {
                var liParameter = new string[4];
                liParameter[0] = type;
                liParameter[1] = style;
                liParameter[2] = property;

                switch (rep.GetContextItemType())
                {
                case EA.ObjectType.otPackage:
                    EA.Package pkg = (EA.Package)rep.GetContextObject();
                    RecursivePackages.DoRecursivePkg(rep, pkg, null, null,
                                                     SetDiagramLinkStyle,
                                                     liParameter,
                                                     changeScope);
                    break;

                case EA.ObjectType.otElement:
                    EA.Element el = (EA.Element)rep.GetContextObject();
                    RecursivePackages.DoRecursiveEl(rep, el, null,
                                                    SetDiagramLinkStyle,
                                                    liParameter,
                                                    changeScope);
                    break;
                }
            }
        }
        public int DoCopyPortsGui()
        {
            Diagram dia = _rep.GetCurrentDiagram();

            if (dia == null)
            {
                return(0);
            }
            int count = dia.SelectedObjects.Count;

            if (count < 2)
            {
                return(0);
            }
            _rep.SaveDiagram(dia.DiagramID);

            // target object/element
            var trgEl = (Element)_rep.GetContextObject();

            if (trgEl.Type != "Class" && trgEl.Type != "Component")
            {
                MessageBox.Show($"Target Element is '{trgEl.Type}'", @"Target element for copy Port has to be Class or Component");
                return(0);
            }

            // over all selected DiagramObjects
            for (int i = 0; i < count; i = i + 1)
            {
                var srcObj = (DiagramObject)dia.SelectedObjects.GetAt((short)i);
                var srcEl  = _rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID)
                {
                    continue;
                }

                if (srcEl.Type == "Port")
                {
                    // selected element was port
                    CopyPort(_rep, srcEl, trgEl);
                    _count += 1;
                }
                else
                {   // selected element was "Port"
                    foreach (Element p in srcEl.EmbeddedElements)
                    {
                        if (srcEl.ElementID == trgEl.ElementID)
                        {
                            continue;
                        }
                        if (p.Type == "Port")
                        {
                            CopyPort(_rep, p, trgEl);
                            _count += 1;
                        }
                    }
                }
            }
            return(_count);
            //_rep.ReloadDiagram(dia.DiagramID);
        }
        /// <summary>
        /// Get the current Diagram with it's selected objects and connectors.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="getAllDiagramObject">True if you want all diagram objects if nothing no diagram object is selected</param>
        public EaDiagram(Repository rep, bool getAllDiagramObject = false)
        {
            _rep = rep;
            _dia = _rep.GetCurrentDiagram();
            IsSelectedObjects = false;
            if (_dia == null)
            {
                return;
            }
            if (_dia.SelectedObjects.Count == 0 && getAllDiagramObject)
            {
                // overall diagram objects
                foreach (EA.DiagramObject obj in _dia.DiagramObjects)
                {
                    _selectedObjects.Add(obj);
                    SelElements.Add(rep.GetElementByID(obj.ElementID));
                }
            }
            // If an context element exists than this is the last selected element
            if (_dia.SelectedObjects.Count > 0)
            {
                EA.ObjectType type = _rep.GetContextItemType();
                // only package and object makes sense, or no context element (than go for selected elements)
                if (type == EA.ObjectType.otElement ||
                    type == EA.ObjectType.otPackage ||
                    type == EA.ObjectType.otNone)
                {
                    // 1. store context element/ last selected element
                    EA.Element elContext = (EA.Element)rep.GetContextObject();
                    // no context element available, take first element
                    if (elContext == null)
                    {
                        EA.DiagramObject obj = (EA.DiagramObject)_dia.SelectedObjects.GetAt(0);
                        elContext = rep.GetElementByID(obj.ElementID);
                    }
                    _conTextDiagramObject = _dia.GetDiagramObjectByID(elContext.ElementID, "");

                    SelElements.Add(elContext);
                    _selectedObjects.Add(_conTextDiagramObject);
                    IsSelectedObjects = true;

                    // over all selected diagram objects
                    foreach (EA.DiagramObject obj in _dia.SelectedObjects)
                    {
                        // skip last selected element / context element
                        if (obj.ElementID == _conTextDiagramObject.ElementID)
                        {
                            continue;
                        }

                        _selectedObjects.Add(obj);
                        SelElements.Add(rep.GetElementByID(obj.ElementID));
                    }
                }
            }
            _selectedConnector = _dia.SelectedConnector;
        }
Example #5
0
        /// <summary>
        /// Bulk Change Diagram Style according to:
        /// liParameter[0]  Styles/StyleEx
        /// liParameter[1]  PDATA/ExtendedStyle
        /// liParameter[2]  Properties
        /// liParameter[3]  Diagram types as comma, semicolon separated list
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="liParameter"></param>
        /// <param name="changeScope"></param>
        public static void ChangeDiagramStyle(Repository rep, string[] liParameter, ChangeScope changeScope = ChangeScope.PackageRecursive)
        {
            switch (rep.GetContextItemType())
            {
            case ObjectType.otDiagram:
                Diagram dia = (Diagram)rep.GetContextObject();
                SetDiagramStyle(rep, dia, liParameter);
                break;

            case ObjectType.otPackage:
                Package pkg = (Package)rep.GetContextObject();
                RecursivePackages.DoRecursivePkg(rep, pkg, null, null, SetDiagramStyle,
                                                 liParameter,
                                                 changeScope);
                break;

            case ObjectType.otElement:
                Element el = (Element)rep.GetContextObject();
                RecursivePackages.DoRecursiveEl(rep, el, null, SetDiagramStyle, liParameter,
                                                changeScope);
                break;
            }
        }
        /// <inheritdoc />
        public override void Initialize()
        {
            SaveCommand   = new SaveCommand();
            CancelCommand = new CancelCommand();
            AddCommand    = new AddCommand();
            RemoveCommand = new RemoveCommand();

            Connector = Repository.GetContextObject();
            SourceEnd = Connector.SupplierEnd;
            TargetEnd = Connector.ClientEnd;

            switch (SourceEnd.Stereotype)
            {
            case "ObjectProperty":
                ShowSourceEnd = SourceEnd.Stereotype == "ObjectProperty" ? Visibility.Visible : Visibility.Collapsed;

                break;

            case "RdfsProperty":
                ShowSourceEnd = SourceEnd.Stereotype == "RdfsProperty" ? Visibility.Visible : Visibility.Collapsed;
                break;
            }

            switch (TargetEnd.Stereotype)
            {
            case "ObjectProperty":
                ShowTargetEnd = TargetEnd.Stereotype == "ObjectProperty" ? Visibility.Visible : Visibility.Collapsed;
                break;

            case "RdfsProperty":
                ShowTargetEnd = TargetEnd.Stereotype == "RdfsProperty" ? Visibility.Visible : Visibility.Collapsed;
                break;
            }

            SourceViewModel = new ConnectorUserControlViewModel {
                ConnectorEnd = SourceEnd, ElementNameValue = Repository.GetElementByID(Connector.SupplierID).Name
            };
            TargetViewModel = new ConnectorUserControlViewModel {
                ConnectorEnd = TargetEnd, ElementNameValue = Repository.GetElementByID(Connector.ClientID).Name
            };

            SourceViewModel.ResourceDictionary = ResourceDictionary;
            TargetViewModel.ResourceDictionary = ResourceDictionary;

            SourceViewModel.Initialize();
            TargetViewModel.Initialize();
        }
        /// <inheritdoc />
        public override void Initialize()
        {
            SaveCommand    = new SaveCommand();
            CancelCommand  = new CancelCommand();
            AddCommand     = new AddCommand();
            RemoveCommand  = new RemoveCommand();
            PackageElement = Repository.GetContextObject().Element;
            UMLNameValue   = PackageElement.Name;
            AliasValue     = PackageElement.Alias;
            TaggedValues   = PackageElement.TaggedValues;

            //Finalize list of stereotype tags to add
            switch (PackageElement.Stereotype)
            {
            case "LogicalModel":
            case "CoreModel":
            case "ApplicationModel":
            case "Vocabulary":
            case "ApplicationProfile":
                _toAddModelMetadataTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "WasDerivedFrom"));
                break;
            }

            //Retrieve all tagged values and store them in a list
            //Tagged values are stored in a list to avoid iterating Collections multiple times, which is very costly
            //In a future iteration of the addin, avoid iterating the collection even once, instead using Repository.SQLQuery to retrieve
            //an XML-formatted list of every Tagged Value where the owner ID is PackageElement.ElementID
            for (short i = 0; i < TaggedValues.Count; i++)
            {
                var tv = TaggedValues.GetAt(i);
                _taggedValuesList.Add(tv);
            }

            // Add tagged values to list of ViewmodelTaggedValues
            DanishViewmodelTaggedValues        = AddTaggedValuesToViewmodelTaggedValues(_toAddDanishTaggedValues, _taggedValuesList);
            EnglishViewmodelTaggedValues       = AddTaggedValuesToViewmodelTaggedValues(_toAddEnglishTaggedValues, _taggedValuesList);
            ModelMetadataViewmodelTaggedValues = AddTaggedValuesToViewmodelTaggedValues(_toAddModelMetadataTaggedValues, _taggedValuesList);
        }
 /// <summary>
 /// Replace macro #Branch={..guid..}# and #InBranch={..guid..}# by IDs of selected packages, recursive nested. 
 /// It uses the package of the guid and not of the selected Package
 /// </summary>
 /// <param name="rep"></param>
 /// <param name="sql">The sql string to replace the macro by the found ID</param>
 /// <returns>sql string with replaced macro</returns>
 static string MacroBranchConstantPackage(Repository rep, string sql)
 {
     // Branch=comma separated Package IDs, Recursive:
     // Example for 3 Packages with their PackageID 7,29,128
     // 7,29,128
     //
     // Branch: complete SQL IN statement ' IN (comma separated Package IDs, Recursive):
     // IN (7,29,128)
     string currentBranchTemplate = GetTemplateText(SqlTemplateId.BranchIds);
     string currrentInBranchTemplate = GetTemplateText(SqlTemplateId.InBranchIds);
     if (sql.Contains(currentBranchTemplate) | sql.Contains(currrentInBranchTemplate))
     {
         ObjectType objectType = rep.GetContextItemType();
         int id = 0;
         switch (objectType)
         {
             // use Package of diagram
             case ObjectType.otDiagram:
                 Diagram dia = (Diagram)rep.GetContextObject();
                 id = dia.PackageID;
                 break;
             // use Package of element
             case ObjectType.otElement:
                 EA.Element el = (EA.Element)rep.GetContextObject();
                 id = el.PackageID;
                 break;
             case ObjectType.otPackage:
                 EA.Package pkg = (EA.Package)rep.GetContextObject();
                 id = pkg.PackageID;
                 break;
         }
         // Context element available
         if (id > 0)
         {
             // get package recursive
             string branch = Package.GetBranch(rep, "", id);
             sql = sql.Replace(currentBranchTemplate, branch);
             sql = sql.Replace(currrentInBranchTemplate, branch);
         }
         else
         // no diagram, element or package selected
         {
             MessageBox.Show(sql, @"No element, diagram or package selected!");
             sql = "";
         }
     }
     return sql;
 }
 public static void SetTaggedValueGui(Repository rep)
 {
     try
     {
         Cursor.Current = Cursors.WaitCursor;
         ObjectType oType = rep.GetContextItemType();
         if (!oType.Equals(ObjectType.otPackage)) return;
         var pkg = (Package) rep.GetContextObject();
         SetDirectoryTaggedValueRecursive(rep, pkg);
         Cursor.Current = Cursors.Default;
     }
     catch (Exception e11)
     {
         MessageBox.Show(e11.ToString(), @"Error set directory tagged values");
     }
     finally
     {
         Cursor.Current = Cursors.Default;
     }
 }
        /// <summary>
        /// Replace macro #DiagramElements_IDS# by a comma separated list of all Element IDs in diagram.
        /// <para/>
        /// If no Element is in the diagram it return '0' for an empty list (not existing ID).
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="sql">The sql string to replace the macro by the found list of Diagram Element IDs</param>
        /// <returns>sql string with replaced macro</returns>
        static string macroDiagramSelectedElements_IDS(Repository rep, string sql)
        {
            // get template
            string template = GetTemplateText(SqlTemplateId.DiagramSelectedElementsIds);

            // template is used
            if (sql.Contains(template))
            {
                // get the diagram
                Diagram dia = rep.GetContextItemType() == ObjectType.otDiagram ? rep.GetContextObject() : rep.GetCurrentDiagram();
                // Diagram selected?
                if (dia == null)
                {
                    MessageBox.Show(sql, $"No Diagram  for '{template}' selected!");
                    sql = "";
                }
                else
                {
                    // make a list of comma separated IDs
                    string listId = "0";
                    foreach (var el in dia.SelectedObjects)
                    {
                        int id = ((EA.DiagramObject)el).ElementID;
                        listId = $"{listId},{id}";

                    }

                    // replace by list of IDs
                    sql = sql.Replace(template, $"{listId}");
                }
            }
            return sql;
        }
        /// <summary>
        /// Replace macro #Diagram_ID# by Diagram_Id of the current diagram or selected Diagram.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="sql"></param>
        /// <returns>sql string with replaced macro</returns>
        static string macroDiagram_ID(Repository rep, string sql)
        {
            // get template
            string template = GetTemplateText(SqlTemplateId.DiagramId);

            // template is used
            if (sql.Contains(template))
            {
                // get the diagram
                Diagram dia;
                if (rep.GetContextItemType() == ObjectType.otDiagram)
                {
                    dia = rep.GetContextObject();
                }
                else
                {
                    dia = rep.GetCurrentDiagram();
                }
                // Diagram selected?
                if (dia == null)
                {
                    MessageBox.Show(sql, $"No Diagram  for '{template}' selected!");
                    sql = "";
                }
                else
                {
                    // replace by list of IDs
                    sql = sql.Replace(template, $"{dia.DiagramID}");
                }

            }
            return sql;
        }
        public static void NavigateComposite(Repository repository)
        {
            ObjectType oType = repository.GetContextItemType();
            // find composite element of diagram
            if (oType.Equals(ObjectType.otDiagram))
            {
                var d = (Diagram) repository.GetContextObject();
                string guid = Util.GetElementFromCompositeDiagram(repository, d.DiagramGUID);
                if (guid != "")
                {
                    repository.ShowInProjectView(repository.GetElementByGuid(guid));
                }
            }
            // find composite diagram of element of element
            if (oType.Equals(ObjectType.otElement))
            {
                var e = (Element) repository.GetContextObject();
                // locate text or frame
                if (LocateTextOrFrame(repository, e)) return;

                repository.ShowInProjectView(e.CompositeDiagram);
            }
        }
 public static void ShowSpecification(Repository rep)
 {
     ObjectType oType = rep.GetContextItemType();
     if (oType.Equals(ObjectType.otElement))
     {
         var el = (Element) rep.GetContextObject();
         //over all file
         foreach (File f in el.Files)
         {
             if (f.Name.Length > 2)
             {
                 Process.Start(f.Name);
             }
         }
     }
 }
 private static string GetGuidfromSelectedItem(Repository rep)
 {
     ObjectType objectType = rep.GetContextItemType();
     string guid = "";
     switch (objectType)
     {
         case ObjectType.otAttribute:
             var a = (EA.Attribute) rep.GetContextObject();
             guid = a.AttributeGUID;
             break;
         case ObjectType.otMethod:
             var m = (Method) rep.GetContextObject();
             guid = m.MethodGUID;
             break;
         case ObjectType.otElement:
             var el = (Element) rep.GetContextObject();
             guid = el.ElementGUID;
             break;
         case ObjectType.otDiagram:
             var dia = (Diagram) rep.GetContextObject();
             guid = dia.DiagramGUID;
             break;
         case ObjectType.otPackage:
             var pkg = (Package) rep.GetContextObject();
             guid = pkg.PackageGUID;
             break;
         default:
             MessageBox.Show(@"Nothing useful selected");
             break;
     }
     return guid;
 }
        public static void ShowFolder(Repository rep, bool isTotalCommander = false)
        {
            string path;
            ObjectType oType = rep.GetContextItemType();
            switch (oType)
            {
                case ObjectType.otPackage:
                    var pkg = (Package) rep.GetContextObject();
                    path = Util.GetVccFilePath(rep, pkg);
                    // remove filename
                    path = Regex.Replace(path, @"[a-zA-Z0-9\s_:.]*\.xml", "");

                    if (isTotalCommander)
                        Util.StartApp(@"totalcmd.exe", "/o " + path);
                    else
                        Util.StartApp(@"Explorer.exe", "/e, " + path);
                    break;

                case ObjectType.otElement:
                    var el = (Element) rep.GetContextObject();
                    path = Util.GetGenFilePath(rep, el);
                    // remove filename
                    path = Regex.Replace(path, @"[a-zA-Z0-9\s_:.]*\.[a-zA-Z0-9]{0,4}$", "");

                    if (isTotalCommander)
                        Util.StartApp(@"totalcmd.exe", "/o " + path);
                    else
                        Util.StartApp(@"Explorer.exe", "/e, " + path);

                    break;
            }
        }
        // ReSharper disable once UnusedMember.Local
        private static void MakeNested(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            int count = dia.SelectedObjects.Count;
            if (count < 2) return;

            rep.SaveDiagram(dia.DiagramID);

            // target object/element

            ObjectType objType = rep.GetContextItemType();
            if (!(objType.Equals(ObjectType.otElement))) return;

            var trgEl = (Element) rep.GetContextObject();
            if (!(trgEl.Type.Equals("Activity")))
            {
                MessageBox.Show($"Target '{trgEl.Name}:{trgEl.Type}' isn't an Activity",
                    @" Only move below Activity is allowed");
                return;
            }
            for (int i = 0; i < count; i = i + 1)
            {
                var srcObj = (DiagramObject) dia.SelectedObjects.GetAt((short) i);
                var srcEl = rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID) continue;
                srcEl.ParentID = trgEl.ElementID;
                srcEl.Update();
            }
        }
        //--------------------------------------------------------------------------------
        /// <summary>
        /// Get context Package from Package, Element, Diagram
        /// </summary>
        /// <param name="rep"></param>
        /// <returns></returns>
        static Package GetContextPackage(Repository rep)
        {
            switch (rep.GetContextItemType())
            {
                case ObjectType.otPackage:
                    return (Package) rep.GetContextObject();

                case ObjectType.otElement:
                    Element el = (Element) rep.GetContextObject();
                    return rep.GetPackageByID(el.PackageID);

                case ObjectType.otDiagram:
                    Diagram dia = (Diagram) rep.GetContextObject();
                    return rep.GetPackageByID(dia.PackageID);

                default:
                    return null;
            }
        }
        // ReSharper disable once UnusedMember.Global
        // dynamical usage as configurable service by reflection
        public static void JoinDiagramObjectsToLastSelected(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            int count = dia.SelectedObjects.Count;
            if (count < 2) return;
            rep.SaveDiagram(dia.DiagramID);

            // target object/element
            var trgEl = (Element) rep.GetContextObject();

            for (int i = 0; i < count; i = i + 1)
            {
                var srcObj = (DiagramObject) dia.SelectedObjects.GetAt((short) i);
                var srcEl = rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID) continue;
                Connectors.Connector connector = GetConnectionDefault();

                var con = (Connector) srcEl.Connectors.AddNew("", connector.Type);
                con.SupplierID = trgEl.ElementID;
                con.Stereotype = connector.Stereotype;
                con.Update();
                srcEl.Connectors.Refresh();
                trgEl.Connectors.Refresh();
                dia.DiagramLinks.Refresh();
                // set line style
                DiagramLink link = GetDiagramLinkForConnector(dia, con.ConnectorID);
                if (link != null) Util.SetLineStyleForDiagramLink("LV", link);
            }

            rep.ReloadDiagram(dia.DiagramID);
            dia.SelectedObjects.AddNew(trgEl.ElementID.ToString(), trgEl.ObjectType.ToString());
        }
 public object GetContextObject()
 {
     return(repo.GetContextObject());
 }
        /// <summary>
        /// Replace macro #CurrentItemGUID# by the GUID of the currently selected Item.
        /// Alias: #CurrentElementGUID#
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="sql">The sql string to replace the macro by the found ID</param>
        /// <returns>sql string with replaced macro</returns>
        static string macroItem_GUID(Repository rep, string sql)
        {
            // replace ID
            string template = GetTemplateText(SqlTemplateId.CurrentItemGuid);
            if (sql.Contains(template) | sql.Contains("#CurrentElementGUID#")) 
            {
                ObjectType objectType = rep.GetContextItemType();
                string guid = "";
                switch (objectType)
                {
                    case ObjectType.otElement:
                        EA.Element el = (EA.Element)rep.GetContextObject();
                        guid = el.ElementGUID;
                        break;
                    case ObjectType.otDiagram:
                        Diagram dia = (Diagram)rep.GetContextObject();
                        guid = dia.DiagramGUID;
                        break;
                    case ObjectType.otPackage:
                        EA.Package pkg = (EA.Package)rep.GetContextObject();
                        guid = pkg.PackageGUID;
                        break;
                    case ObjectType.otAttribute:
                        EA.Attribute attr = (EA.Attribute)rep.GetContextObject();
                        guid = attr.AttributeGUID;
                        break;
                    case ObjectType.otMethod:
                        Method method = (Method)rep.GetContextObject();
                        guid = method.MethodGUID;
                        break;
                }

                if (guid != "")
                {
                    sql = sql.Replace(template, $"{guid}");
                    sql = sql.Replace("#CurrentElementGUID#", $"{guid}");// Alias for EA compatibility
                }
                else
                // no diagram, element or package selected
                {
                    MessageBox.Show(sql, @"No item (Package, Element, Diagram, Operation, Attribute) selected!");
                    sql = "";
                }

            }
            return sql;
        }
        /// <summary>
        /// Connector macros: ConnectorID and ConveyedItemIDS
        /// Note: If Element connector 
        /// <para/>
        /// Replace macro #ConnectorID# by the ID of the selected connector.
        /// <para/>
        /// Replace macro #ConveyedItemIDS# by the IDs of conveyed Elements of the selected connector.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="sql">The sql string to replace the macro by the found ID</param>
        /// <returns>sql string with replaced macro</returns>
        static string MacroConnector(Repository rep, string sql)
        {
            //--------------------------------------------------------------------------------------------
            // CONNECTOR ID
            // CONVEYED_ITEM_ID
            string currentConnectorTemplate = GetTemplateText(SqlTemplateId.ConnectorId);
            string currentConveyedItemTemplate = GetTemplateText(SqlTemplateId.ConveyedItemIds);

            if ((sql.Contains(currentConnectorTemplate) | sql.Contains(currentConveyedItemTemplate)))
            {
                // connector
                if (rep.GetContextItemType() == ObjectType.otConnector)
                {
                    // connector ID
                    Connector con = rep.GetContextObject();
                    if (sql.Contains(currentConnectorTemplate))
                    {
                        
                        sql = sql.Replace(currentConnectorTemplate, $"{con.ConnectorID}");
                    }
                    // conveyed items are a comma separated list of elementIDs
                    if (sql.Contains(currentConveyedItemTemplate))
                    {

                        // to avoid syntax error, 0 will never fit any conveyed item
                        string conveyedItems = "0";

                        // first get "InformationFlows" which carries the conveyed items
                        if (con.MetaType == "Connector")
                        {
                            // get semicolon delimiter list of information flow guids
                            string sqlInformationFlows = "select x.description " +
                                                         "    from  t_xref x " +
                                                         $"    where x.client = '{con.ConnectorGUID}' ";

                            // get semicolon delimiter list of guids of all dependent connectors/information flows
                            List<string> lFlows = rep.GetStringsBySql(sqlInformationFlows);
                            foreach (string flowGuids in lFlows) { 
                                string[] lFlowGuid = flowGuids.Split(',');
                                foreach (string flowGuid in lFlowGuid)
                                {
                                    EA.Connector flow = rep.GetConnectorByGuid(flowGuid);
                                    foreach (EA.Element el in flow.ConveyedItems)
                                    {
                                        conveyedItems = $"{conveyedItems}, {el.ElementID}";
                                    }
                                }

                            }
                        }
                        else
                        {


                            foreach (EA.Element el in con.ConveyedItems)
                            {
                                conveyedItems = $"{conveyedItems}, {el.ElementID}";
                            }

                        }
                        sql = sql.Replace(currentConveyedItemTemplate, $"{conveyedItems}");
                    }
                } else
                // no connector selected
                {
                    MessageBox.Show(sql, @"No connector selected!");
                    sql = "";
                }
            }
            return sql;
        }
        /// <summary>
        /// Get containing Package ID from context element of Package, Element, Diagram, Attribute, Operation
        /// </summary>
        /// <param name="rep"></param>
        /// <returns></returns>
        static int GetParentPackageIdFromContextElement(Repository rep)
        {
            ObjectType objectType = rep.GetContextItemType();
            int id = 0;
            switch (objectType)
            {
                case ObjectType.otDiagram:
                    Diagram dia = (Diagram)rep.GetContextObject();
                    id = dia.PackageID;
                    break;
                case ObjectType.otElement:
                    EA.Element el = (EA.Element)rep.GetContextObject();
                    id = el.PackageID;
                    break;
                case ObjectType.otPackage:
                    EA.Package pkg = (EA.Package)rep.GetContextObject();
                    id = pkg.PackageID;
                    break;
                case ObjectType.otAttribute:
                    EA.Attribute attr = (EA.Attribute)rep.GetContextObject();
                    EA.Element elOfAttr = rep.GetElementByID(attr.ParentID);
                    id = elOfAttr.PackageID;
                    break;
                case ObjectType.otMethod:
                    Method meth = (Method)rep.GetContextObject();
                    EA.Element elOfMeth = rep.GetElementByID(meth.ParentID);
                    id = elOfMeth.PackageID;
                    break;
            }

            return id;
        }
        // ReSharper disable once UnusedMember.Global
        // dynamical usage as configurable service by reflection
        public static void SplitAllDiagramObjectsToLastSelected(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            int count = dia.SelectedObjects.Count;
            if (count == 0) return;
            rep.SaveDiagram(dia.DiagramID);

            // target object/element
            ObjectType objType = rep.GetContextItemType();
            if (!(objType.Equals(ObjectType.otElement))) return;
            var trgEl = (Element) rep.GetContextObject();

            foreach (DiagramObject srcObj in dia.DiagramObjects)
            {
                var srcEl = rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID) continue;
                SplitElementsByConnectorType(srcEl, trgEl);
            }

            rep.ReloadDiagram(dia.DiagramID);
            dia.SelectedObjects.AddNew(trgEl.ElementID.ToString(), trgEl.ObjectType.ToString());
        }
        public static void UpdateActivityParameter(Repository rep)
        {
            ObjectType oType = rep.GetContextItemType();
            if (oType.Equals(ObjectType.otElement))
            {
                var el = (Element) rep.GetContextObject();
                if (el.Type.Equals("Activity"))
                {
                    // get the associated operation
                    Method m = Util.GetOperationFromBrehavior(rep, el);
                    if (el.Locked) return;
                    if (m == null) return;
                    ActivityPar.UpdateParameterFromOperation(rep, el, m); // get parameters from Operation for Activity
                    Diagram dia = rep.GetCurrentDiagram();
                    if (dia == null) return;

                    DiagramObject diaObj = Util.GetDiagramObjectById(rep, dia, el.ElementID);
                    //EA.DiagramObject diaObj = dia.GetDiagramObjectByID(el.ElementID,"");
                    if (diaObj == null) return;

                    int pos = 0;
                    rep.SaveDiagram(dia.DiagramID);
                    foreach (Element actPar in el.EmbeddedElements)
                    {
                        if (!actPar.Type.Equals("ActivityParameter")) continue;
                        Util.VisualizePortForDiagramobject(pos, dia, diaObj, actPar, null);
                        pos = pos + 1;
                    }
                    rep.ReloadDiagram(dia.DiagramID);
                }
                if (el.Type.Equals("Class") | el.Type.Equals("Interface"))
                {
                    UpdateActivityParameterForElement(rep, el);
                }
            }
            if (oType.Equals(ObjectType.otMethod))
            {
                var m = (Method) rep.GetContextObject();
                Element act = Appl.GetBehaviorForOperation(rep, m);
                if (act == null) return;
                if (act.Locked) return;
                ActivityPar.UpdateParameterFromOperation(rep, act, m); // get parameters from Operation for Activity
            }
            if (oType.Equals(ObjectType.otPackage))
            {
                var pkg = (Package) rep.GetContextObject();
                UpdateActivityParameterForPackage(rep, pkg);
            }
        }
        static void CopyReleaseInfoOfModule(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            if (!rep.GetContextItemType().Equals(ObjectType.otElement)) return;
            var elSource = (Element) rep.GetContextObject();
            if (elSource.Type != "Component") return;

            Util.GetDiagramObjectById(rep, dia, elSource.ElementID);
            //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, "");

            string txt = "";
            string nl = "";
            foreach (DiagramObject obj in dia.DiagramObjects)
            {
                var elTarget = rep.GetElementByID(obj.ElementID);
                if (!("Class Interface".Contains(elTarget.Type))) continue;
                txt = txt + nl + AddReleaseInformation(rep, elTarget);
                nl = "\r\n";
            }
            Clipboard.SetText(txt);
        }
        /// <summary>
        /// Locate the type for Connector, Method, Attribute, Diagram, Element, Package
        /// </summary>
        /// <param name="rep"></param>
        public static void LocateType(Repository rep)
        {
            ObjectType oType = rep.GetContextItemType();
            Element el;
            int id;
            string triggerGuid;
            // connector
            // links to trigger
            switch (oType)
            {
                case ObjectType.otConnector:
                    var con = (Connector) rep.GetContextObject();
                    triggerGuid = Util.GetTrigger(rep, con.ConnectorGUID);
                    if (triggerGuid.StartsWith("{", StringComparison.Ordinal) &&
                        triggerGuid.EndsWith("}", StringComparison.Ordinal))
                    {
                        Element trigger = rep.GetElementByGuid(triggerGuid);

                        if (trigger != null) rep.ShowInProjectView(trigger);
                    }
                    else
                    {
                        SelectBehaviorFromConnector(rep, con, DisplayMode.Method);
                    }
                    break;


                case ObjectType.otMethod:
                    var m = (Method) rep.GetContextObject();
                    if (m.ClassifierID != "")
                    {
                        id = Convert.ToInt32(m.ClassifierID);
                        // get type
                        if (id > 0)
                        {
                            el = rep.GetElementByID(id);
                            rep.ShowInProjectView(el);
                        }
                    }
                    break;

                case ObjectType.otAttribute:
                    var attr = (EA.Attribute) rep.GetContextObject();
                    id = attr.ClassifierID;
                    // get type
                    if (id > 0)
                    {
                        el = rep.GetElementByID(attr.ClassifierID);
                        if (el.Type.Equals("Package"))
                        {
                            Package pkg = rep.GetPackageByID(Convert.ToInt32(el.MiscData[0]));
                            rep.ShowInProjectView(pkg);
                        }
                        else
                        {
                            rep.ShowInProjectView(el);
                        }
                    }
                    break;

                // Locate Diagram (e.g. from Search Window)
                case ObjectType.otDiagram:
                    var d = (Diagram) rep.GetContextObject();
                    rep.ShowInProjectView(d);
                    break;


                case ObjectType.otElement:
                    el = (Element) rep.GetContextObject();
                    if (el.ClassfierID > 0)
                    {
                        el = rep.GetElementByID(el.ClassfierID);
                        rep.ShowInProjectView(el);
                    }
                    else
                    {
//MiscData(0) PDATA1,PDATA2,
                        // pdata1 Id for parts, UmlElement
                        // object_id   for text with Hyper link to diagram

                        // locate text or frame
                        if (LocateTextOrFrame(rep, el)) return;

                        string guid = el.MiscData[0];
                        if (guid.EndsWith("}", StringComparison.Ordinal))
                        {
                            el = rep.GetElementByGuid(guid);
                            rep.ShowInProjectView(el);
                        }
                        else
                        {
                            if (el.Type.Equals("Action"))
                            {
                                foreach (CustomProperty custproperty in el.CustomProperties)
                                {
                                    if (custproperty.Name.Equals("kind") && custproperty.Value.Contains("AcceptEvent"))
                                    {
                                        // get the trigger
                                        triggerGuid = Util.GetTrigger(rep, el.ElementGUID);
                                        if (triggerGuid.StartsWith("{", StringComparison.Ordinal) &&
                                            triggerGuid.EndsWith("}", StringComparison.Ordinal))
                                        {
                                            Element trigger = rep.GetElementByGuid(triggerGuid);
                                            rep.ShowInProjectView(trigger);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (el.Type.Equals("Trigger"))
                            {
                                // get the signal
                                string signalGuid = Util.GetSignal(rep, el.ElementGUID);
                                if (signalGuid.StartsWith("RefGUID={", StringComparison.Ordinal))
                                {
                                    Element signal = rep.GetElementByGuid(signalGuid.Substring(8, 38));
                                    rep.ShowInProjectView(signal);
                                }
                            }

                            if (el.Type.Equals("RequiredInterface") || el.Type.Equals("ProvidedInterface"))
                            {
                                rep.ShowInProjectView(el);
                            }
                        }
                    }
                    break;

                case ObjectType.otPackage:
                    var pkgSrc = (Package) rep.GetContextObject();
                    Package pkgTrg = Util.GetModelDocumentFromPackage(rep, pkgSrc);
                    if (pkgTrg != null) rep.ShowInProjectView(pkgTrg);
                    break;
            }
        }
        static void GenerateComponentPorts(Repository rep)
        {
            int pos = 0;
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            if (!rep.GetContextItemType().Equals(ObjectType.otElement)) return;
            var elSource = (Element) rep.GetContextObject();
            if (elSource.Type != "Component") return;

            Util.GetDiagramObjectById(rep, dia, elSource.ElementID);
            //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, "");

            rep.SaveDiagram(dia.DiagramID);
            foreach (DiagramObject obj in dia.DiagramObjects)
            {
                var elTarget = rep.GetElementByID(obj.ElementID);
                if (!("Class Interface".Contains(elTarget.Type))) continue;
                if (!(elTarget.Name.EndsWith("_i", StringComparison.Ordinal)))
                {
                    AddPortToComponent(elSource, elTarget);
                    pos = pos + 1;
                }

                if ("Interface Class".Contains(elTarget.Type))
                {
                    List<Element> lEl = GetIncludedHeaderFiles(rep, elTarget);
                    foreach (Element el in lEl)
                    {
                        if (el == null) continue;
                        if (!(el.Name.EndsWith("_i", StringComparison.Ordinal)))
                        {
                            AddPortToComponent(elSource, el);
                            pos = pos + 1;
                        }
                    }
                }
            }
            ShowEmbeddedElementsGui(rep);
        }
 // ReSharper disable once UnusedMember.Local
 static void CreateNoteFromText(Repository rep, string text)
 {
     if (rep.GetContextItemType().Equals(ObjectType.otElement))
     {
         var el = (Element) rep.GetContextObject();
         string s0 = CallOperationAction.RemoveUnwantedStringsFromText(text.Trim(), false);
         s0 = Regex.Replace(s0, @"\/\*", "//"); // /* ==> //
         s0 = Regex.Replace(s0, @"\*\/", ""); // delete */
         el.Notes = s0;
         el.Update();
     }
 }
        public static void ChangeAuthor(Repository rep)
        {
            string[] args = {""};
            string oldAuthor;
            Element el = null;
            Package pkg = null;
            Diagram dia = null;
            ObjectType oType = rep.GetContextItemType();

            // get the element
            switch (oType)
            {
                case ObjectType.otPackage:
                    pkg = (Package) rep.GetContextObject();
                    el = rep.GetElementByGuid(pkg.PackageGUID);
                    oldAuthor = el.Author;
                    break;
                case ObjectType.otElement:
                    el = (Element) rep.GetContextObject();
                    oldAuthor = el.Author;
                    break;
                case ObjectType.otDiagram:
                    dia = (Diagram) rep.GetContextObject();
                    oldAuthor = dia.Author;
                    break;
                default:
                    return;
            }
            // ask for new user
            var dlg = new dlgUser(rep) {User = oldAuthor};
            dlg.ShowDialog();
            args[0] = dlg.User;
            if (args[0] == "")
            {
                MessageBox.Show($"Author:'{args[0]}'", @"no or invalid user");
                return;
            }
            switch (oType)
            {
                case ObjectType.otPackage:
                    ChangeAuthorPackage(rep, pkg, args);
                    MessageBox.Show($"New author:'{args[0]}'", @"Author changed for package");
                    break;
                case ObjectType.otElement:
                    ChangeAuthorElement(rep, el, args);
                    MessageBox.Show($"New author:'{args[0]}'", @"Author changed for element");
                    break;
                case ObjectType.otDiagram:
                    ChangeAuthorDiagram(rep, dia, args);
                    MessageBox.Show($"New author:'{args[0]}'", @"Author changed for element");
                    break;
                default:
                    return;
            }
        }
        public static void GetVcLatestRecursive(Repository rep)
        {
            ObjectType oType = rep.GetContextItemType();
            if (oType.Equals(ObjectType.otPackage) || oType.Equals(ObjectType.otNone))
            {
                // start preparation
                int count = 0;
                int errorCount = 0;
                DateTime startTime = DateTime.Now;

                rep.CreateOutputTab("Debug");
                rep.EnsureOutputVisible("Debug");
                rep.WriteOutput("Debug", "Start GetLatestRecursive", 0);
                var pkg = (Package) rep.GetContextObject();
                Util.GetLatest(rep, pkg, true, ref count, 0, ref errorCount);
                string s = "";
                if (errorCount > 0) s = " with " + errorCount + " errors";

                // finished
                TimeSpan span = DateTime.Now - startTime;
                rep.WriteOutput("Debug", "End GetLatestRecursive in " + span.Hours + ":" + span.Minutes + " hh:mm. " + s,
                    0);
            }
        }
        public static void CreateActivityForOperation(Repository rep)
        {
            ObjectType oType = rep.GetContextItemType();
            switch (oType)
            {
                case ObjectType.otMethod:
                    var m = (Method) rep.GetContextObject();

                    // Create Activity at the end
                    Element el = rep.GetElementByID(m.ParentID);
                    Package pkg = rep.GetPackageByID(el.PackageID);
                    int pos = pkg.Packages.Count + 1;
                    ActivityPar.CreateActivityForOperation(rep, m, pos);
                    rep.Models.Refresh();
                    rep.RefreshModelView(0);
                    rep.ShowInProjectView(m);
                    break;

                case ObjectType.otElement:
                    el = (Element) rep.GetContextObject();
                    if (el.Locked) return;

                    CreateActivityForOperationsInElement(rep, el);
                    rep.Models.Refresh();
                    rep.RefreshModelView(0);
                    rep.ShowInProjectView(el);
                    break;

                case ObjectType.otPackage:
                    pkg = (Package) rep.GetContextObject();
                    CreateActivityForOperationsInPackage(rep, pkg);
                    // update sort order of packages
                    rep.Models.Refresh();
                    rep.RefreshModelView(0);
                    rep.ShowInProjectView(pkg);
                    break;
            }
        }
        public static void CopyGuidSqlToClipboard(Repository rep)
        {
            string str = @"";
            string str1;
            ObjectType oType = rep.GetContextItemType();
            Diagram diaCurrent = rep.GetCurrentDiagram();
            Connector conCurrent = null;

            if (diaCurrent != null)
            {
                conCurrent = diaCurrent.SelectedConnector;
            }

            if (conCurrent != null)
            {
// Connector 
                Connector con = conCurrent;
                str = con.ConnectorGUID + " " + con.Name + ' ' + con.Type + "\r\n" +
                      "\r\n Connector: Select ea_guid As CLASSGUID, connector_type As CLASSTYPE,* from t_connector con where ea_guid = '" +
                      con.ConnectorGUID + "'" +
                      "\r\n\r\nSelect o.ea_guid As CLASSGUID, o.object_type As CLASSTYPE,o.name As Name, o.object_type AS ObjectType, o.PDATA1, o.Stereotype, " +
                      "\r\n                       con.Name, con.connector_type, con.Stereotype, con.ea_guid As ConnectorGUID, dia.Name As DiagrammName, dia.ea_GUID As DiagramGUID," +
                      "\r\n                       o.ea_guid, o.Classifier_GUID,o.Classifier " +
                      "\r\nfrom (((t_connector con INNER JOIN t_object o              on con.start_object_id   = o.object_id) " +
                      "\r\nINNER JOIN t_diagramlinks diaLink  on con.connector_id      = diaLink.connectorid ) " +
                      "\r\nINNER JOIN t_diagram dia           on diaLink.DiagramId     = dia.Diagram_ID) " +
                      "\r\nINNER JOIN t_diagramobjects diaObj on diaObj.diagram_ID     = dia.Diagram_ID and o.object_id = diaObj.object_id " +
                      "\r\nwhere         con.ea_guid = '" + con.ConnectorGUID + "' " +
                      "\r\nAND dialink.Hidden  = 0 ";
                Clipboard.SetText(str);
                return;
            }
            if (oType.Equals(ObjectType.otElement))
            {
// Element 
                var el = (Element) rep.GetContextObject();
                string pdata1 = el.MiscData[0];
                string pdata1String;
                if (pdata1.EndsWith("}", StringComparison.Ordinal))
                {
                    pdata1String = "/" + pdata1;
                }
                else
                {
                    pdata1 = "";
                    pdata1String = "";
                }
                string classifier = Util.GetClassifierGuid(rep, el.ElementGUID);
                str = el.ElementGUID + ":" + classifier + pdata1String + " " + el.Name + ' ' + el.Type + "\r\n" +
                      "\r\nSelect ea_guid As CLASSGUID, object_type As CLASSTYPE,* from t_object o where ea_guid = '" +
                      el.ElementGUID + "'";
                if (classifier != "")
                {
                    if (el.Type.Equals("ActionPin"))
                    {
                        str = str +
                              "\r\n Type:\r\nSelect ea_guid As CLASSGUID, 'Parameter' As CLASSTYPE,* from t_operationparams op where ea_guid = '" +
                              classifier + "'";
                    }
                    else
                    {
                        str = str +
                              "\r\n Type:\r\nSelect ea_guid As CLASSGUID, object_type As CLASSTYPE,* from t_object o where ea_guid = '" +
                              classifier + "'";
                    }
                }
                if (pdata1 != "")
                {
                    str = str +
                          "\r\n PDATA1:  Select ea_guid As CLASSGUID, object_type As CLASSTYPE,* from t_object o where ea_guid = '" +
                          pdata1 + "'";
                }

                // Look for diagram object
                Diagram curDia = rep.GetCurrentDiagram();
                if (curDia != null)
                {
                    foreach (DiagramObject diaObj in curDia.DiagramObjects)
                    {
                        if (diaObj.ElementID == el.ElementID)
                        {
                            str = str + "\r\n\r\n" +
                                  "select * from t_diagramobjects where object_id = " + diaObj.ElementID;
                            break;
                        }
                    }
                }
            }

            if (oType.Equals(ObjectType.otDiagram))
            {
// Element 
                var dia = (Diagram) rep.GetContextObject();
                str = dia.DiagramGUID + " " + dia.Name + ' ' + dia.Type + "\r\n" +
                      "\r\nSelect ea_guid As CLASSGUID, diagram_type As CLASSTYPE,* from t_diagram dia where ea_guid = '" +
                      dia.DiagramGUID + "'";
            }
            if (oType.Equals(ObjectType.otPackage))
            {
// Element 
                var pkg = (Package) rep.GetContextObject();
                str = pkg.PackageGUID + " " + pkg.Name + ' ' + " Package " + "\r\n" +
                      "\r\nSelect ea_guid As CLASSGUID, 'Package' As CLASSTYPE,* from t_package pkg where ea_guid = '" +
                      pkg.PackageGUID + "'";
            }
            if (oType.Equals(ObjectType.otAttribute))
            {
// Element 
                str1 = "LEFT JOIN  t_object typAttr on (attr.Classifier = typAttr.object_id)";
                if (rep.ConnectionString.Contains(".eap"))
                {
                    str1 = "LEFT JOIN  t_object typAttr on (attr.Classifier = Format(typAttr.object_id))";
                }
                var attr = (EA.Attribute) rep.GetContextObject();
                str = attr.AttributeID + " " + attr.Name + ' ' + " Attribute " + "\r\n" +
                      "\r\n " +
                      "\r\nSelect ea_guid As CLASSGUID, 'Attribute' As CLASSTYPE,* from t_attribute attr where ea_guid = '" +
                      attr.AttributeGUID + "'" +
                      "\r\n Class has Attributes:" +
                      "\r\nSelect attr.ea_guid As CLASSGUID, 'Attribute' As CLASSTYPE, " +
                      "\r\n       o.Name As Class, o.object_type, " +
                      "\r\n       attr.Name As AttrName, attr.Type As Type, " +
                      "\r\n       typAttr.Name " +
                      "\r\n   from (t_object o INNER JOIN t_attribute attr on (o.object_id = attr.object_id)) " +
                      "\r\n                   " + str1 +
                      "\r\n   where attr.ea_guid = '" + attr.AttributeGUID + "'";
            }
            if (oType.Equals(ObjectType.otMethod))
            {
// Element 
                str1 = "LEFT JOIN t_object parTyp on (par.classifier = parTyp.object_id))";
                var str2 = "LEFT JOIN t_object opTyp on (op.classifier = opTyp.object_id)";
                if (rep.ConnectionString.Contains(".eap"))
                {
                    str1 = " LEFT JOIN t_object parTyp on (par.classifier = Format(parTyp.object_id))) ";
                    str2 = " LEFT JOIN t_object opTyp  on (op.classifier  = Format(opTyp.object_id))";
                }

                var op = (Method) rep.GetContextObject();
                str = op.MethodGUID + " " + op.Name + ' ' + " Operation " +
                      "\r\nOperation may have type " +
                      "\r\nSelect op.ea_guid As CLASSGUID, 'Operation' As CLASSTYPE,opTyp As OperationType, op.Name As OperationName, typ.Name As TypName,*" +
                      "\r\n   from t_operation op LEFT JOIN t_object typ on (op.classifier = typ.object_id)" +
                      "\r\n   where op.ea_guid = '" + op.MethodGUID + "';" +
                      "\r\n\r\nClass has Operation " +
                      "\r\nSelect op.ea_guid As CLASSGUID, 'Operation' As CLASSTYPE,* " +
                      "\r\n    from t_operation op INNER JOIN t_object o on (o.object_id = op.object_id)" +
                      "\r\n    where op.ea_guid = '" + op.MethodGUID + "';" +
                      "\r\n\r\nClass has Operation has Parameters/Typ and may have operationtype" +
                      "\r\nSelect op.ea_guid As CLASSGUID, 'Operation' As CLASSTYPE,op.Name As ClassName, op.Name As OperationName, opTyp.Name As OperationTyp, par.Name As ParName,parTyp.name As ParTypeName " +
                      "\r\n   from ((t_operation op INNER JOIN t_operationparams par on (op.OperationID = par.OperationID) )" +
                      "\r\n                        " + str1 +
                      "\r\n                        " + str2 +
                      "\r\n   where op.ea_guid = '" + op.MethodGUID + "' " +
                      "\r\n  Order by par.Pos ";
            }
            Clipboard.SetText(str);
        }
 public static void FindUsage(Repository rep)
 {
     ObjectType oType = rep.GetContextItemType();
     if (oType.Equals(ObjectType.otElement))
     {
         // locate text or frame
         var el = (Element) rep.GetContextObject();
         if (LocateTextOrFrame(rep, el)) return;
         rep.RunModelSearch("Element usage", el.ElementGUID, "", "");
     }
     if (oType.Equals(ObjectType.otMethod))
     {
         var method = (Method) rep.GetContextObject();
         rep.RunModelSearch("Method usage", method.MethodGUID, "", "");
     }
     if (oType.Equals(ObjectType.otDiagram))
     {
         var dia = (Diagram) rep.GetContextObject();
         rep.RunModelSearch("Diagram usage", dia.DiagramGUID, "", "");
     }
     if (oType.Equals(ObjectType.otConnector))
     {
         var con = (Connector) rep.GetContextObject();
         rep.RunModelSearch("Connector is visible in Diagrams",
             con.ConnectorID.ToString(), "", "");
     }
 }
        /// <summary>
        /// createSharedMemoryFromText
        /// 
        /// Create: Shared Memory as Class and interface
        ///         - Class Realize shared memory
        ///         - Class has port shared memory
        ///         Tagged values:
        ///         - StartAdress:
        ///         - EndAddress
        ///         
        /// </summary>
        /// <param name="rep">EA.Repository</param>
        /// <param name="txt">string</param>
        // #define SP_SHM_HW_MIC_START     0x40008000u
        // #define SP_SHM_HW_MIC_END       0x400083FFu
        // ReSharper disable once UnusedMember.Local
        static void CreateSharedMemoryFromText(Repository rep, string txt)
        {
            ObjectType oType = rep.GetContextItemType();
            if (!oType.Equals(ObjectType.otPackage)) return;
            var pkg = (Package) rep.GetContextObject();

            string regexShm = @"#define\sSP_SHM_(.*)_(START|END)\s*(0x[0-9ABCDEF]*)";
            Match matchShm = Regex.Match(txt, regexShm, RegexOptions.Multiline);
            while (matchShm.Success)
            {
                var shm = Utils.Element.CreateElement(rep, pkg, matchShm.Groups[1].Value, "Class", @"shm");
                var ishm = Utils.Element.CreateElement(rep, pkg, "SHM_" + matchShm.Groups[1].Value, "Interface", "");

                if (matchShm.Groups[2].Value == "START")
                {
                    var shmStartAddr = matchShm.Groups[3].Value;
                    // add Tagged Value "StartAddr"
                    var tagStart = TaggedValue.AddTaggedValue(shm, "StartAddr");
                    tagStart.Value = shmStartAddr;
                    tagStart.Update();
                }
                else if (matchShm.Groups[2].Value == "END")
                {
                    var shmEndAddr = matchShm.Groups[3].Value;
                    // add Tagged Value "StartAddr"
                    var tagEnd = TaggedValue.AddTaggedValue(shm, "EndAddr");
                    tagEnd.Value = shmEndAddr;
                    tagEnd.Update();
                }
                // make realize dependency from Interface to shared memory
                bool found = false;
                foreach (Connector c in shm.Connectors)
                {
                    if (c.SupplierID == ishm.ElementID & c.Type == "Realisation")
                    {
                        found = false;
                        break;
                    }
                }
                // currently switched off
                if (found == false)
                {
                    var con = (Connector) shm.Connectors.AddNew("", "Realisation");
                    con.SupplierID = ishm.ElementID;
                    try
                    {
                        con.Update();
                    }
                    catch
                    {
                        //
                    }
                    shm.Connectors.Refresh();
                }
                // make a port with a provided interface
                Utils.Element.CreatePortWithInterface(shm, ishm, "ProvidedInterface");


                matchShm = matchShm.NextMatch();
            }
        }
        // display behavior or definition for selected element
        // enum displayMode: "Behavior" or "Method"
        public static void DisplayOperationForSelectedElement(Repository repository, DisplayMode showBehavior)
        {
            ObjectType oType = repository.GetContextItemType();
            // Method found
            if (oType.Equals(ObjectType.otMethod))
            {
                // display behavior for method
                Appl.DisplayBehaviorForOperation(repository, (Method) repository.GetContextObject());
            }
            if (oType.Equals(ObjectType.otDiagram))
            {
                // find parent element
                var dia = (Diagram) repository.GetContextObject();
                if (dia.ParentID > 0)
                {
                    // find parent element
                    Element parentEl = repository.GetElementByID(dia.ParentID);
                    //
                    LocateOperationFromBehavior(repository, parentEl, showBehavior);
                }
                else
                {
                    // open diagram
                    repository.OpenDiagram(dia.DiagramID);
                }
            }


            // Connector / Message found
            if (oType.Equals(ObjectType.otConnector))
            {
                var con = (Connector) repository.GetContextObject();
                SelectBehaviorFromConnector(repository, con, showBehavior);
            }

            // Element
            if (oType.Equals(ObjectType.otElement))
            {
                var el = (Element) repository.GetContextObject();
                // locate text or frame
                if (LocateTextOrFrame(repository, el)) return;

                if (el.Type.Equals("Activity") & showBehavior.Equals(DisplayMode.Behavior))
                {
                    // Open Behavior for Activity
                    Util.OpenBehaviorForElement(repository, el);
                }
                if (el.Type.Equals("State"))
                {
                    // get operations
                    foreach (Method m in el.Methods)
                    {
                        // display behaviors for methods
                        Appl.DisplayBehaviorForOperation(repository, m);
                    }
                }

                if (el.Type.Equals("Action"))
                {
                    foreach (CustomProperty custproperty in el.CustomProperties)
                    {
                        if (custproperty.Name.Equals("kind") && custproperty.Value.Equals("CallOperation"))
                        {
                            ShowFromElement(repository, el, showBehavior);
                        }
                        if (custproperty.Name.Equals("kind") && custproperty.Value.Equals("CallBehavior"))
                        {
                            el = repository.GetElementByID(el.ClassfierID);
                            Util.OpenBehaviorForElement(repository, el);
                        }
                    }
                }
                if (showBehavior.Equals(DisplayMode.Method) & (
                    el.Type.Equals("Activity") || el.Type.Equals("StateMachine") || el.Type.Equals("Interaction")))
                {
                    LocateOperationFromBehavior(repository, el, showBehavior);
                }
            }
        }
 // ReSharper disable once UnusedMember.Global
 // dynamical usage as configurable service by reflection
 public static void UnLockSelected(Repository rep)
 {
     if (!IsSecurityEnabled(rep)) return;
     bool success;
     switch (rep.GetContextItemType())
     {
         case ObjectType.otPackage:
             Package pkg = (Package) rep.GetContextObject();
             pkg.ReleaseUserLockRecursive(true, true, false);
             success = pkg.ReleaseUserLock();
             break;
         case ObjectType.otElement:
             Element el = (Element) rep.GetContextObject();
             success = el.ReleaseUserLock();
             break;
         case ObjectType.otDiagram:
             Diagram dia = (Diagram) rep.GetContextObject();
             success = dia.ReleaseUserLock();
             break;
         default:
             return;
     }
     if (success) return;
     MessageBox.Show($"Error:'{rep.GetLastError()}'", @"Error unlock item");
 }
Example #37
0
        /// <summary>
        /// Get the current Diagram with it's selected objects and connectors.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="getAllDiagramObject">True if you want all diagram objects if nothing no diagram object is selected</param>
        public EaDiagram(Repository rep, bool getAllDiagramObject = false)
        {
            _rep = rep;
            _selectedConnector = null;
            IsSelectedObjects  = false;

            _dia = rep.GetCurrentDiagram();
            // Nothing selected
            if (_dia == null || (_dia.SelectedConnector == null && _dia.SelectedObjects.Count == 0))
            {
                GetTreeSelected();
                return;
            }

            EA.ObjectType contextObjectType = Rep.GetContextItemType();


            // Check if context is diagram or something inside the current diagram is selected (selected things are never old)
            if (contextObjectType != ObjectType.otDiagram && _dia.SelectedObjects.Count == 0 &&
                _dia.SelectedConnector == null)
            {
                return;
            }


            // Diagram is context or something inside the diagram is selected
            IsSelectedObjects = false;
            if (_dia.SelectedObjects.Count == 0 && getAllDiagramObject)
            {
                // overall diagram objects
                foreach (EA.DiagramObject obj in _dia.DiagramObjects)
                {
                    _selectedObjects.Add(obj);
                    SelElements.Add(rep.GetElementByID(obj.ElementID));
                }
            }
            // If an context element exists than this is the last selected element
            if (_dia.SelectedObjects.Count > 0)
            {
                // The context item isn't always set, try to estimate it
                if (contextObjectType == EA.ObjectType.otElement ||
                    contextObjectType == EA.ObjectType.otPackage ||
                    contextObjectType == EA.ObjectType.otNone ||
                    contextObjectType == EA.ObjectType.otDiagram
                    )
                {
                    // 1. store context element/ last selected element
                    // Context Element may be a Package. EA also stores the package as Element
                    EA.Element elContext = null;
                    switch (rep.GetContextItemType())
                    {
                    case EA.ObjectType.otElement:
                        elContext = (EA.Element)rep.GetContextObject();
                        break;

                    case EA.ObjectType.otPackage:
                        var pkg = (EA.Package)rep.GetContextObject();
                        elContext = rep.GetElementByGuid(pkg.PackageGUID);
                        break;
                    }

                    // no context element available, take first element
                    if (elContext == null)
                    {
                        EA.DiagramObject obj = (EA.DiagramObject)_dia.SelectedObjects.GetAt(0);
                        elContext = rep.GetElementByID(obj.ElementID);
                    }
                    _conTextDiagramObject = _dia.GetDiagramObjectByID(elContext.ElementID, "");

                    SelElements.Add(elContext);
                    _selectedObjects.Add(_conTextDiagramObject);
                    IsSelectedObjects = true;

                    // over all selected diagram objects
                    foreach (EA.DiagramObject obj in _dia.SelectedObjects)
                    {
                        // skip last selected element / context element
                        if (_conTextDiagramObject != null && obj.ElementID == _conTextDiagramObject.ElementID)
                        {
                            continue;
                        }

                        _selectedObjects.Add(obj);
                        SelElements.Add(rep.GetElementByID(obj.ElementID));
                    }
                }
            }
            _selectedConnector = _dia.SelectedConnector;
        }
        public static void UpdateOperationTypes(Repository rep)
        {
            ObjectType oType = rep.GetContextItemType();
            switch (oType)
            {
                case ObjectType.otMethod:
                    UpdateOperationType(rep, (Method) rep.GetContextObject());
                    break;
                case ObjectType.otElement:
                    var el = (Element) rep.GetContextObject();
                    if (el.Type == "Activity")
                    {
                        Method m = Util.GetOperationFromBrehavior(rep, el);
                        if (m == null)
                        {
                            MessageBox.Show(@"Activity hasn't an operation");
                            return;
                        }
                        UpdateOperationType(rep, m);
                    }
                    else
                    {
                        foreach (Method m in el.Methods)
                        {
                            UpdateOperationType(rep, m);
                        }
                    }
                    break;

                case ObjectType.otPackage:
                    var pkg = (Package) rep.GetContextObject();
                    UpdateOperationTypeForPackage(rep, pkg);
                    break;
            }
        }
        /// <inheritdoc />
        public override void Initialize()
        {
            SaveCommand   = new SaveCommand();
            CancelCommand = new CancelCommand();
            AddCommand    = new AddCommand();
            RemoveCommand = new RemoveCommand();

            Element      = Repository.GetContextObject();
            UMLNameValue = Element.Name;
            AliasValue   = Element.Alias;
            TaggedValues = Element.TaggedValues;

            //Finalize list of stereotype tags to add
            switch (Element.Stereotype)
            {
            case "OwlClass":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "EquivalentClass"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SubClassOf"));
                StereotypeString = (string)ResourceDictionary["OwlClassCharacteristics"];
                break;

            case "RdfsClass":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "EquivalentClass"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SubClassOf"));
                StereotypeString = (string)ResourceDictionary["RdfsClassCharacteristics"];
                break;

            case "Individual":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SameAs"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "Type"));
                StereotypeString = (string)ResourceDictionary["IndividualCharacteristics"];
                break;
            }

            //Retrieve all tagged values and store them in a list
            //Tagged values are stored in a list to avoid iterating Collections multiple times, which is very costly
            //In a future iteration of the addin, avoid iterating the collection even once, instead using Repository.SQLQuery to retrieve
            //an XML-formatted list of every Tagged Value where the owner ID is Element.ElementID
            for (short i = 0; i < TaggedValues.Count; i++)
            {
                TaggedValue tv = TaggedValues.GetAt(i);
                _taggedValuesList.Add(tv);
            }

            // Retrieve URI tagged value and save it in URIViewmodelTaggedValue
            var result = RetrieveTaggedValues(_taggedValuesList, "URI");

            URIViewmodelTaggedValue = new ViewModelTaggedValue(result.First())
            {
                ResourceDictionary = ResourceDictionary,
                Key = Definitions.Find(ptv => ptv.Key == "URI").Key
            };
            URIViewmodelTaggedValue.Initialize();
            URIValue = URIViewmodelTaggedValue.Value;

            // Add tagged values to list of ViewmodelTaggedValues
            DanishViewmodelTaggedValues     = AddTaggedValuesToViewmodelTaggedValues(_toAddDanishTaggedValues, _taggedValuesList);
            EnglishViewmodelTaggedValues    = AddTaggedValuesToViewmodelTaggedValues(_toAddEnglishTaggedValues, _taggedValuesList);
            ProvenanceViewmodelTaggedValues = AddTaggedValuesToViewmodelTaggedValues(_toAddProvenanceTaggedValues, _taggedValuesList);
            StereotypeViewmodelTaggedValues = AddTaggedValuesToViewmodelTaggedValues(_toAddStereotypeTaggedValues, _taggedValuesList);
        }
        // ReSharper disable once UnusedMethodReturnValue.Global
        public static bool SetNewXmlPath(Repository rep)
        {
            if (rep.GetContextItemType().Equals(ObjectType.otPackage))
            {
                var pkg = (Package) rep.GetContextObject();
                string guid = pkg.PackageGUID;

                var openFileDialogXml = new OpenFileDialog
                {
                    Filter = @"xml files (*.xml)|*.xml",
                    FileName = Util.GetVccFilePath(rep, pkg)
                };
                if (openFileDialogXml.ShowDialog() == DialogResult.OK)
                {
                    var path = openFileDialogXml.FileName;
                    string rootPath = Util.GetVccRootPath(rep, pkg);
                    // delete root path and an preceding '\'
                    string shortPath = path.Replace(rootPath, "");
                    if (shortPath.StartsWith(@"\", StringComparison.Ordinal)) shortPath = shortPath.Substring(1);

                    // write to repository
                    Util.SetXmlPath(rep, guid, shortPath);

                    // write to file
                    try
                    {
                        // set readonly attribute to false
                        System.IO.File.SetAttributes(path, FileAttributes.Normal);

                        string strFile = System.IO.File.ReadAllText(path);
                        string replace = @"value=[.0-9a-zA-Z_\\-]*\.xml";
                        string replacement = shortPath;
                        strFile = Regex.Replace(strFile, replace, replacement);
                        System.IO.File.WriteAllText(path, strFile);

                        // checkout + checkin to make the change permanent
                        pkg.VersionControlCheckout();
                        pkg.VersionControlCheckin("Re- organization *.xml files");
                    }
                    catch (Exception e1)
                    {
                        MessageBox.Show(e1.ToString(), $"Error writing '{path}'");
                    }

                    MessageBox.Show(path, @"Changed");
                }
            }
            return true;
        }