public void Delete(FileTreeRoot library) { _libraries.TryRemove(library.ObjectId, out _); _libraryDb.Delete(BitConverter.GetBytes(library.ObjectId)); library.Repository.Close(); DirectoryHelper.Delete(Path.Combine(LibraryPath, library.ObjectId.ToString())); }
public virtual async ValueTask <Tuple <ResponseStatus, object> > AddLibrary(FileTreeRoot library) { library = LibraryManager.AddLibrary(library); return(new Tuple <ResponseStatus, object>( library != null ? ResponseStatus.Success : ResponseStatus.BadRequest, library)); }
private void CreateThumbnailLibrary() { if (_libraries.ContainsKey(0)) { return; } var library = new FileTreeRoot() { ObjectId = 0, Path = ThumbnailPath, Scheme = "file" }; AddLibrary(library, false); }
public LevelDbFileTreeNodeRepository(FileTreeRoot library, DB db, Func <byte[], FileTreeNode> deserializer, Func <FileTreeNode, byte[]> serializer) { _library = library; _db = db; _deserializer = deserializer; _serializer = serializer; _cache = new ConcurrentDictionary <long, FileTreeNode>(); _items = new HashSet <long>(); foreach (var(id, _) in _db) { _items.Add(BitConverter.ToInt64(id)); } if (!Contains(0)) { Put(FileTreeNode.Root); } }
public Library(FileTreeRoot library) { if (library == null) { LibraryType = LibraryType.None; return; } ObjectId = library.ObjectId; LibraryType = library.Scheme switch { "file" => LibraryType.Local, "ftp" => LibraryType.Ftp, "ftps" => LibraryType.Ftp, "sftp" => LibraryType.Ftp, _ => LibraryType }; Name = library.Name; Path = library.Path; } }
public FileTreeRoot AddLibrary(FileTreeRoot library, bool generateId = true) { if (generateId) { library.ObjectId = IdGenerator.CreateId(); } if (!IFileTreeRootHandler.Handlers.TryGetValue(library.Scheme, out var handler) || !handler.IsLegal(library)) { return(null); } _libraryDb.Put(BitConverter.GetBytes(library.ObjectId), MessagePackSerializer.Serialize(library, _lz4Options)); _libraries.TryAdd(library.ObjectId, library); library.Repository = new LevelDbFileTreeNodeRepository( library, new DB(_dbOptions, Path.Combine(LibraryPath, library.ObjectId.ToString())), (bytes1 => MessagePackSerializer.Deserialize <FileTreeNode>(bytes1, _lz4Options)), (node => MessagePackSerializer.Serialize(node, _lz4Options))); return(library); }
public bool UpdateLibrary(FileTreeRoot library) { if (!_libraries.TryGetValue(library.ObjectId, out var oldLibrary) || !Monitor.TryEnter(oldLibrary, 0)) { return(false); } try { oldLibrary.Name = library.Name; oldLibrary.Path = library.Path; oldLibrary.Host = library.Host; oldLibrary.Port = library.Port; oldLibrary.Username = library.Username; oldLibrary.Password = library.Password; oldLibrary.Scheme = library.Scheme; oldLibrary.ScraperName = library.ScraperName; _libraryDb.Put(BitConverter.GetBytes(library.ObjectId), MessagePackSerializer.Serialize(library, _lz4Options)); return(true); } finally { Monitor.Exit(oldLibrary); } }
public virtual async ValueTask <Tuple <ResponseStatus, object> > UpdateLibrary(FileTreeRoot library) { var success = LibraryManager.UpdateLibrary(library); return(new Tuple <ResponseStatus, object>( success ? ResponseStatus.Success : ResponseStatus.BadRequest, success)); }