コード例 #1
0
        private void Update()
        {
            string[] removed = { };
            string[] updated = { };
            string[] added   = { };

            lock (updateWaitHandle) {
                Plugin.mbApi.Library_GetSyncDelta(musicBeeDatabase.Files, lastUpdate, LibraryCategory.Music | LibraryCategory.Inbox, ref added, ref updated, ref removed);

                if (numberOfOpenConnections == 0)
                {
                    Clear();
                }
                else
                {
                    int   nextRevision = Current + 1;
                    int[] removedIds   = new int[0];

                    if (receivedNotificationTypes != NotificationType.None)
                    {
                        // Tracks that are re-added after having been removed from musicbee are removed from the revision history
                        if (receivedNotificationTypes.HasFlag(NotificationType.FileAdded))
                        {
                            foreach (string file in added)
                            {
                                int addedId = musicBeeDatabase.GetIdOfTrack(file);

                                if (addedId != 0)
                                {
                                    foreach (Revision revision in revisions)
                                    {
                                        for (int index = 0; index < revision.removedIds.Length; index++)
                                        {
                                            int removedId = revision.removedIds[index];
                                            if (addedId == removedId)
                                            {
                                                revision.removedIds[index] = 0;
                                                goto breakOuter;
                                            }
                                        }
                                    }
                                    breakOuter :;
                                }
                            }
                        }

                        removedIds = musicBeeDatabase.GetIdsOfTracks(removed);
                    }

                    revisions.Push(new Revision
                    {
                        id         = nextRevision,
                        removedIds = removedIds
                    });
                }

                if (receivedNotificationTypes.HasFlag(NotificationType.FileAdded) || receivedNotificationTypes.HasFlag(NotificationType.FileRemoved))
                {
                    musicBeeDatabase.Update(added);
                }

                lastUpdate = DateTime.Now;
                receivedNotificationTypes = NotificationType.None;
                Monitor.PulseAll(updateWaitHandle);
            }
        }