// Use this for initialization private void Start() { if (!VehicleAPI.IsValidIndividualLight(lightType)) { throw new Exception("Light sides need to have a valid value, revise your code."); } GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Capsule); //If you uncomment this wheels won't steer //Destroy(obj.GetComponent<CapsuleCollider>()); obj.name = string.Format("Blinker ({0})", lightType.ToString()); obj.transform.parent = parent; obj.transform.position = parent.position + Vector3.right * (IsLeftSide ? -1 : 1) * .2f; //obj.transform.localRotation = Quaternion.Euler(new Vector3(0, 30 * (IsLeftSide ? -1 : 1), 0)); obj.transform.localScale = Vector3.one * .2f; blinkerRenderer = obj.GetComponent <MeshRenderer>(); blinkerRenderer.material = Resources.Load <Material>("Materials/Blinker"); defaultIntensity = blinkerRenderer.material.GetFloat("_MKGlowPower"); blinkerSwitch = false; InvokeRepeating("Cycle", 0, repeatInterval); }
// Use this for initialization private void Start() { //lightSide = GetVehicleLightSide(lightType); if (!VehicleAPI.IsValidIndividualLight(lightType)) { throw new Exception("Light sides need to have a valid value, revise your code."); } setAppart = gameObject.GetComponent <Light>() != null; GameObject obj = gameObject; if (setAppart) { obj = new GameObject("Blinker"); obj.transform.parent = parent; obj.transform.position = parent.position + Vector3.right * (IsLeftSide ? -1 : 1) * .2f; obj.transform.localRotation = Quaternion.Euler(new Vector3(0, 30 * (IsLeftSide ? -1 : 1), 0)); } blinkerLight = obj.AddComponent <Light>(); VehicleAPI.SetLightProps(lightType, ref blinkerLight, true); defaultIntensity = blinkerLight.intensity; ToggleBlinker(false); InvokeRepeating("Cycle", 0, repeatInterval); }
async private void HistoryList_SelectionChanged(object sender, SelectionChangedEventArgs e) { SearchHistoryItem item = (SearchHistoryItem)HistoryList.SelectedItem; try { // Active ProgressSpinner and Show Progress Text SearchProgress.IsActive = true; txtSearchProgress.Text = "Searching..."; SearchResult.Vehicles = await VehicleAPI.GetVehiclesAsync(item.Query); // Disable ProgressSpinner and Show Progress Text SearchProgress.IsActive = false; txtSearchProgress.Text = ""; if (SearchResult.Vehicles.Count > 0) { Frame.Navigate(typeof(SearchResult), null, new SuppressNavigationTransitionInfo()); } } catch (Exception ex) { MessageDialog dialog = new MessageDialog(ex.Message); dialog.Title = "Info"; await dialog.ShowAsync(); } }
public IndexModel(VehicleAPI vehicleAPI) { _vehicleAPI = vehicleAPI; _controller = new VeiculoController(_vehicleAPI); veiculosBasicos = new List <Veiculo>(); veiculosCompletos = new List <Veiculo>(); veiculosLuxo = new List <Veiculo>(); }
// Get Data from API public void TestLoadData() { QueryBuilder query = new QueryBuilder(); query.AddField(Field.Fields.ID, "8897"); query.Build(QueryBuilder.QueryType.Select); string actual = VehicleAPI.LoadData(query.QueryString); string expected = "[{\"ID\":\"8897\",\"ajoneuvoluokka_koodi\":\"O2\",\"ajoneuvoluokka_lyhytselite\":\"Perävaunu\",\"ajoneuvoluokka_pitkaselite\":\"Perävaunu, 750 < m <= 3500 kg\",\"ensirekisterointipvm\":\"1998-04-22\",\"ajoneuvoryhma\":\"Keskiakseliperävaunu\",\"ajoneuvonkaytto\":\"Yksityinen\",\"variantti\":null,\"versio\":null,\"kayttoonottopvm\":\"1998-04-22\",\"vari\":null,\"ovienLukumaara\":null,\"korityyppi_koodi\":null,\"korityyppi_pitkaselite\":null,\"ohjaamotyyppi\":null,\"istumapaikkojenLkm\":null,\"omamassa\":\"640\",\"teknSuurSallKokmassa\":null,\"tieliikSuurSallKokmassa\":\"2100\",\"ajonKokPituus\":null,\"ajonLeveys\":\"2250\",\"ajonKorkeus\":null,\"kayttovoima\":null,\"iskutilavuus\":null,\"suurinNettoteho\":null,\"sylintereidenLkm\":null,\"ahdin\":null,\"sahkohybridi\":null,\"sahkohybridinluokka\":null,\"merkkiSelvakielinen\":\"Omavalmiste\",\"mallimerkinta\":\"PV 2100\",\"vaihteisto\":null,\"vaihteidenLkm\":null,\"kaupallinenNimi\":null,\"voimanvalJaTehostamistapa\":\"8\",\"tyyppihyvaksyntanro\":null,\"yksittaisKayttovoima\":null,\"kunta\":\"Oulu\",\"Co2\":null,\"matkamittarilukema\":null,\"alue\":\"901\",\"valmistenumero2\":null}]"; Assert.AreEqual(expected, actual); }
// Test Get ChartData public void TestGetChartData() { List <ChartItem> values = VehicleAPI.GetChartData(QueryBuilder.Table.ChartVari); string actual = values[1].Name; string expected = "Turkoosi"; Assert.AreEqual(expected, actual); double actual1 = values[1].Value; double expected1 = 4835; Assert.AreEqual(expected1, actual1); }
// Test Get Vehicles public void TestGetVehicles() { QueryBuilder query = new QueryBuilder(); query.AddField(Field.Fields.ID, "8897"); query.Build(QueryBuilder.QueryType.Select); List <Vehicle> vehicles = VehicleAPI.GetVehicles(query.QueryString); string actual = vehicles[0].Ensirekisterointipvm; string expected = "1998-04-22"; Assert.AreEqual(expected, actual); }
/// <summary> /// Load ComboBox Items from API /// </summary> private async void LoadComboBoxItems() { // Activate ProgressSpinner and Show progress text LoadingProgress.IsActive = true; txtLoadingProgress.Text = "Loading values..."; //Load Values to Vehicle Class Combobox VehicleClasses = await VehicleAPI.GetOptionsAsync(QueryBuilder.Table.VAjoneuvoluokka); cbVehicleClass.ItemsSource = VehicleClasses; cbVehicleClass.SelectedValuePath = "Value"; cbVehicleClass.DisplayMemberPath = "Value"; // Disable ProgressSpinner and Show progress text LoadingProgress.IsActive = false; txtLoadingProgress.Text = ""; }
/// <summary> /// Load ComboBox Items from API /// </summary> private async void LoadComboBoxItems() { // Activate ProgressSpinner and Show progress text LoadingProgress.IsActive = true; txtLoadingProgress.Text = "Loading values..."; //Retrieve data to Color combobox vColor = await VehicleAPI.GetOptionsAsync(QueryBuilder.Table.VVari); cbColor.ItemsSource = vColor; cbColor.SelectedValuePath = "Value"; cbColor.DisplayMemberPath = "Value"; //Retrieve data to FuelType combobox vFuelType = await VehicleAPI.GetOptionsAsync(QueryBuilder.Table.VKayttovoima); cbFuelType.ItemsSource = vFuelType; cbFuelType.SelectedValuePath = "Value"; cbFuelType.DisplayMemberPath = "Value"; //Retrieve data to FrameType combobox vFrameType = await VehicleAPI.GetOptionsAsync(QueryBuilder.Table.VKorityyppi); cbFrameType.ItemsSource = vFrameType; cbFrameType.SelectedValuePath = "Value"; cbFrameType.DisplayMemberPath = "Value"; //Retrieve data to County combobox vCounty = await VehicleAPI.GetOptionsAsync(QueryBuilder.Table.VKunta); cbCounty.ItemsSource = vCounty; cbCounty.SelectedValuePath = "Value"; cbCounty.DisplayMemberPath = "Value"; //Retrieve data to Car Class combobox vCarClass = await VehicleAPI.GetOptionsAsync(QueryBuilder.Table.VAjoneuvoluokka); cbCarClass.ItemsSource = vCarClass; cbCarClass.SelectedValuePath = "Value"; cbCarClass.DisplayMemberPath = "Value"; // Disable ProgressSpinner and Show progress text LoadingProgress.IsActive = false; txtLoadingProgress.Text = ""; }
// Test Get Options public void TestGetOptions() { List <Option> values = VehicleAPI.GetOptions(QueryBuilder.Table.VOhjaamotyyppi); string actual1 = values[0].Value; string expected1 = "Umpiohjaamo"; Assert.AreEqual(expected1, actual1); string actual2 = values[1].Value; string expected2 = "Suojakehys"; Assert.AreEqual(expected2, actual2); string actual3 = values[2].Value; string expected3 = "Jatko-ohjaamo"; Assert.AreEqual(expected3, actual3); string actual4 = values[3].Value; string expected4 = "Avo-ohjaamo"; Assert.AreEqual(expected4, actual4); }
/// <summary> /// Event Handler for Search Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> async private void btnSearch_Click(object sender, RoutedEventArgs e) { try { // Activate ProgressSpinner, Show Progress Text and Disable Search button SearchProgress.IsActive = true; txtSearchProgress.Text = "Searching..."; btnSearch.IsEnabled = false; SearchResult.Clear(); switch (cbType.SelectedItem.ToString()) { case "Ajoneuvoluokka": SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.ChartAjoneuvoluokka); break; case "Väri": SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.ChartVari); SearchResult.RemoveAt(0); break; case "Käyttövoima": SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.ChartKayttovoima); SearchResult.RemoveAt(0); break; case "Ajoneuvon käyttö": SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.ChartAjoneuvonKaytto); SearchResult.RemoveAt(0); break; case "Korityyppi": SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.ChartKorityyppi); SearchResult.RemoveAt(0); break; case "Merkki": string vehicleClass = cbVehicleClass.SelectedValue.ToString(); string query = $"SELECT merkkiSelvakielinen as Name, COUNT(merkkiSelvakielinen) as Value FROM Ajoneuvo WHERE ajoneuvoluokka=(SELECT ID FROM Ajoneuvoluokka WHERE Kooditunnus = '{vehicleClass}') GROUP BY merkkiSelvakielinen HAVING Value > 100 ORDER BY Value DESC;"; SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.Ajoneuvo, query); break; case "Ensirekisteröintimäärät": string startDate = StartDate.Date.ToString("yyyy-MM-dd"); string endDate = EndDate.Date.ToString("yyyy-MM-dd"); string vehicleClass2 = ""; string brand = ""; if (cbVehicleClass.SelectedValue != null) { vehicleClass2 = $" ajoneuvoluokka=(SELECT ID FROM Ajoneuvoluokka WHERE Kooditunnus = '{cbVehicleClass.SelectedValue.ToString()}') AND "; } if (txtBrand.Text != "") { brand = $" merkkiSelvakielinen='{txtBrand.Text}' AND "; } string query2 = $"SELECT YEAR(ensirekisterointipvm) as Name, COUNT(ensirekisterointipvm) as Value FROM Ajoneuvo WHERE{vehicleClass2}{brand} ensirekisterointipvm BETWEEN '{startDate}' AND '{endDate}' GROUP BY YEAR(ensirekisterointipvm) ORDER BY Name DESC;"; SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.Ajoneuvo, query2); break; case "Sähköhybridien määrä": string startDate2 = StartDate.Date.ToString("yyyy-MM-dd"); string endDate2 = EndDate.Date.ToString("yyyy-MM-dd"); string query3 = $"SELECT YEAR(ensirekisterointipvm) as Name, COUNT(sahkohybridi) as Value FROM Ajoneuvo WHERE sahkohybridi=1 AND ensirekisterointipvm BETWEEN '{startDate2}' AND '{endDate2}' GROUP BY YEAR(ensirekisterointipvm) ORDER BY Name DESC;"; SearchResult = await VehicleAPI.GetChartDataAsync(QueryBuilder.Table.Ajoneuvo, query3); break; } // Disable ProgressSpinner, Show Progress Text and Enable Search button SearchProgress.IsActive = false; txtSearchProgress.Text = "Done"; btnSearch.IsEnabled = true; PieChart.DataSource = SearchResult; PieChart.TitleMemberPath = "Name"; PieChart.ValueMemberPath = "Value"; dgData.ItemsSource = SearchResult; } catch (NullReferenceException) { MessageDialog dialog = new MessageDialog("Fill all enabled fields!"); dialog.Title = "Info"; await dialog.ShowAsync(); // Disable ProgressSpinner, Show Progress Text and Enable Search button SearchProgress.IsActive = false; txtSearchProgress.Text = "Done"; btnSearch.IsEnabled = true; } catch (Exception ex) { MessageDialog dialog = new MessageDialog(ex.Message); dialog.Title = "Exception"; await dialog.ShowAsync(); // Disable ProgressSpinner, Show Progress Text and Enable Search button SearchProgress.IsActive = false; txtSearchProgress.Text = "Done"; btnSearch.IsEnabled = true; } }
async private void BtnDoSearch_Click(object sender, RoutedEventArgs e) { //Upon clock perform the folllowing actions if possible. try { QueryBuilder searchquery = new QueryBuilder(); //If Brand field is not empty, perform the following: if (txtBrand.Text != "") { searchquery.AddField(Field.Fields.merkkiSelvakielinen, txtBrand.Text); } //If Model field is not empty, perform the following: if (txtModel.Text != "") { searchquery.AddField(Field.Fields.mallimerkinta, txtModel.Text); } //If Color field is not empty, perform the following: if (cbColor.SelectedValue != null) { searchquery.AddField(Field.Fields.vari, cbColor.SelectedValue.ToString()); } //If First Registration Date field is not empty and the checkbox was checked to activate the field, perform the following: if (dpFirstRegDate1.Date != null && dpFirstRegDate2.Date != null && cbFirstRegDate.IsChecked == true) { searchquery.AddField(Field.Fields.ensirekisterointipvm, dpFirstRegDate1.Date.ToString("yyyy-MM-dd"), dpFirstRegDate2.Date.ToString("yyyy-MM-dd")); } if (dpDeployDate1.Date != null && dpDeployDate2.Date != null && cbDeployDate.IsChecked == true) { searchquery.AddField(Field.Fields.kayttoonottopvm, dpDeployDate1.Date.ToString("yyyy-MM-dd"), dpDeployDate2.Date.ToString("yyyy-MM-dd")); } //If Fuel Type field is not empty, perform the following: if (cbFuelType.SelectedValue != null) { searchquery.AddField(Field.Fields.kayttovoima, cbFuelType.SelectedValue.ToString()); } //If Frame Type field is not empty, perform the following: if (cbFrameType.SelectedValue != null) { searchquery.AddField(Field.Fields.korityyppi_pitkaselite, cbFrameType.SelectedValue.ToString()); } //If County field is not empty, perform the following: if (cbCounty.SelectedValue != null) { searchquery.AddField(Field.Fields.kunta, cbCounty.SelectedValue.ToString()); } //If Gears field is not empty, perform the following: if (txtGears.Text != "") { int value; if (int.TryParse(txtGears.Text, out value) == false) { throw new Exception("Number of Gears value isn't integer"); } searchquery.AddField(Field.Fields.vaihteisto, value.ToString()); } //If Serial Number field is not empty, perform the following: if (txtSerialNmb.Text != "") { searchquery.AddField(Field.Fields.valmistenumero2, txtSerialNmb.Text); } //If Co2 field is not empty and the input is in integer format, perform the following: if (txtStartCo2.Text != "" && txtEndCo2.Text != "") { int start, end; if (int.TryParse(txtStartCo2.Text, out start) == false) { throw new Exception("Co2 Start value isn't integer"); } if (int.TryParse(txtEndCo2.Text, out end) == false) { throw new Exception("Co2 End value isn't integer"); } searchquery.AddField(Field.Fields.Co2, start.ToString(), end.ToString()); } //If Mileage field is not empty and the input is in integer format, perform the following: if (txtStartMileage.Text != "" && txtEndMileage.Text != "") { int start, end; if (int.TryParse(txtStartMileage.Text, out start) == false) { throw new Exception("Mileage Start value isn't integer"); } if (int.TryParse(txtEndMileage.Text, out end) == false) { throw new Exception("Mileage End value isn't integer"); } searchquery.AddField(Field.Fields.matkamittarilukema, start.ToString(), end.ToString()); } //If Mass field is not empty and the input is in integer format, perform the following: if (txtStartMass.Text != "" && txtEndMass.Text != "") { int start, end; if (int.TryParse(txtStartMass.Text, out start) == false) { throw new Exception("Weight Start value isn't integer"); } if (int.TryParse(txtEndMass.Text, out end) == false) { throw new Exception("Weight End value isn't integer"); } searchquery.AddField(Field.Fields.omamassa, start.ToString(), end.ToString()); } //If Cylinder Cap field is not empty and the input is in integer format, perform the following: if (txtStartCylinderCap.Text != "" && txtEndCylinderCap.Text != "") { int start, end; if (int.TryParse(txtStartCylinderCap.Text, out start) == false) { throw new Exception("Engine Size Start value isn't integer"); } if (int.TryParse(txtEndCylinderCap.Text, out end) == false) { throw new Exception("Engine Size End value isn't integer"); } searchquery.AddField(Field.Fields.sylintereidenLkm, start.ToString(), end.ToString()); } //If Power field is not empty and the input is in integer format, perform the following: if (txtStartNetPower.Text != "" && txtEndNetPower.Text != "") { int start, end; if (int.TryParse(txtStartNetPower.Text, out start) == false) { throw new Exception("Power Start value isn't integer"); } if (int.TryParse(txtEndNetPower.Text, out end) == false) { throw new Exception("Power End value isn't integer"); } searchquery.AddField(Field.Fields.suurinNettoteho, start.ToString(), end.ToString()); } //If Car Class field is not empty, perform the following: if (cbCarClass.SelectedValue != null) { searchquery.AddField(Field.Fields.ajoneuvoluokka_koodi, cbCarClass.SelectedValue.ToString()); } //If Electric Hybrid field is checked, perform the following: if (ckbElecHybrid.IsChecked == true) { searchquery.AddField(Field.Fields.sahkohybridi, "1"); } // Build Query and set limit to 100 searchquery.Build(QueryBuilder.QueryType.Select, 1000); // Activate ProgressSpinner, Show Progress Text and Disable Search button SearchProgress.IsActive = true; txtSearchProgress.Text = "Searching..."; btnDoSearch.IsEnabled = false; // Load Vehicles from API asynchronously SearchResult.Vehicles = await VehicleAPI.GetVehiclesAsync(searchquery.QueryString); // Disable ProgressSpinner, Show Progress Text and Enable Search button SearchProgress.IsActive = false; txtSearchProgress.Text = "Done"; btnDoSearch.IsEnabled = true; // If there was no result, stay in search page if (SearchResult.Vehicles.Count > 0) { // Add Search to History SearchHistory.AddItem(new SearchHistoryItem("Search", DateTime.Now, SearchResult.Vehicles.Count + " results", searchquery.QueryString, searchquery.FieldsToString())); SearchHistory.Save(); // Navigate to SearchResult page Frame.Navigate(typeof(SearchResult), null, new SuppressNavigationTransitionInfo()); } } //Handle exceptions catch (Exception ex) { MessageDialog dialog = new MessageDialog(ex.Message); dialog.Title = "Info"; await dialog.ShowAsync(); // Disable ProgressSpinner, Show Progress Text and Enable Search button SearchProgress.IsActive = false; txtSearchProgress.Text = "Done"; btnDoSearch.IsEnabled = true; } }
public void TestMySQLError() { List <Vehicle> vehicles = VehicleAPI.GetVehicles("SELECT FROM Vehicle LIMIT 1;"); }
public void TestZeroResultsError() { List <Vehicle> vehicles = VehicleAPI.GetVehicles("SELECT * FROM Vehicle WHERE ID = 630902340;"); }
public void TestIncorrectAPIKey() { VehicleAPI.URL = $"https://www.jonneokkonen.com/api/ajoneuvorekisteri.php?query=";; List <Vehicle> vehicles = VehicleAPI.GetVehicles("SELECT FROM Vehicle LIMIT 1;"); }
public void TestQueryEmptyError() { List <Vehicle> vehicles = VehicleAPI.GetVehicles(""); }
public VeiculoController(VehicleAPI vehicleAPI) { _vehicleAPI = vehicleAPI; }