예제 #1
0
 public IHttpActionResult GetGt(int id, int deviceid)
 {
     try
     {
         using (SunContext ctx = new SunContext())
         {
             int          maxSampleId = ctx.Samples.Where(s => s.Id >= id && s.deviceid == deviceid || deviceid == 0).Max(s => s.Id);
             SunSampleNew sm          = ctx.Samples.FirstOrDefault(s => s.Id == maxSampleId);
             return(Ok(sm));
         }
     }
     catch (Exception ex)
     {
         return(Ok(ex.ToString()));
     }
 }
예제 #2
0
        public IHttpActionResult PostSunSample(SunSample payload)
        {
            if (payload.deviceid == 10)
            {
                payload.deviceid = 1;
            }
            if (payload.deviceid == 11)
            {
                payload.deviceid = 2;
            }
            if (payload.deviceid == 12)
            {
                payload.deviceid = 3;
            }
            try
            {
                SunSampleNew sample = new SunSampleNew
                {
                    Id       = payload.Id,
                    deviceid = payload.deviceid,
                    voltage  = Int32.Parse(payload.vals.Split(' ').Last()),
                    created  = DateTime.UtcNow
                };


                using (SunContext ctx = new SunContext())
                {
                    ctx.Samples.Add(sample);
                    ctx.SaveChanges();
                }

                using (WebClient webClient = new WebClient())
                {
                    var address = "https://api.powerbi.com/beta/8c92d11f-39b7-4fac-b170-69a3ca72ecd4/datasets/a5e1d0f5-6a4e-469f-9172-0b63f3cc921f/rows?key=N1QwKreol%2B7GhqUsE%2B49ayvwGt%2FQrgs9laLOatw4ErPpSrYtlaOWnCKWsyQRbnfKZPjSrSKmsnuFJ7qL%2BxiLOQ%3D%3D";
                    webClient.UploadString(address,
                                           $"[{{\"Id\" :{sample.Id},\"deviceID\" :{sample.deviceid}, \"voltage\" :{sample.voltage},\"DateTime\" :\"{DateTime.Now.ToString("yyyy - MM - ddTHH:mm: ssZ")}\" }}]");
                }

                return(Ok(payload));
            }
            catch (Exception ex)
            {
                return(Ok(ex.ToString()));
            }
        }