using System; using System.Security.Principal; using WebDAVSharp.Server.MethodHandlers; using WebDAVSharp.Server.Stores.Locks.Interfaces; using WebDAVSharp.Server.Utilities; namespace WebDAVSharp.Server.Stores.BaseClasses { /// /// This class is a base class for implementations. /// public abstract class WebDavStoreBase : IWebDavStore { #region Variables #endregion #region Constructor /// /// Initializes a new instance of the class. /// /// The root . /// /// root /// is null. protected WebDavStoreBase(IWebDavStoreCollection root, IWebDavStoreItemLock lockSystem) { LockSystem = lockSystem ?? throw new ArgumentNullException(nameof(lockSystem)); Root = root ?? throw new ArgumentNullException(nameof(root)); } /// /// protected WebDavStoreBase(IWebDavStoreItemLock lockSystem) { LockSystem = lockSystem; } #endregion #region Properties /// /// Gets the root collection of this . /// public virtual IWebDavStoreCollection Root { get; } /// /// public IWebDavStoreItemLock LockSystem { get; set; } ///// ///// //public WebDavServer.ClearCaches FClearCaches { get; set; } /// /// /// public abstract void UserAuthenticated(IIdentity ident); private readonly WebDavCacheBase _cache = new WebDavCacheBase(); /// /// /// /// /// /// /// internal void AddCacheObject(WebDavMethodHandlerBase handler, string user, string path, object value, TimeSpan timeToExpire) { WebDavCacheBase pathCache = (WebDavCacheBase) _cache.GetCachedObject(path); WebDavCacheBase handlerCache; if (pathCache != null) { handlerCache = (WebDavCacheBase) pathCache.GetCachedObject(handler.GetType().FullName); if (handlerCache != null) { handlerCache.AddCacheObject(user, value, timeToExpire); return; } handlerCache = new WebDavCacheBase(); handlerCache.AddCacheObject(user, value, timeToExpire); pathCache.AddCacheObject(handler.GetType().FullName, handlerCache, timeToExpire); return; } pathCache = new WebDavCacheBase(); handlerCache = new WebDavCacheBase(); handlerCache.AddCacheObject(user, value, timeToExpire); pathCache.AddCacheObject(handler.GetType().FullName, handlerCache, timeToExpire); _cache.AddCacheObject(path, pathCache, timeToExpire); } /// /// /// /// /// /// public void AddCacheObject(WebDavMethodHandlerBase handler, string user, string path, object value) { WebDavCacheBase pathCache = (WebDavCacheBase) _cache.GetCachedObject(path); WebDavCacheBase handlerCache; if (pathCache != null) { handlerCache = (WebDavCacheBase) pathCache.GetCachedObject(handler.GetType().FullName); if (handlerCache != null) { handlerCache.AddCacheObject(user, value); return; } handlerCache = new WebDavCacheBase(); handlerCache.AddCacheObject(user, value); pathCache.AddCacheObject(handler.GetType().FullName, handlerCache); return; } pathCache = new WebDavCacheBase(); handlerCache = new WebDavCacheBase(); handlerCache.AddCacheObject(user, value); pathCache.AddCacheObject(handler.GetType().FullName, handlerCache); _cache.AddCacheObject(path, pathCache); } /// /// /// /// /// /// public object GetCacheObject(WebDavMethodHandlerBase handler, string user, string path) { return ((WebDavCacheBase) (((WebDavCacheBase) _cache.GetCachedObject(path))?.GetCachedObject(handler.GetType().FullName)))?.GetCachedObject(user); } /// /// /// public void RemoveCacheObject(string key) { _cache.RemoveCacheObject(key); } #endregion } }