예제 #1
0
        private CloudService()
        {
            _connection = new HubConnection(Keys.SERVICE_URL);
            _connection.StateChanged += Conn_StateChanged;
            _connection.Error        += Conn_Error;;

            _proxy = _connection.CreateHubProxy("PartyHub");

            // Party owner
            _proxy.On <Song>("UserRequestedSong", (song) => {
                SongRequested?.Invoke(this, song);
            });

            // both
            _proxy.On <string>("UserDisconnected", (userId) => { SomeoneDisconnected?.Invoke(this, userId); });
            _proxy.On <User>("UserAddedToParty", (user) => { SomeoneConnected?.Invoke(this, user); });

            // party user
            _proxy.On("PartyOver", () => { PartyEnded?.Invoke(this, null); });
            _proxy.On <PartyStatus>("StateUpdate", (status) => { PartyStateUpdated?.Invoke(this, status); });
            _proxy.On <Song, int>("SongUpdate", (song, index) =>
            {
                SongAdded?.Invoke(this, new SongAddedEventArgs()
                {
                    Song  = song,
                    Index = index
                });
            });
        }
예제 #2
0
        public async Task AddSongAsync(SongMetadata newMetadata)
        {
            if (!IsInitialized)
            {
                return;
            }

            if (newMetadata.IsUnknownMetadata)
            {
                return;
            }

            var item = new SongHistoryItem()
            {
                Track = newMetadata.Track, Artist = newMetadata.Artist, StationPlayedOn = newMetadata.StationPlayedOn, PlayedDate = DateTime.Now
            };

            SongAdded?.Invoke(this, new SongHistorianSongUpdatedEventArgs(item));

            await historyFileLock.WaitAsync();

            try
            {
                await FileIO.AppendTextAsync(historyFile, FormatSongHistoryItemToTSV(item));
            }
            catch (Exception ex)
            {
            }
            finally
            {
                historyFileLock.Release();
            }
        }
예제 #3
0
        private void CallMetadataAndCompleteHandlers(Action <object, int> completeHandler, int filesAdded)
        {
            Task.Run(() => ArtistAdded?.Invoke(this, EventArgs.Empty));
            Task.Run(() => AlbumAdded?.Invoke(this, EventArgs.Empty));
            Task.Run(() => SongAdded?.Invoke(this, EventArgs.Empty));

            Task.Run(() => completeHandler(this, filesAdded));
        }
예제 #4
0
 public void Handle(SongAdded evt)
 {
     _songRepository.Add(evt.UserId, evt.PlaylistId, evt.SongId, evt.Title, evt.Artist);
 }
예제 #5
0
 public void AddSong(Song song)
 {
     songs.Add(song);
     SongAdded?.Invoke(song);
 }