Ejemplo n.º 1
0
        private static McLockElement GetMcLockElement(OpaqueLockToken lockToken, PropertyInfoCollection propInfoColl)
        {
            if (propInfoColl == null)
            {
                throw new ArgumentNullException("propInfoColl");
            }

            McLockElement retVal         = null;
            PropertyInfo  mcLockDateProp = propInfoColl[PropertyInfo.McLockDateProperty];

            if (mcLockDateProp != null)
            {
                WebDavDocument    document     = WebDavDocument.CreateDocument();
                McLockDateElement mcLockDateEl = (McLockDateElement)
                                                 document.ImportNode((XmlElement)mcLockDateProp.Value, true);

                //Try to find McLock element with same token as lockToken
                foreach (McLockElement lockEl in mcLockDateEl.GetLocks())
                {
                    if (lockEl.Token == lockToken.ToString())
                    {
                        retVal = lockEl;
                        break;
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the active locked webdav resources.
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <WebDavLockInfo> GetActiveLocksInfo()
        {
            WebDavAbstractFactory factory = new WebDavAbstractFactory();

            foreach (WebDavStorageElementPropertiesRow row in WebDavStorageElementPropertiesRow.List())
            {
                WebDavElementStorageProvider provider = factory.Create <WebDavElementStorageProvider>(row.ObjectTypeId);
                ResourceInfo resInfo = GetResourceInfoFromPropertyRow(row);
                if (resInfo != null)
                {
                    foreach (ActiveLockElement activeLockEl in provider.GetActiveLocks(resInfo))
                    {
                        OpaqueLockToken lockToken = OpaqueLockToken.Parse(activeLockEl.LockToken.InnerText);
                        McLockElement   mcLockEl  = GetMcLockElement(lockToken, provider.GetProperties(resInfo));

                        WebDavLockInfo retval = new WebDavLockInfo();
                        retval.WebDavElementPropertyId = row.PrimaryKeyId.Value;
                        retval.FileName      = resInfo.Name;
                        retval.ContentTypeId = ContentTypeResolver.GetContentTypeId(resInfo.ContentType);
                        retval.StartLocking  = new DateTime(mcLockEl.CreationDate * TimeSpan.TicksPerSecond);
                        retval.Duration      = DateTime.UtcNow - retval.StartLocking;
                        UserLight user = UserLight.Load(activeLockEl.Owner);
                        if (user != null)
                        {
                            retval.LockedBy = user.DisplayName;
                        }
                        else
                        {
                            retval.LockedBy = "Unknow";
                        }

                        yield return(retval);
                    }
                }
            }
        }