public StreamInfo(ChannelModule module) : base(module) { }
public Twitch(ChannelModule module) : base(module) { TwitchClient.OnNewSubscriber += TwitchClient_OnNewSubscriber; TwitchClient.OnReSubscriber += TwitchClient_OnReSubscriber; }
public AdminStats(ChannelModule module) : base(module) { _ramCounter = new PerformanceCounter("Memory", "Available MBytes", true); _cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true); TwitchClient.OnWhisperReceived += TwitchWhispers_OnWhisperReceived; }
public DiceCommand(ChannelModule module) : base(module) { }
static async Task MainAsync(string[] args) { Clear(); WriteLine("Available transport types:"); WriteLine("1 - TcpTransport (default)"); WriteLine("2 - PipeTcpTransport"); WriteLine("3 - WebSocketTransport"); WriteLine("4 - PipeWebSocketTransport"); Write("Select type: "); if (!int.TryParse(ReadLine(), out var transportType)) { transportType = 1; } Func <ITransportListener> transportListenerFactory; Func <ITransport> clientTransportFactory; Uri uri; var envelopeSerializer = new EnvelopeSerializer(new DocumentTypeResolver()); RemoteCertificateValidationCallback certificateValidationCallback = (sender, certificate, chain, errors) => true; switch (transportType) { case 2: uri = new Uri("net.tcp://*****:*****@msging.net/default", transportListenerFactory()) .WithChannelConsumers( m => reportActionBlock.SendAsync(m), n => reportActionBlock.SendAsync(n), c => reportActionBlock.SendAsync(c)) .WithEnabledEncryptionOptions(new SessionEncryption[] { SessionEncryption.None, SessionEncryption.TLS }) .WithExceptionHandler(e => { var cursorTop = CursorTop; CursorTop = 20; ForegroundColor = ConsoleColor.Red; WriteLine(e.ToString()); ResetColor(); CursorTop = cursorTop; return(Task.CompletedTask); }) .WithEnvelopeBufferSize(-1) .Build(); await server.StartAsync(CancellationToken.None); WriteLine("Server started."); var cursorLeft = CursorLeft; var cursorTop = CursorTop; while (true) { CursorLeft = cursorLeft; CursorTop = cursorTop; WriteLine(" "); WriteLine(" "); WriteLine(" "); WriteLine(" "); WriteLine(" "); WriteLine(" "); WriteLine(" "); WriteLine(" "); WriteLine(" "); WriteLine(" "); CursorLeft = cursorLeft; CursorTop = cursorTop; Write("Number of channels (ENTER for 1, EXIT to quit): "); var line = ReadLine(); if (line != null && line.ToLowerInvariant().Equals("exit")) { break; } if (!uint.TryParse(line, out var channelCount)) { channelCount = 1; } Write("Envelope buffer size (ENTER for 1): "); if (!int.TryParse(ReadLine(), out var envelopeBufferSize)) { envelopeBufferSize = 1; } Write("Module delay (ENTER for 0): "); if (!uint.TryParse(ReadLine(), out var moduleDelay)) { moduleDelay = 0; } WriteLine("Starting the client..."); var delayMessageChannelModule = new ChannelModule <Message>( async(message, token) => { await Task.Delay((int)moduleDelay, token); return(message); }, async(message, token) => { await Task.Delay((int)moduleDelay, token); return(message); }, state => { }); var channelBuilder = ClientChannelBuilder .Create(clientTransportFactory, uri) .WithEnvelopeBufferSize(envelopeBufferSize) .CreateEstablishedClientChannelBuilder() .AddEstablishedHandler((channel, token) => { if (moduleDelay > 0) { channel.MessageModules.Add(delayMessageChannelModule); } return(Task.CompletedTask); }) .WithEncryption(SessionEncryption.TLS); IEstablishedChannel client; if (channelCount > 1) { client = new MultiplexerClientChannel(channelBuilder); await((MultiplexerClientChannel)client).EstablishAsync(CancellationToken.None); } else { client = await channelBuilder.BuildAndEstablishAsync(CancellationToken.None); } WriteLine("Client started."); Write("Number of tasks (ENTER for 10): "); if (!uint.TryParse(ReadLine(), out var taskCount)) { taskCount = 10; } Write("Number of messages (ENTER for 1000): "); if (!uint.TryParse(ReadLine(), out var messagesCount)) { messagesCount = 1000; } Write("Number of notifications (ENTER for 1000): "); if (!uint.TryParse(ReadLine(), out var notificationsCount)) { notificationsCount = 1000; } Write("Number of commands (ENTER for 1000): "); if (!uint.TryParse(ReadLine(), out var commandsCount)) { commandsCount = 1000; } _reporter = new Reporter( (int)(taskCount * (messagesCount + notificationsCount + commandsCount)), CursorTop + 2, $"Transp {transportType} Ch {channelCount} Buf {envelopeBufferSize} Delay {moduleDelay} Tasks {taskCount} Msgs {messagesCount} Not {notificationsCount} Cmds {commandsCount}"); var to = Node.Parse("name@domain/instance"); var limeUri = new LimeUri("/ping"); await Task.WhenAll( Enumerable .Range(0, (int)taskCount) .Select(i => Task.Run(async() => { var messagesTask = Task.Run(async() => { for (int j = 0; j < messagesCount; j++) { await client.SendMessageAsync( new Message() { Id = $"{i}_{j}", To = to, Content = "Testing a message" }, CancellationToken.None); } }); var notificationsTask = Task.Run(async() => { for (int j = 0; j < notificationsCount; j++) { await client.SendNotificationAsync( new Notification() { Id = $"{i}_{j}", To = to, Event = Event.Received }, CancellationToken.None); } }); var commandsTask = Task.Run(async() => { for (int j = 0; j < commandsCount; j++) { await client.SendCommandAsync( new Command() { Id = $"{i}_{j}", To = to, Method = CommandMethod.Observe, Uri = limeUri }, CancellationToken.None); } }); await Task.WhenAll(messagesTask, notificationsTask, commandsTask); }))); _reporter.ReportSendComplete(); await _reporter.ReportTask; _reporter = null; using var finishCts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); if (client is IOnDemandClientChannel onDemandClientChannel) { await onDemandClientChannel.FinishAsync(finishCts.Token); } else if (client is IClientChannel clientChannel) { await clientChannel.SendFinishingSessionAsync(finishCts.Token); await clientChannel.ReceiveFinishedSessionAsync(finishCts.Token); } client.DisposeIfDisposable(); } using var stopCts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); await server.StopAsync(stopCts.Token); WriteLine("Server stopped. Press ENTER to exit."); ReadLine(); }
public PingCommand(ChannelModule module) : base(module) { }
public Caster(ChannelModule module) : base(module) { }
public Links(ChannelModule module) : base(module) { _permits = new List <Permit>(); _topLevelDomains = DownloadTopLevelDomains(); TwitchClient.OnMessageReceived += TwitchClient_OnMessageReceived; }
public Uptime(ChannelModule module) : base(module) { }
public Caps(ChannelModule module) : base(module) { TwitchClient.OnMessageReceived += TwitchClient_OnMessageReceived; }