示例#1
0
        /// <summary>
        /// Returns the <see cref="Entry"/> corresponding to the given id.
        /// </summary>
        public Entry GetEntry(string entryId)
        {
            if (string.IsNullOrEmpty(entryId))
            {
                throw new ArgumentException($"\"{entryId}\" is not a valid id.", nameof(entryId));
            }

            var split = entryId.Split(IdSeparator);

            if (split.Length != 2)
            {
                throw new ArgumentException($"\"{entryId}\" is not a valid id.", nameof(entryId));
            }

            var entryType = split[0];
            var tmdbId    = split[1];

            if (string.IsNullOrEmpty(entryType) || string.IsNullOrEmpty(tmdbId))
            {
                throw new ArgumentException($"\"{entryId}\" is not a valid id.", nameof(entryId));
            }

            ulong id;

            if (!ulong.TryParse(tmdbId, out id))
            {
                throw new ArgumentException($"\"{entryId}\" is not a valid id.", nameof(entryId));
            }

            // convert the tmdb object to its corresponding Entry
            Entry entry;

            switch (entryType)
            {
            case nameof(Movie):
                var tmdbMovie = _client.GetMovie(id);
                entry = ConvertToMovie(tmdbMovie);
                break;

            case nameof(Artist):
                var tmdbPerson = _client.GetPerson(id);
                entry = ConvertToArtist(tmdbPerson);
                break;

            case nameof(TvSeries):
                var tmdbTvSeries = _client.GetTvSeries(id);
                entry = ConvertToTvSeries(tmdbTvSeries);
                break;

            default:
                throw new ArgumentException(
                          $"\"{entryId}\" cannot be processed because \"{entryType}\" is not a handled entry type.",
                          nameof(entryId));
            }

            return(entry);
        }