private static async Task <bool> RegisterFtpClient() { httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Add("User-Agent", "FTP Client"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var model = new Shared.FtpClientModel { InstanceId = InstanceInfo.InstanceId, MachineName = Environment.MachineName }; var modelStr = JsonSerializer.Serialize(model, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Default }); try { var message = await httpClient.PostAsync($"{CommandAndControlUrl}/FtpClient/register-client", new StringContent(modelStr, Encoding.UTF8, "application/json")); message.EnsureSuccessStatusCode(); Console.WriteLine("Ftp Client registered and waiting for orders..."); return(true); } catch (Exception e) { Console.WriteLine("Ftp Client was not able to register itself on Command and Control, program will be terminated now"); Console.WriteLine(e.Message); Thread.Sleep(5000); } return(false); }
public IActionResult RegisterClient(Shared.FtpClientModel model) { var now = DateTime.UtcNow; var ftpClient = new FtpClient { MachineName = model.MachineName, InstanceId = model.InstanceId, FirstPing = now }; DbContext.FtpClients.Add(ftpClient); DbContext.SaveChanges(); return(Ok()); }