public void AddRaw(string path) { try { DDBWrapper.Add(DatasetFolderPath, path); } catch (DDBException ex) { throw new InvalidOperationException($"Cannot add '{path}' to ddb '{DatasetFolderPath}'", ex); } }
public void Add(string path, Stream stream = null) { if (stream == null) { string folderPath = null; try { folderPath = Path.Combine(DatasetFolderPath, path); Directory.CreateDirectory(folderPath); DDBWrapper.Add(DatasetFolderPath, folderPath); } catch (DDBException ex) { throw new InvalidOperationException($"Cannot add folder '{path}' to ddb '{DatasetFolderPath}'", ex); } finally { if (folderPath != null && Directory.Exists(folderPath)) { if (!CommonUtils.SafeDeleteFolder(folderPath)) { Debug.WriteLine($"Cannot delete folder '{folderPath}'"); } } } } else { string filePath = null; try { filePath = Path.Combine(DatasetFolderPath, path); stream.SafeReset(); CommonUtils.EnsureSafePath(filePath); using (var writer = File.OpenWrite(filePath)) { stream.CopyTo(writer); } DDBWrapper.Add(DatasetFolderPath, filePath); } catch (DDBException ex) { throw new InvalidOperationException($"Cannot add '{path}' to ddb '{DatasetFolderPath}'", ex); } finally { if (filePath != null && File.Exists(filePath)) { if (!CommonUtils.SafeDelete(filePath)) { Debug.WriteLine($"Cannot delete file '{filePath}'"); } } } } }