/// <summary> /// SMTP configuration /// </summary> public static async Task <string> SetEmailFromBody([FromBody] EmailData data) { _logger.Info("[SetEmailFromBody] Method started"); try { var deviceInfoData = await GetRequests.DeviceInfo(); var serial = $"HK-{deviceInfoData.deviceInfo.serialNumber}@camera.ru"; //[email protected] data.mailing.sender.emailAddress = serial; data.mailing.receiverList.receiver[0].emailAddress = serial; using var xmlData = Converters.ToStringContent(data, "mailing"); var response = await WebClient.Client.PutAsync("System/Network/mailing/1", xmlData).Result.Content.ReadAsStringAsync(); var jsonResponse = Converters.XmlToJson(response); var responseData = JsonConvert.DeserializeObject <CamResponses>(jsonResponse); _logger.Info("[SetEmailFromBody] Method has complete"); return($"{responseData.responseStatus.StatusString,-10} Request url {responseData.responseStatus.RequestUrl}"); } catch (Exception e) { _logger.Error($"[SetEmailFromBody] Method failed. \nError message: {e.Message}"); return(e.Message); } }
/// <summary> /// Change DNS on device /// </summary> public static async Task <string> SetDnsFromBody([FromBody] NetworkData data) { _logger.Info("[SetDnsFromBody] Method started"); // запрашиваем конфигурацию сети с камеры // без этих данных камера не примет XML var networkData = await GetRequests.Ethernet(); //извлекаем текущие значения конфигурации сети var addressingType = networkData.ipAddress.AddressingType; if (addressingType != "static") { return($"Addressing type is {addressingType}. Can`t set DNS"); } var ipAddress = networkData.ipAddress.IpAddress; var subnetMask = networkData.ipAddress.SubnetMask; var defaultGateway = networkData.ipAddress.DefaultGateway.IpAddress; //дополняем пришедший json полученными значениями с камер data.ipAddress.IpAddress = ipAddress; data.ipAddress.SubnetMask = subnetMask; data.ipAddress.DefaultGateway.IpAddress = defaultGateway; try { using var xmlData = Converters.ToStringContent(data, "IPAddress"); var response = await WebClient.Client.PutAsync("System/Network/interfaces/1/ipAddress", xmlData).Result.Content.ReadAsStringAsync(); var jsonResponse = Converters.XmlToJson(response); var responseData = JsonConvert.DeserializeObject <CamResponses>(jsonResponse); _logger.Info("[SetDnsFromBody] Method has complete"); return($"{responseData.responseStatus.StatusString,-10} Request url {responseData.responseStatus.RequestUrl}"); } catch (Exception e) { _logger.Error($"[SetDnsFromBody] Method failed. \nError message: {e.Message}"); return(e.Message); } }