/// </summary>
public class ContentDatabase
{
- private bool _isConnected = false;
- internal ContentDatabase()
- {
- }
-
- internal void ConnectToDB()
+ /// <summary>
+ /// Connect to the media database to search, insert, remove or modify media information.
+ /// </summary>
+ /// <remarks>
+ /// For information security, disconnect() after use media database.
+ /// </remarks>
+ public static void Connect()
{
- if (!_isConnected)
- {
- MediaContentValidator.ThrowIfError(Interop.Content.Connect(), "Connect failed");
-
- _isConnected = true;
- }
+ MediaContentValidator.ThrowIfError(Interop.Content.Connect(), "Connect failed");
}
- private void DisconnectFromDB()
+ /// <summary>
+ /// Disconnect from the media database.
+ /// </summary>
+ public static void Disconnect()
{
- if (_isConnected)
- {
- MediaContentValidator.ThrowIfError(Interop.Content.Disconnect(), "Disconnect failed");
-
- _isConnected = false;
- }
+ MediaContentValidator.ThrowIfError(Interop.Content.Disconnect(), "Disconnect failed");
}
private static readonly Interop.Content.MediaContentDBUpdatedCallback s_contentUpdatedCallback = (
groupType = filter.GroupType;
}
- ConnectToDB();
-
if (typeof(T) == typeof(MediaInformation))
{
MediaContentValidator.ThrowIfError(
/// <returns>MediaInformation instance for the associated id.It throws Exception for invalid Id.</returns>
public MediaInformation Select(string id)
{
- ConnectToDB();
Interop.MediaInformation.SafeMediaInformationHandle mediaHandle;
MediaContentValidator.ThrowIfError(
Interop.MediaInformation.GetMediaFromDB(id, out mediaHandle), "Failed to get information");
/// <returns>ContentCollection instance for the associated id.It throws Exception for invalid Id.</returns>
public T Select<T>(string id) where T : ContentCollection
{
- ConnectToDB();
ContentCollection result = null;
IntPtr handle = IntPtr.Zero;
/// <returns>ContentCollection instance for the associated id.It throws Exception for invalid Id.</returns>
public T Select<T>(int id) where T : ContentCollection
{
- ConnectToDB();
ContentCollection result = null;
IntPtr handle = IntPtr.Zero;
/// </returns>
public IEnumerable<T> SelectAll<T>(ContentFilter filter)
{
- ConnectToDB();
if (typeof(T) == typeof(MediaInformation))
{
IEnumerable<MediaInformation> mediaList = GetMediaInformations(filter);
/// <returns>List of media</returns>
private IEnumerable<MediaInformation> GetMediaInformations(ContentFilter filter)
{
- ConnectToDB();
IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
List<MediaInformation> mediaInformationList = new List<MediaInformation>();
Interop.MediaInformation.MediaInformationCallback callback = (IntPtr mediaHandle, IntPtr userData) =>
/// <param name="mediaInfo">The MediaInformation to be deleted</param>
public void Delete(MediaInformation mediaInfo)
{
- ConnectToDB();
MediaContentValidator.ThrowIfError(
Interop.MediaInformation.Delete(mediaInfo.MediaId), "Failed to remove information");
}
/// <param name="contentcollection">The ContentCollection instance to be deleted</param>
public void Delete(ContentCollection contentcollection)
{
- ConnectToDB();
Type type = contentcollection.GetType();
if (type == typeof(Tag))
internal void Delete(MediaBookmark bookmark)
{
- ConnectToDB();
MediaContentValidator.ThrowIfError(
Interop.MediaBookmark.DeleteFromDb(bookmark.Id), "Failed to remove information");
}
internal void Delete(MediaFace face)
{
- ConnectToDB();
MediaContentValidator.ThrowIfError(
Interop.Face.DeleteFromDb(face.Id), "Failed to remove face information");
}
/// <param name="contentCollection">The content collection to be updated</param>
public void Update(ContentCollection contentCollection)
{
- ConnectToDB();
Type type = contentCollection.GetType();
if (type == typeof(Tag))
{
/// <param name="mediaInfo">The MediaInformation object to be updated</param>
public void Update(MediaInformation mediaInfo)
{
- ConnectToDB();
Type type = mediaInfo.GetType();
if (type == typeof(ImageInformation))
{
internal void Update(MediaFace face)
{
- ConnectToDB();
MediaContentValidator.ThrowIfError(Interop.Face.UpdateToDb(face.Handle), "Failed to update DB");
}
/// <param name="contentCollection">The content collection to be inserted</param>
public void Insert(ContentCollection contentCollection)
{
- ConnectToDB();
Type type = contentCollection.GetType();
IntPtr handle = IntPtr.Zero;
if (type == typeof(Tag))
internal void Insert(string mediaId, uint offset, string thumbnailPath)
{
- ConnectToDB();
MediaContentValidator.ThrowIfError(
Interop.MediaBookmark.InsertToDb(mediaId, offset, thumbnailPath), "Failed to insert information");
}
internal void Insert(MediaFace face)
{
- ConnectToDB();
MediaContentValidator.ThrowIfError(
Interop.Face.InsertToDb(((MediaFace)face).Handle), "Failed to insert information");
}
/// </remarks>
public static void Scan(string filePath)
{
- Database.ConnectToDB();
MediaContentValidator.ThrowIfError(Interop.Content.ScanFile(filePath), "Failed scan");
}
/// <returns>the MediaInformation instance about added media path</returns>
public static MediaInformation AddMediaInformation(string filePath)
{
- Database.ConnectToDB();
Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle;
MediaContentValidator.ThrowIfError(
Interop.MediaInformation.Insert(filePath, out mediaInformationHandle), "Failed to Insert MediaInformation to DB");
/// </returns>
public static Task AddMediaInformationBatchAsync(IEnumerable<string> filePaths)
{
- Database.ConnectToDB();
var task = new TaskCompletionSource<int>();
string[] paths = ((List<string>)filePaths).ToArray();
Interop.MediaInformation.MediaInsertCompletedCallback callback = (MediaContentError error, IntPtr userData) =>
/// </returns>
public static Task AddBurstShotImagesAsync(IEnumerable<string> filePaths)
{
- Database.ConnectToDB();
var task = new TaskCompletionSource<int>();
string[] paths = ((List<string>)filePaths).ToArray();
Interop.MediaInformation.MediaInsertBurstShotCompletedCallback callback = (MediaContentError error, IntPtr userData) =>
/// <param name="filter">The content filter to which media will be matched</param>
public static void RemoveMediaInformationBatch(ContentFilter filter)
{
- Database.ConnectToDB();
IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
MediaContentValidator.ThrowIfError(
Interop.MediaInformation.BatchDelete(handle), "Failed to remove items");