123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Text.Json;
- using System.Threading.Tasks;
- using Applications.UniversalApi_WebConsole_App.Models.VeederRoot_ATG_Console_Handler_Models;
- using Edge.Core.IndustryStandardInterface.ATG;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- namespace Applications.UniversalApi_WebConsole_App.Controllers
- {
- public class VeederRoot_ATG_Console_Handler_Controller : Controller
- {
- private static MockAutoTankGaugeController mockAtgController;
- static VeederRoot_ATG_Console_Handler_Controller()
- {
- var tank1 = new Tank()
- {
- TankNumber = 1,
- Diameter = 1800,
- Product = new Product()
- {
- ProductCode = "02",
- ProductLabel = "92#"
- },
- Limit = new TankLimit() { },
- Probe = new Probe()
- {
- ProbeLength = 1800,
- State = "",
- }
- };
- var tank2 = new Tank()
- {
- TankNumber = 2,
- Diameter = 1800,
- Product = new Product()
- {
- ProductCode = "05",
- ProductLabel = "95#"
- },
- Limit = new TankLimit()
- {
-
- },
- Probe = new Probe()
- {
- ProbeLength = 2800,
- State = "",
- }
- };
- var tank3 = new Tank()
- {
- TankNumber = 3,
- Diameter = 1800,
- Product = new Product()
- {
- ProductCode = "08",
- ProductLabel = "98#"
- },
- Limit = new TankLimit()
- {
-
- },
- Probe = new Probe()
- {
- ProbeLength = 1800,
- State = "",
- }
- };
- var tank4 = new Tank()
- {
- TankNumber = 4,
- Diameter = 1800,
- Product = new Product()
- {
- ProductCode = "09",
- ProductLabel = "0#"
- },
- Limit = new TankLimit()
- {
-
- },
- Probe = new Probe()
- {
- ProbeLength = 1800,
- State = "",
- }
- };
- var tank5 = new Tank()
- {
- TankNumber = 5,
- Diameter = 1800,
- Product = new Product()
- {
- ProductCode = "11",
- ProductLabel = "-35#"
- },
- Limit = new TankLimit()
- {
-
- },
- Probe = new Probe()
- {
- ProbeLength = 1800,
- State = "",
- }
- };
- mockAtgController = new MockAutoTankGaugeController(
- new List<Tank>()
- {
- tank1,tank2,tank3,tank4,tank5
- }, SystemUnit.Metric);
- }
- // GET: VeederRoot_ATG_Console_Handler_
- public async Task<ActionResult> Index(int? tankNumber)
- {
- HttpClient client = new HttpClient();
- client.DefaultRequestHeaders.Accept.Clear();
- client.DefaultRequestHeaders.Accept.Add(
- new MediaTypeWithQualityHeaderValue("application/json"));
- client.DefaultRequestHeaders.Add("User-Agent", "UniversalWebConsoleApp");
- var streamTask = client.GetStreamAsync("http://localhost:8384/u/?mn=GetAutoTankGaugeControllerAsync&pn=VeederRoot_ATG_Console_Tcp");
- var atgController = await JsonSerializer.DeserializeAsync<IAutoTankGaugeController>(await streamTask);
- return View("/Views/VeederRoot_ATG_Console_Handler/Index.cshtml", atgController);
- }
- public async Task<ActionResult> IndexMock(int? tankNumber)
- {
- var model = new AtgController()
- {
- Name = mockAtgController.MetaConfigName,
- DeviceId = mockAtgController.DeviceId,
- SystemUnit = mockAtgController.SystemUnit
- };
- if (tankNumber.HasValue)
- model.Tanks = mockAtgController.Tanks.Where(t => t.TankNumber == tankNumber.Value);
- else
- model.Tanks = mockAtgController.Tanks;
- return View("/Views/VeederRoot_ATG_Console_Handler/Index.cshtml", model);
- }
- //public async Task<IActionResult> TankProbeReadingsData(int? tankNumber)
- //{
- // var readings = await App.AutoTankGaugeController.GetTankProbeReadingsAsync(tankNumber);
- // if (readings == null || !readings.Any()) return NoContent();
- // //DataPointWithStringX data = new DataPointWithStringX(DateTime.Now.ToLongTimeString(), 1999);
- // var datas = DataPointProbeReading.From(readings.Select(r => r.Item2));
- // return Content(JsonConvert.SerializeObject(datas, _jsonSetting), "application/json");
- //}
- // GET: VeederRoot_ATG_Console_Handler_/Details/5
- public async Task<ActionResult> Details(int? tankNumber)
- {
- if (tankNumber.HasValue)
- {
- var reading = await mockAtgController.GetTankReadingAsync(tankNumber.Value);
- if (reading == null) return NotFound();
- return Ok(new[]
- {
- new TankReadingDto(){
- tankNumber= tankNumber.Value,
- Height= reading.Height,
- Water= reading.Water,
- Temperature= reading.Temperature,
- Volume= reading.Volume,
- WaterVolume= reading.WaterVolume,
- TimeStamp = DateTime.Now.ToString("HH:mm:ss"),
- }
- });
- }
- else
- {
- List<TankReadingDto> tankReadings = new List<TankReadingDto>();
- foreach (var t in mockAtgController.Tanks)
- {
- var reading = await mockAtgController.GetTankReadingAsync(t.TankNumber);
- if (reading == null) continue;
- var dto = new TankReadingDto()
- {
- tankNumber = t.TankNumber,
- Height = reading.Height,
- Water = reading.Water,
- Temperature = reading.Temperature,
- Volume = reading.Volume,
- WaterVolume = reading.WaterVolume,
- TimeStamp = DateTime.Now.ToString("HH:mm:ss"),
- };
- tankReadings.Add(dto);
- }
- return Ok(tankReadings);
- }
- }
- // GET: VeederRoot_ATG_Console_Handler_/Create
- public ActionResult Create()
- {
- return View();
- }
- // POST: VeederRoot_ATG_Console_Handler_/Create
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create(IFormCollection collection)
- {
- try
- {
- // TODO: Add insert logic here
- return RedirectToAction(nameof(Index));
- }
- catch
- {
- return View();
- }
- }
- // GET: VeederRoot_ATG_Console_Handler_/Edit/5
- public ActionResult Edit(int id)
- {
- return View();
- }
- // POST: VeederRoot_ATG_Console_Handler_/Edit/5
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(int id, IFormCollection collection)
- {
- try
- {
- // TODO: Add update logic here
- return RedirectToAction(nameof(Index));
- }
- catch
- {
- return View();
- }
- }
- // GET: VeederRoot_ATG_Console_Handler_/Delete/5
- public ActionResult Delete(int id)
- {
- return View();
- }
- // POST: VeederRoot_ATG_Console_Handler_/Delete/5
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Delete(int id, IFormCollection collection)
- {
- try
- {
- // TODO: Add delete logic here
- return RedirectToAction(nameof(Index));
- }
- catch
- {
- return View();
- }
- }
- }
- }
|