Beispiel #1
0
        public async Task <bool> SetLockObjectAsync(int objectID, OTID objectTypeID, string userName, int TimeOut)
        {
            if (TimeOut < 0)
            {
                TimeOut *= -1;
            }

            var dbpObjState = await Store.GetObjectstateinfoAsync(a => a.Where(x => x.Objectid == objectID && x.Objecttypeid == (int)objectTypeID), true);

            if (dbpObjState == null)
            {
                return(await Store.AddDbpObjStateAsync(objectID, objectTypeID, userName, TimeOut));
            }

            //设置locklock字段
            DbpObjectstateinfo objectstateinfo = null;

            for (int i = 0; i < 3 && objectstateinfo == null; i++)
            {
                if (i > 0)
                {
                    System.Threading.Thread.Sleep(100);
                }

                objectstateinfo = await Store.LockRowsByConditionAsync(objectID, objectTypeID, userName);
            }

            if (objectstateinfo == null)
            {
                return(false);
            }

            //修改加锁信息,清空locklock
            return(await Store.UnLockRowsAsync(objectstateinfo, TimeOut));

            //return await Store.SetLockObject(objectID, objectTypeID, userName, TimeOut);
        }