/// <summary> /// Changes storage of a specific item (with subitems optionally) based on what filter returns. /// </summary> /// <param name="item">The item.</param> /// <param name="filter">The filter.</param> /// <param name="recursive">if set to <c>true</c> the method will be run recursively.</param> public static void ChangeStorage(Item item, bool recursive, MediaStorageFilter filter) { Assert.ArgumentNotNull(item, "item"); Assert.ArgumentNotNull(filter, "filter"); IterateItems(item, recursive, true, delegate(Item it) { if (!MediaManager.HasMediaContent(it)) { return; } MediaStorageType storageType = filter(it); switch (storageType) { case MediaStorageType.Unchanged: break; case MediaStorageType.FileSystem: ChangeToFileSystem(it, false); break; case MediaStorageType.Database: ChangeToDatabase(it, false); break; default: throw new ApplicationException(string.Format("Unexpected value of media storage type '{0}'", storageType)); } }); }
public async Task MoveMediaAsync(MediaFile media, MediaStorageType destination) { if (media.StorageType == destination) { Log.InfoFormat("MediaFile already in desired destination. Id={0} Destination={1}", media.Id, destination); return; } var url = string.Format("{0}/content/{1}?type={2}", BaseApiUrl, media.BlobId, (int)destination); using (var client = new HttpClient()) { var response = await client.PutAsync(url, null); if (response.IsSuccessStatusCode) { media.StorageType = destination; _mediaRepository.Update(media); _unit.Commit(); Log.InfoFormat("Moving MediaFile to new destination. Id={0} Destination={1}", media.Id, destination); } } }