private static void WaitForIsLoaded(IPlaylistContainer playlistContainer, CancellationToken cancellationToken) { while (!playlistContainer.IsLoaded() || cancellationToken.IsCancellationRequested) { Task.Delay(250, cancellationToken); } }
void pc_PlaylistMoved(IPlaylistContainer pc, PlaylistMovedEventArgs args) { if (PlaylistMoved != null) { PlaylistMoved(this, null); } }
internal static IContainerPlaylist Get( ISession session, IPlaylistContainer container, IntPtr handle, IntPtr folderId, PlaylistType playlistType) { KeyGen key = new KeyGen(handle, folderId, playlistType); lock (_instanceLock) { NativeContainerPlaylist instance; if (!_instances.TryGetValue(key, out instance)) { instance = new NativeContainerPlaylist(session, handle, folderId, playlistType, container); instance.Initialize(); if (SessionFactory.IsInternalCachingEnabled) { _instances.Add(key, instance); } } return(instance); } }
public NativeContainerPlaylist(ISession session, IntPtr handle, IntPtr folderId, PlaylistType type, IPlaylistContainer container) : base(session, handle) { _folderId = folderId; _type = type; _container = container; }
void pc_Loaded(IPlaylistContainer pc, EventArgs args) { if (Loaded != null) { Loaded(this, args); } }
/// <summary> /// Gets the full path to the given playlist item. /// </summary> /// <param name="item">The item to get the path of.</param> /// <returns>The full path to the item.</returns> public static string GetFullPath(this IPlaylistItem item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } var path = item.Path; IPlaylistContainer parent = item.Parent; while (parent != null) { if (Path.IsPathRooted(path)) { break; } path = Path.Combine(parent.IncludesFilename ? Path.GetDirectoryName(parent.Path) : parent.Path, path); parent = parent.Parent; } // when used, the playlist items must be rooted *somewhere* // otherwise the files they correspond to cannot be located if (!Path.IsPathRooted(path)) { throw new InvalidOperationException("The full path couldn't be retrieved. The root playlist must always have a rooted path."); } return(Path.GetFullPath(path)); }
private void OnSearchTextChanged() { searchTaskCancellationTokenSource?.Cancel(); var txt = SearchText; if (string.IsNullOrWhiteSpace(txt)) { FilteredSongsLoader.Items = Enumerable.Empty <FullSongInfo>(); return; } searchTaskCancellationTokenSource = new CancellationTokenSource(); searchTask = Task.Run(async() => { searchPlaylist = await database.Search(txt, searchTaskCancellationTokenSource.Token); return(await Map(searchPlaylist.Playlist.Songs)); }) .ContinueWith( task => dispatcher.Invoke(() => { FilteredSongsLoader.Items = task.Result; LoadPlaylistCommand.Refresh(); }), searchTaskCancellationTokenSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); this.InvokePropertyChanged(PropertyChanged, nameof(IsLoading)); searchTask.ContinueWith(_ => dispatcher.Invoke(() => this.InvokePropertyChanged(PropertyChanged, nameof(IsLoading)))); }
void pc_PlaylistAdded(IPlaylistContainer pc, PlaylistEventArgs args) { if (PlaylistAdded != null) { PlaylistAdded(this, args); } }
internal static IntPtr GetPointer(IPlaylistContainer pc) { if (pc.GetType() == typeof(PlaylistContainerWrapper)) { return(((PlaylistContainerWrapper)pc).pc.pcPtr); } throw new ArgumentException("Invalid pc"); }
internal void OnLoginComplete(SessionEventArgs e) { if (e.Status == Error.OK) { _playlistContainer = PlaylistContainerManager.Get(this, Spotify.sp_session_playlistcontainer(Handle)); } LoginComplete.RaiseEvent(this, e); }
public static bool WaitUntilLoaded(this IPlaylistContainer source, int millisecondsTimeout = 10000) { var reset = new ManualResetEvent(source.IsLoaded); EventHandler handler = (s, e) => reset.Set(); source.Loaded += handler; bool result = reset.WaitOne(millisecondsTimeout); source.Loaded -= handler; return(result); }
public BasePlaylistContainerViewModel(IPlaylistContainer innerContainer) { InnerContainer = innerContainer; foreach (var item in InnerContainer) { switch (item) { case Track track: Items.Add(new TrackViewModel(track)); break; default: throw new NotSupportedException(); } } }
private static async Task <IPlaylist> FindPlaylistByName(IPlaylistContainer playlistContainer, string playlistName) { for (var i = 0; i < playlistContainer.NumPlaylists(); i++) { if (playlistContainer.PlaylistType(i) != PlaylistType.Playlist) { continue; } var playlist = playlistContainer.Playlist(i); await playlist.Load(); if (playlist.Name() == playlistName) { return(playlist); } } return(null); }
public static async Task Load(this IPlaylistContainer playlistContainer, CancellationToken cancellationToken) { await Task.Run(() => WaitForIsLoaded(playlistContainer, cancellationToken), cancellationToken); }
public static async Task Load(this IPlaylistContainer playlistContainer) { await Load(playlistContainer, CancellationToken.None); }
public static async Task Write(string filePath, IPlaylistContainer playlistContainer, IProgress <(double?, string)> progress)
public static PlaylistContainerAssertions Should(this IPlaylistContainer actualValue) => new PlaylistContainerAssertions(actualValue);