public async Task <AddDatagramResponse> Handle(AddDatagramCommand request, CancellationToken cancellation)
        {
            var          id       = Guid.NewGuid().ToString();
            FullDatagram datagram = new FullDatagram();

            if (request.currentUsage > 10)
            {
                datagram.Id           = id;
                datagram.timeStamp    = DateTime.Now.ToString("dd_MMM_yyyy_HH_mm_ss");
                datagram.currentUsage = request.currentUsage / 1000;
                datagram.totalLow     = request.totalLow / 1000;
                datagram.totalHigh    = request.totalHigh / 1000;
                datagram.returnLow    = request.returnLow / 1000;
                datagram.returnHigh   = request.returnHigh / 1000;
                datagram.gasUsage     = request.gasUsage / 1000;
                datagram.signature    = request.signature;
            }
            else
            {
                datagram.Id           = id;
                datagram.timeStamp    = DateTime.Now.ToString("dd_MMM_yyyy_HH_mm_ss");
                datagram.currentUsage = request.currentUsage;
                datagram.totalLow     = request.totalLow;
                datagram.totalHigh    = request.totalHigh;
                datagram.returnLow    = request.returnLow;
                datagram.returnHigh   = request.returnHigh;
                datagram.gasUsage     = request.gasUsage;
                datagram.signature    = request.signature;
            }

            await _datagramRepo.AddAsync(datagram);

            return(new AddDatagramResponse(id));
        }
Ejemplo n.º 2
0
        public async Task <FullDatagram> AddAsync(FullDatagram datagram)
        {
            if (datagram == null)
            {
                throw new ArgumentNullException("datagram was null");
            }
            else
            {
                datagram.Id = Guid.NewGuid().ToString();
                string jsonString = JsonSerializer.Serialize(datagram);
                var    content    = new StringContent(datagram.ToString(), Encoding.UTF8, "application/json");
                var    result     = await client.PostAsync("https://localhost:44371/api/Datagram/PostDatagram", content);

                Console.WriteLine("Status Code:  " + result.StatusCode);
                return(datagram);
            }
        }
        public async Task <FullDatagram> AddAsync(FullDatagram datagram)
        {
            if (datagram == null)
            {
                throw new ArgumentNullException("datagram was null");
            }
            else
            {
                try
                {
                    await _meterContext.AddAsync(datagram);

                    await _meterContext.SaveChangesAsync();

                    return(datagram);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
 public GetLastDatagramResponse(FullDatagram datagram)
 {
     _datagram = datagram;
 }
Ejemplo n.º 5
0
        private void HandleMessageReceived(MqttApplicationMessage message)
        {
            Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###");
            Console.WriteLine($"+ Topic = {message.Topic}");

            Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(message.Payload)}");
            Console.WriteLine($"+ QoS = {message.QualityOfServiceLevel}");
            Console.WriteLine($"+ Retain = {message.Retain}");
            Console.WriteLine();
            string payload    = Encoding.UTF8.GetString(message.Payload);
            var    testObject = JsonConvert.DeserializeObject <highestObject>(payload);

            FullDatagram datagram = new FullDatagram();

            datagram.signature = testObject.datagram.signature;
            datagram.Id        = Guid.NewGuid().ToString();
            datagram.timeStamp = DateTime.Now.ToString("MMM_dd_yyyy_HH_mm_ss");
            foreach (var substring in testObject.datagram.p1.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (substring.Contains("1-0:1.8.1"))
                {
                    double value = Convert.ToDouble(removeExcessData(substring.ToString(), "1-0:1.8.1", "*kWh"));
                    datagram.totalHigh = value;
                }
                else if (substring.Contains("1-0:1.8.2"))
                {
                    double value = Convert.ToDouble(removeExcessData(substring.ToString(), "1-0:1.8.2", "*kWh"));
                    datagram.totalLow = value;
                }
                else if (substring.Contains("1-0:1.7.0"))
                {
                    double value = Convert.ToDouble(removeExcessData(substring.ToString(), "1-0:1.7.0", "*kW"));
                    datagram.currentUsage = value;
                }
                else if (substring.Contains("1-0:2.8.1"))
                {
                    double value = Convert.ToDouble(removeExcessData(substring.ToString(), "1-0:2.8.1", "*kWh"));
                    datagram.returnHigh = value;
                }
                else if (substring.Contains("1-0:2.8.2"))
                {
                    double value = Convert.ToDouble(removeExcessData(substring.ToString(), "1-0:2.8.2", "*kWh"));
                    datagram.returnLow = value;
                }
                else if (substring.Contains("0-1:24.2.1"))
                {
                    double value = Convert.ToDouble(removeExcessData(substring.ToString(), "0-1:24.2.1", "*m3", "210330112500S"));
                    datagram.gasUsage = value;
                }
            }
            if (datagram.currentUsage > 10)
            {
                datagram.currentUsage = datagram.currentUsage / 1000;
                datagram.totalHigh    = datagram.totalHigh / 1000;
                datagram.totalLow     = datagram.totalLow / 1000;
                datagram.returnHigh   = datagram.returnHigh / 1000;
                datagram.returnLow    = datagram.returnLow / 1000;
                datagram.gasUsage     = datagram.gasUsage / 1000;
            }
            context.datagrams.Add(datagram);
            context.SaveChanges();
            Console.WriteLine("datagram added");
        }
Ejemplo n.º 6
0
 public async void addScantoDB(FullDatagram datagram)
 {
     await repository.AddAsync(datagram);
 }
Ejemplo n.º 7
0
 public void saveDatagram(FullDatagram datagram)
 {
     addScantoDB(datagram);
 }