public void Close(IStateInfo stateInfo) { ContractAssertions.IsElementContained(_loadedFiles, stateInfo, "loadedFiles", nameof(stateInfo)); _parentPluginManager.Close(stateInfo); _loadedFiles.Remove(stateInfo); }
public CloseResult Close(IStateInfo stateInfo) { ContractAssertions.IsElementContained(_loadedFiles, stateInfo, "loadedFiles", nameof(stateInfo)); var closeResult = _parentPluginManager.Close(stateInfo); _loadedFiles.Remove(stateInfo); return(closeResult); }
public void Close() { _pluginManager.Close(_archiveStateInfo); foreach (var imageStateInfo in _imageStateInfos ?? Array.Empty <IStateInfo>()) { _pluginManager.Close(imageStateInfo); } _archiveStateInfo = null; _imageStateInfos = null; }
private void ExtractWith(IFileSystem sourceFileSystem, UPath filePath, Guid pluginId) { // Load file LoadResult loadResult; try { loadResult = pluginId == Guid.Empty ? _pluginManager.LoadFile(sourceFileSystem, filePath).Result : _pluginManager.LoadFile(sourceFileSystem, filePath, pluginId).Result; } catch (Exception e) { Console.WriteLine($"Batch Error: {filePath}: {e.Message}"); return; } if (!loadResult.IsSuccessful) { Console.WriteLine($"Batch Error: {filePath}: {loadResult.Message}"); return; } var absolutePath = (UPath)sourceFileSystem.ConvertPathToInternal(filePath); var destinationDirectory = absolutePath.GetDirectory() / absolutePath.GetName().Replace('.', '_'); var destinationFileSystem = FileSystemFactory.CreatePhysicalFileSystem(destinationDirectory, new StreamManager()); switch (loadResult.LoadedState.PluginState) { case IArchiveState archiveState: foreach (var afi in archiveState.Files) { var newFileStream = destinationFileSystem.OpenFile(afi.FilePath, FileMode.Create, FileAccess.Write); afi.GetFileData().Result.CopyTo(newFileStream); newFileStream.Close(); } break; case IImageState imageState: var index = 0; foreach (var img in imageState.Images) { var kanvasImage = new KanvasImage(imageState, img); kanvasImage.GetImage().Save(destinationDirectory + "/" + (img.Name ?? $"{index:00}") + ".png"); index++; } break; default: Console.WriteLine($"Batch Error: {filePath}: '{loadResult.LoadedState.PluginState.GetType().Name}' is not supported."); break; } _pluginManager.Close(loadResult.LoadedState); }