WebDavStoreItemLockInstanceBase.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Xml;
  3. using WebDAVSharp.Server.Stores.Locks.Enums;
  4. using WebDAVSharp.Server.Stores.Locks.Interfaces;
  5. namespace WebDAVSharp.Server.Stores.Locks
  6. {
  7. /// <summary>
  8. /// </summary>
  9. public abstract class WebDavStoreItemLockInstanceBase : IWebDavStoreItemLockInstance
  10. {
  11. /// <summary>
  12. /// </summary>
  13. /// <param name="path"></param>
  14. /// <param name="lockscope"></param>
  15. /// <param name="locktype"></param>
  16. /// <param name="owner"></param>
  17. /// <param name="requestedlocktimeout"></param>
  18. /// <param name="token"></param>
  19. /// <param name="requestdocument"></param>
  20. /// <param name="depth"></param>
  21. /// <param name="lockSystem"></param>
  22. /// <param name="createdate"></param>
  23. protected WebDavStoreItemLockInstanceBase(string path, WebDavLockScope lockscope, WebDavLockType locktype, string owner, double? requestedlocktimeout, Guid? token, XmlDocument requestdocument, int depth, IWebDavStoreItemLock lockSystem, DateTime? createdate = null)
  24. {
  25. Path = path;
  26. LockScope = lockscope;
  27. LockType = locktype;
  28. Owner = owner;
  29. Token = token;
  30. RequestDocument = requestdocument;
  31. Token = token; // token = "urn:uuid:" + Guid.NewGuid();
  32. Depth = depth;
  33. LockSystem = lockSystem;
  34. if (createdate == null)
  35. CreateDate = DateTime.Now;
  36. else
  37. CreateDate = (DateTime) createdate;
  38. RequestedLockTimeout = requestedlocktimeout;
  39. RefreshLock(requestedlocktimeout);
  40. }
  41. /// <summary>
  42. /// Refreshes a lock
  43. /// </summary>
  44. /// <param name="seconds"></param>
  45. public void RefreshLock(double? seconds)
  46. {
  47. if (seconds == null)
  48. {
  49. if (LockSystem.AllowInfiniteCheckouts)
  50. {
  51. ExpirationDate = null;
  52. RequestedTimeout = "Infinite, Second-4100000000";
  53. return;
  54. }
  55. RequestedTimeout = "Second-" + LockSystem.MaxCheckOutSeconds;
  56. ExpirationDate = CreateDate.AddSeconds(LockSystem.MaxCheckOutSeconds);
  57. return;
  58. }
  59. if (seconds > LockSystem.MaxCheckOutSeconds)
  60. seconds = LockSystem.MaxCheckOutSeconds;
  61. ExpirationDate = CreateDate + TimeSpan.FromSeconds((double) seconds);
  62. RequestedTimeout = "Second-" + seconds;
  63. }
  64. /// <summary>
  65. /// </summary>
  66. public double? RequestedLockTimeout { get; set; }
  67. /// <summary>
  68. /// The Path locked
  69. /// </summary>
  70. public virtual string Path { get; }
  71. /// <summary>
  72. /// </summary>
  73. public IWebDavStoreItemLock LockSystem { get; set; }
  74. /// <summary>
  75. /// </summary>
  76. public DateTime CreateDate { get; set; }
  77. /// <summary>
  78. /// Lock Scope
  79. /// </summary>
  80. public virtual WebDavLockScope LockScope { get; }
  81. /// <summary>
  82. /// Lock Type
  83. /// </summary>
  84. public virtual WebDavLockType LockType { get; }
  85. /// <summary>
  86. /// Owner
  87. /// </summary>
  88. public virtual string Owner { get; }
  89. /// <summary>
  90. /// Requested Timeout
  91. /// </summary>
  92. public string RequestedTimeout { get; set; }
  93. /// <summary>
  94. /// Token Issued
  95. /// </summary>
  96. public Guid? Token { get; set; }
  97. /// <summary>
  98. /// Request Document
  99. /// </summary>
  100. public XmlDocument RequestDocument { get; }
  101. /// <summary>
  102. /// If null, it's an infinite checkout.
  103. /// </summary>
  104. public DateTime? ExpirationDate { get; set; }
  105. /// <summary>
  106. /// </summary>
  107. public int Depth { get; }
  108. }
  109. }