コード例 #1
0
        public static async Task ClearGuildQueue(this QueueDBContext ctx, ulong guildId)
        {
            var them = await GetGuildQueue(ctx, guildId);

            ctx.QueueEntries.RemoveRange(them);
            await ctx.SaveChangesAsync();
        }
コード例 #2
0
        private static async Task ReorderQueue(QueueDBContext ctx, ulong guildId, List <QueueEntryInfo> queueEntries)
        {
            queueEntries.Reverse();
            await ClearGuildQueue(ctx, guildId);

            for (int i = 0; i < queueEntries.Count; i++)
            {
                queueEntries[i].Position = i;
            }
            await ctx.AddRangeAsync(queueEntries);

            await ctx.SaveChangesAsync();
        }
コード例 #3
0
        public static async Task <QueueEntryInfo> DeleteFromGuildQueue(this QueueDBContext ctx, ulong guildId, int position)
        {
            var queue = await GetGuildQueue(ctx, guildId);

            var deletedEntry = queue[0];

            queue.RemoveAt(0);
            await ReorderQueue(ctx, guildId, queue);

            await ctx.SaveChangesAsync();

            return(deletedEntry);
        }
コード例 #4
0
        public static async Task <QueueEntryInfo> AddToGuildQueue(this QueueDBContext ctx, ulong guildId, ulong userId, ServiceResult queueEntry)
        {
            var baseDB     = new DBQueueEntryJson(queueEntry);
            var baseDBJson = JsonConvert.SerializeObject(baseDB);
            var baseBytes  = Encoding.UTF8.GetBytes(baseDBJson);
            var queueCount = await ctx.QueueEntries.Where(x => x.GuildId == guildId).CountAsync();

            var items = await ctx.QueueEntries.AddAsync(new QueueEntryInfo
            {
                AddedBy        = userId,
                AdditionTime   = DateTime.Now,
                DBTrackInfoRaw = Convert.ToBase64String(baseBytes),
                GuildId        = guildId,
                Position       = queueCount
            });

            await ctx.SaveChangesAsync();

            items.Entity.DBTrackInfo = new DBQueueEntryJson(queueEntry);
            return(items.Entity);
        }
コード例 #5
0
        public static async Task <QueueEntryInfo> InsertToGuildQueue(this QueueDBContext ctx, ulong guildId, ulong userId, ServiceResult queueEntry, int position)
        {
            var queue = await GetGuildQueue(ctx, guildId);

            var baseDB     = new DBQueueEntryJson(queueEntry);
            var baseDBJson = JsonConvert.SerializeObject(baseDB);
            var baseBytes  = Encoding.UTF8.GetBytes(baseDBJson);
            var item       = new QueueEntryInfo
            {
                AddedBy        = userId,
                AdditionTime   = DateTime.Now,
                DBTrackInfoRaw = Convert.ToBase64String(baseBytes),
                GuildId        = guildId,
                Position       = -1
            };

            queue.Insert(position, item);
            await ReorderQueue(ctx, guildId, queue);

            await ctx.SaveChangesAsync();

            item.DBTrackInfo = new DBQueueEntryJson(queueEntry);
            return(item);
        }