private void ExecutePlayArtist(string artistName)
        {
            if (string.IsNullOrEmpty(artistName))
            {
                return;
            }

            GetArtistTracksAsync(artistName)
            .ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    _logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium);
                }
                else
                {
                    if (task.Result.Any())
                    {
                        _radio.Play(task.Result.ToTrackStream(artistName));
                    }
                    else
                    {
                        _toastService.Show("Unable to find track for artist " + artistName);
                    }
                }
            });
        }
Exemple #2
0
        private void NotifyClicked(object sender, RoutedEventArgs e)
        {
            var toast = GetToastNotification();

            if (toast != null)
            {
                _toastService.Show(toast);
            }
        }
Exemple #3
0
        public void Play(ITrackStream trackStream)
        {
            _trackQueue = new ConcurrentQueue <Track>();
            _dispatcher.BeginInvoke(new Action(_trackQueuePublic.Clear));

            CurrentTrackStream = trackStream;

            try
            {
                if (_currentTokenSource != null && !_currentTokenSource.IsCancellationRequested)
                {
                    _currentTokenSource.Cancel();
                }
            }
            catch (Exception e)
            {
                _logger.Log(e.ToString(), Category.Exception, Priority.Low);
            }

            _currentTokenSource = new CancellationTokenSource();
            var tct = _currentTokenSource.Token;

            Task
            .Factory
            .StartNew(() =>
            {
                using (_loadingIndicatorService.EnterLoadingBlock())
                {
                    GetNextBatch(tct);

                    _corePlayer.Stop();

                    while (!MoveToNextTrack())
                    {
                        if (!GetNextBatch(tct))
                        {
                            break;
                        }
                    }

                    PeekToNextTrack();
                }
            }, tct)
            .ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    task.Exception.Handle(e =>
                    {
                        _toastService.Show("Error while playing track.");
                        _logger.Log(e.ToString(), Category.Exception, Priority.High);
                        return(true);
                    });
                }
            });
        }
        public void Save()
        {
            try
            {
                using (var session = _documentStore.OpenSession())
                {
                    var settings = session.Query <ApplicationSettings>().FirstOrDefault();

                    if (settings != null)
                    {
                        settings.AccentColor = CurrentAccentColor;
                        session.Store(settings);
                        session.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                _toastService.Show(new ToastData
                {
                    Message = "Error while saving general settings"
                });

                _logger.Log(e.ToString(), Category.Exception, Priority.Medium);
            }
        }
        public bool MoveNext(CancellationToken token)
        {
            if (_songQueue == null)
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    var response = session.Query <Static>().Execute(_argument);

                    if (response == null)
                    {
                        // Try desperatly once more to see if its really not possible to get a proper response
                        response = session.Query <Static>().Execute(_argument);
                    }

                    if (response == null)
                    {
                        _toastService.Show("Trouble getting customized playlist from EchoNest");
                        return(false);
                    }

                    if (response.Status.Code == ResponseCode.Success)
                    {
                        _songQueue = new Queue <SongBucketItem>(response.Songs);
                    }
                    else
                    {
                        _songQueue = new Queue <SongBucketItem>();
                    }
                }
            }

            while (_songQueue.Count > 0)
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var song = _songQueue.Dequeue();

                var queryResult = _radio.GetTracksByName(song.ArtistName + " " + song.Title).ToArray();

                if (!queryResult.Any())
                {
                    queryResult = _radio.GetTracksByName(song.ArtistName).ToArray();
                }

                _currentTracks = queryResult.Take(1).ToArray();

                if (_currentTracks.Any())
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #6
0
        private async Task OnCopyIdButtonClicked()
        {
            try
            {
                await Clipboard.SetTextAsync(Id);

                if (ToastService == null)
                {
                    ToastService = DependencyService.Get <IToastService>();
                }

                ToastService?.Show(AppResources.TransactionIdCopied, ToastPosition.Top, Application.Current.RequestedTheme.ToString());
            }
            catch (Exception)
            {
                await Application.Current.MainPage.DisplayAlert(AppResources.Error, AppResources.CopyError, AppResources.AcceptButton);
            }
        }
 /// <summary>
 /// Shows the toast message with specify state.
 /// </summary>
 /// <param name="toastService">The toast service.</param>
 /// <param name="message">The message to show.</param>
 /// <param name="title">The title to show. It can be <c>null</c>.</param>
 /// <param name="state">The state of toast.</param>
 /// <param name="iconClass">The icon class.</param>
 /// <param name="key">The key of container.</param>
 public static void Show(this IToastService toastService, string message, string title = default, State?state = default, string iconClass = default, string key = "Default")
 => toastService.Show(setting =>
 {
     setting.Key       = key;
     setting.State     = state;
     setting.Message   = message;
     setting.Title     = title;
     setting.IconClass = iconClass;
 });
Exemple #8
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            // push a toast notification
            var toast = _toastService.Factory.CreateToastText02(_localizer.Get("Welcome.Text"), DateTime.Now.ToString());

            _toastService.Show(toast);

            // just a short delay to simulate some work
            await Task.Delay(100);

            deferral.Complete();
        }
Exemple #9
0
        public void Load()
        {
            try
            {
                using (var session = _documentStore.OpenSession())
                {
                    var settings = session.Query <ApplicationSettings>().FirstOrDefault();

                    if (settings != null)
                    {
                        if (settings.TrackSources != null && settings.TrackSources.Any())
                        {
                            _trackSourcePriority.AddRange(settings.TrackSources);
                        }
                        else
                        {
                            foreach (var trackSource in _trackSources)
                            {
                                _trackSourcePriority.Add(new TrackSourceConfig
                                {
                                    Name = trackSource.Metadata.Name
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _toastService.Show(new ToastData
                {
                    Message = "Error while loading general settings"
                });

                _logger.Log(e.ToString(), Category.Exception, Priority.Medium);
            }
        }
Exemple #10
0
        private void Messages_OnLinkClicked(object sender, LinkClicked e)
        {
            if (string.IsNullOrEmpty(e.Href))
            {
                return;
            }

            if (!e.Href.Contains("://"))
            {
                LoadChapter(e.Href);
            }
            else
            {
                try
                {
                    var uri = new Uri(e.Href);
                    Device.OpenUri(uri);
                }
                catch (Exception ex)
                {
                    _toastService.Show("Failed to open url: " + ex.Message);
                }
            }
        }
Exemple #11
0
 private void ExecuteTogglePlayPause()
 {
     try
     {
         if (_player.IsPlaying)
         {
             _player.Pause();
         }
         else
         {
             _player.Play();
         }
     }
     catch (Exception e)
     {
         _toastService.Show("Error while toggling play/pause");
         _logger.Log(e.ToString(), Category.Exception, Priority.Medium);
     }
 }
Exemple #12
0
        private async Task UpdatePicture(IStorageFile file)
        {
            try
            {
                SetChanging(true);

                if (_pictureType == PictureType.Cover)
                {
                    var storageFile = file as StorageFile;
                    if (storageFile != null)
                    {
                        var properties = await storageFile.Properties.GetImagePropertiesAsync();

                        if (properties != null)
                        {
                            if (properties.Width < 800 || properties.Height < 600)
                            {
                                _toastService.Show(Resources.ErrorImageTooSmall);
                                return;
                            }
                        }
                    }
                }

                using (var stream = await file.OpenAsync(FileAccessMode.Read))
                {
                    using (var actualStream = stream.AsStream())
                    {
                        var user = await SendPictureData(AuthenticationService.Current.LoggedInUserId, actualStream, file.ContentType, file.Name);

                        UpdateUserInfo(user);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            SetChanging(false);
        }
 /// <summary>
 /// Shows the success of toast message with green color.
 /// </summary>
 /// <param name="toastService">The toast service.</param>
 /// <param name="message">The message to show.</param>
 /// <param name="title">The title to show. It can be <c>null</c>.</param>
 /// <param name="iconClass">The icon class.</param>
 /// <param name="key">The key of container.</param>
 public static void ShowSuccess(this IToastService toastService, string message, string title = default, string iconClass = "check circle", string key = "Default")
 => toastService.Show(message, title, State.Success, iconClass, key);
 /// <summary>
 /// Shows the error of toast message with red color.
 /// </summary>
 /// <param name="toastService">The toast service.</param>
 /// <param name="message">The message to show.</param>
 /// <param name="title">The title to show. It can be <c>null</c>.</param>
 /// <param name="iconClass">The icon class.</param>
 /// <param name="key">The key of container.</param>
 public static void ShowError(this IToastService toastService, string message, string title = default, string iconClass = "times circle", string key = "Default")
 => toastService.Show(message, title, State.Error, iconClass, key);
        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
            Task.Factory
            .StartNew(() =>
            {
                var response = MemoryCache.Default.Get("TopHotArtists") as TopHotttResponse;

                if (response == null)
                {
                    using (_loadingIndicator.EnterLoadingBlock())
                    {
                        using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                        {
                            response = session.Query <TopHottt>().Execute(99, bucket:
                                                                          ArtistBucket.Images |
                                                                          ArtistBucket.Songs);

                            if (response != null)
                            {
                                MemoryCache
                                .Default
                                .Add("TopHotArtists", response, DateTimeOffset.Now.AddHours(6));

                                return(response);
                            }
                        }
                    }
                }

                return(response);
            })
            .ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    _logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium);
                    _toastService.Show("Unable to fetch artists");
                }
                else
                {
                    if (task.Result != null)
                    {
                        if (task.Result.Status.Code == ResponseCode.Success)
                        {
                            var artists = task.Result.Artists.Select((a, i) =>
                            {
                                string name  = a.Name;
                                string image = a.Images.Count > 0 ? a.Images[0].Url : null;
                                string song  = a.Songs.Count > 0 ? a.Songs[0].Title : null;
                                return(new HotArtistModel((i + 1), name, image, song));
                            });

                            const int numberOfObjectsPerPage = 10;
                            int numberOfObjectsTaken         = 0;
                            int count      = artists.Count();
                            int pageNumber = 0;

                            while (numberOfObjectsTaken < count)
                            {
                                IEnumerable <HotArtistModel> queryResultPage = artists
                                                                               .Skip(numberOfObjectsPerPage * pageNumber)
                                                                               .Take(numberOfObjectsPerPage).ToArray();

                                numberOfObjectsTaken += queryResultPage.Count();
                                pageNumber++;

                                _dispatcher
                                .BeginInvoke(
                                    new Action <IEnumerable <HotArtistModel> >(m => m.ForEach(model => _artists.Add(model))),
                                    DispatcherPriority.Background,
                                    queryResultPage);
                            }
                        }
                        else
                        {
                            _toastService.Show(task.Result.Status.Message);
                        }
                    }
                }
            });
        }
Exemple #16
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);
        }
 /// <summary>
 /// Show a toast notification for a given time frame.
 /// </summary>
 /// <param name="title">The title of the toast.</param>
 /// <param name="body">The message to display.</param>
 /// <param name="type">The toast type to be displayed.</param>
 /// <param name="isPersistent">If true, the toast will remain visible until the user closes it.</param>
 public static void Show(this IToastService toastService, string title, string body, Enum type, bool isPersistent)
 {
     toastService.Show(new ToastViewModel(title, body, type, isPersistent));
 }
Exemple #18
0
 public static void ShowToast(this IToastService service, string?text)
 {
     service.Show(new DefaultToastModel(text, ToastIcon.None, null, false));
 }
 public void OnLoggedIn()
 {
     _toastService.Show("Spotify: Logged in");
 }
Exemple #20
0
 public static void ShowToast(this IToastService service, string?text, IEnumerable <ToastButton>?buttons, bool stacked)
 {
     service.Show(new DefaultToastModel(text, ToastIcon.None, buttons, stacked));
 }
        public bool MoveNext(CancellationToken token)
        {
            if (string.IsNullOrEmpty(_sessionId))
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    var argument = new DynamicArgument();
                    argument.Type = "artist-radio";
                    argument.Artist.Add(_initialArtistName);
                    argument.Dmca = true;

                    var response = session.Query <Dynamic>().Execute(argument);

                    if (response.Status.Code == ResponseCode.Success)
                    {
                        _sessionId = response.SessionId;

                        var song = response
                                   .Songs
                                   .FirstOrDefault(s => s.ArtistName.Equals(_initialArtistName, StringComparison.InvariantCultureIgnoreCase));

                        if (song == null)
                        {
                            song = response.Songs.FirstOrDefault();
                        }

                        if (song != null)
                        {
                            if (token.IsCancellationRequested)
                            {
                                token.ThrowIfCancellationRequested();
                            }

                            var queryResult = _radio.GetTracksByName(_initialArtistName + " " + song.Title);

                            if (!queryResult.Any())
                            {
                                queryResult = _radio.GetTracksByName(_initialArtistName);
                            }

                            _currentTracks =
                                queryResult
                                .Where(s => s.Artist.Equals(_initialArtistName, StringComparison.InvariantCultureIgnoreCase))
                                .Take(1)
                                .ToArray();

                            if (!_currentTracks.Any())
                            {
                                _toastService.Show("Unable to find any tracks matching the query");
                                return(false);
                            }

                            return(true);
                        }
                    }
                    else
                    {
                        _toastService.Show(response.Status.Message);
                    }
                }
            }
            else
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    if (token.IsCancellationRequested)
                    {
                        token.ThrowIfCancellationRequested();
                    }

                    var argument = new DynamicArgument
                    {
                        SessionId = _sessionId
                    };

                    if (_likesCurrentTrack.HasValue)
                    {
                        if (!_likesCurrentTrack.Value)
                        {
                            argument.Ban = "artist";
                        }
                    }

                    if (_currentTrackRating.HasValue)
                    {
                        argument.Rating = Convert.ToInt32(_currentTrackRating.GetValueOrDefault(1));
                    }

                    var response = session.Query <Dynamic>().Execute(argument);

                    _likesCurrentTrack  = null;
                    _currentTrackRating = null;

                    if (response.Status.Code == ResponseCode.Success)
                    {
                        var song = response.Songs.FirstOrDefault();

                        if (song != null)
                        {
                            var queryResult = _radio.GetTracksByName(song.ArtistName + " " + song.Title);

                            if (!queryResult.Any())
                            {
                                queryResult = _radio.GetTracksByName(song.ArtistName);
                            }

                            _currentTracks =
                                queryResult
                                .Where(s => s.Artist.Equals(song.ArtistName, StringComparison.InvariantCultureIgnoreCase))
                                .Take(1)
                                .ToArray();

                            if (!_currentTracks.Any())
                            {
                                _toastService.Show("Unable to find any tracks matching the query");

                                if (response.Songs.Any())
                                {
                                    return(MoveNext(token));
                                }

                                return(false);
                            }

                            return(true);
                        }
                    }
                    else
                    {
                        _toastService.Show(response.Status.Message);
                    }
                }
            }

            return(false);
        }
Exemple #22
0
        private void ExecuteStartRadio()
        {
            Task.Factory.StartNew(() =>
            {
                SelectedMoods.ForEach(s => s.Count  = s.Count + 1);
                SelectedStyles.ForEach(s => s.Count = s.Count + 1);

                using (var session = _documentStore.OpenSession())
                {
                    foreach (var selectedStyle in SelectedStyles)
                    {
                        var styleTerm = session.Load <StyleTerm>(selectedStyle.ID);

                        if (styleTerm != null)
                        {
                            styleTerm.Count = selectedStyle.Count;
                            session.Store(styleTerm);
                        }
                    }

                    foreach (var selectedMood in SelectedMoods)
                    {
                        var styleTerm = session.Load <MoodTerm>(selectedMood.ID);

                        if (styleTerm != null)
                        {
                            styleTerm.Count = selectedMood.Count;
                            session.Store(styleTerm);
                        }
                    }

                    session.SaveChanges();
                }
            })
            .ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    _logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium);
                }
            });

            Task.Factory.StartNew(() =>
            {
                using (_loadingIndicatorService.EnterLoadingBlock())
                {
                    using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                    {
                        SearchArgument arg = new SearchArgument();
                        FillTermList(SelectedMoods, arg.Moods);
                        FillTermList(SelectedStyles, arg.Styles);
                        arg.MinFamiliarity = ArtistFamiliarity.Minimum;
                        arg.MinHotttnesss  = ArtistHotness.Minimum;

                        var response = session.Query <Search>().Execute(arg);

                        if (response == null)
                        {
                            _toastService.Show("Unable to generate playlist");
                            return;
                        }

                        if (response.Status.Code == ResponseCode.Success && response.Artists.Count > 0)
                        {
                            StaticArgument arg2 = new StaticArgument();
                            arg2.Results        = 75;
                            FillTermList(SelectedMoods, arg2.Moods);
                            FillTermList(SelectedStyles, arg2.Styles);
                            arg2.Type = "artist-radio";
                            arg2.Artist.Add(response.Artists[0].Name);
                            arg2.MinTempo             = Tempo.Minimum;
                            arg2.MinLoudness          = Loudness.Minimum;
                            arg2.MinDanceability      = Danceability.Minimum;
                            arg2.MinEnergy            = Energy.Minimum;
                            arg2.ArtistMinFamiliarity = ArtistFamiliarity.Minimum;
                            arg2.ArtistMinHotttnesss  = ArtistHotness.Minimum;
                            arg2.SongMinHotttnesss    = SongHotness.Minimum;

                            _radio.Play(new StyleTrackStream(arg2, _radio, _toastService));
                        }
                        else
                        {
                            if (response.Artists != null && response.Artists.Count == 0)
                            {
                                // TODO : Localize
                                _toastService.Show("Unable to find songs matching the current criterias");
                            }
                            else
                            {
                                _toastService.Show("EchoNest : " + response.Status.Message);
                            }
                        }
                    }
                }
            })
            .ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    _logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium);
                }
            });
        }
Exemple #23
0
 public static void ShowToast(this IToastService service, string?text, ToastIcon icon, IEnumerable <ToastButton>?buttons)
 {
     service.Show(new DefaultToastModel(text, icon, buttons, false));
 }
 /// <summary>
 /// Shows the information of toast message with blue color.
 /// </summary>
 /// <param name="toastService">The toast service.</param>
 /// <param name="message">The message to show.</param>
 /// <param name="title">The title to show. It can be <c>null</c>.</param>
 /// <param name="iconClass">The icon class.</param>
 /// <param name="key">The key of container.</param>
 public static void ShowInfo(this IToastService toastService, string message, string title = default, string iconClass = "info circle", string key = "Default")
 => toastService.Show(message, title, State.Info, iconClass, key);
 /// <summary>
 /// Shows the warning of toast message with orange color.
 /// </summary>
 /// <param name="toastService">The toast service.</param>
 /// <param name="message">The message to show.</param>
 /// <param name="title">The title to show. It can be <c>null</c>.</param>
 /// <param name="iconClass">The icon class.</param>
 /// <param name="key">The key of container.</param>
 public static void ShowWarning(this IToastService toastService, string message, string title = default, string iconClass = "attention circle", string key = "Default")
 => toastService.Show(message, title, State.Warning, iconClass, key);
Exemple #26
0
 public static void ShowToast(this IToastService service, string?text, ToastIcon icon, int displayTime)
 {
     service.Show(new DefaultToastModel(text, icon, null, false), displayTime);
 }
 /// <summary>
 /// Show a toast notification for 5 seconds.
 /// </summary>
 /// <param name="title">The title of the toast.</param>
 /// <param name="body">The message to display.</param>
 /// <param name="toastType">The toast type to be displayed.</param>
 public static void Show(this IToastService toastService, string title, string body, ToastType toastType)
 {
     toastService.Show(title, body, toastType, false);
 }
Exemple #28
0
 public static void ShowToast(this IToastService service, string?text, ToastIcon icon, IEnumerable <ToastButton>?buttons, bool stacked, int displayTime)
 {
     service.Show(new DefaultToastModel(text, icon, buttons, stacked), displayTime);
 }