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 SetDirectoryTaggedValues(Repository rep, Package pkg)
        {
            bool withCheckIn = false;
            string guid = pkg.PackageGUID;

            Element el = rep.GetElementByGuid(guid);
            if (IsTaggedValuesComplete(el)) return;
            if (pkg.IsVersionControlled)
            {
                int state = pkg.VersionControlGetStatus();
                if (state == 4)
                {
                    MessageBox.Show("", @"Package checked out by another user, break");
                    return;
                }
                if (state == 1) // checked in
                {
                    CheckOut(rep, pkg);
                    withCheckIn = true;
                }
            }
            pkg = rep.GetPackageByGuid(guid);
            SetSvnProperty(rep, pkg);

            // set tagged values
            el = rep.GetElementByGuid(guid);
            bool createSvnDate = true;
            bool createSvnRevision = true;
            foreach (EA.TaggedValue t in el.TaggedValues)
            {
                createSvnDate &= t.Name != "svnDate";
                createSvnRevision &= t.Name != "svnRevision";
            }
            EA.TaggedValue tag;
            if (createSvnDate)
            {
                tag = (EA.TaggedValue) el.TaggedValues.AddNew("svnDate", "");
                tag.Value = "$Date: $";
                el.TaggedValues.Refresh();
                tag.Update();
            }
            if (createSvnRevision)
            {
                tag = (EA.TaggedValue) el.TaggedValues.AddNew("svnRevision", "");
                tag.Value = "$Revision: $";
                el.TaggedValues.Refresh();
                tag.Update();
            }


            if (pkg.IsVersionControlled)
            {
                int state = pkg.VersionControlGetStatus();
                if (state == 2 & withCheckIn) // checked out to this user
                {
                    //EaService.checkIn(rep, pkg, "");
                    CheckIn(rep, pkg, withGetLatest: true, comment: @"svn tags added");
                }
            }
        }
        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;
            }
        }
        /// <summary>
        /// Check in of a package. If there are the following package tagged values a get latest is performed to update keywords:
        /// -- svnDoc
        /// -- svnRevision
        /// </summary>
        /// <param name="rep">Repository</param>
        /// <param name="pkg">Package, default null</param>
        /// <param name="withGetLatest">false if you want to avoid a getLatest to update VC keywords
        /// Tagged Value "svnDoc" or "svnRevision" of package are true</param>
        /// <param name="comment">A check in comment, default="0" = aks for checkin comment</param>
        static void CheckIn(Repository rep, Package pkg = null, bool withGetLatest = false, string comment = "0")
        {
            if (pkg == null) pkg = rep.GetTreeSelectedPackage();
            if (pkg == null) return;

            pkg = Util.GetFirstControlledPackage(rep, pkg);
            if (pkg == null) return;

            var svnHandle = new Svn(rep, pkg);
            string userNameLockedPackage = svnHandle.GetLockingUser();
            if (userNameLockedPackage == "")
            {
                MessageBox.Show(@"Package isn't checked out");
                return;
            }


            if (InputBox(@"Checkin comment", @"Checkin", ref comment) == DialogResult.OK)
            {
                //
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    pkg.VersionControlCheckin(comment);
                    Cursor.Current = Cursors.Default;
                }
                catch (Exception e)
                {
                    MessageBox.Show($"{e} \n\n {pkg.GetLastError()}", @"Error Checkin");
                    return;
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
            if (withGetLatest)
            {
                // check if GetLatest is appropriate
                Element el = rep.GetElementByGuid(pkg.PackageGUID);
                foreach (EA.TaggedValue t in el.TaggedValues)
                {
                    if (t.Name == "svnDoc" | t.Name == "svnRevision")
                    {
                        pkg.VersionControlResynchPkgStatus(false);
                        if (pkg.Flags.Contains("Checkout"))
                        {
                            MessageBox.Show($"Flags={pkg.Flags}", @"Package Checked out, Break!");
                            return;
                        }
                        pkg.VersionControlGetLatest(true);
                        return;
                    }
                }
            }
        }
        // ReSharper disable once UnusedMember.Global
        // dynamical usage as configurable service by reflection
        public static void UnLockAllForCurrentUser(Repository rep)
        {
            if (!IsSecurityEnabled(rep)) return;

            string logInUserGuid = rep.GetCurrentLoginUser(true);

            string sqlItems =
                $"select EntityType as [TYPE], EntityID as [GUID] from t_seclocks where UserId = '{logInUserGuid}'";
            XDocument x = XDocument.Parse(rep.SQLQuery(sqlItems));

            var fields = from row in x.Descendants("Row").Descendants()
                         where row.Name == "TYPE" ||
                               row.Name == "Id"
                         // 'Class','Action','Diagram', 
                         select row;
            int i = 0;
            string type = "";
            foreach (var field in fields)
            {
                switch (i % 2)
                {
                    case 0:
                        type = field.Value;
                        break;
                    case 1:
                        var guid = field.Value;
                        switch (type)
                        {
                            case "Element":
                                Element el = rep.GetElementByGuid(guid);
                                el.ReleaseUserLock();
                                break;
                            case "Diagram":
                                EA.Diagram dia = rep.GetDiagramByGuid(guid);
                                dia.ReleaseUserLock();
                                break;
                        }
                        break;
                }
                i = i + 1;
            }
        }
        /// <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 ChangeAuthorPackage(Repository rep, Package pkg, string[] args)
 {
     Element el = rep.GetElementByGuid(pkg.PackageGUID);
     el.Author = args[0];
     el.Update();
 }
 // ReSharper disable once UnusedMember.Local
 static void BehaviorForOperation(Repository repository, Method method)
 {
     string behavior = method.Behavior;
     if (behavior.StartsWith("{", StringComparison.Ordinal) & behavior.EndsWith("}", StringComparison.Ordinal))
     {
         // get object according to behavior
         Element el = repository.GetElementByGuid(behavior);
         // Activity
         if (el == null)
         {
         }
         else
         {
             if (el.Type.Equals("Activity") || el.Type.Equals("Interaction") || el.Type.Equals("StateMachine"))
             {
                 Util.OpenBehaviorForElement(repository, el);
             }
         }
     }
 }