コード例 #1
0
        protected override async Task OnLoadMoreData(int offset)
        {
            if (_actionResult != null &&
                offset >= _actionResult.TotalMatches)
            {
                return;
            }

            var apiDevice  = SonosMusicApi.GetMusicApiDevice(_currentMusicServiceContainer);
            var memStorage = GetMemoryStorage(apiDevice.FriendlyName);

            ActionResult actionResult;

            using (Loader.Loading("Loading 64 items"))
            {
                if (_currentMusicServiceContainer == null)
                {
                    return;
                }
                actionResult = await apiDevice
                               .MusicApiService
                               .GetMetadata(_currentMusicServiceContainer.Token, offset, 64);
            }
            _actionResult = actionResult;
            if (actionResult.Exception != null)
            {
                return;
            }
            if (offset >= actionResult.TotalMatches)
            {
                return;
            }

            var loadedData = memStorage.Load <XElement>(_currentMusicServiceContainer.Token);

            if (loadedData != null)
            {
                loadedData.Add(actionResult.Result.Elements());
                memStorage.Save(_currentMusicServiceContainer.Token, loadedData);
            }

            var query = Query(actionResult.Result);

            foreach (var item in query)
            {
                Items.Add(item);
            }
        }
コード例 #2
0
        public override async Task <XElement> GetData(Container container, uint offset = 0)
        {
            if (_currentMusicServiceContainer == null)
            {
                throw new Exception("musicService MUST be typeof MusicServiceContainer");
            }

            var apiDevice = SonosMusicApi.GetMusicApiDevice(_currentMusicServiceContainer);


            var loadedData = GetMemoryStorage(apiDevice.FriendlyName)
                             .Load <XElement>(_currentMusicServiceContainer.Token);

            if (loadedData != null)
            {
                return(loadedData);
            }


            // we need to check credentials and ask user to enable service if we dont have the
            // service credentials
            var credentialsOk = await apiDevice
                                .MusicApiService.CheckCredentials()
                                .ConfigureAwait(false);

            if (!credentialsOk)
            {
                if (!await TryGetCredentialsFromUser(apiDevice, _currentMusicServiceContainer.Auth)
                    .ConfigureAwait(false))
                {
                    Items = new ObservableCollection <MusicServiceContainer>
                    {
                        ContainerFactory.Create(container.Id, container.ParentId,
                                                "No credentials for " + _currentMusicServiceContainer.Title,
                                                container.ClassId) as MusicServiceContainer
                    };
                    return(null);
                }
            }

            ActionResult actionResult;

            using (Loader.Loading("Loading..."))
            {
                actionResult = await apiDevice
                               .MusicApiService
                               .GetMetadata(_currentMusicServiceContainer.Token, 0, 64)
                               .ConfigureAwait(false);
            }
            Debug.WriteLine(actionResult.Result);
            _actionResult = actionResult;
            // disable cache for services.
            if (actionResult.Exception != null)
            {
                Items = new ObservableCollection <MusicServiceContainer>
                {
                    ContainerFactory.Create <MusicServiceContainer>(container.Id, container.ParentId,
                                                                    "Error getting items...", container.ClassId)
                };
            }

            GetMemoryStorage(apiDevice.FriendlyName)
            .Save(_currentMusicServiceContainer.Token, actionResult.Result);
            return(actionResult.Result);
        }