Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: vladimir.liba on April 25, 2014, 12:37:34 am

Title: Is it possible to get, which user locked element?
Post by: vladimir.liba on April 25, 2014, 12:37:34 am
In the EA.Element class there is boolean atrribute Locked, which identifies some user has locked the element. How is it possible to check in code, who locked the element?

Also, the method ApplyUserLock() just returns true/false, but no identification, who locked the element.

Thanks for hints.
Title: Re: Is it possible to get, which user locked eleme
Post by: qwerty on April 25, 2014, 09:57:29 am
You can find that out with a query. I'm off-site atm but will post tomorrow if nobody else was faster :)

q.
Title: Re: Is it possible to get, which user locked eleme
Post by: Geert Bellekens on April 25, 2014, 03:23:36 pm
Here's what I use
Code: [Select]
/// <summary>
/// returns the name of the user currently locking this element
/// </summary>
/// <returns>the name of the user currently locking this element</returns>
public override string getLockedUser()
{
      string lockedUser = string.Empty;
      //if (this.wrappedElement.Locked)
      //{
            string SQLQuery = @"select u.FirstName, u.Surname from t_seclocks s
                                          inner join t_secuser u on s.userID = u.userID
                                          where s.entityID = '" + this.wrappedElement.ElementGUID + "'";
            XmlDocument result = ((EAModel)this.model).SQLQuery(SQLQuery);
            XmlNode firstNameNode = result.SelectSingleNode("//FirstName");
            XmlNode lastNameNode = result.SelectSingleNode("//Surname");
            if (firstNameNode != null && lastNameNode != null)
            {
                  lockedUser = firstNameNode.InnerText + " " + lastNameNode.InnerText;
            }
      //}
      return lockedUser;
}

This works on SQL Server. I haven't tested it on other backends.

Geert