/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace Tizen.Content.MediaContent
{
///
/// Provides commands to manage bookmarks in the database.
///
///
/// 4
public class BookmarkCommand : MediaCommand
{
///
/// Initializes a new instance of the class with the specified .
///
/// The that the commands run on.
/// is null.
/// has already been disposed.
/// 4
public BookmarkCommand(MediaDatabase database) : base(database)
{
}
///
/// Retrieves the number of bookmarks.
///
/// The number of bookmarks.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// 4
public int Count()
{
return Count(null);
}
///
/// Retrieves the number of bookmarks with .
///
/// The criteria to use to filter. This value can be null.
/// The number of bookmarks.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// 4
public int Count(CountArguments arguments)
{
ValidateDatabase();
return CommandHelper.Count(Interop.Bookmark.GetCount, arguments);
}
///
/// Inserts a new bookmark into the database with the specified media and offset.
///
/// http://tizen.org/privilege/content.write
/// The media ID to be associated with.
/// The time offset in milliseconds.
/// The instance that contains the record information inserted.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// is null.
/// is a zero-length string, contains only white space.
/// The caller has no required privilege.
/// 4
public Bookmark Insert(string mediaId, int offset)
{
return Insert(mediaId, offset, null);
}
///
/// Inserts a new bookmark into the database with the specified media ID, offset, and name.
///
/// http://tizen.org/privilege/content.write
/// The media ID to be associated with.
/// The time offset in milliseconds.
/// The name of the bookmark. This value can be null.
/// The instance that contains the record information inserted.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// is null.
/// is a zero-length string, contains only white space.
/// The caller has no required privilege.
/// 4
public Bookmark Insert(string mediaId, int offset, string name)
{
return Insert(mediaId, offset, name, null);
}
///
/// Inserts a new bookmark into the database with the specified media ID, offset, name, and thumbnail path.
///
/// http://tizen.org/privilege/content.write
///
/// The thumbnail may be useful only when the media is video.
///
/// The media ID to be associated with.
/// The time offset in milliseconds.
/// The name of the bookmark. This value can be null.
/// The thumbnail path of the bookmark. This value can be null.
/// The instance that contains the record information inserted.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// is null.
/// is a zero-length string, contains only white space.
/// The caller has no required privilege.
/// 4
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);
}
}
///
/// Deletes a bookmark from the database.
///
/// http://tizen.org/privilege/content.write
/// The bookmark ID to delete.
/// true if the matched record was found and deleted, otherwise false.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// is less than zero.
/// The caller has no required privilege.
/// 4
public bool Delete(int bookmarkId)
{
ValidateDatabase();
if (bookmarkId < 0)
{
throw new ArgumentOutOfRangeException(nameof(bookmarkId), bookmarkId,
"Bookmark id shouldn't be negative.");
}
if (CommandHelper.Count(Interop.Bookmark.GetCount, $"{BookmarkColumns.Id}={bookmarkId}") == 0)
{
return false;
}
CommandHelper.Delete(Interop.Bookmark.Delete, bookmarkId);
return true;
}
///
/// Retrieves the bookmarks.
///
/// The containing the results.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// 4
public MediaDataReader Select()
{
return Select(null);
}
///
/// Retrieves the bookmarks with .
///
/// The criteria to use to filter. This value can be null.
/// The containing the results.
/// The is disconnected.
/// The has already been disposed.
/// An error occurred while executing the command.
/// 4
public MediaDataReader Select(SelectArguments filter)
{
ValidateDatabase();
return CommandHelper.Select(filter, Interop.Bookmark.ForeachFromDb, Bookmark.FromHandle);
}
}
}