Esempio n. 1
0
        private void TrackingStopped(DateTime stopTime)
        {
            if (distance > 0)
            {
                var trackEntity = new TrackEntity
                {
                    StartDate = startTime,
                    EndDate   = stopTime, // TODO: utc?
                    Distance  = distance
                };

                _trackService.Add(trackEntity);

                var json   = JsonConvert.SerializeObject(trackEntity);
                var intent = new Intent("TrackingStopped");
                intent.PutExtra("TrackEntity", json);

                LocalBroadcastManager.SendBroadcast(intent);
            }

            isStarted    = false;
            startTime    = default(DateTime);
            distance     = 0;
            currentModel = null;

            textViewTrackingCoordinates.Text = string.Empty;
            textViewTrackingDuration.Text    = string.Empty;
            textViewTrackingStarted.Text     = string.Empty;
            textViewTrackingDistance.Text    = string.Empty;
        }
Esempio n. 2
0
        public IActionResult PostTrack([FromBody] TrackEntity newTrack)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            return(Ok(_trackService.Add(newTrack)));
        }
Esempio n. 3
0
        public bool Update(TrackEntity track)
        {
            var trackDTO  = _mapper.Map <Track>(track);
            var opSuccess = _trackRepository.Update(trackDTO).Result;

            if (!opSuccess)
            {
                _logger.LogInformation("Failed to edit track.");
                return(opSuccess);
            }

            _logger.LogInformation("Edited track.");
            return(opSuccess);
        }
Esempio n. 4
0
        public bool Add(TrackEntity newTrack)
        {
            newTrack.ID = 0;
            var trackDTO  = _mapper.Map <Track>(newTrack);
            var opSuccess = _trackRepository.Add(trackDTO).Result;

            if (!opSuccess)
            {
                _logger.LogInformation("Failed to add new track.");
                return(opSuccess);
            }

            _logger.LogInformation("Added new track.");
            return(opSuccess);
        }
Esempio n. 5
0
        public IActionResult PutTrack([FromRoute] int id, [FromBody] TrackEntity editTrack)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != editTrack.ID)
            {
                return(BadRequest());
            }

            _trackService.Update(editTrack);

            return(NoContent());
        }
Esempio n. 6
0
 public static PlayedTrackViewModel Map(TrackEntity track, int index, List <PlaylistTrack> playlistTracks)
 {
     return(new PlayedTrackViewModel
     {
         RowKey = Guid.NewGuid().ToString(),
         PartitionKey = Guid.NewGuid().ToString(),
         Name = track.Name,
         Artist = track.Artist,
         Album = track.Album,
         AlbumArtUrl = track.AlbumArtUrl,
         Popularity = track.Popularity,
         Position = 100 - index,
         TrackLength = track.TrackLength,
         AddedBy = playlistTracks.Find(x => x.Name == track.Name && x.Artist == track.Artist)?.AddedBy
     });
 }
Esempio n. 7
0
        public TrackEntity FromBusinessEntity(Track businessEntity, AlbumEntity parent)
        {
            if (businessEntity == null || parent == null)
            {
                return(null);
            }

            TrackEntity dataEntity = new TrackEntity()
            {
                ID     = businessEntity.ID,
                Index  = businessEntity.Index,
                Length = (int)businessEntity.Length.TotalSeconds,
                Name   = businessEntity.Name,
                Album  = parent
            };

            return(dataEntity);
        }
Esempio n. 8
0
        public Track FromDataEntity(TrackEntity dataEntity, Album parent)
        {
            if (dataEntity == null || parent == null)
            {
                return(null);
            }

            Track businessEntity = new Track()
            {
                ID     = dataEntity.ID,
                Index  = dataEntity.Index,
                Length = new TimeSpan(0, 0, 0, dataEntity.Length, 0),
                Name   = dataEntity.Name,
                Album  = parent
            };

            return(businessEntity);
        }
Esempio n. 9
0
        public TrackWindow(TrackEntity entity, ProjectTrackView trackView, TaskCompletionSource <bool> tcs)
        {
            _entity = entity;

            ProjectTrackView = trackView;

            PlusColumRightCommand   = new RelayCommand(PlusColumRight);
            MinusColumnRightCommand = new RelayCommand(MinusColumnRight);
            PlusRowBottomCommand    = new RelayCommand(PlusRowBottom);
            MinusRowBottomCommand   = new RelayCommand(MinusRowBottom);

            ZoomResetCommand = new RelayCommand(ZoomReset);
            ZoomPlusCommand  = new RelayCommand(ZoomPlus);
            ZoomMinusCommand = new RelayCommand(ZoomMinus);
            EditCommand      = new RelayCommand(EditState, CheckEditState);

            SaveCommand = new RelayCommand(Save);

            RaisePropertyChanged("BlockEventNames");
        }
Esempio n. 10
0
        public void SetTrack(TrackEntity track)
        {
            if (track == null)
            {
                throw new ArgumentNullException(nameof(track));
            }

            var validationMessages = new List <string>();

            var messages = _trackEntityValidator.Validate(track);

            validationMessages.AddRange(messages);

            if (validationMessages.Any())
            {
                // TODO: Handle validation failures gracefully.
                throw new ArgumentException();
            }

            _trackRepository.SetById(track);
        }
        public async void AddTrack(TrackEntity track)
        {
            CreateTracksTableIfNotExists();

            // Create the TableOperation that inserts the customer entity.
            TableOperation insertOperation = TableOperation.Insert(track);

            var tracksTable = GetTracksCloudTable();
            // TODO Fix exception here on duplicate

            TableOperation retrieve = TableOperation.Retrieve <TrackEntity>(track.PartitionKey, track.RowKey);
            TableResult    result   = await tracksTable.ExecuteAsync(retrieve);

            if (result.Result != null)
            {
                return;
            }

            // Execute the insert operation.
            await tracksTable.ExecuteAsync(insertOperation);
        }
Esempio n. 12
0
        private Track SaveTrack(Track track, SoundCloudLiteContext context)
        {
            TrackEntity changingEntity;

            var artist = GetArtistEntityById(track.Artist.Id, context);

            if (track.Id != Guid.Empty)
            {
                changingEntity = context.Tracks.First(
                    x => x.Id == track.Id).MapToEntity(track, artist);
            }
            else
            {
                changingEntity    = new TrackEntity().MapToEntity(track, artist);
                changingEntity.Id = Guid.NewGuid();
                context.Tracks.Add(changingEntity);
            }

            var model = changingEntity.MapToModel(artist.MapToModel());

            return(model);
        }
Esempio n. 13
0
        public void GetById_ReturnsTrack_WhenTrackExists()
        {
            // Arrange
            var trackID   = 1;
            var trackName = "Master of Puppets";
            var artistID  = 1;
            var trackDTO  = new Track
            {
                ID       = trackID,
                Name     = trackName,
                ArtistID = artistID
            };

            _trackMockRepo.Setup(x => x.GetByID(trackID)).ReturnsAsync(trackDTO);

            // Act
            TrackEntity track = _trackService.GetByID(trackID);

            // Assert
            Assert.Equal(trackID, track.ID);
            Assert.Equal(trackName, track.Name);
        }
        public Mp3RecordManager(IActorRef resourceDownloader, IActorRef resourceStorer)
        {
            Receive<NewRecordMessage>(async message =>
            {
                newRecord = message;
                path = message.Artist + "\\" + message.Album + "\\" + message.Track + ".mp3";
                var pathHash = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(path));
                var rowKey = message.Album + " - " + message.Track; //BitConverter.ToString(pathHash).Replace("-", "");
                var tableClient = storageAccount.CreateCloudTableClient();
                var table = tableClient.GetTableReference(StorageTableName);
                trackEntity = new TrackEntity
                {
                    Album = message.Album,
                    AlbumArtUrl = message.AlbumImageLocation.AbsoluteUri,
                    AlbumArtDownloaded = false,
                    Artist = message.Artist,
                    Track = message.Track,
                    TrackDownloaded = false,
                    TrackUrl = message.FileLocation.AbsoluteUri,
                    PartitionKey = message.Artist,
                    RowKey = rowKey,
                    Timestamp = DateTime.UtcNow
                };
                var partitionFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal,
                    trackEntity.PartitionKey);
                var rowFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, trackEntity.RowKey);
                var finalFilter = TableQuery.CombineFilters(partitionFilter, TableOperators.And, rowFilter);
                var query = new TableQuery<TrackEntity>().Where(finalFilter);

                var entities = table.ExecuteQuery(query, new TableRequestOptions {RetryPolicy = new NoRetry()});
                if (!entities.Any())
                {
                    var insertOperation = TableOperation.Insert(trackEntity);
                    table.Execute(insertOperation);

                    if (message.AlbumImageLocation != null)
                    {
                        var albumArtDownloadedMessage =
                            await
                                resourceDownloader.Ask<AlbumArtDownloaded>(
                                    new DownloadAlbumArt(message.AlbumImageLocation));
                        trackEntity.AlbumImage = albumArtDownloadedMessage.Resource;
                    }
                    var mp3Downloaded =
                        await resourceDownloader.Ask<Mp3Downloaded>(new DownloadMp3(message.FileLocation));

                    Log.Information("Received downloaded MP3. Length: {length}, Location: {resourceUri}", mp3Downloaded.Resource.Length,
                        mp3Downloaded.ResourceUri);

                    var memoryStream = new MemoryStream();
                    memoryStream.Write(mp3Downloaded.Resource, 0, mp3Downloaded.Resource.Length);

                    var simpleFile = new SimpleFile(path, memoryStream);
                    var simpleFileAbstraction = new SimpleFileAbstraction(simpleFile);
                    var file = File.Create(simpleFileAbstraction);

                    file.Tag.Composers = new[] {newRecord.Artist};
                    file.Tag.AlbumArtists = new[] {newRecord.Artist};
                    file.Tag.Title = newRecord.Track;
                    file.Tag.Album = newRecord.Album;

                    file.Tag.Pictures = new IPicture[]
                    {
                        new Picture(trackEntity.AlbumImage)
                    };

                    file.Save();
                    var savedFile = ReadToEnd(simpleFile.Stream);
                    resourceStorer.Tell(new StoreBlobRequest(path, savedFile));

                    Log.Information("Creating record: {artist}", message.Artist);
                }
            });

            Receive<Mp3Downloaded>(message =>
            {
                Log.Information("receieved downloaded MP3. Length: {length}, Resource URI: {resourceUri}",
                    message.Resource.Length,
                    message.ResourceUri);

                var memoryStream = new MemoryStream();
                memoryStream.Write(message.Resource, 0, message.Resource.Length);

                var simpleFile = new SimpleFile(path, memoryStream);
                var simpleFileAbstraction = new SimpleFileAbstraction(simpleFile);
                var file = File.Create(simpleFileAbstraction);

                file.Tag.Composers = new[] {newRecord.Artist};
                file.Tag.AlbumArtists = new[] {newRecord.Artist};
                file.Tag.Title = newRecord.Track;
                file.Tag.Album = newRecord.Album;

                file.Tag.Pictures = new IPicture[]
                {
                    new Picture(trackEntity.AlbumImage)
                };

                file.Save();
                var savedFile = ReadToEnd(simpleFile.Stream);
                resourceStorer.Tell(new StoreBlobRequest(path, savedFile));
            });

            Receive<AlbumArtDownloaded>(message =>
            {
                // this is the Album Art Image file.
                if (newRecord.AlbumImageLocation != null &&
                    message.ResourceUri.AbsoluteUri == newRecord.AlbumImageLocation.AbsoluteUri)
                {
                    var path = newRecord.Artist + "\\" + newRecord.Album + ".jpg";
                    resourceStorer.Tell(new StoreBlobRequest(path, message.Resource));
                }
            });
        }
Esempio n. 15
0
        public static void Initialize(MediaPlayerContext context)
        {
            if (initialized)
            {
                return;
            }

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            ArtistEntity DevonPortielje = new ArtistEntity()
            {
                Name = "Devon Portielje"
            };

            ArtistEntity ConnerMolander = new ArtistEntity()
            {
                Name = "Conner Molander"
            };

            ArtistEntity DylanPhillips = new ArtistEntity()
            {
                Name = "Dylan Phillips"
            };

            ArtistEntity IsaacSymonds = new ArtistEntity()
            {
                Name = "Isaac Symonds"
            };

            ArtistEntity TylerJoseph = new ArtistEntity()
            {
                Name = "Tyler Joseph"
            };

            ArtistEntity JoshDun = new ArtistEntity()
            {
                Name = "Josh Dun"
            };

            TrackEntity ThenAgain = new TrackEntity()
            {
                Name        = "Then Again",
                Length      = 199,
                ReleaseDate = new DateTime(2019, 11, 1)
            };

            TrackEntity FavouriteBoy = new TrackEntity()
            {
                Name        = "Favourite Boy",
                Length      = 242,
                ReleaseDate = new DateTime(2019, 11, 1)
            };

            TrackEntity Jumpsuit = new TrackEntity()
            {
                Name        = "Jumpsuit",
                Length      = 239,
                ReleaseDate = new DateTime(2018, 10, 5)
            };

            TrackEntity Levitate = new TrackEntity()
            {
                Name        = "Levitate",
                Length      = 146,
                ReleaseDate = new DateTime(2018, 10, 5)
            };

            TrackEntity Morph = new TrackEntity()
            {
                Name        = "Morph",
                Length      = 259,
                ReleaseDate = new DateTime(2018, 10, 5)
            };

            AlbumEntity ABlemishInTheGreatLight = new AlbumEntity()
            {
                Name          = "A Blemish in the Great Light",
                TrackEntities = new List <TrackEntity>()
                {
                    ThenAgain, FavouriteBoy
                }
            };

            AlbumEntity Trench = new AlbumEntity()
            {
                Name          = "Trench",
                TrackEntities = new List <TrackEntity>()
                {
                    Jumpsuit, Levitate, Morph
                }
            };

            BandEntity HalfMoonRun = new BandEntity()
            {
                Name          = "Half Moon Run",
                AlbumEntities = new List <AlbumEntity>()
                {
                    ABlemishInTheGreatLight
                },
                ArtistEntities = new List <ArtistEntity>()
                {
                    DevonPortielje, ConnerMolander, DylanPhillips, IsaacSymonds
                }
            };

            BandEntity TwentyOnePilots = new BandEntity()
            {
                Name          = "twenty one pilots",
                AlbumEntities = new List <AlbumEntity>()
                {
                    Trench
                },
                ArtistEntities = new List <ArtistEntity>()
                {
                    TylerJoseph, JoshDun
                }
            };

            context.BandContextEntities.Add(HalfMoonRun);
            context.BandContextEntities.Add(TwentyOnePilots);

            context.SaveChanges();

            initialized = true;
        }
Esempio n. 16
0
 public void Add(TrackEntity entity)
 {
     _databaseService.Insert(entity);
 }
        public Mp3RecordManager(IActorRef resourceDownloader, IActorRef resourceStorer)
        {
            Receive <NewRecordMessage>(async message =>
            {
                newRecord       = message;
                path            = message.Artist + "\\" + message.Album + "\\" + message.Track + ".mp3";
                var pathHash    = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(path));
                var rowKey      = message.Album + " - " + message.Track; //BitConverter.ToString(pathHash).Replace("-", "");
                var tableClient = storageAccount.CreateCloudTableClient();
                var table       = tableClient.GetTableReference(StorageTableName);
                trackEntity     = new TrackEntity
                {
                    Album              = message.Album,
                    AlbumArtUrl        = message.AlbumImageLocation.AbsoluteUri,
                    AlbumArtDownloaded = false,
                    Artist             = message.Artist,
                    Track              = message.Track,
                    TrackDownloaded    = false,
                    TrackUrl           = message.FileLocation.AbsoluteUri,
                    PartitionKey       = message.Artist,
                    RowKey             = rowKey,
                    Timestamp          = DateTime.UtcNow
                };
                var partitionFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal,
                                                                         trackEntity.PartitionKey);
                var rowFilter   = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, trackEntity.RowKey);
                var finalFilter = TableQuery.CombineFilters(partitionFilter, TableOperators.And, rowFilter);
                var query       = new TableQuery <TrackEntity>().Where(finalFilter);


                var entities = table.ExecuteQuery(query, new TableRequestOptions {
                    RetryPolicy = new NoRetry()
                });
                if (!entities.Any())
                {
                    var insertOperation = TableOperation.Insert(trackEntity);
                    table.Execute(insertOperation);

                    if (message.AlbumImageLocation != null)
                    {
                        var albumArtDownloadedMessage =
                            await
                            resourceDownloader.Ask <AlbumArtDownloaded>(
                                new DownloadAlbumArt(message.AlbumImageLocation));
                        trackEntity.AlbumImage = albumArtDownloadedMessage.Resource;
                    }
                    var mp3Downloaded =
                        await resourceDownloader.Ask <Mp3Downloaded>(new DownloadMp3(message.FileLocation));

                    Log.Information("Received downloaded MP3. Length: {length}, Location: {resourceUri}", mp3Downloaded.Resource.Length,
                                    mp3Downloaded.ResourceUri);


                    var memoryStream = new MemoryStream();
                    memoryStream.Write(mp3Downloaded.Resource, 0, mp3Downloaded.Resource.Length);

                    var simpleFile            = new SimpleFile(path, memoryStream);
                    var simpleFileAbstraction = new SimpleFileAbstraction(simpleFile);
                    var file = File.Create(simpleFileAbstraction);

                    file.Tag.Composers    = new[] { newRecord.Artist };
                    file.Tag.AlbumArtists = new[] { newRecord.Artist };
                    file.Tag.Title        = newRecord.Track;
                    file.Tag.Album        = newRecord.Album;

                    file.Tag.Pictures = new IPicture[]
                    {
                        new Picture(trackEntity.AlbumImage)
                    };

                    file.Save();
                    var savedFile = ReadToEnd(simpleFile.Stream);
                    resourceStorer.Tell(new StoreBlobRequest(path, savedFile));

                    Log.Information("Creating record: {artist}", message.Artist);
                }
            });

            Receive <Mp3Downloaded>(message =>
            {
                Log.Information("receieved downloaded MP3. Length: {length}, Resource URI: {resourceUri}",
                                message.Resource.Length,
                                message.ResourceUri);



                var memoryStream = new MemoryStream();
                memoryStream.Write(message.Resource, 0, message.Resource.Length);

                var simpleFile            = new SimpleFile(path, memoryStream);
                var simpleFileAbstraction = new SimpleFileAbstraction(simpleFile);
                var file = File.Create(simpleFileAbstraction);

                file.Tag.Composers    = new[] { newRecord.Artist };
                file.Tag.AlbumArtists = new[] { newRecord.Artist };
                file.Tag.Title        = newRecord.Track;
                file.Tag.Album        = newRecord.Album;

                file.Tag.Pictures = new IPicture[]
                {
                    new Picture(trackEntity.AlbumImage)
                };

                file.Save();
                var savedFile = ReadToEnd(simpleFile.Stream);
                resourceStorer.Tell(new StoreBlobRequest(path, savedFile));
            });

            Receive <AlbumArtDownloaded>(message =>
            {
                // this is the Album Art Image file.
                if (newRecord.AlbumImageLocation != null &&
                    message.ResourceUri.AbsoluteUri == newRecord.AlbumImageLocation.AbsoluteUri)
                {
                    var path = newRecord.Artist + "\\" + newRecord.Album + ".jpg";
                    resourceStorer.Tell(new StoreBlobRequest(path, message.Resource));
                }
            });
        }
Esempio n. 18
0
 private void TrackingStopped(TrackEntity entity)
 {
     LoadTracks();
 }