Ejemplo n.º 1
0
 public bool IsHostAccessible()
 {
     bool isAccessible = false;
     using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
     {
         using (System.Data.Objects.ObjectContext objectContext = tunesEntity.ObjectContext())
         {
             isAccessible = objectContext.DatabaseExists();
         }
     }
     return isAccessible;
 }
Ejemplo n.º 2
0
        public bool UpdateHistory(History history)
        {
            bool hasUpdated = false;
            if (history != null)
            {
                HistoryEntity entity = new HistoryEntity
                {
                    AppID = history.AppId,
                    TitelID = history.AlbumId,
                    LiedID = history.TrackId,
                    Zeit = history.PlayedAt,
                    Benutzer = history.UserName,
                    Interpret = string.Empty,
                    Titel = string.Empty,
                    Lied = string.Empty
                };

                using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
                {
                    tunesEntity.history.Add(entity);
                    hasUpdated = tunesEntity.SaveChanges() > 0;
                }
            }
            return hasUpdated;
        }
Ejemplo n.º 3
0
        public Track[] GetTrackSearchResults(Query query)
        {
            Track[] tracks = null;
            if (query != null && string.IsNullOrEmpty(query.SearchPhrase) == false)
            {
                query.PageSize = query.PageSize == 0 ? 1 : query.PageSize;

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT al.titelid AS AlbumId, a.interpretid AS ArtistId, a.interpret AS ArtistName, al.titel AS AlbumName, al.Guid, t.liedid as TrackId, t.lied AS Track");
                stringBuilder.Append(" FROM titel al");
                stringBuilder.Append(" JOIN interpreten a ON al.interpretid = a.interpretid");
                stringBuilder.Append(" JOIN lieder t ON al.titelid = t.titelid AND t.liedpfad IS NOT NULL");
                stringBuilder.Append(" WHERE MATCH (t.lied) AGAINST (?querystring IN BOOLEAN MODE)");
                stringBuilder.Append(" ORDER BY t.lied, a.interpret ,al.titel");
                stringBuilder.Append(" LIMIT ?limit OFFSET ?offset");

                using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
                {
                    if (tunesEntity != null)
                    {
                        MySqlParameter paramQueryString = new MySqlParameter("querystring", MySqlDbType.VarChar, 60);
                        paramQueryString.Direction = ParameterDirection.Input;
                        paramQueryString.Value = query.SearchPhrase;

                        MySqlParameter paramLimit = new MySqlParameter("limit", MySqlDbType.Int32, 0);
                        paramLimit.Direction = ParameterDirection.Input;
                        paramLimit.Value = query.PageSize;

                        MySqlParameter paramOffset = new MySqlParameter("offset", MySqlDbType.Int32, 0);
                        paramOffset.Direction = ParameterDirection.Input;
                        paramOffset.Value = query.PageIndex;

                        List<Track> trackCollection = null;
                        using (System.Data.Objects.ObjectContext objectContext = tunesEntity.ObjectContext())
                        {
                            var results = objectContext.ExecuteStoreQuery<SearchResult>(stringBuilder.ToString(), paramQueryString, paramLimit, paramOffset);
                            if (results != null)
                            {
                                if (trackCollection == null)
                                {
                                    trackCollection = new List<Track>();
                                }
                                foreach (var result in results)
                                {
                                    if (result != null)
                                    {
                                        trackCollection.Add(new Track
                                        {
                                            Id = result.TrackId,
                                            Name = result.Track,
                                            Album = new Album
                                            {
                                                Id = result.AlbumId,
                                                Title = result.AlbumName,
												AlbumId = string.IsNullOrEmpty(result.Guid) ? Guid.Empty : new Guid(result.Guid),
                                                Artist = new Artist
                                                {
                                                    Id = result.ArtistId,
                                                    Name = result.ArtistName
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                        }
                        if (trackCollection != null)
                        {
                            tracks = trackCollection.ToArray();
                        }
                    }
                }
            }
            return tracks;
        }
Ejemplo n.º 4
0
 public bool DeletePlaylists(IList<Playlist> playlists)
 {
     bool hasDeleted = false;
     if (playlists != null)
     {
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             foreach (var playlist in playlists)
             {
                 if (playlist != null)
                 {
                     var entryEntities = tunesEntity.playlistentries.Where(entry => entry.PlaylistId == playlist.Id);
                     if (entryEntities != null)
                     {
                         foreach (var entry in entryEntities)
                         {
                             if (entry != null)
                             {
                                 tunesEntity.playlistentries.Remove(entry);
                             }
                         }
                     }
                     var playlistEntity = tunesEntity.playlist.Where(list => list.ListId == playlist.Id).FirstOrDefault();
                     if (playlistEntity != null)
                     {
                         tunesEntity.playlist.Remove(playlistEntity);
                     }
                 }
             }
             tunesEntity.SaveChanges();
             hasDeleted = true;
         }
     }
     return hasDeleted;
 }
Ejemplo n.º 5
0
 public bool UpdatePlaylistEntries(Playlist playlist)
 {
     bool hasUpdated = false;
     if (playlist != null && playlist.Entries != null)
     {
         List<PlaylistEntry> entries = new List<PlaylistEntry>(playlist.Entries);
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             if (tunesEntity != null)
             {
                 var entr = tunesEntity.playlistentries.Where((e) => e.PlaylistId == playlist.Id).ToList();
                 entr.ForEach((e) =>
                 {
                     if (e != null)
                     {
                         tunesEntity.playlistentries.Remove(e);
                     }
                 });
                 foreach (var e in playlist.Entries)
                 {
                     if (e != null)
                     {
                         PlaylistEntryEntity entity = new PlaylistEntryEntity
                         {
                             Guid = e.Guid,
                             LiedId = e.TrackId,
                             PlaylistId = playlist.Id,
                             Timestamp = DateTime.Now,
                             sortorder = e.SortOrder
                         };
                         tunesEntity.playlistentries.Add(entity);
                     }
                 }
                 tunesEntity.SaveChanges();
                 hasUpdated = true;
             }
         }
     }
     return hasUpdated;
 }
Ejemplo n.º 6
0
 public Playlist AppendToPlaylist(Playlist playlist)
 {
     if (playlist != null && playlist.Entries != null)
     {
         List<PlaylistEntry> entries = new List<PlaylistEntry>(playlist.Entries);
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             if (tunesEntity != null)
             {
                 int sortOrder = tunesEntity.playlistentries.Where(pe => pe.PlaylistId == playlist.Id).Count();
                 entries.ForEach((playlistEntry) =>
                     {
                         if (playlistEntry != null)
                         {
                             tunesEntity.playlistentries.Add(new PlaylistEntryEntity
                             {
                                 Guid = playlistEntry.Guid,
                                 LiedId = playlistEntry.TrackId,
                                 PlaylistId = playlist.Id,
                                 sortorder = sortOrder,
                                 Timestamp = DateTime.Now
                             });
                         }
                     });
                 tunesEntity.SaveChanges();
             }
         }
     }
     return playlist = this.GetPlaylistById(playlist.Id, playlist.UserName);
 }
Ejemplo n.º 7
0
 public Playlist InsertPlaylist(Playlist playlist)
 {
     if (playlist != null)
     {
         PlaylistEntity entity = new PlaylistEntity
         {
             ListId = playlist.Id,
             ListName = playlist.Name,
             User = playlist.UserName,
             guid = playlist.Guid.ToString(),
             Timestamp = DateTime.Now
         };
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             PlaylistEntity playlistEntity = tunesEntity.playlist.FirstOrDefault(pl => pl.ListId == playlist.Id);
             if (playlistEntity == null)
             {
                 if (tunesEntity.playlist.FirstOrDefault(
                     pl => string.Compare(pl.ListName, entity.ListName) == 0 && string.Compare(pl.User, entity.User) == 0) != null)
                 {
                     string playlistExistsExceptionMessage = string.Format(CultureInfo.InvariantCulture, SRResources.PlaylistExistsException, playlist.Name);
                     throw new PlaylistExistsException(playlistExistsExceptionMessage);
                 }
                 tunesEntity.playlist.Add(entity);
             }
             tunesEntity.SaveChanges();
             playlist = new Playlist
             {
                 Id = entity.ListId,
                 Name = entity.ListName,
                 UserName = entity.User,
                 Guid = new Guid(entity.guid)
             };
         }
     }
     return playlist;
 }