public IActionResult TankSpecs(TankSpecs tankSpecs) { if (ModelState.IsValid) { _formDataService.SetTankSpecs(tankSpecs); _aquaI2CController.UpdateTankSpecs(tankSpecs.Width, tankSpecs.Height, tankSpecs.Depth); _pinMasterController.UpdateWaterChangeTime(tankSpecs.WaterChangeTime); return(RedirectToAction("Index", nameof(HomeController).RemoveControllerFromName())); } return(View(tankSpecs)); }
public void FormDataService_DeSerializeTankSpecs_Deserializes() { double expectedHeight = 6; double expectedWidth = 12; double expectedDepth = 22; DateTime expectedWaterChangeTime = new DateTime(2018, 10, 10, 11, 00, 00); FormDataService formDataService = new FormDataService(); TankSpecs tankSpecs = formDataService.DeSerializeTankSpecs(tankSpecsXML); Assert.AreEqual(expectedWaterChangeTime, tankSpecs.WaterChangeTime, $"{nameof(tankSpecs.WaterChangeTime)} is not the same"); Assert.AreEqual(expectedDepth, tankSpecs.Depth, $"{nameof(tankSpecs.Depth)} is not the same"); Assert.AreEqual(expectedWidth, tankSpecs.Width, $"{nameof(tankSpecs.Width)} is not the same"); Assert.AreEqual(expectedHeight, tankSpecs.Height, $"{nameof(tankSpecs.Height)} is not the same"); }
/// <summary> /// Sets the tank size specs, <see cref="TankSpecs"/> /// </summary> /// <param name="tankSpecs"></param> public void SetTankSpecs(TankSpecs tankSpecs) { using (XmlTextWriter xmlWriter = new XmlTextWriter(TANK_SPEC_FILE, Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement(TANK_SPECS_START_ELM); xmlWriter.WriteElementString(TANK_SPECS_WATER_CHANGE, tankSpecs.WaterChangeTime.ToString()); xmlWriter.WriteElementString(TANK_SPECS_HEIGHT, tankSpecs.Height.ToString()); xmlWriter.WriteElementString(TANK_SPECS_WIDTH, tankSpecs.Width.ToString()); xmlWriter.WriteElementString(TANK_SPECS_DEPTH, tankSpecs.Depth.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); } }
/// <summary> /// Deserializes the <see cref="TankSpecs"/> /// </summary> /// <param name="xmlData"></param> /// <returns></returns> public TankSpecs DeSerializeTankSpecs(string xmlData) { TankSpecs tankSpecs = new TankSpecs(); if (!string.IsNullOrEmpty(xmlData)) { XmlDocument document = new XmlDocument(); document.SecureLoadXml(xmlData); XmlNode rootNode = document.SelectSingleNode(TANK_SPECS_START_ELM); tankSpecs.WaterChangeTime = GetDateTime(rootNode.SelectSingleNode($"{TANK_SPECS_WATER_CHANGE}").FirstChild.Value).Value; tankSpecs.Depth = double.Parse(rootNode.SelectSingleNode(TANK_SPECS_DEPTH).FirstChild.Value); tankSpecs.Height = double.Parse(rootNode.SelectSingleNode(TANK_SPECS_HEIGHT).FirstChild.Value); tankSpecs.Width = double.Parse(rootNode.SelectSingleNode(TANK_SPECS_WIDTH).FirstChild.Value); } return(tankSpecs); }
/// <summary> /// Gets the tank size specs, <see cref="TankSpecs"/> /// </summary> public TankSpecs GetTankSpecs() { TankSpecs tankSpecs; try { string tankSpecsXml = TANK_SPEC_FILE; tankSpecsXml = GetXmlFromFile(tankSpecsXml); tankSpecs = DeSerializeTankSpecs(tankSpecsXml); } catch (Exception exp) { Console.WriteLine(exp.Message); tankSpecs = new TankSpecs(); } return(tankSpecs); }
/// <summary> /// Creates a new <see cref="Startup"/> object /// </summary> /// <param name="env"></param> public Startup(IHostingEnvironment env) { IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); _formDataService = new FormDataService(); FeedingTimes feedingTimes = _formDataService.GetFeedingTimes(); _pinController = new AquaPinController(feedingTimes.Feedings, feedingTimes.Pinches); TankSpecs tankSpecs = _formDataService.GetTankSpecs(); _i2CController = new AquaI2CController(tankSpecs.Width, tankSpecs.Height, tankSpecs.Depth); _pinMasterController = new PinMasterController(_i2CController, _pinController, tankSpecs.WaterChangeTime); }
// GET: /<controller>/ /// <summary> /// Gets the <see cref="TankSpecs"/> model for the tank view /// </summary> /// <returns></returns> public IActionResult TankSpecs() { TankSpecs tankSpecs = _formDataService.GetTankSpecs(); return(View(tankSpecs)); }