Author Topic: Api to know which user have locked the object  (Read 2108 times)

kotrick

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Api to know which user have locked the object
« on: September 05, 2011, 01:50:36 pm »
hi,
if i try to lock an object in EA through automation which is already locked by other user then i get an exception .so is there any way or api to identify whether i can lock that object or not.i.e. is there any api to identify who has locked the object

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13247
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Api to know which user have locked the object
« Reply #1 on: September 06, 2011, 05:44:27 pm »
The only way I found was by querying the database directly.
Here's the code 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;
        }
Geert