Esempio n. 1
0
        void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
        {
            Microsoft.Practices.Prism.UriQuery q = new Microsoft.Practices.Prism.UriQuery();

            var selectedMoods = SelectedMoods.Select(t => WebUtility.HtmlEncode(t.Name)).ToArray();

            if (selectedMoods.Any())
            {
                q.Add("Moods", string.Join(",", selectedMoods));
            }

            var selectedStyles = SelectedStyles.Select(t => WebUtility.HtmlEncode(t.Name)).ToArray();

            if (selectedStyles.Any())
            {
                q.Add("Styles", string.Join(",", selectedStyles));
            }

            SetParameterValue("Tempo", q, Tempo.Minimum);
            SetParameterValue("Loudness", q, Loudness.Minimum);
            SetParameterValue("Danceability", q, Danceability.Minimum);
            SetParameterValue("Energy", q, Energy.Minimum);
            SetParameterValue("ArtistHotness", q, ArtistHotness.Minimum);
            SetParameterValue("ArtistFamiliarity", q, ArtistFamiliarity.Minimum);
            SetParameterValue("SongHotness", q, SongHotness.Minimum);

            var newUri = typeof(MainStationView).FullName + q;

            navigationContext.NavigationService.Journal.CurrentEntry.Uri = new Uri(newUri, UriKind.RelativeOrAbsolute);
        }
        private void OnSelectionChanged(object parameter)
        {
            if (SelectedStyles != null)
            {
                SelectedStyles.Clear();
            }
            else
            {
                SelectedStyles = new ObservableCollection <RFQSubHeader>();
            }

            var selectedRecords = (parameter as IList);

            if (selectedRecords == null)
            {
                return;
            }
            foreach (RFQSubHeader selectedRecord in selectedRecords)
            {
                SelectedStyles.Add(selectedRecord);
            }
        }
Esempio n. 3
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);
                }
            });
        }