public ISNMPDeviceDataDTO BuildSNMPDevice(IPAddress targetIP, int targetMask) { ISNMPDeviceDataDTO device = new SNMPDeviceDataDTO(targetIP, targetMask, ChangeTrackerHandler); DeviceData.Add(targetIP.ToString(), device); return(device); }
/// <summary> /// Sends a notification using the specified request. /// </summary> private bool SendNotification(HttpRequestMessage request, string tagCode) { try { // send request and receive response Log.WriteLine(Locale.IsRussian ? "Отправка запроса:" : "Send request:"); Log.WriteLine(request.RequestUri.ToString()); HttpStatusCode responseStatus; string responseContent; stopwatch.Restart(); using (HttpResponseMessage response = httpClient.SendAsync(request).Result) { responseStatus = response.StatusCode; responseContent = response.Content.ReadAsStringAsync().Result; } stopwatch.Stop(); // output response to log Log.WriteLine(Locale.IsRussian ? "Ответ получен за {0} мс. Статус: {1} ({2})" : "Response received in {0} ms. Status: {1} ({2})", stopwatch.ElapsedMilliseconds, (int)responseStatus, responseStatus); if (responseContent.Length > 0) { Log.WriteLine(Locale.IsRussian ? "Содержимое ответа:" : "Response content:"); if (responseContent.Length <= ResponseDisplayLenght) { Log.WriteLine(responseContent); } else { Log.WriteLine(responseContent.Substring(0, ResponseDisplayLenght)); Log.WriteLine("..."); } } // update tag values DeviceData.Add(tagCode, 1); DeviceData.Set(TagCode.Response, (int)responseStatus); return(true); } catch (Exception ex) { Log.WriteLine(Locale.IsRussian ? "Ошибка при отправке запроса: {0}" : "Error sending request: {0}", ex.Message); DeviceData.Invalidate(TagCode.Response); return(false); } }
public async Task Add([FromBody] DeviceModel model) { DeviceData data = new DeviceData(_config); var device = new DeviceModel() { Hostname = model.Hostname, IpAddress = model.IpAddress, MACAddress = model.MACAddress, Vendor = model.Vendor, UserId = model.UserId, DeviceDescription = model.DeviceDescription }; data.Add(model); }
/// <summary> /// Sends the mail message. /// </summary> private bool SendMessage(MailMessage message, string tagCode) { try { smtpClient.Send(message); DeviceData.Add(tagCode, 1); Log.WriteLine(Locale.IsRussian ? "Письмо отправлено на {0}" : "Mail has been sent to {0}", message.To.ToString()); return(true); } catch (Exception ex) { Log.WriteLine(Locale.IsRussian ? "Ошибка при отправке письма на {0}: {1}" : "Error sending mail to {0}: {1}", message.To.ToString(), ex.Message); return(false); } }