public async void PostItemHttpTask(TemperaturLib.Temperatur temperatur)
        {
            string EventWebApi = "https://goldenice20200505111435.azurewebsites.net/";

            // Measurement.Measurement newMeasure = new Measurement.Measurement(DateTime.Now, "D5.16", "Ozon", 9.12, "Rasp v.1.0");

            using (HttpClient client = new HttpClient())
            {
                string newItemJson = JsonConvert.SerializeObject(temperatur);
                Console.WriteLine("Serialized object: " + newItemJson);
                var content = new StringContent(newItemJson, Encoding.UTF8, "application/json");
                client.BaseAddress = new Uri(EventWebApi);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                IEnumerable <string> headers;
                headers = client.DefaultRequestHeaders.GetValues("Accept");
                foreach (var VARIABLE in headers)
                {
                    Console.WriteLine(VARIABLE);
                }
                var response = client.PostAsync("api/Weathers", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    var responseEvent = client.GetAsync("api/Weathers" + temperatur).Result;
                    if (responseEvent.IsSuccessStatusCode)
                    {
                        //var Event = responseEvent.Content.ReadAsStreamAsync<Event>().Result;
                        //   string saveEvent = await responseEvent.Content.ReadAsStringAsync<Event>().Result;
                    }
                }
            }

            //return await GetItemsHttpTask();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World receiver ready press enter!");
            Console.ReadLine();
            PostService postMeasure = new PostService();

            TemperaturLib.Temperatur temperatur;


            UdpClient receiveUdp = new UdpClient(11111);

            IPEndPoint receiveEndPoint = new IPEndPoint(IPAddress.Any, 0);

            Console.WriteLine("ready to receive data");

            try
            {
                while (true)
                {
                    Byte[] receiveBytes = receiveUdp.Receive(ref receiveEndPoint);
                    string receivedData = Encoding.ASCII.GetString(receiveBytes);

                    Console.WriteLine("This message was sent from " +
                                      receiveEndPoint.Address.ToString() +
                                      " on their port number " +
                                      receiveEndPoint.Port.ToString());

                    Console.WriteLine(receivedData);

                    string[] txtSplit = receivedData.Split(" ");
                    for (int i = 0; i < txtSplit.Length; i++)
                    {
                        Console.WriteLine(txtSplit[i]);
                    }

                    temperatur = new TemperaturLib.Temperatur(System.Convert.ToDecimal(txtSplit[0]), Convert.ToDateTime(txtSplit[1] + " " + txtSplit[2]));
                    postMeasure.PostItemHttpTask(temperatur);
                    Thread.Sleep(3000);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }