示例#1
0
        public static IRdioObject ConvertDictionaryToRdioObject(IDictionary <string, object> d,
                                                                RdioType type = RdioType.Unknown)
        {
            IRdioObject rdioObject = null;

            if (type == RdioType.Unknown)
            {
                type = ParseRdioType((string)d["type"]);
            }
            switch (type)
            {
            case RdioType.CollectionAlbum:
            case RdioType.Album:
                var album = new RdioAlbum
                {
                    Artist        = (string)d["artist"],
                    ArtistKey     = (string)d["artistKey"],
                    ArtistUrl     = (string)d["artistUrl"],
                    BaseIcon      = (string)d["baseIcon"],
                    CanSample     = (bool)d["canSample"],
                    CanStream     = (bool)d["canStream"],
                    CanTether     = (bool)d["canTether"],
                    Duration      = (int)d["duration"],
                    EmbedUrl      = (string)d["embedUrl"],
                    Icon          = (string)d["icon"],
                    IsClean       = (bool)d["isClean"],
                    IsExplicit    = (bool)d["isExplicit"],
                    IsCompilation = d.GetOptionalKey <bool>("isCompilation"),
                    Key           = (string)d["key"],
                    Length        = (int)d["length"],
                    Name          = (string)d["name"],
                    Price         = (string)d["price"],
                    ReleaseDate   = DateTime.Parse((string)d["releaseDate"]),
                    ShortUrl      = (string)d["shortUrl"],
                    Type          = (string)d["type"],
                    Url           = (string)d["url"]
                };
                object keys;
                if (d.TryGetValue("trackKeys", out keys))
                {
                    album.TrackKeys = new List <object>((object[])keys).Cast <string>().ToList();
                }
                album.BigIcon = d.GetOptionalKey <string>("bigIcon");

                rdioObject = album;
                break;

            case RdioType.CollectionArtist:
            case RdioType.Artist:
                var artist = new RdioArtist
                {
                    BaseIcon   = (string)d["baseIcon"],
                    HasRadio   = (bool)d["hasRadio"],
                    Icon       = (string)d["icon"],
                    Key        = (string)d["key"],
                    Name       = (string)d["name"],
                    ShortUrl   = (string)d["shortUrl"],
                    Length     = (int)d["length"],
                    Type       = (string)d["type"],
                    Url        = (string)d["url"],
                    AlbumCount = d.GetOptionalKey <int>("albumCount")
                };

                rdioObject = artist;
                break;

            case RdioType.Playlist:
                var playlist = new RdioPlaylist
                {
                    BaseIcon    = (string)d["baseIcon"],
                    EmbedUrl    = (string)d["embedUrl"],
                    Icon        = (string)d["icon"],
                    Key         = (string)d["key"],
                    LastUpdated = (decimal)d["lastUpdated"],
                    Length      = (int)d["length"],
                    Name        = (string)d["name"],
                    Owner       = (string)d["owner"],
                    OwnerIcon   = (string)d["ownerIcon"],
                    OwnerKey    = (string)d["ownerKey"],
                    OwnerUrl    = (string)d["ownerUrl"],
                    ShortUrl    = (string)d["shortUrl"],
                    Type        = (string)d["type"],
                    Url         = (string)d["url"]
                };
                object playlistTrackKeys;
                if (d.TryGetValue("trackKeys", out playlistTrackKeys))
                {
                    playlist.TrackKeys = new List <object>((object[])playlistTrackKeys).Cast <string>().ToList();
                }
                playlist.BigIcon = d.GetOptionalKey <string>("bigIcon");

                rdioObject = playlist;
                break;

            case RdioType.Track:
                var track = new RdioTrack
                {
                    Album                = (string)d["album"],
                    AlbumArtistKey       = (string)d["albumArtistKey"],
                    AlbumArtistName      = (string)d["albumArtist"],
                    AlbumKey             = (string)d["albumKey"],
                    AlbumUrl             = (string)d["albumUrl"],
                    Artist               = (string)d["artist"],
                    ArtistKey            = (string)d["artistKey"],
                    ArtistUrl            = (string)d["artistUrl"],
                    BaseIcon             = (string)d["baseIcon"],
                    CanDownload          = (bool)d["canDownload"],
                    CanDownloadAlbumOnly = (bool)d["canDownloadAlbumOnly"],
                    CanSample            = (bool)d["canSample"],
                    CanStream            = (bool)d["canStream"],
                    CanTether            = (bool)d["canTether"],
                    Duration             = (int)d["duration"],
                    EmbedUrl             = (string)d["embedUrl"],
                    Icon            = (string)d["icon"],
                    IsClean         = (bool)d["isClean"],
                    IsExplicit      = (bool)d["isExplicit"],
                    IsOnCompilation = d.GetOptionalKey <bool>("isOnCompilation"),
                    Key             = (string)d["key"],
                    Name            = (string)d["name"],
                    Price           = (string)d["price"],
                    ShortUrl        = (string)d["shortUrl"],
                    Type            = (string)d["type"],
                    Url             = (string)d["url"]
                };
                track.PlayCount = d.GetOptionalKey <int>("playCount");
                track.BigIcon   = d.GetOptionalKey <string>("bigIcon");

                rdioObject = track;
                break;

            case RdioType.User:
                var user = new RdioUser
                {
                    BaseIcon         = (string)d["baseIcon"],
                    FirstName        = (string)d["firstName"],
                    Gender           = (string)d["gender"],
                    Icon             = (string)d["icon"],
                    Key              = (string)d["key"],
                    LastName         = (string)d["lastName"],
                    LibraryVersion   = (int)d["libraryVersion"],
                    Type             = (string)d["type"],
                    Url              = (string)d["url"],
                    DisplayName      = d.GetOptionalKey <string>("displayName"),
                    LastSongPlayed   = d.GetOptionalKey <string>("lastSongPlayed"),
                    LastSongPlayTime = d.GetOptionalKey <DateTime>("lastSongPlayTime"),
                    TrackCount       = d.GetOptionalKey <int>("trackCount"),
                    Username         = d.GetOptionalKey <string>("username")
                };

                user.IsSubscriber = d.GetOptionalKey <bool>("isSubscriber");
                user.IsUnlimited  = d.GetOptionalKey <bool>("isUnlimited");
                user.IsTrial      = d.GetOptionalKey <bool>("isTrial");

                rdioObject = user;
                break;

            default:
                break;
            }
            return(rdioObject);
        }
示例#2
0
        public static IRdioObject ConvertDictionaryToRdioObject(IDictionary <string, object> d,
                                                                RdioType type = RdioType.Unknown)
        {
            IRdioObject rdioObject = null;

            if (type == RdioType.Unknown)
            {
                type = ParseRdioType((string)d["type"]);
            }
            switch (type)
            {
            case RdioType.CollectionAlbum:
            case RdioType.Album:
                var album = new RdioAlbum
                {
                    Artist      = (string)d["artist"],
                    ArtistKey   = (string)d["artistKey"],
                    ArtistUrl   = (string)d["artistUrl"],
                    BaseIcon    = (string)d["baseIcon"],
                    CanSample   = (bool)d["canSample"],
                    CanStream   = (bool)d["canStream"],
                    CanTether   = (bool)d["canTether"],
                    Duration    = (int)d["duration"],
                    EmbedUrl    = (string)d["embedUrl"],
                    Icon        = (string)d["icon"],
                    IsClean     = (bool)d["isClean"],
                    IsExplicit  = (bool)d["isExplicit"],
                    Key         = (string)d["key"],
                    Length      = (int)d["length"],
                    Name        = (string)d["name"],
                    Price       = (string)d["price"],
                    ReleaseDate = DateTime.Parse((string)d["releaseDate"]),
                    ShortUrl    = (string)d["shortUrl"],
                    Type        = (string)d["type"],
                    Url         = (string)d["url"]
                };
                object keys;
                if (d.TryGetValue("trackKeys", out keys))
                {
                    album.TrackKeys = new List <object>((object[])keys).Cast <string>().ToList();
                }
                rdioObject = album;
                break;

            case RdioType.CollectionArtist:
            case RdioType.Artist:
                var artist = new RdioArtist
                {
                    BaseIcon = (string)d["baseIcon"],
                    HasRadio = (bool)d["hasRadio"],
                    Icon     = (string)d["icon"],
                    Key      = (string)d["key"],
                    Name     = (string)d["name"],
                    ShortUrl = (string)d["shortUrl"],
                    Length   = (int)d["length"],
                    Type     = (string)d["type"],
                    Url      = (string)d["url"]
                };
                object albumCount;
                if (d.TryGetValue("albumCount", out albumCount))
                {
                    artist.AlbumCount = (int)albumCount;
                }
                rdioObject = artist;
                break;

            case RdioType.Playlist:
                var playlist = new RdioPlaylist
                {
                    BaseIcon    = (string)d["baseIcon"],
                    EmbedUrl    = (string)d["embedUrl"],
                    Icon        = (string)d["icon"],
                    Key         = (string)d["key"],
                    LastUpdated = (decimal)d["lastUpdated"],
                    Length      = (int)d["length"],
                    Name        = (string)d["name"],
                    Owner       = (string)d["owner"],
                    OwnerIcon   = (string)d["ownerIcon"],
                    OwnerKey    = (string)d["ownerKey"],
                    OwnerUrl    = (string)d["ownerUrl"],
                    ShortUrl    = (string)d["shortUrl"],
                    Type        = (string)d["type"],
                    Url         = (string)d["url"]
                };
                rdioObject = playlist;
                break;

            case RdioType.Track:
                var track = new RdioTrack
                {
                    Album                = (string)d["album"],
                    AlbumArtistKey       = (string)d["albumArtistKey"],
                    AlbumArtistName      = (string)d["albumArtist"],
                    AlbumKey             = (string)d["albumKey"],
                    AlbumUrl             = (string)d["albumUrl"],
                    Artist               = (string)d["artist"],
                    ArtistKey            = (string)d["artistKey"],
                    ArtistUrl            = (string)d["artistUrl"],
                    BaseIcon             = (string)d["baseIcon"],
                    CanDownload          = (bool)d["canDownload"],
                    CanDownloadAlbumOnly = (bool)d["canDownloadAlbumOnly"],
                    CanSample            = (bool)d["canSample"],
                    CanStream            = (bool)d["canStream"],
                    CanTether            = (bool)d["canTether"],
                    Duration             = (int)d["duration"],
                    EmbedUrl             = (string)d["embedUrl"],
                    Icon       = (string)d["icon"],
                    IsClean    = (bool)d["isClean"],
                    IsExplicit = (bool)d["isExplicit"],
                    Key        = (string)d["key"],
                    Name       = (string)d["name"],
                    Price      = (string)d["price"],
                    ShortUrl   = (string)d["shortUrl"],
                    Type       = (string)d["type"],
                    Url        = (string)d["url"]
                };
                object playCount;
                if (d.TryGetValue("playCount", out playCount))
                {
                    track.PlayCount = (int)playCount;
                }
                rdioObject = track;
                break;

            case RdioType.User:
                var user = new RdioUser
                {
                    BaseIcon       = (string)d["baseIcon"],
                    FirstName      = (string)d["firstName"],
                    Gender         = (string)d["gender"],
                    Icon           = (string)d["icon"],
                    Key            = (string)d["key"],
                    LastName       = (string)d["lastName"],
                    LibraryVersion = (int)d["libraryVersion"],
                    Type           = (string)d["type"],
                    Url            = (string)d["url"]
                };
                object displayName, lastSongPlayed, lastSongPlayTime, trackCount, username;
                if (d.TryGetValue("displayName", out displayName))
                {
                    user.DisplayName = (string)displayName;
                }
                if (d.TryGetValue("lastSongPlayed", out lastSongPlayed))
                {
                    user.LastSongPlayed = (string)lastSongPlayed;
                }
                if (d.TryGetValue("lastSongPlayTime", out lastSongPlayTime))
                {
                    user.LastSongPlayTime = (DateTime)lastSongPlayTime;
                }
                if (d.TryGetValue("trackCount", out trackCount))
                {
                    user.TrackCount = (int)trackCount;
                }
                if (d.TryGetValue("username", out username))
                {
                    user.Username = (string)username;
                }
                rdioObject = user;
                break;

            default:
                break;
            }
            return(rdioObject);
        }
示例#3
0
        public static IRdioObject ConvertDictionaryToRdioObject(IDictionary<string, object> d,
            RdioType type = RdioType.Unknown)
        {
            IRdioObject rdioObject = null;
            if (type == RdioType.Unknown) type = ParseRdioType((string) d["type"]);
            switch (type)
            {
                case RdioType.CollectionAlbum:
                case RdioType.Album:
                    var album = new RdioAlbum
                    {
                        Artist = (string)d["artist"],
                        ArtistKey = (string)d["artistKey"],
                        ArtistUrl = (string)d["artistUrl"],
                        BaseIcon = (string)d["baseIcon"],
                        CanSample = (bool)d["canSample"],
                        CanStream = (bool)d["canStream"],
                        CanTether = (bool)d["canTether"],
                        Duration = (int)d["duration"],
                        EmbedUrl = (string)d["embedUrl"],
                        Icon = (string)d["icon"],
                        IsClean = (bool)d["isClean"],
                        IsExplicit = (bool)d["isExplicit"],
                        IsCompilation = d.GetOptionalKey<bool>("isCompilation"),
                        Key = (string)d["key"],
                        Length = (int)d["length"],
                        Name = (string)d["name"],
                        Price = (string)d["price"],
                        ReleaseDate = DateTime.Parse((string)d["releaseDate"]),
                        ShortUrl = (string)d["shortUrl"],
                        Type = (string)d["type"],
                        Url = (string)d["url"]
                    };
                    object keys;
                    if (d.TryGetValue("trackKeys", out keys))
                        album.TrackKeys = new List<object>((object[])keys).Cast<string>().ToList();
                    album.BigIcon = d.GetOptionalKey<string>("bigIcon");

                    rdioObject = album;
                    break;
                case RdioType.CollectionArtist:
                case RdioType.Artist:
                    var artist = new RdioArtist
                    {
                        BaseIcon = (string)d["baseIcon"],
                        HasRadio = (bool)d["hasRadio"],
                        Icon = (string)d["icon"],
                        Key = (string)d["key"],
                        Name = (string)d["name"],
                        ShortUrl = (string)d["shortUrl"],
                        Length = (int)d["length"],
                        Type = (string)d["type"],
                        Url = (string)d["url"],
                        AlbumCount = d.GetOptionalKey<int>("albumCount")
                    };

                    rdioObject = artist;
                    break;
                case RdioType.Playlist:
                    var playlist = new RdioPlaylist
                    {
                        BaseIcon = (string)d["baseIcon"],
                        EmbedUrl = (string)d["embedUrl"],
                        Icon = (string)d["icon"],
                        Key = (string)d["key"],
                        LastUpdated = (decimal)d["lastUpdated"],
                        Length = (int)d["length"],
                        Name = (string)d["name"],
                        Owner = (string)d["owner"],
                        OwnerIcon = (string)d["ownerIcon"],
                        OwnerKey = (string)d["ownerKey"],
                        OwnerUrl = (string)d["ownerUrl"],
                        ShortUrl = (string)d["shortUrl"],
                        Type = (string)d["type"],
                        Url = (string)d["url"]
                    };
                    object playlistTrackKeys;
                    if (d.TryGetValue("trackKeys", out playlistTrackKeys))
                        playlist.TrackKeys = new List<object>((object[])playlistTrackKeys).Cast<string>().ToList();
                    playlist.BigIcon = d.GetOptionalKey<string>("bigIcon");

                    rdioObject = playlist;
                    break;
                case RdioType.Track:
                    var track = new RdioTrack
                    {
                        Album = (string)d["album"],
                        AlbumArtistKey = (string)d["albumArtistKey"],
                        AlbumArtistName = (string)d["albumArtist"],
                        AlbumKey = (string)d["albumKey"],
                        AlbumUrl = (string)d["albumUrl"],
                        Artist = (string)d["artist"],
                        ArtistKey = (string)d["artistKey"],
                        ArtistUrl = (string)d["artistUrl"],
                        BaseIcon = (string)d["baseIcon"],
                        CanDownload = (bool)d["canDownload"],
                        CanDownloadAlbumOnly = (bool)d["canDownloadAlbumOnly"],
                        CanSample = (bool)d["canSample"],
                        CanStream = (bool)d["canStream"],
                        CanTether = (bool)d["canTether"],
                        Duration = (int)d["duration"],
                        EmbedUrl = (string)d["embedUrl"],
                        Icon = (string)d["icon"],
                        IsClean = (bool)d["isClean"],
                        IsExplicit = (bool)d["isExplicit"],
                        IsOnCompilation = d.GetOptionalKey<bool>("isOnCompilation"),
                        Key = (string)d["key"],
                        Name = (string)d["name"],
                        Price = (string)d["price"],
                        ShortUrl = (string)d["shortUrl"],
                        Type = (string)d["type"],
                        Url = (string)d["url"]
                    };
                    track.PlayCount = d.GetOptionalKey<int>("playCount");
                    track.BigIcon = d.GetOptionalKey<string>("bigIcon");

                    rdioObject = track;
                    break;
                case RdioType.User:
                    var user = new RdioUser
                    {
                        BaseIcon = (string)d["baseIcon"],
                        FirstName = (string)d["firstName"],
                        Gender = (string)d["gender"],
                        Icon = (string)d["icon"],
                        Key = (string)d["key"],
                        LastName = (string)d["lastName"],
                        LibraryVersion = (int)d["libraryVersion"],
                        Type = (string)d["type"],
                        Url = (string)d["url"],
                        DisplayName = d.GetOptionalKey<string>("displayName"),
                        LastSongPlayed = d.GetOptionalKey<string>("lastSongPlayed"),
                        LastSongPlayTime = d.GetOptionalKey<DateTime>("lastSongPlayTime"),
                        TrackCount = d.GetOptionalKey<int>("trackCount"),
                        Username = d.GetOptionalKey<string>("username")
                    };

                    user.IsSubscriber = d.GetOptionalKey<bool>("isSubscriber");
                    user.IsUnlimited = d.GetOptionalKey<bool>("isUnlimited");
                    user.IsTrial = d.GetOptionalKey<bool>("isTrial");

                    rdioObject = user;
                    break;
                default:
                    break;
            }
            return rdioObject;
        }