예제 #1
0
        private Task <IList <Subtitle> > SearchSubtitlesInternal(SearchSubtitlesRequest request)
        {
            var tcs = new TaskCompletionSource <IList <Subtitle> >();

            try
            {
                var response = Proxy.SearchSubtitles(Token, new[] { request });
                VerifyResponseCode(response);

                var subtitles     = new List <Subtitle>();
                var subtitlesInfo = response.data as object[];
                if (null != subtitlesInfo)
                {
                    foreach (var infoObject in subtitlesInfo)
                    {
                        var subInfo = SimpleObjectMapper.MapToObject <SearchSubtitlesInfo>((XmlRpcStruct)infoObject);
                        subtitles.Add(BuildSubtitleObject(subInfo));
                    }
                }
                tcs.TrySetResult(subtitles);
            }
            catch (Exception ex)
            {
                tcs.TrySetException(ex);
            }

            return(tcs.Task);
        }
예제 #2
0
        public IEnumerable <UserComment> GetComments(string idsubtitle)
        {
            var response = proxy.GetComments(token, new string[] { idsubtitle });

            VerifyResponseCode(response);

            var comments       = new List <UserComment>();
            var commentsStruct = response.data as XmlRpcStruct;

            if (commentsStruct == null)
            {
                return(comments);
            }

            if (commentsStruct.ContainsKey("_" + idsubtitle))
            {
                object[] commentsList = commentsStruct["_" + idsubtitle] as object[];
                if (commentsList != null)
                {
                    foreach (XmlRpcStruct commentStruct in commentsList)
                    {
                        var comment = SimpleObjectMapper.MapToObject <CommentsData>(commentStruct);
                        comments.Add(BuildUserCommentObject(comment));
                    }
                }
            }

            return(comments);
        }
예제 #3
0
        private IList <Subtitle> SearchSubtitlesInternal(SearchSubtitlesRequest request)
        {
            var response = _proxy.SearchSubtitles(_token, new[] { request });

            VerifyResponseCode(response);

            var subtitles = new List <Subtitle>();

            var subtitlesInfo = response.data as object[];

            if (null != subtitlesInfo)
            {
                foreach (var infoObject in subtitlesInfo)
                {
                    var subInfo = SimpleObjectMapper.MapToObject <SearchSubtitlesInfo>((XmlRpcStruct)infoObject);
                    subtitles.Add(BuildSubtitleObject(subInfo));
                }
            }
            return(subtitles);
        }
예제 #4
0
        public async Task <IEnumerable <UserComment> > GetComments(string idsubtitle)
        {
            var tcs = new TaskCompletionSource <IEnumerable <UserComment> >();
            await Task.Run(() =>
            {
                try
                {
                    var response = Proxy.GetComments(Token, new[] { idsubtitle });
                    VerifyResponseCode(response);

                    var comments       = new List <UserComment>();
                    var commentsStruct = response.data as XmlRpcStruct;
                    if (commentsStruct == null)
                    {
                        tcs.TrySetResult(comments);
                        return;
                    }

                    if (commentsStruct.ContainsKey("_" + idsubtitle))
                    {
                        var commentsList = commentsStruct["_" + idsubtitle] as object[];
                        if (commentsList != null)
                        {
                            foreach (XmlRpcStruct commentStruct in commentsList)
                            {
                                var comment = SimpleObjectMapper.MapToObject <CommentsData>(commentStruct);
                                comments.Add(BuildUserCommentObject(comment));
                            }
                        }
                    }

                    tcs.TrySetResult(comments);
                }
                catch (Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            }).ConfigureAwait(false);

            return(await tcs.Task.ConfigureAwait(false));
        }
예제 #5
0
        public IEnumerable <MovieInfo> CheckMovieHash(string moviehash)
        {
            var response = proxy.CheckMovieHash(token, new string[] { moviehash });

            VerifyResponseCode(response);

            var movieInfoList = new List <MovieInfo>();

            var hashInfo = response.data as XmlRpcStruct;

            if (null != hashInfo && hashInfo.ContainsKey(moviehash))
            {
                var movieInfoArray = hashInfo[moviehash] as object[];
                foreach (XmlRpcStruct movieInfoStruct in movieInfoArray)
                {
                    var movieInfo = SimpleObjectMapper.MapToObject <CheckMovieHashInfo>(movieInfoStruct);
                    movieInfoList.Add(BuildMovieInfoObject(movieInfo));
                }
            }

            return(movieInfoList);
        }
예제 #6
0
        public async Task <IEnumerable <MovieInfo> > CheckMovieHash(string moviehash)
        {
            var tcs = new TaskCompletionSource <IEnumerable <MovieInfo> >();
            await Task.Run(() =>
            {
                try
                {
                    var response = Proxy.CheckMovieHash(Token, new[] { moviehash });
                    VerifyResponseCode(response);

                    var movieInfoList = new List <MovieInfo>();

                    var hashInfo = response.data as XmlRpcStruct;
                    if (hashInfo != null && hashInfo.ContainsKey(moviehash))
                    {
                        var movieInfoArray = hashInfo[moviehash] as object[];
                        if (movieInfoArray != null)
                        {
                            foreach (XmlRpcStruct movieInfoStruct in movieInfoArray)
                            {
                                var movieInfo = SimpleObjectMapper.MapToObject <CheckMovieHashInfo>(movieInfoStruct);
                                movieInfoList.Add(BuildMovieInfoObject(movieInfo));
                            }
                        }
                    }

                    tcs.TrySetResult(movieInfoList);
                }
                catch (Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            }).ConfigureAwait(false);

            return(await tcs.Task.ConfigureAwait(false));
        }