public static void Enqueue <T>(this DefaultQueue <T> queue, IEnumerable <T> ts) where T : IQueueable { foreach (var t in ts) { queue.Enqueue(t); } }
public void NoExceptionHandling() { var repo = new MockRepository(); var action = repo.CreateMock <Action>(); var failure = new Exception(); action(); LastCall.Throw(failure); repo.ReplayAll(); var queue = new DefaultQueue(); queue.Enqueue(action); try { queue.ExecuteNextBatch(); Assert.Fail("Should throw Exception"); } catch (Exception commFailure) { Assert.AreSame(failure, commFailure); } repo.VerifyAll(); }
public void ShouldOnlyExecuteActionsQueuedWhileNotStopped() { var mockery = new MockRepository(); var action1 = mockery.CreateMock <Action>(); var action2 = mockery.CreateMock <Action>(); var action3 = mockery.CreateMock <Action>(); using (mockery.Record()) { action1(); action2(); } using (mockery.Playback()) { var queue = new DefaultQueue(); queue.Enqueue(action1); var run = new Thread(queue.Run); run.Start(); Thread.Sleep(100); queue.Enqueue(action2); queue.Stop(); queue.Enqueue(action3); Thread.Sleep(100); run.Join(); } }
public void TestEnqueue() { var q = new DefaultQueue(); q.Enqueue(() => { }); TestContext.WriteLine($"q.Count():{q.Count()}"); Assert.AreEqual(1, q.Count()); }
public async Task Dequeue_EmptyQueue_ReturnsNull() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); var queue = new DefaultQueue <string>(connection); var item = await queue.DequeueAsync(); Assert.IsNull(item); } }
public void TestDequeueAll() { var q = new DefaultQueue(); q.Run(); q.Enqueue(() => { }); q.Enqueue(() => { }); q.Enqueue(() => { }); var r = q.DequeueAll(); TestContext.WriteLine($"q.Count():{q.Count()} r.Count():{r.Count}"); Assert.AreEqual(3, r.Count); }
public async Task Command(params int[] args) { LavaPlayer player = ConfigProperties.LavaNode.GetPlayer(Context.Guild); PlayerState playerState = player.PlayerState; DefaultQueue <IQueueable> queue = player.Queue; if (!(playerState == PlayerState.Playing || playerState == PlayerState.Paused) || !queue.Any()) { await SendBasicErrorEmbedAsync("The player must be either playing " + "or paused and must have at least 1 song " + "in the queue."); return; } int failedAttempts = 0; const int LIMIT_ATTEMPTS = 3; // Maximum amount of error messages to send in one session. var descSb = new StringBuilder(); foreach (int num in args.OrderByDescending(x => x)) { if (failedAttempts >= LIMIT_ATTEMPTS) { return; } IQueueable match = queue.ElementAtOrDefault(num - 1); if (match == null) { await SendBasicErrorEmbedAsync($"{Context.User.Mention} There is no track `#{num}` in the current queue."); failedAttempts++; continue; } player.Queue.RemoveAt(num - 1); descSb.AppendLine($"Successfully removed track `#{num}`."); } var embed = new KaguyaEmbedBuilder { Description = descSb.ToString() }; await SendEmbedAsync(embed); }
public void InitServer() { var activator = new ServiceActivator(); var invoker = new ServiceInvoker(); var logger = new RedisLogger(new Uri("test")); var queue = new DefaultQueue(); var handler = new CfHandler(activator, invoker, logger, queue); var configurationProvider = new DefaultConfigurationProvider(); configurationProvider.BaseAddress = "http://localhost:8090"; var bus = new CfServiceBus(handler, logger, configurationProvider); bus.Host <IPingPongService>(new PingPongService()); bus.Start(); }
static void Main(string[] args) { var activator = new ServiceActivator(); var invoker = new ServiceInvoker(); var logger = new ConsoleLogger(); var queue = new DefaultQueue(); var handler = new CfHandler(activator, invoker, logger, queue); var configurationProvider = new DefaultConfigurationProvider(); configurationProvider.BaseAddress = "http://localhost:8090"; configurationProvider.QueuePath = "SchedulerQueue"; var bus = new CfServiceBus(handler, logger, configurationProvider); bus.Host <IPingService>(new PingService()); bus.Start(); Console.ReadLine(); }
public static async Task OnTrackEnd(TrackEndedEventArgs e) { LavaPlayer player = e.Player; DefaultQueue <IQueueable> queue = player.Queue; if (player != null && queue?.Count > 0 && e.Reason.ShouldPlayNext()) { bool success = queue.TryDequeue(out IQueueable val); if (success) { var track = (LavaTrack)val; await player.PlayAsync(track); if (player.TextChannel != null) { var sb = new StringBuilder(); sb.AppendLine($"Songs left in queue: `{queue.Count:N0}`"); sb.AppendLine($"Title: `{track.Title}`"); sb.AppendLine($"Duration: `{track.Duration.Humanize(2)}`"); sb.AppendLine($"Track Name: `{track.Title}`"); var embed = new KaguyaEmbedBuilder { Title = $"New Track", Fields = new List <EmbedFieldBuilder> { new EmbedFieldBuilder { Name = "Track Information", Value = sb.ToString() } } }; await player.TextChannel.SendEmbedAsync(embed); } await ConsoleLogger.LogAsync("Successfully continued the music " + $"queue in guild {e.Player.VoiceChannel.Guild}", LogLvl.DEBUG); } } }
static void Main(string[] args) { ILogger logger = new ConsoleLogger(); IServiceActivator activator = new ServiceActivator(); IServiceInvoker invoker = new ServiceInvoker(); IQueue queue = new DefaultQueue(); ICfHandler handler = new CfHandler(activator, invoker, logger, queue); IConfigurationProvider configurationProvider = new DefaultConfigurationProvider(); configurationProvider.BaseAddress = "http://localhost:8088"; configurationProvider.QueuePath = "CustumerMessageQueue"; ICfBus bus = new CfServiceBus(handler, logger, configurationProvider); bus.Host <ICustomerService>(new CustomerService(new CashierProxy("http://localhost:8089"))); bus.Start(); logger.Write("Customer cashierService has started"); Console.ReadLine(); }
public async Task ProcessAsync_SingleItemInQueue_ProcessesAndEmptiesQueue() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("An item")); var queue = new DefaultQueue <string>(connection); var handler = new FakePayloadHandler(); var queueProcessor = new DefaultQueueProcessor <string>(queue, handler); var processed = await queueProcessor.ProcessAsync(); Assert.IsTrue(processed); processed = await queueProcessor.ProcessAsync(); Assert.IsFalse(processed); } }
public async Task Dequeue_TwoItemsInQueue_DequeueItemsInOrder() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Item1")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Item2")); var queue = new DefaultQueue <string>(connection); var item1 = await queue.DequeueAsync(); Assert.AreEqual("Item1", item1.Payload); var item2 = await queue.DequeueAsync(); Assert.AreEqual("Item2", item2.Payload); } }
public async Task Dequeue_TwoConcurrentCalls_DequeueDifferentItems() { using (var scope = new IsolationScope(TestFixtureContext.Provider)) { var connection = scope.Provider.GetRequiredService <IDbConnection>(); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("An item")); await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Another item")); var queue1 = new DefaultQueue <string>(connection); var queue2 = new DefaultQueue <string>(connection); var t1 = queue1.DequeueAsync(); var t2 = queue2.DequeueAsync(); var items = await Task.WhenAll(t1, t2); Assert.IsTrue(items.First().Payload != items.Last().Payload); } }
public CustomLavaPlayer(LavaSocket lavaSocket, IVoiceChannel voiceChannel, ITextChannel textChannel) : base(lavaSocket, voiceChannel, textChannel) { CustomQueue = new DefaultQueue <CustomLavaTrack>(); LastFinishTime = DateTime.Now; }