/
PlaylistPluginBase.cs
349 lines (272 loc) · 15.6 KB
/
PlaylistPluginBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// Copyright (c) Arlo Godfrey. All Rights Reserved.
// Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms.
// See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using OwlCore.ComponentModel;
using StrixMusic.Sdk.AdapterModels;
using StrixMusic.Sdk.AppModels;
using StrixMusic.Sdk.CoreModels;
using StrixMusic.Sdk.MediaPlayback;
namespace StrixMusic.Sdk.Plugins.Model
{
/// <summary>
/// An implementation of <see cref="IPlaylist"/> which delegates all member access to the <see cref="Inner"/> implementation,
/// unless the member is overridden in a derived class which changes the behavior.
/// </summary>
public class PlaylistPluginBase : IModelPlugin, IPlaylist, IDelegatable<IPlaylist>
{
/// <summary>
/// Creates a new instance of <see cref="PlaylistPluginBase"/>.
/// </summary>
/// <param name="registration">Metadata about the plugin which was provided during registration.</param>
/// <param name="inner">The implementation which all member access is delegated to, unless the member is overridden in a derived class which changes the behavior.</param>
internal protected PlaylistPluginBase(ModelPluginMetadata registration, IPlaylist inner)
{
Metadata = registration;
Inner = inner;
InnerTrackCollection = inner;
InnerImageCollection = inner;
InnerUrlCollection = inner;
InnerPlayable = inner;
InnerDownloadable = inner;
}
/// <summary>
/// Metadata about the plugin which was provided during registration.
/// </summary>
public ModelPluginMetadata Metadata { get; }
/// <inheritdoc/>
public IPlaylist Inner { get; set; }
/// <summary>
/// A wrapped implementation which member access can be delegated to. Defaults to <see cref="Inner"/>.
/// </summary>
public IPlayable InnerPlayable { get; set; }
/// <summary>
/// A wrapped implementation which member access can be delegated to. Defaults to <see cref="Inner"/>.
/// </summary>
public IDownloadable InnerDownloadable { get; set; }
/// <summary>
/// A wrapped implementation which member access can be delegated to. Defaults to <see cref="Inner"/>.
/// </summary>
public ITrackCollection InnerTrackCollection { get; set; }
/// <summary>
/// A wrapped implementation which member access can be delegated to. Defaults to <see cref="Inner"/>.
/// </summary>
public IImageCollection InnerImageCollection { get; set; }
/// <summary>
/// A wrapped implementation which member access can be delegated to. Defaults to <see cref="Inner"/>.
/// </summary>
public IUrlCollection InnerUrlCollection { get; set; }
/// <inheritdoc/>
public event EventHandler? SourcesChanged
{
add => Inner.SourcesChanged += value;
remove => Inner.SourcesChanged -= value;
}
/// <inheritdoc/>
public virtual DownloadInfo DownloadInfo => InnerDownloadable.DownloadInfo;
/// <inheritdoc/>
public virtual Task StartDownloadOperationAsync(DownloadOperation operation, CancellationToken cancellationToken = default) => InnerDownloadable.StartDownloadOperationAsync(operation, cancellationToken);
/// <inheritdoc/>
public virtual event EventHandler<DownloadInfo>? DownloadInfoChanged
{
add => InnerDownloadable.DownloadInfoChanged += value;
remove => InnerDownloadable.DownloadInfoChanged -= value;
}
/// <inheritdoc/>
public virtual int TotalUrlCount => InnerUrlCollection.TotalUrlCount;
/// <inheritdoc/>
public virtual Task RemoveUrlAsync(int index, CancellationToken cancellationToken = default) => InnerUrlCollection.RemoveUrlAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual Task<bool> IsAddUrlAvailableAsync(int index, CancellationToken cancellationToken = default) => InnerUrlCollection.IsAddUrlAvailableAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual Task<bool> IsRemoveUrlAvailableAsync(int index, CancellationToken cancellationToken = default) => InnerUrlCollection.IsRemoveUrlAvailableAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual event EventHandler<int>? UrlsCountChanged
{
add => InnerUrlCollection.UrlsCountChanged += value;
remove => InnerUrlCollection.UrlsCountChanged -= value;
}
/// <inheritdoc/>
public virtual bool Equals(ICoreUrlCollection? other) => InnerUrlCollection.Equals(other!);
/// <inheritdoc/>
IReadOnlyList<ICorePlaylistCollectionItem> IMerged<ICorePlaylistCollectionItem>.Sources => ((IMerged<ICorePlaylist>)Inner).Sources;
/// <inheritdoc/>
IReadOnlyList<ICorePlaylist> IMerged<ICorePlaylist>.Sources => ((IMerged<ICorePlaylist>)Inner).Sources;
/// <inheritdoc/>
IReadOnlyList<ICoreImageCollection> IMerged<ICoreImageCollection>.Sources => InnerImageCollection.Sources;
/// <inheritdoc/>
IReadOnlyList<ICoreUrlCollection> IMerged<ICoreUrlCollection>.Sources => InnerUrlCollection.Sources;
/// <inheritdoc/>
IReadOnlyList<ICoreTrackCollection> IMerged<ICoreTrackCollection>.Sources =>
((IMerged<ICoreTrackCollection>)InnerTrackCollection).Sources;
/// <inheritdoc/>
public virtual IAsyncEnumerable<IUrl> GetUrlsAsync(int limit, int offset, CancellationToken cancellationToken = default) => InnerUrlCollection.GetUrlsAsync(limit, offset, cancellationToken);
/// <inheritdoc/>
public virtual Task AddUrlAsync(IUrl url, int index, CancellationToken cancellationToken = default) => InnerUrlCollection.AddUrlAsync(url, index, cancellationToken);
/// <inheritdoc/>
public virtual event CollectionChangedEventHandler<IUrl>? UrlsChanged
{
add => InnerUrlCollection.UrlsChanged += value;
remove => InnerUrlCollection.UrlsChanged -= value;
}
/// <inheritdoc/>
public virtual Task<bool> IsAddImageAvailableAsync(int index, CancellationToken cancellationToken = default) => InnerImageCollection.IsAddImageAvailableAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual Task<bool> IsRemoveImageAvailableAsync(int index, CancellationToken cancellationToken = default) => InnerImageCollection.IsRemoveImageAvailableAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual Task RemoveImageAsync(int index, CancellationToken cancellationToken = default) => InnerImageCollection.RemoveImageAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual int TotalImageCount => InnerImageCollection.TotalImageCount;
/// <inheritdoc/>
public virtual event EventHandler<int>? ImagesCountChanged
{
add => InnerImageCollection.ImagesCountChanged += value;
remove => InnerImageCollection.ImagesCountChanged -= value;
}
/// <inheritdoc/>
public virtual bool Equals(ICoreImageCollection? other) => InnerImageCollection.Equals(other!);
/// <inheritdoc/>
public virtual IAsyncEnumerable<IImage> GetImagesAsync(int limit, int offset, CancellationToken cancellationToken = default) => InnerImageCollection.GetImagesAsync(limit, offset, cancellationToken);
/// <inheritdoc/>
public virtual Task AddImageAsync(IImage image, int index, CancellationToken cancellationToken = default) => InnerImageCollection.AddImageAsync(image, index, cancellationToken);
/// <inheritdoc/>
public virtual event CollectionChangedEventHandler<IImage>? ImagesChanged
{
add => InnerImageCollection.ImagesChanged += value;
remove => InnerImageCollection.ImagesChanged -= value;
}
/// <inheritdoc/>
public virtual string Id => InnerPlayable.Id;
/// <inheritdoc/>
public virtual string Name => InnerPlayable.Name;
/// <inheritdoc/>
public virtual string? Description => InnerPlayable.Description;
/// <inheritdoc/>
public virtual DateTime? LastPlayed => InnerPlayable.LastPlayed;
/// <inheritdoc/>
public virtual PlaybackState PlaybackState => InnerPlayable.PlaybackState;
/// <inheritdoc/>
public virtual TimeSpan Duration => InnerPlayable.Duration;
/// <inheritdoc/>
public virtual bool IsChangeNameAsyncAvailable => InnerPlayable.IsChangeNameAsyncAvailable;
/// <inheritdoc/>
public virtual bool IsChangeDescriptionAsyncAvailable => InnerPlayable.IsChangeDescriptionAsyncAvailable;
/// <inheritdoc/>
public virtual bool IsChangeDurationAsyncAvailable => InnerPlayable.IsChangeDurationAsyncAvailable;
/// <inheritdoc/>
public virtual Task ChangeNameAsync(string name, CancellationToken cancellationToken = default) => InnerPlayable.ChangeNameAsync(name, cancellationToken);
/// <inheritdoc/>
public virtual Task ChangeDescriptionAsync(string? description, CancellationToken cancellationToken = default) => InnerPlayable.ChangeDescriptionAsync(description, cancellationToken);
/// <inheritdoc/>
public virtual Task ChangeDurationAsync(TimeSpan duration, CancellationToken cancellationToken = default) => InnerPlayable.ChangeDurationAsync(duration, cancellationToken);
/// <inheritdoc/>
public virtual event EventHandler<PlaybackState>? PlaybackStateChanged
{
add => InnerPlayable.PlaybackStateChanged += value;
remove => InnerPlayable.PlaybackStateChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<string>? NameChanged
{
add => InnerPlayable.NameChanged += value;
remove => InnerPlayable.NameChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<string?>? DescriptionChanged
{
add => InnerPlayable.DescriptionChanged += value;
remove => InnerPlayable.DescriptionChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<TimeSpan>? DurationChanged
{
add => InnerPlayable.DurationChanged += value;
remove => InnerPlayable.DurationChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<DateTime?>? LastPlayedChanged
{
add => InnerPlayable.LastPlayedChanged += value;
remove => InnerPlayable.LastPlayedChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<bool>? IsChangeNameAsyncAvailableChanged
{
add => InnerPlayable.IsChangeNameAsyncAvailableChanged += value;
remove => InnerPlayable.IsChangeNameAsyncAvailableChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<bool>? IsChangeDescriptionAsyncAvailableChanged
{
add => InnerPlayable.IsChangeDescriptionAsyncAvailableChanged += value;
remove => InnerPlayable.IsChangeDescriptionAsyncAvailableChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<bool>? IsChangeDurationAsyncAvailableChanged
{
add => InnerPlayable.IsChangeDurationAsyncAvailableChanged += value;
remove => InnerPlayable.IsChangeDurationAsyncAvailableChanged -= value;
}
/// <inheritdoc/>
public virtual DateTime? AddedAt => Inner.AddedAt;
/// <inheritdoc/>
public virtual int TotalTrackCount => InnerTrackCollection.TotalTrackCount;
/// <inheritdoc/>
public virtual bool IsPlayTrackCollectionAsyncAvailable => InnerTrackCollection.IsPlayTrackCollectionAsyncAvailable;
/// <inheritdoc/>
public virtual bool IsPauseTrackCollectionAsyncAvailable => InnerTrackCollection.IsPauseTrackCollectionAsyncAvailable;
/// <inheritdoc/>
public virtual Task PlayTrackCollectionAsync(CancellationToken cancellationToken = default) => InnerTrackCollection.PlayTrackCollectionAsync(cancellationToken);
/// <inheritdoc/>
public virtual Task PauseTrackCollectionAsync(CancellationToken cancellationToken = default) => InnerTrackCollection.PauseTrackCollectionAsync(cancellationToken);
/// <inheritdoc/>
public virtual Task RemoveTrackAsync(int index, CancellationToken cancellationToken = default) => InnerTrackCollection.RemoveTrackAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual Task<bool> IsAddTrackAvailableAsync(int index, CancellationToken cancellationToken = default) => InnerTrackCollection.IsAddTrackAvailableAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual Task<bool> IsRemoveTrackAvailableAsync(int index, CancellationToken cancellationToken = default) => InnerTrackCollection.IsRemoveTrackAvailableAsync(index, cancellationToken);
/// <inheritdoc/>
public virtual event EventHandler<bool>? IsPlayTrackCollectionAsyncAvailableChanged
{
add => InnerTrackCollection.IsPlayTrackCollectionAsyncAvailableChanged += value;
remove => InnerTrackCollection.IsPlayTrackCollectionAsyncAvailableChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<bool>? IsPauseTrackCollectionAsyncAvailableChanged
{
add => InnerTrackCollection.IsPauseTrackCollectionAsyncAvailableChanged += value;
remove => InnerTrackCollection.IsPauseTrackCollectionAsyncAvailableChanged -= value;
}
/// <inheritdoc/>
public virtual event EventHandler<int>? TracksCountChanged
{
add => InnerTrackCollection.TracksCountChanged += value;
remove => InnerTrackCollection.TracksCountChanged -= value;
}
/// <inheritdoc/>
public virtual bool Equals(ICoreTrackCollection? other) => InnerTrackCollection.Equals(other!);
/// <inheritdoc/>
public virtual Task PlayTrackCollectionAsync(ITrack track, CancellationToken cancellationToken = default) => InnerTrackCollection.PlayTrackCollectionAsync(track, cancellationToken);
/// <inheritdoc/>
public virtual IAsyncEnumerable<ITrack> GetTracksAsync(int limit, int offset, CancellationToken cancellationToken = default) => InnerTrackCollection.GetTracksAsync(limit, offset, cancellationToken);
/// <inheritdoc/>
public virtual Task AddTrackAsync(ITrack track, int index, CancellationToken cancellationToken = default) => InnerTrackCollection.AddTrackAsync(track, index, cancellationToken);
/// <inheritdoc/>
public virtual event CollectionChangedEventHandler<ITrack>? TracksChanged
{
add => InnerTrackCollection.TracksChanged += value;
remove => InnerTrackCollection.TracksChanged -= value;
}
/// <inheritdoc/>
public virtual bool Equals(ICorePlaylistCollectionItem? other) => Inner.Equals(other!);
/// <inheritdoc/>
public virtual bool Equals(ICorePlaylist? other) => Inner.Equals(other!);
/// <inheritdoc/>
public virtual IUserProfile? Owner => Inner.Owner;
/// <inheritdoc/>
public virtual IPlayableCollectionGroup? RelatedItems => Inner.RelatedItems;
}
}