Example #1
0
        private async Task RunLineHandler(Socket clientSocket, CancellationToken cToken)
        {
            clientSocket.ReceiveTimeout = (int)config.TimeoutSeconds * 1000;
            ConnectedEndpoint           = (IPEndPoint)clientSocket.RemoteEndPoint;
            arcLog.Log($"Running line handler for {ConnectedEndpoint}");
            await Read(clientSocket, cToken);

            arcLog.Log($"Closing line handler for {ConnectedEndpoint}");
            clientSocket.Close();
            LineHandlerRunning = false;
        }
Example #2
0
 public void LoadAccounts()
 {
     arcLog.Log("Loading Account data");
     lock (busy)
     {
         accounts = File.Exists(config.AccountsFilename)
             ? JsonConvert.DeserializeObject <List <Account> >(File.ReadAllText(config.AccountsFilename))
             : new List <Account>();
         arcLog.Log($"Loaded {accounts.Count} accounts");
     }
 }
Example #3
0
        public async Task RunServer(CancellationToken cToken)
        {
            socket.Bind(endpoint);
            socket.Listen(10);

            arcLog.Log($"ARC Server started - listening on port {endpoint.Port}");
            _ = Task.Run(() => Cleaner(cToken), cToken);

            while (!cToken.IsCancellationRequested)
            {
                var newSocket = await socket.AcceptAsync().WithCancellation(cToken);

                Console.WriteLine($"Incoming connection from {newSocket.RemoteEndPoint}");
                var lineHandler = lineHandlerFactory.NewInstance();
                lineHandler.StartLineHandler(newSocket, cToken);
                lock (listLock)
                {
                    lineHandlers.Add(lineHandler);
                }
            }
        }
Example #4
0
        private async Task SendToWebhook(string username, string content)
        {
            if (configured)
            {
                var context = new WebhookContext
                {
                    username = username,
                    content  = content
                };
                var jsonContent = JsonConvert.SerializeObject(context);
                var request     = new RestRequest(Method.POST);
                request.AddHeader("content-type", "application/json");
                request.AddJsonBody(jsonContent);
                var response = await restClient.ExecuteAsync(request);

                if (!response.IsSuccessful)
                {
                    arcLog.Log($"Webhook request failed - {response.Content}");
                }
            }
        }