public bool ApplyToDatabase(ServerDataSource dataSource) { if (IsServer()) { pathUids = new List <long>(); } lock (dataSource.Lock) { int i = 0; foreach (PlaylistItem pi in IsServer() ? paths.Select(x => new PlaylistItem() { Item = x }) : paths.Select(x => new PlaylistItem() { Item = x, UID = pathUids[i++] })) { dataSource.LibraryPlaylist.PlaylistItems.Add(pi); if (IsServer()) { pathUids.Add(pi.UID); } } } return(false); }
public bool ApplyToDatabase(ServerDataSource dataSource) { bool result = false; lock (dataSource.Lock) { Playlist pl = dataSource.Playlists.FastGet(uid); if (dataSource.CurrentItem != null && items.Contains(dataSource.CurrentItem.UID)) { dataSource.CurrentItem = null; result = true; } if (dataSource.NextItemOverride != null && items.Contains(dataSource.NextItemOverride.UID)) { dataSource.NextItemOverride = null; } // This is a performance-critical area in the client, because Remove is a costly operation on INotifyCollectionChanged objects if (items.Count > 1) { HashSet <long> fastItems = new HashSet <long>(items); pl.PlaylistItems.RemoveAll(x => fastItems.Contains(x.UID)); } else if (items.Count > 0) { pl.PlaylistItems.Remove(pl.PlaylistItems.FastGet(items[0])); } } return(result); }
public bool ApplyToDatabase(ServerDataSource dataSource) { Playlist pl = dataSource.Playlists.FastGet(uid); pl.Name = name; return(false); }
public bool ApplyToDatabase(ServerDataSource dataSource) { if (IsServer()) { pathUids = new List <long>(); } lock (dataSource.Lock) { Playlist pl = dataSource.Playlists.FastGet(uid); int i = 0; int index = after < 0 ? 0 : pl.PlaylistItems.IndexOf(pl.PlaylistItems.FastGet(after)) + 1; foreach (PlaylistItem pi in IsServer() ? paths.Select(x => new PlaylistItem() { Item = x }) : paths.Select(x => new PlaylistItem() { Item = x, UID = pathUids[i++] })) { pl.PlaylistItems.Insert(index++, pi); if (IsServer()) { pathUids.Add(pi.UID); } } } return(false); }
public bool ApplyToDatabase(ServerDataSource dataSource) { // Note - we MUST change Action before the item itself, because bindings to NextItemOverride may check Action and assume // it is the current action. dataSource.NextItemOverrideAction = type; dataSource.NextItemOverride = uid < 0 ? null : dataSource.GetItem(uid, true); return(false); }
public bool ApplyToDatabase(ServerDataSource dataSource) { dataSource.CurrentItem = uid < 0 ? null : dataSource.GetItem(uid, true); if (dataSource.NextItemOverride != null && dataSource.NextItemOverride.UID == uid) { dataSource.NextItemOverride = null; } return(true); }
public bool ApplyToDatabase(ServerDataSource dataSource) { bool abortClient = false; List <long> needles; if (items.Contains(after)) { return(false); } List <PlaylistItem> foundNeedles = new List <PlaylistItem>(); needles = items.ToList(); HashSet <Playlist> relevantPlaylists = new HashSet <Playlist>(); for (int haystackIndex = 0; haystackIndex < dataSource.Playlists.Count && needles.Count > 0; haystackIndex++) { Playlist haystack = dataSource.Playlists[haystackIndex]; for (int needleIndex = 0; needleIndex < needles.Count; needleIndex++) { PlaylistItem foundNeedle; long uid = needles[needleIndex]; if (haystack.PlaylistItems.FastTryGet(uid, out foundNeedle)) { foundNeedles.Add(foundNeedle); relevantPlaylists.Add(haystack); } } } if (needles.Count != foundNeedles.Count) { // This is bad, some UIDs were not found - abort the client, but only after we re-add the items we removed abortClient = true; } HashSet <long> fastNeedles = new HashSet <long>(needles); foreach (Playlist haystack in relevantPlaylists) { haystack.PlaylistItems.RemoveAll(x => fastNeedles.Contains(x.UID)); } Playlist pl = dataSource.Playlists.FastGet(pid); int index = after < 0 ? 0 : pl.PlaylistItems.IndexOf(pl.PlaylistItems.FastGet(after)) + 1; foreach (PlaylistItem currItem in foundNeedles) { pl.PlaylistItems.Insert(index++, currItem); } if (abortClient) { throw new Exception("Could not find UIDs: " + needles.Select(x => x.ToString()).Aggregate((x, y) => x + " " + y)); } return(false); }
public bool ApplyToDatabase(ServerDataSource dataSource) { Playlist pl = IsServer() ? new Playlist() : new Playlist() { UID = uid }; dataSource.Playlists.Add(pl); if (IsServer()) { uid = pl.UID; } return(false); }
public MainForm() { HaProtoImpl.Entity = HaProtoImpl.HaMusicEntity.Server; InitializeComponent(); CreateLogger(); DataSource = new ServerDataSource(); DataSource.Playlists.Add(new Playlist()); Mover = new Mover(this); listenerThread = new Thread(new ThreadStart(ListenerMain)); player = new HaMusicPlayerManager(new NAudioPlayer(this), this, 50); player.SongChanged += player_SongChanged; player.PlayingChanged += player_PlayingChanged; RestoreState(); hashell = new HaShell(this, console); }
public bool ApplyToDatabase(ServerDataSource dataSource) { bool result = false; Playlist pl = dataSource.Playlists.FastGet(uid); if (dataSource.CurrentItem != null && pl.PlaylistItems.ContainsKey(dataSource.CurrentItem.UID)) { dataSource.CurrentItem = null; result = true; } if (dataSource.NextItemOverride != null && pl.PlaylistItems.ContainsKey(dataSource.NextItemOverride.UID)) { dataSource.NextItemOverride = null; } pl.PlaylistItems.Clear(); return(result); }
public bool ApplyToDatabase(ServerDataSource dataSource) { if (IsServer()) { pathUids = new List <long>(); } bool result = false; lock (dataSource.Lock) { if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.CurrentItem)) { dataSource.CurrentItem = null; result = true; } if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.NextItemOverride)) { dataSource.NextItemOverride = null; } dataSource.LibraryPlaylist.PlaylistItems.Clear(); if (paths == null) { return(result); } int i = 0; foreach (PlaylistItem pi in IsServer() ? paths.Select(x => new PlaylistItem() { Item = x }) : paths.Select(x => new PlaylistItem() { Item = x, UID = pathUids[i++] })) { dataSource.LibraryPlaylist.PlaylistItems.Add(pi); if (IsServer()) { pathUids.Add(pi.UID); } } } return(result); }
public bool ApplyToDatabase(ServerDataSource dataSource) { HashSet <string> paths_set = new HashSet <string>(paths); bool result = false; if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.CurrentItem) && paths_set.Contains(dataSource.CurrentItem.Item)) { dataSource.CurrentItem = null; result = true; } if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.NextItemOverride) && paths_set.Contains(dataSource.NextItemOverride.Item)) { dataSource.NextItemOverride = null; } foreach (string path in paths) { dataSource.LibraryPlaylist.PlaylistItems.RemoveAll(x => paths_set.Contains(x.Item)); } return(result); }
public bool ApplyToDatabase(ServerDataSource dataSource) { bool result = false; lock (dataSource.Lock) { if (dataSource.Playlists.Count < 2) { return(result); } Playlist pl = dataSource.Playlists.FastGet(uid); if (dataSource.CurrentItem != null && pl.PlaylistItems.ContainsKey(dataSource.CurrentItem.UID)) { dataSource.CurrentItem = null; result = true; } if (dataSource.NextItemOverride != null && pl.PlaylistItems.ContainsKey(dataSource.NextItemOverride.UID)) { dataSource.NextItemOverride = null; } dataSource.Playlists.Remove(pl); } return(result); }
public bool ApplyToDatabase(ServerDataSource dataSource) { if (IsServer()) pathUids = new List<long>(); lock (dataSource.Lock) { int i = 0; foreach (PlaylistItem pi in IsServer() ? paths.Select(x => new PlaylistItem() { Item = x }) : paths.Select(x => new PlaylistItem() { Item = x, UID = pathUids[i++] })) { dataSource.LibraryPlaylist.PlaylistItems.Add(pi); if (IsServer()) pathUids.Add(pi.UID); } } return false; }
public bool ApplyToDatabase(ServerDataSource dataSource) { lock (dataSource.Lock) { // Note - we MUST change Action before the item itself, because bindings to NextItemOverride may check Action and assume // it is the current action. dataSource.NextItemOverrideAction = type; dataSource.NextItemOverride = uid < 0 ? null : dataSource.GetItem(uid, true); } return false; }
public bool ApplyToDatabase(ServerDataSource dataSource) { throw new NotSupportedException(); }
public bool ApplyToDatabase(ServerDataSource dataSource) { bool result = false; lock (dataSource.Lock) { if (dataSource.Playlists.Count < 2) { return result; } Playlist pl = dataSource.Playlists.FastGet(uid); if (dataSource.CurrentItem != null && pl.PlaylistItems.ContainsKey(dataSource.CurrentItem.UID)) { dataSource.CurrentItem = null; result = true; } if (dataSource.NextItemOverride != null && pl.PlaylistItems.ContainsKey(dataSource.NextItemOverride.UID)) { dataSource.NextItemOverride = null; } dataSource.Playlists.Remove(pl); } return result; }
public bool ApplyToDatabase(ServerDataSource dataSource) { bool abortClient = false; List<long> needles; if (items.Contains(after)) return false; lock (dataSource.Lock) { List<PlaylistItem> foundNeedles = new List<PlaylistItem>(); needles = items.ToList(); HashSet<Playlist> relevantPlaylists = new HashSet<Playlist>(); for (int haystackIndex = 0; haystackIndex < dataSource.Playlists.Count && needles.Count > 0; haystackIndex++) { Playlist haystack = dataSource.Playlists[haystackIndex]; for (int needleIndex = 0; needleIndex < needles.Count; needleIndex++) { PlaylistItem foundNeedle; long uid = needles[needleIndex]; if (haystack.PlaylistItems.FastTryGet(uid, out foundNeedle)) { foundNeedles.Add(foundNeedle); relevantPlaylists.Add(haystack); } } } if (needles.Count != foundNeedles.Count) { // This is bad, some UIDs were not found - abort the client, but only after we re-add the items we removed abortClient = true; } HashSet<long> fastNeedles = new HashSet<long>(needles); foreach (Playlist haystack in relevantPlaylists) { haystack.PlaylistItems.RemoveAll(x => fastNeedles.Contains(x.UID)); } Playlist pl = dataSource.Playlists.FastGet(pid); int index = after < 0 ? 0 : pl.PlaylistItems.IndexOf(pl.PlaylistItems.FastGet(after)) + 1; foreach (PlaylistItem currItem in foundNeedles) { pl.PlaylistItems.Insert(index++, currItem); } } if (abortClient) { throw new Exception("Could not find UIDs: " + needles.Select(x => x.ToString()).Aggregate((x, y) => x + " " + y)); } return false; }
public bool ApplyToDatabase(ServerDataSource dataSource) { bool result = false; lock (dataSource.Lock) { Playlist pl = dataSource.Playlists.FastGet(uid); if (dataSource.CurrentItem != null && items.Contains(dataSource.CurrentItem.UID)) { dataSource.CurrentItem = null; result = true; } if (dataSource.NextItemOverride != null && items.Contains(dataSource.NextItemOverride.UID)) { dataSource.NextItemOverride = null; } // This is a performance-critical area in the client, because Remove is a costly operation on INotifyCollectionChanged objects if (items.Count > 1) { HashSet<long> fastItems = new HashSet<long>(items); pl.PlaylistItems.RemoveAll(x => fastItems.Contains(x.UID)); } else if (items.Count > 0) { pl.PlaylistItems.Remove(pl.PlaylistItems.FastGet(items[0])); } } return result; }
public bool ApplyToDatabase(ServerDataSource dataSource) { dataSource.Mode = move; return false; }
public static HaProtoImpl.HaProtoPacket ApplyPacketToDatabase(HaProtoImpl.Opcode op, byte[] data, ServerDataSource dataSource, out bool result) { HaProtoPacket packet; switch (op) { case HaProtoImpl.Opcode.ADD: packet = HaProtoImpl.ADD.Parse(data); break; case HaProtoImpl.Opcode.REMOVE: packet = HaProtoImpl.REMOVE.Parse(data); break; case HaProtoImpl.Opcode.CLEAR: packet = HaProtoImpl.CLEAR.Parse(data); break; case HaProtoImpl.Opcode.SETSONG: packet = HaProtoImpl.SETSONG.Parse(data); break; case HaProtoImpl.Opcode.SKIP: packet = HaProtoImpl.SKIP.Parse(data); break; case HaProtoImpl.Opcode.ADDPL: packet = HaProtoImpl.ADDPL.Parse(data); break; case HaProtoImpl.Opcode.DELPL: packet = HaProtoImpl.DELPL.Parse(data); break; case HaProtoImpl.Opcode.RENPL: packet = HaProtoImpl.RENPL.Parse(data); break; case HaProtoImpl.Opcode.SETMOVE: packet = HaProtoImpl.SETMOVE.Parse(data); break; case HaProtoImpl.Opcode.REORDER: packet = HaProtoImpl.REORDER.Parse(data); break; case HaProtoImpl.Opcode.INJECT: packet = HaProtoImpl.INJECT.Parse(data); break; case HaProtoImpl.Opcode.LIBRARY_ADD: packet = HaProtoImpl.LIBRARY_ADD.Parse(data); break; case HaProtoImpl.Opcode.LIBRARY_REMOVE: packet = HaProtoImpl.LIBRARY_REMOVE.Parse(data); break; case HaProtoImpl.Opcode.LIBRARY_RESET: packet = HaProtoImpl.LIBRARY_RESET.Parse(data); break; default: throw new NotImplementedException(); } result = packet.ApplyToDatabase(dataSource); return packet; }
public bool ApplyToDatabase(ServerDataSource dataSource) { lock (dataSource.Lock) { dataSource.NextItemOverride = uid < 0 ? null : dataSource.GetItem(uid); } return false; }
public bool ApplyToDatabase(ServerDataSource dataSource) { dataSource.Mode = move; return(false); }
public bool ApplyToDatabase(ServerDataSource dataSource) { HashSet<string> paths_set = new HashSet<string>(paths); bool result = false; lock (dataSource.Lock) { if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.CurrentItem) && paths_set.Contains(dataSource.CurrentItem.Item)) { dataSource.CurrentItem = null; result = true; } if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.NextItemOverride) && paths_set.Contains(dataSource.NextItemOverride.Item)) { dataSource.NextItemOverride = null; } foreach (string path in paths) { dataSource.LibraryPlaylist.PlaylistItems.RemoveAll(x => paths_set.Contains(x.Item)); } } return result; }
public bool ApplyToDatabase(ServerDataSource dataSource) { if (IsServer()) pathUids = new List<long>(); bool result = false; lock (dataSource.Lock) { if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.CurrentItem)) { dataSource.CurrentItem = null; result = true; } if (dataSource.LibraryPlaylist.PlaylistItems.Contains(dataSource.NextItemOverride)) { dataSource.NextItemOverride = null; } dataSource.LibraryPlaylist.PlaylistItems.Clear(); if (paths == null) return result; int i = 0; foreach (PlaylistItem pi in IsServer() ? paths.Select(x => new PlaylistItem() { Item = x }) : paths.Select(x => new PlaylistItem() { Item = x, UID = pathUids[i++] })) { dataSource.LibraryPlaylist.PlaylistItems.Add(pi); if (IsServer()) pathUids.Add(pi.UID); } } return result; }
public bool ApplyToDatabase(ServerDataSource dataSource) { lock (dataSource.Lock) { dataSource.CurrentItem = uid < 0 ? null : dataSource.GetItem(uid, true); if (dataSource.NextItemOverride != null && dataSource.NextItemOverride.UID == uid) { dataSource.NextItemOverride = null; } } return true; }
public bool ApplyToDatabase(ServerDataSource dataSource) { lock (dataSource.Lock) { Playlist pl = dataSource.Playlists.FastGet(uid); pl.Name = name; } return false; }
public bool ApplyToDatabase(ServerDataSource dataSource) { if (IsServer()) pathUids = new List<long>(); lock (dataSource.Lock) { Playlist pl = dataSource.Playlists.FastGet(uid); int i = 0; int index = after < 0 ? 0 : pl.PlaylistItems.IndexOf(pl.PlaylistItems.FastGet(after)) + 1; foreach (PlaylistItem pi in IsServer() ? paths.Select(x => new PlaylistItem() { Item = x }) : paths.Select(x => new PlaylistItem() { Item = x, UID = pathUids[i++] })) { pl.PlaylistItems.Insert(index++, pi); if (IsServer()) pathUids.Add(pi.UID); } } return false; }
public bool ApplyToDatabase(ServerDataSource dataSource) { lock (dataSource.Lock) { Playlist pl = IsServer() ? new Playlist() : new Playlist() { UID = uid }; dataSource.Playlists.Add(pl); if (IsServer()) uid = pl.UID; } return false; }
public static HaProtoImpl.HaProtoPacket ApplyPacketToDatabase(HaProtoImpl.Opcode op, byte[] data, ServerDataSource dataSource, out bool result) { HaProtoPacket packet; switch (op) { case HaProtoImpl.Opcode.ADD: packet = HaProtoImpl.ADD.Parse(data); break; case HaProtoImpl.Opcode.REMOVE: packet = HaProtoImpl.REMOVE.Parse(data); break; case HaProtoImpl.Opcode.CLEAR: packet = HaProtoImpl.CLEAR.Parse(data); break; case HaProtoImpl.Opcode.SETSONG: packet = HaProtoImpl.SETSONG.Parse(data); break; case HaProtoImpl.Opcode.SKIP: packet = HaProtoImpl.SKIP.Parse(data); break; case HaProtoImpl.Opcode.ADDPL: packet = HaProtoImpl.ADDPL.Parse(data); break; case HaProtoImpl.Opcode.DELPL: packet = HaProtoImpl.DELPL.Parse(data); break; case HaProtoImpl.Opcode.RENPL: packet = HaProtoImpl.RENPL.Parse(data); break; case HaProtoImpl.Opcode.SETMOVE: packet = HaProtoImpl.SETMOVE.Parse(data); break; case HaProtoImpl.Opcode.REORDER: packet = HaProtoImpl.REORDER.Parse(data); break; case HaProtoImpl.Opcode.INJECT: packet = HaProtoImpl.INJECT.Parse(data); break; case HaProtoImpl.Opcode.LIBRARY_ADD: packet = HaProtoImpl.LIBRARY_ADD.Parse(data); break; case HaProtoImpl.Opcode.LIBRARY_REMOVE: packet = HaProtoImpl.LIBRARY_REMOVE.Parse(data); break; case HaProtoImpl.Opcode.LIBRARY_RESET: packet = HaProtoImpl.LIBRARY_RESET.Parse(data); break; default: throw new NotImplementedException(); } result = packet.ApplyToDatabase(dataSource); return(packet); }