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 /// <since_tizen> 4 </since_tizen>
26 public abstract class MediaCommand
29 /// Initializes a new instance of the <see cref="MediaCommand"/> class with the specified <see cref="MediaDatabase"/>.
31 /// <param name="database">The <see cref="MediaDatabase"/> that the commands run on.</param>
32 /// <exception cref="ArgumentNullException"><paramref name="database"/> is null.</exception>
33 /// <exception cref="ObjectDisposedException"><paramref name="database"/> has already been disposed.</exception>
34 /// <since_tizen> 4 </since_tizen>
35 protected MediaCommand(MediaDatabase database)
37 Database = database ?? throw new ArgumentNullException(nameof(database));
39 if (database.IsDisposed)
41 throw new ObjectDisposedException(nameof(database));
45 internal void ValidateDatabase()
47 Database.ValidateState();
51 /// Gets the <see cref="MediaDatabase"/>.
53 /// <value>The <see cref="MediaDatabase"/> which commands execute on.</value>
54 /// <since_tizen> 4 </since_tizen>
55 public MediaDatabase Database { get; }
59 /// Provides a means of reading results obtained by executing a query.
61 /// <since_tizen> 4 </since_tizen>
62 public interface IMediaDataReader
65 /// Advances to the next record.
67 /// <returns>true if there are more rows; otherwise false.</returns>
68 /// <since_tizen> 4 </since_tizen>
72 /// Gets the current record.
74 /// <value>The current record object.</value>
75 /// <since_tizen> 4 </since_tizen>
76 object Current { get; }
80 /// Provides a means of reading results obtained by executing a query.
82 /// <typeparam name="TRecord"></typeparam>
83 /// <since_tizen> 4 </since_tizen>
84 public class MediaDataReader<TRecord> : IMediaDataReader, IDisposable
86 private readonly IEnumerator<TRecord> _enumerator;
88 internal MediaDataReader(IEnumerable<TRecord> items)
90 _enumerator = items.GetEnumerator();
94 /// Gets the current record.
96 /// <value>The current record if the position is valid; otherwise null.</value>
97 /// <since_tizen> 4 </since_tizen>
98 public TRecord Current
102 ValidateNotDisposed();
103 return _enumerator.Current;
108 /// Advances to the next record.
110 /// <returns>true if there are more rows; otherwise false.</returns>
111 /// <since_tizen> 4 </since_tizen>
114 ValidateNotDisposed();
115 return _enumerator.MoveNext();
118 object IMediaDataReader.Current => Current;
120 #region IDisposable Support
121 private bool _disposed = false;
124 /// Disposes of the resources (other than memory) used by the MediaDataReader.
126 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
127 /// <since_tizen> 4 </since_tizen>
128 protected virtual void Dispose(bool disposing)
137 /// Releases all resources used by the current instance.
139 /// <since_tizen> 4 </since_tizen>
140 public void Dispose()
145 internal void ValidateNotDisposed()
149 throw new ObjectDisposedException(GetType().Name);