102 lines
3.7 KiB
C#
102 lines
3.7 KiB
C#
namespace CommonConsole
|
|
{
|
|
using Newtonsoft.Json;
|
|
|
|
using OmniPlus.Inspection;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Sockets;
|
|
|
|
public class Program
|
|
{
|
|
private static readonly IDictionary<OmniPlusTestPoint, OmniPlusTest> results
|
|
= new SortedDictionary<OmniPlusTestPoint, OmniPlusTest>();
|
|
|
|
public static void Main()
|
|
{
|
|
Console.WriteLine(Dns.GetHostName());
|
|
|
|
try
|
|
{
|
|
using (var httpRequestMessage = new HttpRequestMessage())
|
|
{
|
|
var hostName = Dns.GetHostName();
|
|
var ipAddress = Dns
|
|
.GetHostEntry(hostName)
|
|
.AddressList
|
|
.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork)
|
|
.ToString();
|
|
var content = JsonConvert.SerializeObject(new
|
|
{
|
|
//[Required]
|
|
//public string StationNr { get; set; }
|
|
StationNr = "2024",
|
|
|
|
//[Required]
|
|
//public string PCName { get; set; }
|
|
PCName = hostName,
|
|
|
|
//[Required]
|
|
//public string IPAddress { get; set; }
|
|
IPAddress = ipAddress,
|
|
|
|
//[Required]
|
|
//public string Trace { get; set; }
|
|
Trace = $"CommonConsole.{nameof(Program)}.{nameof(Main)}",
|
|
|
|
//[Required]
|
|
//public string Sender { get; set; }
|
|
Sender = "stoyan.zlatev@xylem.com",
|
|
|
|
//[Required]
|
|
//public string Subject { get; set; }
|
|
Subject = "test email",
|
|
|
|
//[Required]
|
|
//public string Body { get; set; }
|
|
Body = "<h1>It works!</h1>",
|
|
|
|
//public bool IsHtml { get; set; }
|
|
IsHtml = true,
|
|
|
|
//[Required]
|
|
//public string[] Recipients { get; set; }
|
|
Recipients = new[] { "roland.drabesch@xylem.com" },
|
|
|
|
//public string[] CC { get; set; }
|
|
CC = new[] { "roland.drabesch@xylem.com", "stoyan.zlatev@xylem.com" }
|
|
}, Formatting.Indented);
|
|
|
|
httpRequestMessage.Content = new StringContent(content);
|
|
httpRequestMessage.Content.Headers.ContentType.MediaType = "application/json";
|
|
httpRequestMessage.Headers.Add("Accept", "application/json");
|
|
httpRequestMessage.Method = HttpMethod.Post;
|
|
httpRequestMessage.RequestUri = new Uri("http://sla12iis01.emea.sensus.net/LaaProductionWeb/api/Send/Email");
|
|
|
|
Console.WriteLine(httpRequestMessage);
|
|
|
|
using (var httpClient = new HttpClient())
|
|
{
|
|
using (var httpResponseMessage = httpClient.SendAsync(httpRequestMessage).Result)
|
|
{
|
|
Console.WriteLine(httpResponseMessage);
|
|
|
|
var response = httpResponseMessage.Content.ReadAsStringAsync().Result;
|
|
|
|
Console.WriteLine(response);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
}
|
|
}
|