2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
20 namespace Tizen.Content.MediaContent
23 /// The <see cref="MediaCommand"/> is a base class for command classes.
25 public abstract class MediaCommand
28 /// Initializes a new instance of the <see cref="MediaCommand"/> class with the specified <see cref="MediaDatabase"/>.
30 /// <param name="database">The <see cref="MediaDatabase"/> that the commands run on.</param>
31 /// <exception cref="ArgumentNullException"><paramref name="database"/> is null.</exception>
32 /// <exception cref="ObjectDisposedException"><paramref name="database"/> has already been disposed of.</exception>
33 protected MediaCommand(MediaDatabase database)
35 Database = database ?? throw new ArgumentNullException(nameof(database));
37 if (database.IsDisposed)
39 throw new ObjectDisposedException(nameof(database));
43 internal void ValidateDatabase()
45 Database.ValidateState();
49 /// Gets the <see cref="MediaDatabase"/>.
51 /// <value>The <see cref="MediaDatabase"/> which commands execute on.</value>
52 public MediaDatabase Database { get; }
56 /// Provides a means of reading results obtained by executing a query.
58 public interface IMediaDataReader
61 /// Advances to the next record.
63 /// <returns>true if there are more rows; otherwise false.</returns>
67 /// Gets the current record.
69 /// <value>The current record object.</value>
70 object Current { get; }
74 /// Provides a means of reading results obtained by executing a query.
76 /// <typeparam name="TRecord"></typeparam>
77 public class MediaDataReader<TRecord> : IMediaDataReader, IDisposable
79 private readonly IEnumerator<TRecord> _enumerator;
81 internal MediaDataReader(IEnumerable<TRecord> items)
83 _enumerator = items.GetEnumerator();
87 /// Gets the current record.
89 /// <value>The current record if the position is valid; otherwise null.</value>
90 public TRecord Current
94 ValidateNotDisposed();
95 return _enumerator.Current;
100 /// Advances to the next record.
102 /// <returns>true if there are more rows; otherwise false.</returns>
105 ValidateNotDisposed();
106 return _enumerator.MoveNext();
109 object IMediaDataReader.Current => Current;
111 #region IDisposable Support
112 private bool _disposed = false;
115 /// Disposes of the resources (other than memory) used by the MediaDataReader.
117 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
118 protected virtual void Dispose(bool disposing)
127 /// Releases all resources used by the current instance.
129 public void Dispose()
134 internal void ValidateNotDisposed()
138 throw new ObjectDisposedException(GetType().Name);