Пример #1
0
        internal static ILink Get(ISession session, IntPtr handle, ISearch search = null)
        {
            lock (_instanceLock)
            {
                NativeLink instance;

                if (!_instances.TryGetValue(handle, out instance))
                {
                    LinkType type;
                    lock (Spotify.Mutex)
                    {
                        type = Spotify.sp_link_type(handle);
                    }

                    switch (type)
                    {
                        case LinkType.Track:
                            instance = new NativeTrackAndOffsetLink(session, handle);
                            break;
                        case LinkType.Album:
                            instance = new NativeAlbumLink(session, handle);
                            break;
                        case LinkType.Artist:
                            instance = new NativeArtistLink(session, handle);
                            break;
                        case LinkType.Search:
                            instance = new NativeSearchLink(session, handle, search);
                            break;
                        case LinkType.Playlist:
                            instance = new NativePlaylistLink(session, handle);
                            break;
                        case LinkType.Profile:
                            instance = new NativeUserLink(session, handle);
                            break;
                        case LinkType.Starred:
                            instance = new NativePlaylistLink(session, handle);
                            break;
                        case LinkType.LocalTrack:
                            instance = new NativeTrackAndOffsetLink(session, handle);
                            break;
                        case LinkType.Image:
                            instance = new NativeImageLink(session, handle);
                            break;
                        default:
                            throw new ArgumentException("Invalid link.");
                    }

                    _instances.Add(handle, instance);
                    instance.Initialize();
                }

                return instance;
            }
        }
Пример #2
0
        internal static ILink Get(
            ISession session,
            IntPtr handle,
            string linkAsString      = null,
            TimeSpan?trackLinkOffset = null)
        {
            lock (_instanceLock)
            {
                NativeLink instance;

                if (!_instances.TryGetValue(handle, out instance))
                {
                    LinkType type;
                    lock (Spotify.Mutex)
                    {
                        type = Spotify.sp_link_type(handle);
                    }

                    switch (type)
                    {
                    case LinkType.Track:
                    case LinkType.LocalTrack:
                        if (!string.IsNullOrEmpty(linkAsString))
                        {
                            instance = new NativeTrackAndOffsetLink(session, handle, linkAsString);
                        }
                        else if (trackLinkOffset.HasValue)
                        {
                            instance = new NativeTrackAndOffsetLink(session, handle, trackLinkOffset);
                        }
                        else
                        {
                            instance = new NativeTrackAndOffsetLink(session, handle);
                        }

                        break;

                    case LinkType.Album:
                        instance = new NativeAlbumLink(session, handle);
                        break;

                    case LinkType.Artist:
                        instance = new NativeArtistLink(session, handle);
                        break;

                    case LinkType.Search:
                        instance = new NativeSearchLink(session, handle, linkAsString);
                        break;

                    case LinkType.Playlist:
                        instance = new NativePlaylistLink(session, handle);
                        break;

                    case LinkType.Profile:
                        instance = new NativeUserLink(session, handle);
                        break;

                    case LinkType.Starred:
                        instance = new NativePlaylistLink(session, handle);
                        break;

                    case LinkType.Image:
                        instance = new NativeImageLink(session, handle);
                        break;

                    default:
                        throw new ArgumentException("Invalid link.");
                    }

                    if (SessionFactory.IsInternalCachingEnabled)
                    {
                        _instances.Add(handle, instance);
                    }

                    instance.Initialize();
                }

                return(instance);
            }
        }
Пример #3
0
        internal static ILink Get(
            ISession session,
            IntPtr handle,
            string linkAsString = null,
            TimeSpan? trackLinkOffset = null)
        {
            lock (_instanceLock)
            {
                NativeLink instance;

                if (!_instances.TryGetValue(handle, out instance))
                {
                    LinkType type;
                    lock (Spotify.Mutex)
                    {
                        type = Spotify.sp_link_type(handle);
                    }

                    switch (type)
                    {
                        case LinkType.Track:
                        case LinkType.LocalTrack:
                            if (!string.IsNullOrEmpty(linkAsString))
                            {
                                instance = new NativeTrackAndOffsetLink(session, handle, linkAsString);
                            }
                            else if (trackLinkOffset.HasValue)
                            {
                                instance = new NativeTrackAndOffsetLink(session, handle, trackLinkOffset);
                            }
                            else
                            {
                                instance = new NativeTrackAndOffsetLink(session, handle);
                            }

                            break;
                        case LinkType.Album:
                            instance = new NativeAlbumLink(session, handle);
                            break;
                        case LinkType.Artist:
                            instance = new NativeArtistLink(session, handle);
                            break;
                        case LinkType.Search:
                            instance = new NativeSearchLink(session, handle, linkAsString);
                            break;
                        case LinkType.Playlist:
                            instance = new NativePlaylistLink(session, handle);
                            break;
                        case LinkType.Profile:
                            instance = new NativeUserLink(session, handle);
                            break;
                        case LinkType.Starred:
                            instance = new NativePlaylistLink(session, handle);
                            break;
                        case LinkType.Image:
                            instance = new NativeImageLink(session, handle);
                            break;
                        default:
                            throw new ArgumentException("Invalid link.");
                    }

                    if (SessionFactory.IsInternalCachingEnabled)
                    {
                        _instances.Add(handle, instance);
                    }

                    instance.Initialize();
                }

                return instance;
            }
        }