/*
* 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;
using System.Collections.Generic;
namespace Tizen.Content.MediaContent
{
///
/// is a base class for command classes.
///
public abstract class MediaCommand
{
///
/// Initializes a new instance of the class with the specified .
///
/// A that the commands run on.
/// is null.
/// has already been disposed of.
protected MediaCommand(MediaDatabase database)
{
Database = database ?? throw new ArgumentNullException(nameof(database));
if (database.IsDisposed)
{
throw new ObjectDisposedException(nameof(database));
}
}
internal void ValidateDatabase()
{
Database.ValidateState();
}
///
/// Gets the .
///
/// The which commands execute on.
public MediaDatabase Database { get; }
}
///
/// Provides a means of reading results obtained by executing a query.
///
public interface IMediaDataReader
{
///
/// Advances to the next record.
///
/// true if there are more rows; otherwise false.
bool Read();
///
/// Gets the current record.
///
/// The current record object.
object Current { get; }
}
///
/// Provides a means of reading results obtained by executing a query.
///
///
public class MediaDataReader : IMediaDataReader, IDisposable
{
private readonly IEnumerator _enumerator;
internal MediaDataReader(IEnumerable items)
{
_enumerator = items.GetEnumerator();
}
///
/// Gets the current record.
///
/// The current record if the position is valid; otherwise null.
public TRecord Current
{
get
{
ValidateNotDisposed();
return _enumerator.Current;
}
}
///
/// Advances to the next record.
///
/// true if there are more rows; otherwise false.
public bool Read()
{
ValidateNotDisposed();
return _enumerator.MoveNext();
}
object IMediaDataReader.Current => Current;
#region IDisposable Support
private bool _disposed = false;
///
/// Disposes of the resources (other than memory) used by the MediaDataReader.
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
_disposed = true;
}
}
///
/// Releases all resources used by the current instance.
///
public void Dispose()
{
Dispose(true);
}
internal void ValidateNotDisposed()
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
}
#endregion
}
}