public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); if (user == null || (user.Rank != AppUserRank.Editor && user.Rank != AppUserRank.Admin)) { throw new RestException(HttpStatusCode.Unauthorized); } var dict = await GetSubTree(request.Ids); FSObject fs = null; foreach (var item in dict) { fs = item.Value; if (fs.Type != FSType.FOLDER && fs.Url != null) { System.IO.File.Delete(FSObjectConfig.BaseFolderName + "/" + fs.Url); } } var list = dict.Values.ToList(); _context.FSObjects.RemoveRange(list); if (await _context.SaveChangesAsync() == 0) { throw new RestException(HttpStatusCode.InternalServerError, new { FSObject = "Problem saving changes" }); } return(Unit.Value); }
private void AddToWatch(FSObject dir) { if (!dir.IsDir()) { return; } if (IsWatching(dir)) { return; } WatchDirs.Add(dir); }
private void MakePath(string path) { CurrentDirPath = new LinkedList <FSObject>(); var items = CurrentDirPath; if (path != "root") { DirectoryInfo dir = new DirectoryInfo(path); while (dir != null) { items.AddFirst(new FSObject(dir)); dir = dir.Parent; } } items.AddFirst(FSObject.Root()); }
public static bool Exist(string path, FSObject type = FSObject.File) { var b = false; switch (type) { case FSObject.File: b = File.Exists(path); break; case FSObject.Directory: b = Directory.Exists(path); break; default: b = false; break; } return(b); }
private void RemoveFromWatch(FSObject dir) { }
private bool IsWatching(FSObject dir) { return(WatchDirs.Any(i => i.FullPath == dir.FullPath)); }