/// <summary> /// Inserts a new bookmark into the database with the specified media ID, offset, name, and thumbnail path. /// </summary> /// <privilege>http://tizen.org/privilege/content.write</privilege> /// <remarks> /// The thumbnail may be useful only when the media is video. /// </remarks> /// <param name="mediaId">The media ID to be associated with.</param> /// <param name="offset">The time offset in milliseconds.</param> /// <param name="name">The name of the bookmark. This value can be null.</param> /// <param name="thumbnailPath">The thumbnail path of the bookmark. This value can be null.</param> /// <returns>The <see cref="Bookmark"/> instance that contains the record information inserted.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <since_tizen> 4 </since_tizen> public Bookmark Insert(string mediaId, int offset, string name, string thumbnailPath) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); Interop.Bookmark.Create(mediaId, offset, out var handle).ThrowIfError("Failed to insert new bookmark"); try { Interop.Bookmark.SetName(handle, name).ThrowIfError("Failed to insert new bookmark"); if (thumbnailPath != null) { Interop.Bookmark.SetThumbnailPath(handle, thumbnailPath). ThrowIfError("Failed to insert new bookmark"); } Interop.Bookmark.Insert(handle).ThrowIfError("Failed to insert new bookmark"); return(new Bookmark(handle)); } finally { Interop.Bookmark.Destroy(handle); } }
/// <summary> /// Exports the playlist to a M3U file. /// </summary> /// <remarks> /// If the file already exists in the file system, then it will be overwritten.<br/> /// <br/> /// If you want to access an internal storage, you should add privilege http://tizen.org/privilege/mediastorage.<br/> /// If you want to access an external storage, you should add privilege http://tizen.org/privilege/externalstorage. /// </remarks> /// <privilege>http://tizen.org/privilege/mediastorage</privilege> /// <privilege>http://tizen.org/privilege/externalstorage</privilege> /// <param name="playlistId">The playlist ID to export.</param> /// <param name="path">The path to a M3U file.</param> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length string, contains only white space.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception> /// <exception cref="RecordNotFoundException">No matching playlist exists.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <since_tizen> 4 </since_tizen> public void ExportToFile(int playlistId, string path) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path)); if (playlistId <= 0) { throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, "Playlist id can't be less than or equal to zero."); } IntPtr handle = IntPtr.Zero; try { Interop.Playlist.GetPlaylistFromDb(playlistId, out handle).ThrowIfError("Failed to query"); Interop.Playlist.ExportToFile(handle, path).ThrowIfError("Failed to export"); } catch (ArgumentException) { // Native FW returns ArgumentException when there's no matched record. throw new RecordNotFoundException("No matching playlist exists."); } finally { if (handle != IntPtr.Zero) { Interop.Playlist.Destroy(handle); } } }
/// <summary> /// Inserts new face information to the database with the specified media ID, area, orientation, and tag. /// </summary> /// <privilege>http://tizen.org/privilege/content.write</privilege> /// <param name="mediaId">The media ID to be associated with the face.</param> /// <param name="area">The region of face in the media.</param> /// <param name="orientation">The orientation of specified media.</param> /// <param name="tag">The tag value.</param> /// <returns>The <see cref="FaceInfo"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null. </exception> /// <exception cref="ArgumentException"> /// <paramref name="mediaId"/> is a zero-length string, contains only white space.<br/> /// -or-<br/> /// <paramref name="orientation"/> is not valid enumeration. /// </exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <since_tizen> 6 </since_tizen> public FaceInfo Insert(string mediaId, Rectangle area, Orientation orientation, string tag) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); ValidationUtil.ValidateEnum(typeof(Orientation), orientation, nameof(orientation)); Interop.Face.Create(mediaId, out IntPtr handle).ThrowIfError("Failed to create face handle"); try { Interop.Face.SetFaceRect(handle, area.X, area.Y, area.Width, area.Height). ThrowIfError("Failed to set face area"); Interop.Face.SetOrientation(handle, orientation).ThrowIfError("Failed to set face orientation"); if (tag != null) { Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to set face tag"); } Interop.Face.Insert(handle).ThrowIfError("Failed to insert face information"); return(new FaceInfo(handle)); } finally { Interop.Face.Destroy(handle).ThrowIfError("Failed to destroy face handle"); } }
/// <summary> /// Updates a tag with the specified tag. /// </summary> /// <privilege>http://tizen.org/privilege/content.write</privilege> /// <param name="faceInfoId">The face information ID to update.</param> /// <param name="tag">The tag value for update.</param> /// <returns>true if the matched record was found and updated, otherwise false.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <since_tizen> 4 </since_tizen> public bool UpdateTag(string faceInfoId, string tag) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId)); if (tag == null) { throw new ArgumentNullException(nameof(tag)); } var handle = CommandHelper.SelectScalar(Interop.Face.ForeachFromDb, $"{FaceInfoColumns.Id}='{faceInfoId}'", Interop.Face.Clone); if (handle == IntPtr.Zero) { return(false); } try { Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to update(setting tag)"); Interop.Face.Update(handle).ThrowIfError("Failed to update(executing query)"); return(true); } finally { Interop.Face.Destroy(handle); } }
public Storage Select(string storageId) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(storageId, nameof(storageId)); IntPtr handle = IntPtr.Zero; try { Interop.Storage.GetStorageInfoFromDb(storageId, out handle).ThrowIfError("Failed to query"); return(new Storage(handle)); } catch (ArgumentException) { // Native FW returns ArgumentException when there's no matched record. return(null); } finally { if (handle != IntPtr.Zero) { Interop.Storage.Destroy(handle); } } }
/// <summary> /// Retrieves the media information under the folder with the <see cref="SelectArguments"/>. /// </summary> /// <param name="folderId">The ID of the folder to select media in the folder.</param> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <MediaInfo> SelectMedia(string folderId, SelectArguments filter) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId)); return(CommandHelper.SelectMedia(Interop.Folder.ForeachMediaFromDb, folderId, filter)); }
/// <summary> /// Requests to scan a media file. /// </summary> /// <param name="path">The path of the media to be scanned.</param> /// <remarks> /// It requests to scan a media file to the media server.<br/> /// If the specified file is not registered to the database yet, /// the media file information will be added to the database.<br/> /// If it is already registered to the database, the media information is refreshed.<br/> /// If the specified file does not exist, /// the record of the media file will be deleted from the database.<br/> /// <br/> /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.<br/> /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. /// </remarks> /// <privilege>http://tizen.org/privilege/content.write</privilege> /// <privilege>http://tizen.org/privilege/mediastorage</privilege> /// <privilege>http://tizen.org/privilege/externalstorage</privilege> /// <exception cref="InvalidOperationException">The database is not connected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="path"/> is a zero-length string, contains only white space.<br/> /// -or-<br/> /// <paramref name="path"/> contains a hidden path that starts with '.'.<br/> /// -or-<br/> /// <paramref name="path"/> contains a directory containing the ".scan_ignore" file. /// </exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <since_tizen> 4 </since_tizen> public void ScanFile(string path) { ValidateState(); ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path)); Interop.Content.ScanFile(path).Ignore(MediaContentError.InvalidParameter).ThrowIfError("Failed to scan"); }
/// <summary> /// Retrieves the number of media information under the folder with the <see cref="CountArguments"/>. /// </summary> /// <param name="folderId">The ID of the folder to count media in the folder.</param> /// <param name="arguments">The criteria to use to filter. This value can be null.</param> /// <returns>The number of media information.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception> /// <since_tizen> 4 </since_tizen> public int CountMedia(string folderId, CountArguments arguments) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId)); return(CommandHelper.Count(Interop.Folder.GetMediaCountFromDb, folderId, arguments)); }
/// <summary> /// Requests to scan a folder. /// </summary> /// <remarks> /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage.<br/> /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage. /// </remarks> /// <privilege>http://tizen.org/privilege/content.write</privilege> /// <privilege>http://tizen.org/privilege/mediastorage</privilege> /// <privilege>http://tizen.org/privilege/externalstorage</privilege> /// <param name="folderPath">The path to scan.</param> /// <param name="recursive">The value indicating if the folder is to be recursively scanned.</param> /// <param name="cancellationToken">The token to stop scanning.</param> /// <remarks>Folders that contains a file named ".scan_ignore" will not be scanned.</remarks> /// <returns>A task that represents the asynchronous scan operation.</returns> /// <exception cref="InvalidOperationException">The database is not connected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <exception cref="ArgumentNullException"><paramref name="folderPath"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="folderPath"/> is a zero-length string, contains only white space.<br/> /// -or-<br/> /// <paramref name="folderPath"/> contains a hidden path that starts with '.'.<br/> /// -or-<br/> /// <paramref name="folderPath"/> contains a directory containing the ".scan_ignore" file. /// </exception> /// <since_tizen> 4 </since_tizen> public Task ScanFolderAsync(string folderPath, bool recursive, CancellationToken cancellationToken) { ValidateState(); ValidationUtil.ValidateNotNullOrEmpty(folderPath, nameof(folderPath)); return(cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) : ScanFolderAsyncCore(folderPath, recursive, cancellationToken)); }
private bool Exists(string storageId) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(storageId, nameof(storageId)); return(Count(new CountArguments { FilterExpression = $"{StorageColumns.Id}='{storageId}'" }) != 0); }
/// <summary> /// Deletes the face information from the database. /// </summary> /// <privilege>http://tizen.org/privilege/content.write</privilege> /// <param name="faceInfoId">The face information ID to delete.</param> /// <returns>true if the matched record was found and deleted, otherwise false.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <since_tizen> 4 </since_tizen> public bool Delete(string faceInfoId) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId)); var reader = Select(new SelectArguments { FilterExpression = $"{FaceInfoColumns.Id}='{faceInfoId}'" }); if (reader.Read() == false) { return(false); } CommandHelper.Delete(Interop.Face.DeleteFromDb, faceInfoId); return(true); }
/// <summary> /// Retrieves the member ID of the media in the playlist. /// </summary> /// <param name="playlistId">The playlist ID.</param> /// <param name="mediaId">The media ID.</param> /// <returns>The member ID if the member was found in the playlist, otherwise -1.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception> /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception> /// <since_tizen> 4 </since_tizen> public int GetMemberId(int playlistId, string mediaId) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); if (playlistId <= 0) { throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, "Playlist id can't be less than or equal to zero."); } var reader = SelectMember(playlistId, new SelectArguments() { FilterExpression = $"{MediaInfoColumns.Id}='{mediaId}'" }); reader.Read(); return(reader.Current?.MemberId ?? -1); }
/// <summary> /// Retrieves the storage with the specified ID. /// </summary> /// <param name="storageId">The storage ID to select.</param> /// <returns>The <see cref="Storage"/> instance if the matched record was found in the database, otherwise null.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="storageId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="storageId"/> is a zero-length string, contains only white space.</exception> /// <since_tizen> 4 </since_tizen> public Storage Select(string storageId) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(storageId, nameof(storageId)); IntPtr handle = IntPtr.Zero; try { Interop.Storage.GetStorageInfoFromDb(storageId, out handle).ThrowIfError("Failed to query"); return(handle == IntPtr.Zero ? null : new Storage(handle)); } finally { if (handle != IntPtr.Zero) { Interop.Storage.Destroy(handle); } } }
/// <summary> /// Retrieves the folder. /// </summary> /// <param name="folderId">The folder ID to query with.</param> /// <returns>The <see cref="Folder"/> instance if the matched record was found in the database, otherwise null.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception> /// <since_tizen> 4 </since_tizen> public Folder Select(string folderId) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId)); Interop.Folder.GetFolderFromDb(folderId, out var handle).ThrowIfError("Failed to query"); if (handle == IntPtr.Zero) { return(null); } try { return(new Folder(handle)); } finally { Interop.Folder.Destroy(handle); } }
/// <summary> /// Inserts the playlist into the database from the specified M3U file. /// </summary> /// <remarks> /// If you want to access an internal storage, you should add privilege http://tizen.org/privilege/mediastorage.<br/> /// If you want to access an external storage, you should add privilege http://tizen.org/privilege/externalstorage. /// </remarks> /// <privilege>http://tizen.org/privilege/content.write</privilege> /// <privilege>http://tizen.org/privilege/mediastorage</privilege> /// <privilege>http://tizen.org/privilege/externalstorage</privilege> /// <param name="name">The name of the playlist.</param> /// <param name="path">The path to a M3U file to import.</param> /// <returns>The <see cref="Playlist"/> instance that contains the record information inserted.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"> /// <paramref name="name"/> is null.<br/> /// -or-<br/> /// <paramref name="path"/> is null. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="name"/> is a zero-length string.<br/> /// -or-<br/> /// <paramref name="path"/> is a zero-length string, contains only white space. /// </exception> /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exists.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <since_tizen> 4 </since_tizen> public Playlist InsertFromFile(string name, string path) { ValidateDatabase(); if (name == null) { throw new ArgumentNullException(nameof(name)); } if (name.Length == 0) { throw new ArgumentException("Playlist name can't be an empty string."); } ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path)); if (File.Exists(path) == false) { throw new FileNotFoundException("The specified path does not exists.", path); } IntPtr handle = IntPtr.Zero; Interop.Playlist.ImportFromFile(path, name, out handle).ThrowIfError("Failed to insert"); try { return(new Playlist(handle)); } finally { if (handle != IntPtr.Zero) { Interop.Playlist.Destroy(handle); } } }
/// <summary> /// Removes the media from a tag. /// </summary> /// <param name="tagId">The tag ID.</param> /// <param name="mediaId">The media ID to remove from the tag.</param> /// <returns>true if the matched record was found and updated, otherwise false.</returns> /// <remarks>The invalid media ID will be ignored.</remarks> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="tagId"/> is less than or equal to zero.</exception> /// <since_tizen> 4 </since_tizen> public bool RemoveMedia(int tagId, string mediaId) { ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); return(RemoveMedia(tagId, new string[] { mediaId })); }
/// <summary> /// Adds the media to the playlist. /// </summary> /// <param name="playlistId">The playlist ID that the media will be added to.</param> /// <param name="mediaId">The media ID to add to the playlist.</param> /// <returns>true if the matched record was found and updated, otherwise false.</returns> /// <remarks>The invalid media ID will be ignored.</remarks> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception> /// <since_tizen> 4 </since_tizen> public bool AddMember(int playlistId, string mediaId) { ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); return(AddMembers(playlistId, new string[] { mediaId })); }