Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
            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);
            }
Ejemplo n.º 3
0
            public bool ApplyToDatabase(ServerDataSource dataSource)
            {
                Playlist pl = dataSource.Playlists.FastGet(uid);

                pl.Name = name;
                return(false);
            }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
            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);
            }
Ejemplo n.º 8
0
            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);
            }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
            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);
            }
Ejemplo n.º 11
0
            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);
            }
Ejemplo n.º 12
0
            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);
            }
Ejemplo n.º 13
0
            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);
            }
Ejemplo n.º 14
0
 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;
 }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 public bool ApplyToDatabase(ServerDataSource dataSource)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 17
0
 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;
 }
Ejemplo n.º 18
0
            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;
            }
Ejemplo n.º 19
0
            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;
            }
Ejemplo n.º 20
0
 public bool ApplyToDatabase(ServerDataSource dataSource)
 {
     dataSource.Mode = move;
     return false;
 }
Ejemplo n.º 21
0
 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;
 }
Ejemplo n.º 22
0
 public bool ApplyToDatabase(ServerDataSource dataSource)
 {
     lock (dataSource.Lock)
     {
         dataSource.NextItemOverride = uid < 0 ? null : dataSource.GetItem(uid);
     }
     return false;
 }
Ejemplo n.º 23
0
 public bool ApplyToDatabase(ServerDataSource dataSource)
 {
     dataSource.Mode = move;
     return(false);
 }
Ejemplo n.º 24
0
 public bool ApplyToDatabase(ServerDataSource dataSource)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 25
0
 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;
 }
Ejemplo n.º 26
0
            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;
            }
Ejemplo n.º 27
0
 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;
 }
Ejemplo n.º 28
0
 public bool ApplyToDatabase(ServerDataSource dataSource)
 {
     lock (dataSource.Lock)
     {
         Playlist pl = dataSource.Playlists.FastGet(uid);
         pl.Name = name;
     }
     return false;
 }
Ejemplo n.º 29
0
 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;
 }
Ejemplo n.º 30
0
 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;
 }
Ejemplo n.º 31
0
        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);
        }