void INavigationAware.OnNavigatedTo(NavigationContext navigationContext) { Task.Factory.StartNew(() => { Logger.Log("Opening db-session", Category.Debug, Priority.Medium); _session = DocumentStore.OpenSession(); using (LoadingIndicatorService.EnterLoadingBlock()) { FavoriteList = new ObservableCollection <Favorite>(_session.Query <Favorite>().OrderBy(f => f.Index).ToList()); } }) .ContinueWith(task => { if (task.Exception != null) { ToastService.Show("An error occurred during fetching of your favorites"); task.Exception.Handle(e => { Logger.Log(e.ToString(), Category.Exception, Priority.Medium); return(true); }); } }); }
private void ExecuteSearch(string query) { var ui = TaskScheduler.FromCurrentSynchronizationContext(); Task .Factory .StartNew(state => { LoadingIndicatorService.Push(); return(Radio.GetTracksByName(state.ToString())); }, query) .ContinueWith(task => { if (task.Exception != null) { ToastService.Show("Error while search for " + task.AsyncState); Logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium); } else { _results.Clear(); foreach (var track in task.Result) { _results.Add(track); } } LoadingIndicatorService.Pop(); }, ui); }
public MainViewModel() { _autoCompleteList = new ObservableCollection <string>(); SearchBarLoadingIndicatorService = new LoadingIndicatorService(); NavigateBackCommand = new AutomaticCommand(ExecuteNavigateBack, CanExecuteNavigateBack); NavigateForwardCommand = new AutomaticCommand(ExecuteNavigateForward, CanExecuteNavigateForward); NavigateToHomeCommand = new AutomaticCommand(ExecuteNavigateToHome, CanExecuteNavigateToHome); NavigateToSettingsCommand = new AutomaticCommand(ExecuteNavigateToSettings, CanExecuteNavigateToSettings); SearchCommand = new AutomaticCommand <string>(ExecuteSearch, CanExecuteSearch); }
private TrackContainer GetAlbumMatchingName(object state) { var data = (Tuple <string, string>)state; using (LoadingIndicatorService.EnterLoadingBlock()) { return(Radio .GetAlbumsByArtist(data.Item1) .FirstOrDefault(a => a.Name.Equals(data.Item2, StringComparison.InvariantCultureIgnoreCase))); } }
public SpotifyWizardPage1() { InitializeComponent(); _deferredLoginTimer = new DispatcherTimer(); _deferredLoginTimer.Interval = TimeSpan.FromMilliseconds(750); _deferredLoginTimer.Tick += DeferredLoginTimerOnTick; _client = new LoginServiceClient(new InstanceContext(this)); LoadingIndicator = new LoadingIndicatorService(); DataContext = this; }
private void PresentSimilarArtists(IEnumerable <ArtistBucketItem> similarArtists) { using (LoadingIndicatorService.EnterLoadingBlock()) { _similarArtists.Clear(); foreach (var bucket in similarArtists) { _similarArtists.Add(ConvertToModel(bucket)); } } }
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); }
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); }
private IEnumerable <ArtistBucketItem> GetSimilarArtists(string artistName) { using (LoadingIndicatorService.EnterLoadingBlock()) { using (var session = new EchoNestSession(EchoNestModule.ApiKey)) { var arg = new SimilarArtistsArgument(); arg.Name = artistName; arg.Results = 50; arg.Bucket = ArtistBucket.Images | ArtistBucket.Terms; var response = session .Query <SimilarArtists>() .Execute(arg); if (response.Status.Code == ResponseCode.Success) { return(response.Artists); } } } return(new ArtistBucketItem[0]); }
void INavigationAware.OnNavigatedTo(NavigationContext navigationContext) { CurrentArtist = new ArtistModel(); CurrentArtist.Name = navigationContext.Parameters["artistName"]; // Retrieve artist information Task.Factory.StartNew(state => { var artist = (ArtistModel)state; using (LoadingIndicatorService.EnterLoadingBlock()) { using (var session = new EchoNestSession(EchoNestModule.ApiKey)) { var response = session.Query <Profile>().Execute(artist.Name, ArtistBucket.Images | ArtistBucket.YearsActive | ArtistBucket.Biographies); if (response != null && response.Status.Code == ResponseCode.Success) { var image = response.Artist.Images.FirstOrDefault(); if (image != null) { artist.ArtistInfo.Image = image.Url; } var biography = response.Artist.Biographies.OrderByDescending(b => b.Text.Length).FirstOrDefault(); if (biography != null) { artist.ArtistInfo.Biography = biography.Text; } if (response.Artist.YearsActive.Count > 0) { var @select = response.Artist.YearsActive.Select(t => t.Start + "-" + (t.End.HasValue ? t.End.Value.ToString() : string.Empty)); artist.ArtistInfo.YearsActive = string.Join(", ", @select); } } } } artist.ArtistInfo.Owner = new TrackContainerOwner(CurrentArtist.Name); }, CurrentArtist) .ContinueWith(task => { if (task.IsFaulted && task.Exception != null) { task.Exception.Handle(e => { Logger.Log(e.ToString(), Category.Exception, Priority.Medium); return(true); }); } }); // Retrieve albums Task.Factory .StartNew(state => { var artist = (ArtistModel)state; using (LoadingIndicatorService.EnterLoadingBlock()) { artist.Albums = GetAlbums(artist); } }, CurrentArtist) .ContinueWith(task => { if (task.Exception != null) { task.Exception.Handle(e => { Logger.Log(e.ToString(), Category.Exception, Priority.Medium); return(true); }); } }); }
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); }
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); }
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); }