コード例 #1
0
 public static void SetHttpClientMaxResponseContentBufferSize(this EightTracksSession session, int bufferSize)
 {
     if ((_eightTracksSessionHttpClientField != null) && (_httpClientMaxResponseContentBufferSizeProperty != null))
     {
         var httpClient = _eightTracksSessionHttpClientField.GetValue(session);
         if (httpClient != null)
         {
             _httpClientMaxResponseContentBufferSizeProperty.SetValue(httpClient, bufferSize, null);
         }
     }
 }
コード例 #2
0
        private void GetTags(int page = 1)
        {
            Task.Factory.StartNew(() =>
            {
                using (LoadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                    {
                        session.SetHttpClientMaxResponseContentBufferSize(OneMegaByte);
                        var response = session.Query <Tags>().Execute(
                            page: page);

                        if (response != null)
                        {
                            if (!response.NextPage.IsNull)
                            {
                                _nextTagPage = response.NextPage.Number;
                            }
                            else
                            {
                                _nextTagPage = null;
                            }

                            if (!response.PreviousPage.IsNull)
                            {
                                _previousTagPage = response.PreviousPage.Number;
                            }
                            else
                            {
                                _previousTagPage = null;
                            }

                            return(response.Tags);
                        }
                    }
                }

                return(null);
            })
            .ContinueWith(t =>
            {
                _tags.Clear();

                foreach (var tag in t.Result)
                {
                    _tags.Add(tag);
                }

                RefreshCommands();
            }, _ui);
        }
コード例 #3
0
        private void GetMixes(int page = 1, string filter = null)
        {
            Task.Factory.StartNew(() =>
            {
                using (LoadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                    {
                        session.SetHttpClientMaxResponseContentBufferSize(OneMegaByte);
                        var response = session.Query <Mixes>().GetMix(
                            sorting: global::EightTracks.Mixes.Sort.Popular,
                            filter: filter,
                            page: page,
                            resultsPerPage: 25);

                        if (response != null)
                        {
                            _currentMixPage   = response.Page;
                            _numberOfMixPages = response.TotalPages;

                            return(response.Mixes);
                        }
                    }
                }

                return(null);
            })
            .ContinueWith(t =>
            {
                RefreshCommands();

                if (t.Exception != null)
                {
                    ToastService.Show(t.Exception.Message);
                    Logger.Log(t.Exception.ToString(), Category.Exception, Priority.Medium);
                    return;
                }

                if (t.Result != null)
                {
                    _mixes.Clear();

                    foreach (var mix in t.Result)
                    {
                        _mixes.Add(mix);
                    }
                }
            }, _ui);
        }
コード例 #4
0
        private Task <Mix> GetFavoriteMix(EightTracksMixTrackStreamData streamData)
        {
            return(Task.Factory
                   .StartNew(state =>
            {
                var d = (EightTracksMixTrackStreamData)state;
                using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                {
                    return session.Query <Mixes>().GetMix(d.MixId);
                }
            }, streamData)
                   .ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    ToastService.Show("Error while getting 8track mix");
                }
                else
                {
                    var errorNodes = task.Result.Errors as XmlNode[];

                    if (errorNodes != null && errorNodes.Any())
                    {
                        var errorNode = errorNodes.FirstOrDefault();
                        if (errorNode != null && (errorNode.Name != "nil" && errorNode.Value != "true"))
                        {
                            var errorText = errorNode.InnerText;
                            ToastService.Show(errorText);
                        }
                        else
                        {
                            return task.Result.Mix;
                        }
                    }
                    else if (task.Result.Mix != null)
                    {
                        return task.Result.Mix;
                    }
                    else
                    {
                        ToastService.Show("Unable to find 8tracks mix");
                    }
                }

                return null;
            }));
        }
コード例 #5
0
        private IEnumerable <string> GetMixesByTag(string tag)
        {
            try
            {
                using (var session = new EightTracksSession(ApiKey))
                {
                    TagsResponse response = session.Query <Tags>().Execute(1, tag);
                    return(response.Tags.Select(t => t.Name));
                }
            }
            catch (Exception e)
            {
                Logger.Log("Error while getting 8tracks mixes. " + e.Message, Category.Exception, Priority.Medium);
            }

            return(new string[0]);
        }
コード例 #6
0
        private void SearchForMixes(string text, string type)
        {
            _tagFilterList.Clear();

            if (type == "Tag")
            {
                _tagFilterList.Add(text);
            }

            var ui = TaskScheduler.FromCurrentSynchronizationContext();
            Task.Factory.StartNew(() =>
            {
                using (LoadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                    {
                        session.SetHttpClientMaxResponseContentBufferSize(OneMegaByte);
                        if (type == "Tag")
                        {
                            var response = session.Query<Mixes>().GetMix(tag: text);
                            _currentPage = response.Page;
                            _numberOfPages = response.TotalPages;
                            return response.Mixes;
                        }
                        else
                        {
                            var response = session.Query<Mixes>().GetMix(filter: text);
                            _currentPage = response.Page;
                            _numberOfPages = response.TotalPages;
                            return response.Mixes;
                        }
                    }
                }
            })
            .ContinueWith(t =>
            {
                GoToNextPageCommand.NotifyCanExecuteChanged();
                GoToPreviousPageCommand.NotifyCanExecuteChanged();

                _tags.Clear();

                foreach (var mix in t.Result)
                {
                    foreach (var tag in mix.TagListCacheAsArray)
                    {
                        var value = tag.Trim();
                        if (!_tags.Contains(value) && !_tagFilterList.Contains(value))
                        {
                            _tags.Add(value);
                        }
                    }
                }

                _mixes.Clear();
                foreach (var mix in t.Result)
                {
                    _mixes.Add(mix);
                }
            }, ui);
        }
コード例 #7
0
        private void SearchForRecentMixes()
        {
            var ui = TaskScheduler.FromCurrentSynchronizationContext();
            Task.Factory.StartNew(() =>
            {
                using (LoadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                    {
                        session.SetHttpClientMaxResponseContentBufferSize(OneMegaByte);
                        var response = session.Query<Mixes>().GetMix(
                            sorting: global::EightTracks.Mixes.Sort.Random,
                            resultsPerPage: 25);
                        _currentPage = response.Page;
                        _numberOfPages = response.TotalPages;
                        return response.Mixes;
                    }
                }
            })
            .ContinueWith(t =>
            {
                GoToNextPageCommand.NotifyCanExecuteChanged();
                GoToPreviousPageCommand.NotifyCanExecuteChanged();

                if (t.Exception != null)
                {
                    Logger.Log("Error while fetching mixes: " + t.Exception, Category.Exception, Priority.Medium);
                    ToastService.Show("An error occurred while getting mixes");
                }
                else
                {
                    _tags.Clear();

                    if (t.Result == null)
                    {
                        return;
                    }

                    foreach (var mix in t.Result)
                    {
                        foreach (var tag in mix.TagListCacheAsArray)
                        {
                            var value = tag.Trim();
                            if (!_tags.Contains(value) && !_tagFilterList.Contains(value))
                            {
                                _tags.Add(value);
                            }
                        }
                    }

                    if (!t.Result.Any())
                    {
                        ToastService.Show("No results found");
                        return;
                    }

                    _mixes.Clear();

                    foreach (var mix in t.Result)
                    {
                        _mixes.Add(mix);
                    }
                }
            }, ui);
        }
コード例 #8
0
        private IEnumerable<string> GetMixesByTag(string tag)
        {
            try
            {
                using (var session = new EightTracksSession(ApiKey))
                {
                    TagsResponse response = session.Query<Tags>().Execute(1, tag);
                    return response.Tags.Select(t => t.Name);
                }
            }
            catch (Exception e)
            {
                Logger.Log("Error while getting 8tracks mixes. " + e.Message, Category.Exception, Priority.Medium);
            }

            return new string[0];
        }
コード例 #9
0
        private void SearchForMixes(string text, string type)
        {
            _tagFilterList.Clear();

            if (type == "Tag")
            {
                _tagFilterList.Add(text);
            }

            var ui = TaskScheduler.FromCurrentSynchronizationContext();

            Task.Factory.StartNew(() =>
            {
                using (LoadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                    {
                        session.SetHttpClientMaxResponseContentBufferSize(OneMegaByte);
                        if (type == "Tag")
                        {
                            var response   = session.Query <Mixes>().GetMix(tag: text);
                            _currentPage   = response.Page;
                            _numberOfPages = response.TotalPages;
                            return(response.Mixes);
                        }
                        else
                        {
                            var response   = session.Query <Mixes>().GetMix(filter: text);
                            _currentPage   = response.Page;
                            _numberOfPages = response.TotalPages;
                            return(response.Mixes);
                        }
                    }
                }
            })
            .ContinueWith(t =>
            {
                GoToNextPageCommand.NotifyCanExecuteChanged();
                GoToPreviousPageCommand.NotifyCanExecuteChanged();

                _tags.Clear();

                foreach (var mix in t.Result)
                {
                    foreach (var tag in mix.TagListCacheAsArray)
                    {
                        var value = tag.Trim();
                        if (!_tags.Contains(value) && !_tagFilterList.Contains(value))
                        {
                            _tags.Add(value);
                        }
                    }
                }

                _mixes.Clear();
                foreach (var mix in t.Result)
                {
                    _mixes.Add(mix);
                }
            }, ui);
        }
コード例 #10
0
        private void SearchForRecentMixes()
        {
            var ui = TaskScheduler.FromCurrentSynchronizationContext();

            Task.Factory.StartNew(() =>
            {
                using (LoadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                    {
                        session.SetHttpClientMaxResponseContentBufferSize(OneMegaByte);
                        var response = session.Query <Mixes>().GetMix(
                            sorting: global::EightTracks.Mixes.Sort.Random,
                            resultsPerPage: 25);
                        _currentPage   = response.Page;
                        _numberOfPages = response.TotalPages;
                        return(response.Mixes);
                    }
                }
            })
            .ContinueWith(t =>
            {
                GoToNextPageCommand.NotifyCanExecuteChanged();
                GoToPreviousPageCommand.NotifyCanExecuteChanged();

                if (t.Exception != null)
                {
                    Logger.Log("Error while fetching mixes: " + t.Exception, Category.Exception, Priority.Medium);
                    ToastService.Show("An error occurred while getting mixes");
                }
                else
                {
                    _tags.Clear();

                    if (t.Result == null)
                    {
                        return;
                    }

                    foreach (var mix in t.Result)
                    {
                        foreach (var tag in mix.TagListCacheAsArray)
                        {
                            var value = tag.Trim();
                            if (!_tags.Contains(value) && !_tagFilterList.Contains(value))
                            {
                                _tags.Add(value);
                            }
                        }
                    }

                    if (!t.Result.Any())
                    {
                        ToastService.Show("No results found");
                        return;
                    }

                    _mixes.Clear();

                    foreach (var mix in t.Result)
                    {
                        _mixes.Add(mix);
                    }
                }
            }, ui);
        }
コード例 #11
0
        public bool MoveNext(CancellationToken token)
        {
            using (var session = new EightTracksSession(EightTracksModule.ApiKey))
            {
                if (_playToken == null)
                {
                    _playToken = session.Query <Play>().GetPlayToken();
                }

                if (_currentPlayResponse == null)
                {
                    _currentPlayResponse = session.Query <Play>().Execute(_playToken.PlayToken, _currentMix.ID);
                }
                else if (!_currentPlayResponse.Set.AtEnd)
                {
                    _currentPlayResponse = session.Query <Play>().Next(_playToken.PlayToken, _currentMix.ID);
                }

                if (_currentPlayResponse.Errors != null)
                {
                    var errorNodes = _currentPlayResponse.Errors as XmlNode[];

                    if (errorNodes != null && errorNodes.Any())
                    {
                        var errorNode = errorNodes.FirstOrDefault();
                        if (errorNode != null && (errorNode.Name != "nil" && errorNode.Value != "true"))
                        {
                            var errorText = errorNode.InnerText;
                            _toastService.Show(errorText);
                        }
                    }
                }

                if (MoveToNextSimilarMixAtEnd)
                {
                    if (_currentPlayResponse.Set == null || _currentPlayResponse.Set.AtEnd)
                    {
                        if (_currentMix != null)
                        {
                            var nextMixResponse = session.Query <Mixes>().GetNextMix(_playToken.PlayToken, _currentMix.ID);
                            _currentMix = nextMixResponse.NextMix;

                            if (_currentMix != null)
                            {
                                Description = _currentMix.Name;

                                _currentPlayResponse = session.Query <Play>().Execute(_playToken.PlayToken,
                                                                                      _currentMix.ID);
                            }
                        }

                        // TODO : Add user-notification and logging if there is any errors
                    }
                }

                if (_currentPlayResponse.Set == null)
                {
                    return(false);
                }
            }

            return(_currentPlayResponse != null && !_currentPlayResponse.Set.AtEnd);
        }
コード例 #12
0
        public bool MoveNext(CancellationToken token)
        {
            using (var session = new EightTracksSession(EightTracksModule.ApiKey))
            {
                if (_playToken == null)
                {
                    _playToken = session.Query<Play>().GetPlayToken();
                }

                if (_currentPlayResponse == null)
                {
                    _currentPlayResponse = session.Query<Play>().Execute(_playToken.PlayToken, _currentMix.ID);
                }
                else if (!_currentPlayResponse.Set.AtEnd)
                {
                    _currentPlayResponse = session.Query<Play>().Next(_playToken.PlayToken, _currentMix.ID);
                }

                if (_currentPlayResponse.Errors != null)
                {
                    var errorNodes = _currentPlayResponse.Errors as XmlNode[];

                    if (errorNodes != null && errorNodes.Any())
                    {
                        var errorNode = errorNodes.FirstOrDefault();
                        if (errorNode != null && (errorNode.Name != "nil" && errorNode.Value != "true"))
                        {
                            var errorText = errorNode.InnerText;
                            _toastService.Show(errorText);
                        }
                    }
                }

                if (MoveToNextSimilarMixAtEnd)
                {
                    if (_currentPlayResponse.Set == null || _currentPlayResponse.Set.AtEnd)
                    {
                        if (_currentMix != null)
                        {
                            var nextMixResponse = session.Query<Mixes>().GetNextMix(_playToken.PlayToken, _currentMix.ID);
                            _currentMix = nextMixResponse.NextMix;

                            if (_currentMix != null)
                            {
                                Description = _currentMix.Name;

                                _currentPlayResponse = session.Query<Play>().Execute(_playToken.PlayToken,
                                                                                     _currentMix.ID);
                            }
                        }

                        // TODO : Add user-notification and logging if there is any errors
                    }
                }

                if (_currentPlayResponse.Set == null)
                {
                    return false;
                }
            }

            return _currentPlayResponse != null && !_currentPlayResponse.Set.AtEnd;
        }
コード例 #13
0
        protected virtual void SearchForMixes(Mixes.Sort sortType, int page = 1)
        {
            Task.Factory.StartNew(() =>
            {
                using (LoadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EightTracksSession(EightTracksModule.ApiKey))
                    {
                        session.SetHttpClientMaxResponseContentBufferSize(OneMegaByte);
                        var response = session.Query <Mixes>().GetMix(
                            sorting: sortType,
                            filter: String.Join("+", TagFilterList),
                            page: page,
                            resultsPerPage: 25);

                        if (response != null)
                        {
                            _currentPage   = response.Page;
                            _numberOfPages = response.TotalPages;
                            return(response.Mixes);
                        }
                    }
                }

                return(null);
            })
            .ContinueWith(t =>
            {
                GoToNextPageCommand.NotifyCanExecuteChanged();
                GoToPreviousPageCommand.NotifyCanExecuteChanged();

                if (t.Exception != null)
                {
                    ToastService.Show(t.Exception.Message);
                    Logger.Log(t.Exception.ToString(), Category.Exception, Priority.Medium);
                    return;
                }

                if (t.Result != null)
                {
                    _tags.Clear();

                    foreach (var mix in t.Result)
                    {
                        foreach (var tag in mix.TagListCacheAsArray)
                        {
                            var value = tag.Trim();
                            if (!_tags.Contains(value) && !_tagFilterList.Contains(value))
                            {
                                _tags.Add(value);
                            }
                        }
                    }

                    if (!t.Result.Any() && SortType != global::EightTracks.Mixes.Sort.Random)
                    {
                        ToastService.Show("No results found");
                        return;
                    }

                    _mixes.Clear();

                    foreach (var mix in t.Result)
                    {
                        _mixes.Add(mix);
                    }
                }
                else
                {
                    // TODO : Notify user
                }
            }, _ui);
        }