public SolarPanel GetById(int id) { string query = "select p.ID,Naam,Serienummer,Prijs,Merk,Omschrijving,Garantie,vermogen,kleur,celtype,lengte,breedte,hoogte,voorraad from Product p inner join ProductEigenschappen pe on pe.Id = p.EigenschappenID where TypeID = 1 and p.id = @id"; if (OpenConnection()) { try { using (SqlCommand command = new SqlCommand(query, Connection)) { command.Parameters.AddWithValue("@id", id); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { SolarPanel solarpanel = CreateFromReader(reader); return(solarpanel); } } } } catch (SqlException exception) { } finally { CloseConnection(); } } throw new Exception(); }
public void CreateShouldHappenIfPanelIsValid() { //arrange DateTime date = DateTime.Parse("02/02/2019"); SolarPanel panel = new SolarPanel { Section = "TestSection", Row = 8, Column = 8, DateInstalled = date, Material = MaterialType.AmorphousSilicon, IsTracking = false }; string testFileName = $"Test{DateTime.Now.Ticks}.csv"; FileSolarPanelRepository repo = new FileSolarPanelRepository(testFileName); SolarPanelService service = new SolarPanelService(repo); //act SolarPanelResult result = service.Create(panel); //assert Assert.IsTrue(result.Success); Assert.AreEqual("Success. TestSection-8-8 added.", result.Message); Assert.AreEqual(panel, result.Data); File.Delete(testFileName); }
public void Update(int id, SolarPanel entity) { if (OpenConnection()) { try { SqlConnection Connection = this.Connection; SqlCommand insertSolarPanel = Connection.CreateCommand(); insertSolarPanel.CommandText = "EXECUTE insertSolarpanel @Naam,@Merk,@Omschrijving,@Garantie,@Vermogen,@Celtype,@lengte,@Breedte,@Hoogte,@Serienummer,@Prijs,@Kleur,@ProductId,@Voorraad"; insertSolarPanel.Parameters.AddWithValue("@Naam", entity.Name); insertSolarPanel.Parameters.AddWithValue("@Merk", entity.Brand); insertSolarPanel.Parameters.AddWithValue("@Omschrijving", entity.Description); insertSolarPanel.Parameters.AddWithValue("@Garantie", entity.Warranty); insertSolarPanel.Parameters.AddWithValue("@Vermogen", entity.Power); insertSolarPanel.Parameters.AddWithValue("@Celtype", entity.Celtype.ToString()); insertSolarPanel.Parameters.AddWithValue("@lengte", entity.Length); insertSolarPanel.Parameters.AddWithValue("@Breedte", entity.Width); insertSolarPanel.Parameters.AddWithValue("@Hoogte", entity.Height); insertSolarPanel.Parameters.AddWithValue("@Serienummer", entity.Serial); insertSolarPanel.Parameters.AddWithValue("@Prijs", entity.Price); insertSolarPanel.Parameters.AddWithValue("@Kleur", entity.Color); insertSolarPanel.Parameters.AddWithValue("@ProductId", entity.Id); insertSolarPanel.Parameters.AddWithValue("@Voorraad", entity.Stock); insertSolarPanel.ExecuteNonQuery(); } catch (SqlException exception) { } finally { CloseConnection(); } } }
public void DeletePanelShouldDeleteGivenPanelAndReturnResult() { //arrange string testFileName = $"Test{DateTime.Now.Ticks}.csv"; FileSolarPanelRepository repo = new FileSolarPanelRepository(testFileName); SolarPanelService service = new SolarPanelService(repo); SolarPanel toDeletePanel = new SolarPanel { Section = "TestSection", Row = 8, Column = 8, DateInstalled = DateTime.Parse("10/01/2021"), Material = MaterialType.MulticrystallineSilicon, IsTracking = true }; //act service.Create(toDeletePanel); SolarPanelResult result = service.Delete(toDeletePanel); //assert Assert.IsTrue(result.Success); Assert.AreEqual($"{toDeletePanel.GetKey()} removed.", result.Message); Assert.AreEqual(toDeletePanel, result.Data); }
public static bool Prefix(SolarPanel __instance) { Constructable component = __instance.gameObject.GetComponent <Constructable>(); if (component.constructed) { float producedPower = (float)funcGetRechargeScalar.Invoke(__instance, new object[] { }) * DayNightCycle.main.deltaTime * 0.25f * 5f; float excessPower = Mathf.Max(0f, producedPower - (__instance.powerSource.maxPower - __instance.powerSource.power)) * DW_Tweaks_Settings.Instance.RenewablePowerPushExcess; __instance.powerSource.power = Mathf.Clamp(__instance.powerSource.power + producedPower, 0f, __instance.powerSource.maxPower); if (excessPower > 0) { float transferredPower = 0; if (__instance.powerSource.connectedRelay != null) { if (!__instance.powerSource.connectedRelay.AddEnergy(excessPower, out transferredPower)) { __instance.GetComponent <PowerRelay>().GetEndpoint().AddEnergy(excessPower - transferredPower, out transferredPower); } } else { __instance.GetComponent <PowerRelay>().GetEndpoint().AddEnergy(excessPower, out transferredPower); } } } return(false); }
public void DeleteShouldRemovePanelAndSaveFile() { //Arrange string testFile = "TestDataDeleteBefore.csv"; ISolarPanelRepository beforeRepo = new FileSolarPanelRepository(testFile); string afterFile = "TestDataDeleteAfter.csv"; ISolarPanelRepository afterRepo = new FileSolarPanelRepository(afterFile); SolarPanel panel = new SolarPanel { Section = "DeleterTest", Row = 2, Column = 3, DateInstalled = DateTime.Parse("03/03/2020"), Material = MaterialType.CadmiumTelluride, IsTracking = true }; beforeRepo.Create(panel); //Act Dictionary <string, SolarPanel> panelList = beforeRepo.ReadAll(); beforeRepo.Delete(panel); //Assert Assert.IsFalse(panelList.ContainsKey("DeleterTest-2-3")); Assert.AreEqual(0, panelList.Count); Assert.AreEqual(afterRepo.ReadAll(), beforeRepo.ReadAll()); File.Delete(testFile); }
public void CreateShouldNotHappenIfPanelIsInvalid(string section, int row, int column, string date, string material, string isTracking) { //arrange SolarPanel panel = new SolarPanel { Section = section, Row = row, Column = column, DateInstalled = DateTime.Parse(date), Material = Enum.Parse <MaterialType>(material), IsTracking = bool.Parse(isTracking) }; ISolarPanelRepository repo = new FileSolarPanelRepository("TestDataBLLBadCreate.csv"); SolarPanelService service = new SolarPanelService(repo); //act SolarPanelResult result = service.Create(panel); //assert Assert.IsFalse(result.Success); Assert.IsNotEmpty(result.Message); Assert.IsNotNull(result.Message); Assert.AreEqual(panel, result.Data); Assert.AreEqual(1, repo.ReadAll().Count); }
public void addNewSolarPanel(object sender, RoutedEventArgs e) { SolarPanel sp = new SolarPanel(); foreach (SolarPanel item in SolarPanels) { if (item.Name == name.Text) { MessageBox.Show("Name already exist"); return; } } try { sp = new SolarPanel(name.Text, double.Parse(power.Text)); proxy.AddNewSolarPanelInSystem(sp); } catch (Exception exc) { Console.WriteLine("Bad power value"); return; } lock (lockObject) { SolarPanels.Add(sp); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(txtBox_solarPanelName.Text)) { MessageBox.Show("Pls enter valid name for solar panel."); return; } int power; if (!int.TryParse(txtBox_solarPanelPower.Text, out power)) { MessageBox.Show("Please enter valid power."); return; } ShesDbContext context = new ShesDbContext(); SolarPanel sp = new SolarPanel(power, txtBox_solarPanelName.Text); context.SolarPanels.Add(sp); context.SaveChanges(); MessageBox.Show("Success"); txtBox_solarPanelName.Text = ""; txtBox_solarPanelPower.Text = ""; shes.SolarPanels.List.Add(sp); }
public void CreateSholdCreateAddPanelToDictionaryAndSave() { //arrange DateTime date = DateTime.Parse("02/02/2019"); SolarPanel panel = new SolarPanel { Section = "TestSection", Row = 8, Column = 8, DateInstalled = date, Material = MaterialType.AmorphousSilicon, IsTracking = false }; string testFileName = $"Test{DateTime.Now.Ticks}.csv"; FileSolarPanelRepository repo = new FileSolarPanelRepository(testFileName); //act repo.Create(panel); Dictionary <string, SolarPanel> panelList = repo.ReadAll(); //assert Assert.IsNotNull(panelList); Assert.IsNotNull(panelList["TestSection-8-8"]); Assert.AreEqual(1, panelList.Count); Assert.AreEqual(DateTime.Parse("02/02/2019"), panelList["TestSection-8-8"].DateInstalled); Assert.AreEqual(MaterialType.AmorphousSilicon, panelList["TestSection-8-8"].Material); Assert.IsFalse(panelList["TestSection-8-8"].IsTracking); File.Delete(testFileName); }
// Update is called once per frame void Update() { Transform t = GetComponentInParent <Transform>(); for (int i = 0; i < solarPanels.Length; i++) { SolarPanel panel = solarPanels[i]; float adjustValue = panel.adjust_value; if (!disable) { panel.transform.Rotate(Vector3.right * adjustValue); } float elapsed_time = Time.time - start_time; elapsed_delta += Time.deltaTime; if (socket.connected && elapsed_delta > 0.05) { //float solar_angle = Vector3.SignedAngle(panel.resting_pos.forward, panel.calculated_solar_dir, transform.right); float actualSolarAngle = Vector3.SignedAngle(panel.resting_pos.forward, sun.transform.position - panel.transform.position, transform.right); elapsed_delta = 0; //string msg = "{ \"adjust_value\": { \"time\":" + elapsed_time.ToString().Replace(",", ".") + ", \"value\": "+ adjustValue.ToString().Replace(",", ".")+"} }"; string msg = "{ \"adjust_value_" + i + "\": " + adjustValue.ToString().Replace(",", ".") + " , \"actual_angle_" + i + "\": " + panel.current_offset_angle.ToString().Replace(",", ".") + ", \"desired_position_" + i + "\": " + panel.desired_position.ToString().Replace(",", ".") + ", \"actual_solar_angle_" + i + "\": " + actualSolarAngle.ToString().Replace(",", ".") + "}"; socket.Send(msg); } logWriters[i].WriteLine(elapsed_time.ToString().Replace(",", ".") + "," + adjustValue.ToString().Replace(",", ".")); } }
public IEnumerable <SolarPanel> FindAll() { string query = "select idsp, power from solarpanels"; List <SolarPanel> solarPanelList = new List <SolarPanel>(); using (IDbConnection connection = ConnectionUtil_Pooling.GetConnection()) { connection.Open(); using (IDbCommand command = connection.CreateCommand()) { command.CommandText = query; command.Prepare(); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { SolarPanel sp = new SolarPanel(reader.GetString(0), reader.GetDouble(1)); solarPanelList.Add(sp); } } } } return(solarPanelList); }
public SolarPanel FindById(string id) { string query = "select idsp, power from solarpanels where idsp = :idsp"; SolarPanel sp = null; using (IDbConnection connection = ConnectionUtil_Pooling.GetConnection()) { connection.Open(); using (IDbCommand command = connection.CreateCommand()) { command.CommandText = query; ParameterUtil.AddParameter(command, "idsp", DbType.String); command.Prepare(); ParameterUtil.SetParameterValue(command, "idsp", id); using (IDataReader reader = command.ExecuteReader()) { if (reader.Read()) { sp = new SolarPanel(reader.GetString(0), reader.GetDouble(1)); } } } } return(sp); }
public bool CanPanelFit(SolarPanel solarPanel, List <Point> sitePoints, List <Point> restrictionPoints) { var panelPoints = CreatePanelPoints(solarPanel); return(!IsAnyPointInside(panelPoints, restrictionPoints) && IsAllPointsInside(panelPoints, sitePoints)); }
public static void Postfix(SolarPanel __instance) { if (onAwake != null) { onAwake.Invoke(__instance); } }
private void LoadPanels() { if (!File.Exists(_fileName)) { File.Create(_fileName).Close(); } else { using (StreamReader sr = new StreamReader(_fileName)) { sr.ReadLine(); //first row is just headers for (string line = sr.ReadLine(); line != null; line = sr.ReadLine()) { if (!string.IsNullOrEmpty(line))//lines may be blank after deleting in-program { string[] fields = line.Split(','); SolarPanel panel = new SolarPanel(); panel.Section = fields[0]; panel.Row = int.Parse(fields[1]); panel.Column = int.Parse(fields[2]); panel.DateInstalled = DateTime.Parse(fields[3]); panel.Material = Enum.Parse <MaterialType>(fields[4]); panel.IsTracking = bool.Parse(fields[5]); _panelList.Add(panel.GetKey(), panel); } else { continue; } } } } }
public Buildable AddSolarPanel(GameObject clone) { SolarPanel newSolarPanel = new SolarPanel(clone); this.SolarPanels.Add(newSolarPanel); newSolarPanel.Id = this.SolarPanels.Count - 1; return newSolarPanel; }
/// <summary> /// Updates a panel with a certain Section-row-column identifier. Cannot update section/row/column for now /// </summary> /// <param name="panel">The panel containing the new information</param> /// <returns>SolarPanelResult indicating success, Data is the new panel if changes are valid null if not</returns> public SolarPanelResult Update(SolarPanel panel) { //DateInstalled must be past if (panel.DateInstalled > DateTime.Now) { return(new SolarPanelResult { Success = false, Message = "Date Installed cannot be in the future", Data = null }); } //IsTracking can't be empty if (panel.IsTracking != true) { if (panel.IsTracking != false) { return(new SolarPanelResult { Success = false, Message = "IsTracking must be true or false", Data = null }); } } //Doesn't check material type because that will be validated at input point (chosen from list of valid material types) _repo.Update(panel.GetKey(), panel); return(new SolarPanelResult { Success = true, Message = "Success.", Data = panel }); }
//Not currently able to change a panel's section/row/column public void Update(string section, SolarPanel panel) { _panelList[section].DateInstalled = panel.DateInstalled; _panelList[section].Material = panel.Material; _panelList[section].IsTracking = panel.IsTracking; SavePanels(); }
private static void AddSolarPanel() { Console.Clear(); Console.WriteLine("Please enter information about solar panel in format id:mawPower"); string input = Console.ReadLine(); string[] parts = input.Split(':'); if (parts.Length != 2) { Console.Clear(); Console.WriteLine("Error while parsing information. Try again"); return; } double maxPower = 0; if (!double.TryParse(parts[1], out maxPower)) { Console.Clear(); Console.WriteLine("Error while parsing information. Try again"); return; } SolarPanelCreator creator = new SolarPanelCreator(); SolarPanel sp = creator.Create(parts[0], maxPower); Console.WriteLine("Success!!!"); //add to db ? }
public SolarPylon(String pylonKey) { _pylonKey = pylonKey; _vRotor = new SolarRotor(_pylonKey, SolarRotorType.Vertical); _hRotors.Add(new SolarRotor(_pylonKey, SolarRotorType.HorizontalLeft)); _hRotors.Add(new SolarRotor(_pylonKey, SolarRotorType.HorizontalRight)); _panel = new SolarPanel(_hRotors); }
public void Save(SolarPanel entity) { using (IDbConnection connection = ConnectionUtil_Pooling.GetConnection()) { connection.Open(); Save(entity, connection); } }
public SolarRotor(string prefix, List <IMyMotorStator> rotors, SolarPanel panel, Action <string> logger) { this.logger = logger; this.id.Prefix = prefix; this.panel = panel; this.setupRotors(rotors, out this.mainRotor); this.updateNames(); }
public void SolarPanelConstructor_BadExample2(string id) { Assert.Throws <ArgumentNullException>(() => { SolarPanel sp = new SolarPanel(id); } ); }
public List <Point> GetPlacingPoints(SolarPanel solarPanel, List <Point> siteCoordinationPoints, List <Point> restrictionCoordinationPoints, ZoneCalculations zoneCalculations) { GetTiltedPanelWidth(solarPanel); var siteRange = zoneCalculations.GetRange(siteCoordinationPoints); return(FindPlacingPoints(solarPanel, siteCoordinationPoints, restrictionCoordinationPoints, siteRange)); }
public bool AddNewSolarPanelInSystem(SolarPanel sp) { lock (lockSolars) { SolarPanels.Add(sp); serializer.SerializeObject <ObservableCollection <SolarPanel> >(SolarPanels, "SolarPanels.xml"); } return(true); }
public List <Point> CreatePanelPoints(SolarPanel solarPanelData) { var panelPoints = new List <Point>(); panelPoints.AddRange(GetCornerPoints(solarPanelData)); panelPoints.AddRange(GetMiddlePoints(solarPanelData)); return(panelPoints); }
public void GetTiltedPanelWidth_TiltAngleIsZero_Return() { var panelCalculations = new PanelCalculations(); var testSolarPanel = new SolarPanel(0, 0, 0, 0, 0, 0, 0); panelCalculations.GetTiltedPanelWidth(testSolarPanel); Assert.AreEqual(0, testSolarPanel.Width); }
public void GetTiltedPanelWidth_TiltAngleIsTen_ReturnNewWidth() { var panelCalculations = new PanelCalculations(); var testSolarPanel = new SolarPanel(10, 0, 0, 0, 10, 0, 0); panelCalculations.GetTiltedPanelWidth(testSolarPanel); Assert.AreEqual(9.84807753012208, testSolarPanel.Width); }
public void Panel_ConstructorTest(string name, double maxPower, double currentPower) { SolarPanel panel = new SolarPanel { Name = name, MaxPower = maxPower, CurrentPower = currentPower }; Assert.AreEqual(panel.Name, name); Assert.AreEqual(panel.MaxPower, maxPower); Assert.AreEqual(panel.CurrentPower, currentPower); }
public List <Point> GetCornerPoints(SolarPanel solarPanelData) { return(new List <Point> { solarPanelData.OriginPoint, new Point(solarPanelData.OriginPoint.X + solarPanelData.Length, solarPanelData.OriginPoint.Y), new Point(solarPanelData.OriginPoint.X, solarPanelData.OriginPoint.Y + solarPanelData.Width), new Point(solarPanelData.OriginPoint.X + solarPanelData.Length, solarPanelData.OriginPoint.Y + solarPanelData.Width) }); }