// Main Method static async Task Main() { ThreadPool.SetMinThreads(Environment.ProcessorCount * 15, Environment.ProcessorCount * 10); AuditServer server = new AuditServer(); _ = server.DisplayLogs(); await server.Run(); server.Dispose(); }
public async Task Process() { UserCommandType command; LogType log_in; ReadOnlySequence <byte>?msgpack; using (var streamReader = new MessagePackStreamReader(client.GetStream())) { while (client.Connected) { command = null; try { msgpack = await streamReader.ReadAsync(_tokenSource.Token); if (!msgpack.HasValue) { if (!_tokenSource.IsCancellationRequested) { // Bad state, leave break; } } log_in = MessagePackSerializer.Typeless.Deserialize(msgpack.Value, cancellationToken: _tokenSource.Token) as LogType; if (log_in == null) { continue; } AuditServer.AddBulkRecords(log_in.Items); for (int i = log_in.Items.Length - 1; i >= 0; i--) { var record = log_in.Items[i]; if (record.GetType() == typeof(UserCommandType)) { command = (UserCommandType)record; if (command.command == commandType.DUMPLOG) { AuditServer.DumpLog(command.filename); } } } } catch (IOException) { // Client connection closed, eat and move on break; } catch (Exception e) { Console.WriteLine(e); DebugType debugEvent = new DebugType { server = Server.AUDIT_SERVER.Abbr, debugMessage = e.Message }; if (command != null) { debugEvent.command = command.command; debugEvent.transactionNum = command.transactionNum; debugEvent.username = command.username; } AuditServer.AddRecord(debugEvent); } } } client.Close(); client.Dispose(); }