public async Task<BoxSet> CreateCollection(CollectionCreationOptions options) { var name = options.Name; // Need to use the [boxset] suffix // If internet metadata is not found, or if xml saving is off there will be no collection.xml // This could cause it to get re-resolved as a plain folder var folderName = _fileSystem.GetValidFilename(name) + " [boxset]"; var parentFolder = GetParentFolder(options.ParentId); if (parentFolder == null) { throw new ArgumentException(); } var path = Path.Combine(parentFolder.Path, folderName); _iLibraryMonitor.ReportFileSystemChangeBeginning(path); try { Directory.CreateDirectory(path); var collection = new BoxSet { Name = name, Parent = parentFolder, DisplayMediaType = "Collection", Path = path, IsLocked = options.IsLocked, ProviderIds = options.ProviderIds }; await parentFolder.AddChild(collection, CancellationToken.None).ConfigureAwait(false); await collection.RefreshMetadata(new MetadataRefreshOptions(), CancellationToken.None) .ConfigureAwait(false); if (options.ItemIdList.Count > 0) { await AddToCollection(collection.Id, options.ItemIdList, false); } EventHelper.FireEventIfNotNull(CollectionCreated, this, new CollectionCreatedEventArgs { Collection = collection, Options = options }, _logger); return collection; } finally { // Refresh handled internally _iLibraryMonitor.ReportFileSystemChangeComplete(path, false); } }
public async Task CreateCollection(CollectionCreationOptions options) { var name = options.Name; var folderName = _fileSystem.GetValidFilename(name); var parentFolder = _libraryManager.GetItemById(options.ParentId) as Folder; if (parentFolder == null) { throw new ArgumentException(); } var path = Path.Combine(parentFolder.Path, folderName); _iLibraryMonitor.ReportFileSystemChangeBeginning(path); try { Directory.CreateDirectory(path); var collection = new BoxSet { Name = name, Parent = parentFolder, DisplayMediaType = "Collection", Path = path, DontFetchMeta = options.IsLocked }; await parentFolder.AddChild(collection, CancellationToken.None).ConfigureAwait(false); await collection.RefreshMetadata(new MetadataRefreshOptions(), CancellationToken.None) .ConfigureAwait(false); } finally { // Refresh handled internally _iLibraryMonitor.ReportFileSystemChangeComplete(path, false); } }