public override IWebDavFileInfo GetFileInfo() { if (_fileinfo != null) { return(_fileinfo); } using (var context = new OnlineFilesEntities()) { File file = context.Files.AsNoTracking().Include(x => x.FileDatas).FirstOrDefault(d => d.pk_FileId == ObjectGuid); if (file == null) { return new WebDaveSqlStoreFileInfo { Parent = ParentCollection, Path = string.Empty, Exists = false, Directory = false } } ; _fileinfo = new WebDaveSqlStoreFileInfo(file.GetFileInfo(), ParentCollection, ItemPath); return(_fileinfo); } } }
/// <summary> /// </summary> /// <param name="name"></param> /// <returns></returns> public IWebDavStoreItem GetItemByName(string name) { string path = Path.Combine(ItemPath, name); #if DEBUG Log.Warn("Parent: " + ObjectGuid + " - Requesting Item by name: " + path); #endif using (var context = new OnlineFilesEntities()) { Folder folder = context.Folders.AsNoTracking().FirstOrDefault(d => d.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) && d.fk_ParentFolderId == ObjectGuid && !d.IsDeleted ); if (folder != null) { return(WebDavSqlStoreCollectionFactory.Instance.GetCollection(this, Path.Combine(ItemPath, folder.Name), RootPath, RootGuid)); } File file = context.Files.AsNoTracking().FirstOrDefault(d => d.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) && d.fk_FolderId == ObjectGuid && !d.IsDeleted); if (file != null) { return(WebDavSqlStoreDocumentFactory.Instance.GetDocument(this, Path.Combine(ItemPath, file.Name), RootPath, RootGuid)); } } return(null); }
/// <summary> /// </summary> /// <param name="name"></param> /// <returns></returns> public IWebDavStoreDocument CreateDocument(string name) { File.Create(ObjectGuid, name, PrincipleFactory.Instance.GetPrinciple(FromType.WebDav).UserProfile); WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(ItemPath); WebDavSqlStoreDocumentFactory.Instance.InvalidateDocumentPath(Path.Combine(ItemPath, name)); return(WebDavSqlStoreDocumentFactory.Instance.GetDocument(this, Path.Combine(ItemPath, name), RootPath, RootGuid)); }
/// <summary> /// </summary> /// <returns></returns> public Stream OpenReadStream() { using (var context = new OnlineFilesEntities()) { File file = context.Files.FirstOrDefault(d => d.pk_FileId == ObjectGuid); if (file == null) { throw new Exception("File Object Not Found."); } return(file.OpenReadStream(PrincipleFactory.Instance.GetPrinciple(FromType.WebDav))); } }
private Guid?GetObjectGuid(string path) { //Remove the \\Data path = path.Substring(RootPath.Length).Trim(); using (var context = new OnlineFilesEntities()) { if (path == RootPath) { return(RootGuid); } List <string> dirpath = path.Split('\\').ToList(); while (dirpath.Contains("")) { dirpath.Remove(""); } Folder parent = context.Folders.FirstOrDefault(d => d.pk_FolderId == RootGuid); if (parent == null) { throw new Exception("No Parent"); } Guid?returnValue = parent.pk_FolderId; for (int index = 0; index < dirpath.Count; index++) { string s = dirpath[index]; Folder child = context.Folders.FirstOrDefault(d => d.Name.Equals(s, StringComparison.InvariantCultureIgnoreCase) && d.fk_ParentFolderId == parent.pk_FolderId); if (child != null) { parent = child; returnValue = parent.pk_FolderId; } else { if (index != dirpath.Count - 1) { throw new Exception("Couldn't find folder."); } File file = context.Files.FirstOrDefault(d => d.Name.Equals(s, StringComparison.InvariantCultureIgnoreCase) && d.fk_FolderId == returnValue && !d.IsDeleted); if (file != null) { returnValue = file.pk_FileId; } } } return(returnValue); } }
/// <summary> /// </summary> /// <param name="append"></param> /// <returns></returns> public Stream OpenWriteStream(bool append) { if (append) { throw new Exception("File Stream Append Not supported."); } using (var context = new OnlineFilesEntities()) { File f = context.Files.FirstOrDefault(d => d.pk_FileId == ObjectGuid); return(f?.OpenWriteStream(PrincipleFactory.Instance.GetPrinciple(FromType.WebDav), ItemPath)); } }
/// <summary> /// </summary> /// <param name="item"></param> public void Delete(IWebDavStoreItem item) { #if DEBUG Log.Info("Deleting Item: " + item.Name); #endif if (IsCheckedOut(item)) { throw new Exception("Item is checked out."); } using (var context = new OnlineFilesEntities()) { var collection = item as WebDavSqlStoreCollection; if (collection != null) { Folder folder = context.Folders.FirstOrDefault(d => d.pk_FolderId == collection.ObjectGuid); if (folder == null) { throw new WebDavNotFoundException("Folder Not Found."); } folder.SetDeleted(PrincipleFactory.Instance.GetPrinciple(FromType.WebDav).UserProfile); context.SaveChanges(); WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(item.ItemPath); WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(ItemPath); } else { WebDavSqlStoreDocument document = item as WebDavSqlStoreDocument; if (document == null) { return; } var doc = document; File file = context.Files.FirstOrDefault(d => d.pk_FileId == doc.ObjectGuid); if (file == null) { throw new WebDavNotFoundException("Folder Not Found."); } file.SetDeleted(PrincipleFactory.Instance.GetPrinciple(FromType.WebDav).UserProfile); context.SaveChanges(); WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(ItemPath); WebDavSqlStoreDocumentFactory.Instance.InvalidateDocumentPath(doc.ItemPath); } } }
/// <summary> /// </summary> /// <param name="parentCollection"></param> /// <param name="name"></param> /// <param name="rootPath"></param> /// <param name="rootGuid"></param> /// <param name="store"></param> public WebDavSqlStoreDocument(IWebDavStoreCollection parentCollection, string name, String rootPath, Guid rootGuid, IWebDavStore store) : base(parentCollection, name, rootPath, rootGuid, store) { using (var context = new OnlineFilesEntities()) { File file = context.Files.AsNoTracking() .Include(x => x.FileDatas) .FirstOrDefault(d => d.pk_FileId == ObjectGuid && !d.IsDeleted); if (file == null) { throw new Exception("Non existant file."); } _createDate = file.CreateDt; FileData lastmod = file.FileDatas.OrderByDescending(d => d.Revision).FirstOrDefault(); _modificationDate = lastmod?.CreateDt ?? file.CreateDt; _filesize = lastmod?.Size ?? 1; } }