123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System.Collections.Generic;
- using System.Linq;
- using RamDavisk.Ramfs.Inters;
- using WebDAVSharp.Server.Exceptions;
- using WebDAVSharp.Server.Stores;
- namespace RamDavisk.Ramfs
- {
- internal class WebDavRamfsStoreCollection : WebDavRamfsStoreItem, IWebDavStoreCollection
- {
- private List<WebDavRamfsStoreItem> Items { get; }
- IEnumerable<IWebDavStoreItem> IWebDavStoreCollection.Items => Items;
- public WebDavRamfsStoreCollection()
- {
- Items = new List<WebDavRamfsStoreItem>();
- }
- public IWebDavStoreItem GetItemByName(string name) => Items.FirstOrDefault(p => p.Name == name);
- public IWebDavStoreCollection CreateCollection(string name)
- {
- if (Items.Any(p => p.Name == name)) throw new WebDavConflictException();
- var nc = new WebDavRamfsStoreCollection
- {
- Name = name,
- ParentCollection = this
- };
- Items.Add(nc);
- return nc;
- }
- public void Delete(IWebDavStoreItem item)
- {
- var webDavRamfsStoreItem = (WebDavRamfsStoreItem)item;
- Items.Remove(webDavRamfsStoreItem);
- webDavRamfsStoreItem.Dispose();
- }
- public IWebDavStoreDocument CreateDocument(string name)
- {
- if (Items.Any(p => p.Name == name)) throw new WebDavConflictException();
- var nd = new WebDavRamfsStoreDocument
- {
- Name = name,
- ParentCollection = this,
- };
- Items.Add(nd);
- return nd;
- }
- public IWebDavStoreItem CopyItemHere(IWebDavStoreItem source, string destinationName, bool includeContent)
- {
- throw new WebDavConflictException();
- }
- public IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destinationName)
- {
- if (Items.Any(p => p.Name == destinationName)) throw new WebDavConflictException();
- var item = (WebDavRamfsStoreItem)source;
- //remove from orig collection, change name, and add to mine collection
- item.ParentCollection.Items.Remove(item);
- item.Name = destinationName;
- item.ParentCollection = this;
- Items.Add(item);
- return item;
- }
- public override long Size => 0;
- public override bool IsCollection => true;
- public override string Etag => Items
- .Select(p => $"{p.IsCollection},{p.Name},{p.ModificationDate}")
- .JoinString("|")
- .GetHashCode()
- .ToString();
- public override void Dispose()
- {
- base.Dispose();
- foreach (var document in Items.ToArray())
- {
- Items.Remove(document);
- document.Dispose();
- }
- }
- }
- }
|