/// <summary> /// Initializes a new instance of the <see cref="ActiveLock"/> class. /// </summary> /// <param name="path">The file system path (root-relative) this lock should be applied to</param> /// <param name="href">The href this lock should be applied to (might be relative or absolute)</param> /// <param name="recursive">Must the lock be applied recursively to all children?</param> /// <param name="owner">The owner of the lock</param> /// <param name="accessType">The <see cref="LockAccessType"/> of the lock</param> /// <param name="shareMode">The <see cref="LockShareMode"/> of the lock</param> /// <param name="timeout">The lock timeout</param> /// <param name="issued">The date/time when this lock was issued</param> /// <param name="lastRefresh">The date/time of the last refresh</param> /// <param name="stateToken">The stateTokenh</param> internal ActiveLock( [NotNull] string path, [NotNull] string href, bool recursive, [CanBeNull] XElement owner, LockAccessType accessType, LockShareMode shareMode, TimeSpan timeout, DateTime issued, DateTime?lastRefresh, [NotNull] string stateToken) : base( path, href, recursive, owner, accessType.Name.LocalName, shareMode.Name.LocalName, timeout) { Issued = issued; LastRefresh = lastRefresh; Expiration = timeout == TimeoutHeader.Infinite ? DateTime.MaxValue : (lastRefresh ?? issued) + timeout; StateToken = stateToken; }
/// <summary> /// Initializes a new instance of the <see cref="ActiveLock"/> class. /// </summary> /// <param name="l">The lock to create this active lock from</param> /// <param name="issued">The date/time when this lock was issued</param> /// <param name="timeout">Override the timeout from the original lock (to enforce rounding)</param> internal ActiveLock([NotNull] ILock l, DateTime issued, TimeSpan timeout) : this( l.Path, l.Href, l.Recursive, l.GetOwner(), LockAccessType.Parse(l.AccessType), LockShareMode.Parse(l.ShareMode), timeout, issued, null) { }
private static ActiveLock Refresh(IActiveLock activeLock, DateTime lastRefresh, TimeSpan timeout) { return(new ActiveLock( activeLock.Path, activeLock.Href, activeLock.Recursive, activeLock.GetOwner(), LockAccessType.Parse(activeLock.AccessType), LockShareMode.Parse(activeLock.ShareMode), timeout, activeLock.Issued, lastRefresh, activeLock.StateToken)); }
/// <summary> /// Initializes a new instance of the <see cref="Lock"/> class. /// </summary> /// <param name="path">The file system path (root-relative) this lock should be applied to</param> /// <param name="href">The href this lock should be applied to (might be relative or absolute)</param> /// <param name="recursive">Must the lock be applied recursively to all children?</param> /// <param name="owner">The owner of the lock</param> /// <param name="accessType">The <see cref="LockAccessType"/> of the lock</param> /// <param name="shareMode">The <see cref="LockShareMode"/> of the lock</param> /// <param name="timeout">The lock timeout</param> public Lock( [NotNull] string path, [NotNull] string href, bool recursive, [CanBeNull] XElement owner, LockAccessType accessType, LockShareMode shareMode, TimeSpan timeout) : this( path, href, recursive, owner, accessType.Name.LocalName, shareMode.Name.LocalName, timeout) { }
/// <summary> /// Creates an <see cref="XElement"/> for a <see cref="IActiveLock"/> /// </summary> /// <param name="l">The active lock to create the <see cref="XElement"/> for</param> /// <param name="omitOwner">Should the owner be omitted?</param> /// <param name="omitToken">Should the lock state token be omitted?</param> /// <returns>The newly created <see cref="XElement"/> for the active lock</returns> public static XElement ToXElement(this IActiveLock l, bool omitOwner = false, bool omitToken = false) { var timeout = l.Timeout == TimeoutHeader.Infinite ? "Infinite" : $"Second-{l.Timeout.TotalSeconds:F0}"; var depth = l.Recursive ? DepthHeader.Infinity : DepthHeader.Zero; var lockScope = LockShareMode.Parse(l.ShareMode); var lockType = LockAccessType.Parse(l.AccessType); var owner = l.GetOwner(); var result = new XElement( WebDavXml.Dav + "activelock", new XElement( WebDavXml.Dav + "lockscope", new XElement(lockScope.Name)), new XElement( WebDavXml.Dav + "locktype", new XElement(lockType.Name)), new XElement( WebDavXml.Dav + "depth", depth.Value)); if (owner != null && !omitOwner) { result.Add(owner); } result.Add( new XElement( WebDavXml.Dav + "timeout", timeout)); if (!omitToken) { result.Add( new XElement( WebDavXml.Dav + "locktoken", new XElement(WebDavXml.Dav + "href", l.StateToken))); } result.Add( new XElement( WebDavXml.Dav + "lockroot", new XElement(WebDavXml.Dav + "href", l.Href))); return(result); }