using System;
using System.Xml;
using WebDAVSharp.Server.Stores.Locks.Enums;
using WebDAVSharp.Server.Stores.Locks.Interfaces;
namespace WebDAVSharp.Server.Stores.Locks
{
///
///
public abstract class WebDavStoreItemLockInstanceBase : IWebDavStoreItemLockInstance
{
///
///
///
///
///
///
///
///
///
///
///
///
protected WebDavStoreItemLockInstanceBase(string path, WebDavLockScope lockscope, WebDavLockType locktype, string owner, double? requestedlocktimeout, Guid? token, XmlDocument requestdocument, int depth, IWebDavStoreItemLock lockSystem, DateTime? createdate = null)
{
Path = path;
LockScope = lockscope;
LockType = locktype;
Owner = owner;
Token = token;
RequestDocument = requestdocument;
Token = token; // token = "urn:uuid:" + Guid.NewGuid();
Depth = depth;
LockSystem = lockSystem;
if (createdate == null)
CreateDate = DateTime.Now;
else
CreateDate = (DateTime) createdate;
RequestedLockTimeout = requestedlocktimeout;
RefreshLock(requestedlocktimeout);
}
///
/// Refreshes a lock
///
///
public void RefreshLock(double? seconds)
{
if (seconds == null)
{
if (LockSystem.AllowInfiniteCheckouts)
{
ExpirationDate = null;
RequestedTimeout = "Infinite, Second-4100000000";
return;
}
RequestedTimeout = "Second-" + LockSystem.MaxCheckOutSeconds;
ExpirationDate = CreateDate.AddSeconds(LockSystem.MaxCheckOutSeconds);
return;
}
if (seconds > LockSystem.MaxCheckOutSeconds)
seconds = LockSystem.MaxCheckOutSeconds;
ExpirationDate = CreateDate + TimeSpan.FromSeconds((double) seconds);
RequestedTimeout = "Second-" + seconds;
}
///
///
public double? RequestedLockTimeout { get; set; }
///
/// The Path locked
///
public virtual string Path { get; }
///
///
public IWebDavStoreItemLock LockSystem { get; set; }
///
///
public DateTime CreateDate { get; set; }
///
/// Lock Scope
///
public virtual WebDavLockScope LockScope { get; }
///
/// Lock Type
///
public virtual WebDavLockType LockType { get; }
///
/// Owner
///
public virtual string Owner { get; }
///
/// Requested Timeout
///
public string RequestedTimeout { get; set; }
///
/// Token Issued
///
public Guid? Token { get; set; }
///
/// Request Document
///
public XmlDocument RequestDocument { get; }
///
/// If null, it's an infinite checkout.
///
public DateTime? ExpirationDate { get; set; }
///
///
public int Depth { get; }
}
}