Book a Demo

Author Topic: EA crashes when Element.ApplyUserLock is called  (Read 3273 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
EA crashes when Element.ApplyUserLock is called
« on: January 21, 2010, 06:12:42 pm »
We use the security feature with "require user lock to edit" option.
I've written an addin that allows me to edit the body of the postconditions in an external text editor and save it back to EA.

Before saving the changed postconditions to EA I check if the Element that owns the operation that owns the postcondition is editable. (the only way to test this is to try update() (without having changed anything) on the element and catch the exception if it isn't locked by the user)
Now when a user doesn't have a lock  I call Element.ApplyUserLock().
If that fails (either by throwing an exception, or returning false) I inform the user that somebody else has locked the element.

The problems happen when somebody else has a lock on the Element. The first time it is all fine, I can inform the user of the existing lock on the element. The second time I try this (the case where this or another element is locked by somebody else then the current user) EA crashes hard. No exceptions, no errors, it just plain disappears.

I have found a workaround for this by querying the seclocks table, but I would rather not have to do this.

Steps to reproduce

  • Setup security with option "require user lock to edit"
  • loging with user A
  • Lock element A
  • Login with user B
  • Call ApplyUserLock() on element A
  • notice all is still fine
  • Call ApplyUserLock() on element A
  • notice that EA is gone.

The code for the workaround looks like this:
Code: [Select]
       /// <summary>
        /// locks the element by the current user
        /// </summary>
        /// <returns>true if successful</returns>
        public override bool enableWrite()
        {
            //because of some nasty bug in EA the application will crash if the element is already locked
            // by another user.
            // therefore we check first if this element is locked before even trying.
            string SQLQuery = "select s.entityID from t_seclocks s where s.entityID = '" + this.wrappedElement.ElementGUID + "'";
            XmlDocument result = ((EAModel)this.model).SQLQuery(SQLQuery);
            XmlNode lockNode = result.SelectSingleNode("//entityID");
            if (lockNode == null)
            {
                //no lock found, go ahead and try to lock the element
                try
                {
                    return this.wrappedElement.ApplyUserLock();
                }
                catch (Exception)
                {
                    return false;
                }
            }
            else  
            {
                //lock found, don't even try it.
                return false;
            }
        }
(this.wrappedElement is the actual EA.Element)

The EAModel.SQLQuery method looks like this:
Code: [Select]
       /// <summary>
        /// generic query operation on the model.
        /// Returns results in an xml format
        /// </summary>
        /// <param name="sqlQuery">the query to execute</param>
        /// <returns>the results of the query in an xml format</returns>
        public XmlDocument SQLQuery(string sqlQuery)
        {
            XmlDocument results = new XmlDocument();
            results.LoadXml(this.wrappedModel.SQLQuery(sqlQuery));
            return results;
        }
(this.wrappedModel is the actual EA.Repository)

Reported to Sparx

Geert