private async void AddArtist()
        {
            if (string.IsNullOrEmpty(TitleTextBox.Text))
            {
                return;
            }

            IsWorking = true;

            try
            {
                var artist = await RadioService.FindArtist(TitleTextBox.Text);

                if (artist != null)
                {
                    Artists.Add(artist);
                    TitleTextBox.Text = string.Empty;
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }

            IsWorking = false;
        }
示例#2
0
        private async void AddStation(IEnumerable <EchoArtist> artists)
        {
            var titleArtist = artists.First();

            var newStation = new RadioStation()
            {
                Artists = artists.ToList(),
                Title   = string.Join(", ", artists.Select(s => s.Name)),
            };

            Stations.Add(newStation);

            try
            {
                var artistImage = await DataService.GetArtistImage(titleArtist.Name, false);

                if (artistImage != null)
                {
                    newStation.ImageUrl = artistImage.OriginalString;
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }

            RadioService.SaveStations(Stations);
        }
示例#3
0
        static void ConfigureRadioService()
        {
            var conn = ConfigurationManager.ConnectionStrings["MusCatDbContext"].ConnectionString;

            Radio = new RadioService(new RandomSongSelector(conn));

            Radio.MakeSonglist();
        }
        /// <summary>
        /// Extract human service class description.
        /// </summary>
        /// <param name="op">Service class to parse.</param>
        /// <returns>Tuple of service class and human readble description.</returns>
        private Tuple <RadioService, String> GetRadioServiceType(String service)
        {
            RadioService serviceEnum = RadioService.Unknown;

            if (!String.IsNullOrWhiteSpace(service) && Enum.TryParse <RadioService>(service, out serviceEnum))
            {
                return(Tuple.Create <RadioService, String>(serviceEnum, Util.GetEnumDescription(serviceEnum)));
            }

            return(Tuple.Create <RadioService, String>(RadioService.Unknown, service));
        }
示例#5
0
        public async void Activate()
        {
            IsWorking = true;

            var stations = await RadioService.LoadStations();

            if (stations != null)
            {
                Stations = new ObservableCollection <RadioStation>(stations);
            }

            IsWorking = false;
        }
示例#6
0
 /// <summary>
 /// 设置播放内容为播放列表或电台
 /// </summary>
 /// <param name="source">播放来源,null代表播放列表</param>
 public void SetPlaybackSource(RadioService source)
 {
     if (radio?.Radio == source?.Radio)
         return;
     var e = new ChangedEventArgs<IPlaylist>(radio ?? (IPlaylist)PlaylistService.Instance, source ?? (IPlaylist)PlaylistService.Instance);
     if (source == null)
     {
         radio = null;
         _isPlayingRadio = false;
     }
     else
     {
         radio = source;
         _isPlayingRadio = true;
     }
     PlaybackSourceChanged?.Invoke(this, e);
     InternalPlaybackSourceChanged(_isPlayingRadio);
     SkipNext();
 }
        private void InitializeCommands()
        {
            CloseWindowCommand = new RelayCommand(() => Application.Current.MainWindow.Close());

            MinimizeWindowCommand = new RelayCommand(() => WindowState = WindowState.Minimized);

            MaximizeWindowCommand = new RelayCommand(() => WindowState = IsWindowMaximized ? WindowState.Normal : WindowState.Maximized);

            GoToPageCommand = new RelayCommand <string>(page => OnNavigateToPage(new NavigateToPageMessage()
            {
                Page = page
            }));

            GoToSettingsCommand = new RelayCommand(() =>
            {
                ShowSidebar = false;
                OnNavigateToPage(new NavigateToPageMessage()
                {
                    Page = "/Settings.SettingsView"
                });
            });

            PrevAudioCommand = new RelayCommand(AudioService.Prev);

            NextAudioCommand = new RelayCommand(AudioService.SkipNext);

            PlayPauseCommand = new RelayCommand(() =>
            {
                if (IsPlaying)
                {
                    AudioService.Pause();
                }
                else
                {
                    AudioService.Play();
                }
            });

            GoBackCommand = new RelayCommand(() =>
            {
                var frame = Application.Current.MainWindow.GetVisualDescendents().OfType <Frame>().FirstOrDefault(f => f.Name == "RootFrame");
                if (frame == null)
                {
                    return;
                }

                if (frame.CanGoBack)
                {
                    frame.GoBack();
                }

                UpdateCanGoBack();
            });

            SearchCommand = new RelayCommand <string>(query =>
            {
                if (!string.IsNullOrWhiteSpace(query))
                {
                    MessengerInstance.Send(new NavigateToPageMessage()
                    {
                        Page       = "/Search.SearchResultsView",
                        Parameters = new Dictionary <string, object>()
                        {
                            { "query", query }
                        }
                    });
                }
            });

            SearchKeyUpCommand = new RelayCommand <KeyEventArgs>(args =>
            {
                if (args.Key == Key.Enter)
                {
                    var textBox = args.Source as TextBox;
                    if (textBox != null && !string.IsNullOrWhiteSpace(textBox.Text))
                    {
                        SearchCommand.Execute(textBox.Text);
                    }
                }
            });

            RestartCommand = new RelayCommand(() =>
            {
                Process.Start(Application.ResourceAssembly.Location);
                Application.Current.Shutdown();
            });

            AddRemoveAudioCommand = new RelayCommand <VkAudio>(audio =>
            {
                audio.IsAddedByCurrentUser = !audio.IsAddedByCurrentUser;
                LikeDislikeAudio(audio);
            });

            DownloadCommand = new RelayCommand <VkAudio>(audio =>
            {
                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = new DownloadAudioView(audio);
                flyout.Show();
            });

            EditAudioCommand = new RelayCommand <VkAudio>(audio =>
            {
                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = new EditAudioView(audio);
                flyout.Show();
            });

            ShowLyricsCommand = new RelayCommand <VkAudio>(audio =>
            {
                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = new LyricsView(audio);
                flyout.Show();
            });

            CopyInfoCommand = new RelayCommand <Audio>(audio =>
            {
                if (audio == null)
                {
                    return;
                }

                try
                {
                    Clipboard.SetData(DataFormats.UnicodeText, audio.Artist + " - " + audio.Title);
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            });

            PlayAudioNextCommand = new RelayCommand <Audio>(track =>
            {
                AudioService.PlayNext(track);
            });

            AddToNowPlayingCommand = new RelayCommand <Audio>(track =>
            {
                NotificationService.Notify(MainResources.NotificationAddedToNowPlaying);
                AudioService.Playlist.Add(track);
            });

            RemoveFromNowPlayingCommand = new RelayCommand <Audio>(track =>
            {
                AudioService.Playlist.Remove(track);
            });

            ShareAudioCommand = new RelayCommand <VkAudio>(audio =>
            {
                ShowShareBar = true;

                //костыль #2
                var shareControl = Application.Current.MainWindow.GetVisualDescendent <ShareBarControl>();
                if (shareControl == null)
                {
                    return;
                }

                var shareViewModel = ((ShareViewModel)((FrameworkElement)shareControl.Content).DataContext);
                shareViewModel.Tracks.Add(audio);
            });

            SwitchUIModeCommand = new RelayCommand(() =>
            {
                if (CurrentUIMode == UIMode.Normal)
                {
                    SwitchUIMode(Settings.Instance.LastCompactMode == UIMode.CompactLandscape ? UIMode.CompactLandscape : UIMode.Compact);
                }
                else
                {
                    SwitchUIMode(UIMode.Normal);
                }
            });

            SwitchToUIModeCommand = new RelayCommand <string>(s =>
            {
                UIMode mode;
                if (Enum.TryParse(s, true, out mode))
                {
                    SwitchUIMode(mode);
                }
            });

            StartTrackRadioCommand = new RelayCommand <Audio>(track =>
            {
                RadioService.StartRadioFromSong(track.Title, track.Artist);
                MessengerInstance.Send(new NavigateToPageMessage()
                {
                    Page = "/Main.NowPlayingView"
                });
            });

            ShowArtistInfoCommand = new RelayCommand <string>(async artist =>
            {
                NotificationService.Notify(MainResources.NotificationLookingArtist);

                try
                {
                    var response = await DataService.GetArtistInfo(null, artist);
                    if (response != null)
                    {
                        MessengerInstance.Send(new NavigateToPageMessage()
                        {
                            Page       = "/Search.ArtistView",
                            Parameters = new Dictionary <string, object>()
                            {
                                { "artist", response }
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                    NotificationService.Notify(MainResources.NotificationArtistNotFound);
                }
            });

            ShowLocalSearchCommand = new RelayCommand(() =>
            {
                var frame = Application.Current.MainWindow.GetVisualDescendents().OfType <Frame>().FirstOrDefault();
                if (frame == null)
                {
                    return;
                }

                var page = (Page)frame.Content;
                if (page != null)
                {
                    var localSearchBox = page.GetVisualDescendents().OfType <LocalSearchControl>().FirstOrDefault();
                    if (localSearchBox != null)
                    {
                        localSearchBox.IsActive = true;
                    }
                }
            });

            AddToAlbumCommand = new RelayCommand <VkAudio>(track =>
            {
                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = new AddToAlbumView(track);
                flyout.Show();
            });
        }
示例#8
0
        public IAsyncAction FreshRadio(RadioService radio)
        {
            return Run(async token =>
            {
                try
                {
                    LogService.DebugWrite($"Fresh Radio Songlist {radio.Radio.ToString()}", nameof(WebApi));

                    var gettask = HttpHelper.GetAsync($"http://www.xiami.com/radio/xml/type/{(int)(radio.Radio.Type)}/id/{radio.Radio.OID}");
                    token.Register(() => gettask.Cancel());
                    var content = await gettask;
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(content);
                    radio.Clear();
                    foreach (var item in doc.DocumentElement.SelectNodes(".//track"))
                    {
                        SongModel song = SongModel.GetNew(uint.Parse(item.ElementText("song_id")));
                        song.Name = item.Element("title").InnerText;
                        if (song.Album == null)
                        {
                            AlbumModel am = AlbumModel.GetNew(uint.Parse(item.ElementText("album_id")));
                            am.Name = item.ElementText("album_name");
                            if (am.Artist == null)
                            {
                                ArtistModel ar = ArtistModel.GetNew(uint.Parse(item.ElementText("artist_id")));
                                ar.Name = item.ElementText("artist");
                                am.Artist = ar;
                            }
                            var image = item.ElementText("pic");
                            am.Art = new Uri(image.Replace("_1", "_2"));
                            am.ArtFull = new Uri(image.Replace("_1", ""));
                            song.Album = am;
                            var encry = item.ElementText("location");
                            var decry = DataApi.ParseDownloadLink(int.Parse(encry[0].ToString()), encry.Substring(1));
                            song.MediaUri = new Uri(System.Net.WebUtility.UrlDecode(decry).Replace('^', '0'));
                            song.Duration = TimeSpan.FromSeconds(double.Parse(item.ElementText("length")) * 1000 + 1);
                        }
                        radio.Enqueue(song);
                    }
                }
                catch (Exception e)
                {
                    LogService.ErrorWrite(e, nameof(WebApi));
                    throw e;
                }
            });
        }
示例#9
0
        private void InitializeCommands()
        {
            CreateStationCommand = new RelayCommand(async() =>
            {
                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = new CreateRadioStationView();
                var artists          = await flyout.ShowAsync() as IList <EchoArtist>;

                if (artists != null)
                {
                    AddStation(artists);
                }
            });

            PlayStationCommand = new RelayCommand <RadioStation>(station =>
            {
                RadioService.PlayRadio(station);
                MessengerInstance.Send(new NavigateToPageMessage()
                {
                    Page = "/Main.NowPlayingView"
                });
            });

            RemoveStationCommand = new RelayCommand <RadioStation>(station =>
            {
                Stations.Remove(station);
                RadioService.SaveStations(Stations);
            });

            EditStationCommand = new RelayCommand <RadioStation>(async station =>
            {
                var createRadioStationView     = new CreateRadioStationView();
                createRadioStationView.Artists = new ObservableCollection <EchoArtist>(station.Artists);

                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = createRadioStationView;
                var artists          = await flyout.ShowAsync() as IList <EchoArtist>;

                if (artists != null)
                {
                    var titleArtist = station.Artists.First();
                    station.Artists = artists.ToList();


                    //update image and title
                    station.Title = string.Join(", ", station.Artists.Select(s => s.Name));

                    if (station.Artists.First().Name != titleArtist.Name)
                    {
                        station.ImageUrl = null;

                        try
                        {
                            var artistImage = await DataService.GetArtistImage(station.Artists.First().Name, false);
                            if (artistImage != null)
                            {
                                station.ImageUrl = artistImage.OriginalString;
                            }
                        }
                        catch (Exception ex)
                        {
                            LoggingService.Log(ex);
                        }
                    }

                    RadioService.SaveStations(Stations);
                }
            });
        }
示例#10
0
 public RemoteControlCommandProcessor(RadioService radioService, AlarmService alarmService, GpioService gpioService)
 {
     _radioService = radioService;
     _alarmService = alarmService;
     _gpioService  = gpioService;
 }
示例#11
0
        public RadioServiceUnitTests()
        {
            _clientMock = new Mock <IMusicClient>();

            _sut = new RadioService(_clientMock.Object);
        }
示例#12
0
 public AlarmService(RadioService radioService)
 {
     _radioService = radioService;
 }
示例#13
0
        public void Start()
        {
            if (NbxJobTask == null)
            {
                NbxJobTask = Task.Run(() =>
                {
                    IPEndPoint local   = new IPEndPoint(IPAddress.Parse(Ip), 0);
                    IPEndPoint destino = new IPEndPoint(IPAddress.Parse(ServerIp), ServerPort);
                    try
                    {
                        Error = false;
                        using (UdpClient client = new UdpClient(local))
                        {
                            int count = 20;
                            Running   = true;
                            while (Running)
                            {
                                Task.Delay(100).Wait();
                                if (count-- <= 0)
                                {
                                    count = 20;
                                    if (Active)
                                    {
                                        try
                                        {
#if _NBX_NOT_SPLITTED__
                                            Byte[] msg =
                                            {
                                                (Byte)CfgService,       (Byte)RadioService, (Byte)TifxService, (Byte)PresService,
                                                (Byte)0xff,             (Byte)0xff,         (Byte)0xff,        (Byte)0xff,
                                                (Byte)(WebPort & 0xff),
                                                (Byte)(WebPort >> 8)
                                            };
                                            client.Send(msg, msg.Length, destino);
                                            NotifyChange?.Invoke(String.Format("{0}: Sending msg C:{1}, R:{2}, T:{3}, P:{4}", Ip, msg[0], msg[1], msg[2], msg[3]));
#else
                                            if (UlisesNbxItem.Mode == "Mixed")
                                            {
                                                var data = new
                                                {
                                                    Machine         = Environment.MachineName,
                                                    ServerType      = "Mixed",
                                                    GlobalMaster    = "Master",
                                                    RadioService    = RadioService.ToString(),
                                                    CfgService      = CfgService.ToString(),
                                                    PhoneService    = PhoneService.ToString(),
                                                    TifxService     = TifxService.ToString(),
                                                    PresenceService = PresService.ToString(),
                                                    WebPort,
                                                    TimeStamp = DateTime.Now
                                                };
                                                string msg = JsonConvert.SerializeObject(data);
                                                Byte[] bin = Encoding.ASCII.GetBytes(msg);
                                                client.Send(bin, bin.Length, destino);

                                                NotifyChange?.Invoke(String.Format("{0}: Sending msg {1}", Ip, msg));
                                            }
                                            else
                                            {
                                                if (NbxType == NbxTypes.Radio || NbxType == NbxTypes.Ambos)
                                                {
                                                    var data = new
                                                    {
                                                        Machine         = Environment.MachineName,
                                                        ServerType      = "Radio",
                                                        GlobalMaster    = "Master",
                                                        RadioService    = RadioService.ToString(),
                                                        CfgService      = CfgService.ToString(),
                                                        PhoneService    = PhoneService.ToString(),
                                                        TifxService     = TifxService.ToString(),
                                                        PresenceService = PresService.ToString(),
                                                        WebPort,
                                                        TimeStamp = DateTime.Now
                                                    };
                                                    string msg = JsonConvert.SerializeObject(data);
                                                    Byte[] bin = Encoding.ASCII.GetBytes(msg);
                                                    client.Send(bin, bin.Length, destino);

                                                    NotifyChange?.Invoke(String.Format("{0}: Sending msg {1}", Ip, msg));
                                                }

                                                if (NbxType == NbxTypes.Telefonia || NbxType == NbxTypes.Ambos)
                                                {
                                                    var data = new
                                                    {
                                                        Machine         = Environment.MachineName,
                                                        ServerType      = "Phone",
                                                        GlobalMaster    = "Master",
                                                        RadioService    = RadioService.ToString(),
                                                        CfgService      = CfgService.ToString(),
                                                        PhoneService    = PhoneService.ToString(),
                                                        TifxService     = TifxService.ToString(),
                                                        PresenceService = PresService.ToString(),
                                                        WebPort,
                                                        TimeStamp = DateTime.Now
                                                    };
                                                    string msg = JsonConvert.SerializeObject(data);
                                                    Byte[] bin = Encoding.ASCII.GetBytes(msg);
                                                    client.Send(bin, bin.Length, destino);

                                                    NotifyChange?.Invoke(String.Format("{0}: Sending msg {1}", Ip, msg));
                                                }
                                            }
#endif
                                        }
                                        catch (Exception x)
                                        {
                                            _log.Error($"UlisesNbx Exception", x);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Error = true;
                    }
                });
            }
        }