/// <summary> /// Triggers when the chart data is fully loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ChartDataRetriever_OnAgeDataComplete(object sender, ChartDataRetriever.OnAgeEventArgs e) { List <int> ageValues = new List <int>(); List <int> ageGroups = new List <int>(); ageGroups = e.Age; if (ageGroups != null) { ageValues.Add((from age in ageGroups where age < 15 select age).Count()); ageValues.Add((from age in ageGroups where age >= 15 && age < 25 select age).Count()); ageValues.Add((from age in ageGroups where age >= 25 && age < 55 select age).Count()); ageValues.Add((from age in ageGroups where age >= 55 && age < 65 select age).Count()); ageValues.Add((from age in ageGroups where age >= 65 select age).Count()); } else { string error = "There was a problem retrieving the record."; mActivity.RunOnUiThread(() => { AlertGenerator.ShowError(error, mActivity); }); } DataEntries(ageValues); }
/// <summary> /// Triggers when the chart data is fully loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ChartDataRetriever_OnPlayTimeDataComplete(object sender, ChartDataRetriever.OnPlayTimeEventArgs e) { List <int> playTimeValues = new List <int>(); List <TimeSpan> playTimes = new List <TimeSpan>(); playTimes = e.PlayTime; if (playTimes != null) { playTimeValues.Add((from time in playTimes where time < new TimeSpan(1, 0, 0) select time).Count()); playTimeValues.Add((from time in playTimes where time >= new TimeSpan(1, 0, 0) && time < new TimeSpan(5, 0, 0) select time).Count()); playTimeValues.Add((from time in playTimes where time >= new TimeSpan(5, 0, 0) && time < new TimeSpan(20, 0, 0) select time).Count()); playTimeValues.Add((from time in playTimes where time >= new TimeSpan(20, 0, 0) && time < new TimeSpan(100, 0, 0) select time).Count()); playTimeValues.Add((from time in playTimes where time >= new TimeSpan(100, 0, 0) select time).Count()); } else { string error = "There was a problem retrieving the record."; mActivity.RunOnUiThread(() => { AlertGenerator.ShowError(error, mActivity); }); } DataEntries(playTimeValues); }
/// <summary> /// Method for loading data into the listview /// </summary> private void LoadData() { mProgressBar = FindViewById <ProgressBar>(Resource.Id.leaderboardProgressBar); Task.Factory.StartNew(() => { RunOnUiThread(() => mProgressBar.Visibility = ViewStates.Visible); if (DbConnector.OpenSQLConnection()) { // Connection opened PlayerStatsDA statsDA = new PlayerStatsDA(); mItems = statsDA.GetAllStats(); RunOnUiThread(() => { // Refresh ListView mAdapter = new MyListViewAdapter(this, mItems); mListView.Adapter = mAdapter; }); } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { //Enabling the controls back AlertGenerator.ShowError(error, this); }); } DbConnector.CloseSQLConnection(); // Close connection to the database RunOnUiThread(() => mProgressBar.Visibility = ViewStates.Gone); }); }
public IHttpActionResult PutAlertGenerator(long id, AlertGenerator alertGenerator) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != alertGenerator.ID) { return(BadRequest()); } repository.Put(alertGenerator); try { repository.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AlertGeneratorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Handles BtnSend event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnSend_Click(object sender, EventArgs e) { string message = mTxtFeedback.Text.Trim(); if (message.Length > 255) { string error = "Sorry, the feedback message is too long."; AlertGenerator.ShowError(error, this); } else { DisableEnableControls(false); Task.Factory.StartNew(() => { if (DbConnector.OpenSQLConnection()) { // Connection opened Feedback feedback = new Feedback() { Username = Intent.GetStringExtra("Username"), Rating = mRatingBar.Rating, Message = message, Date = DateTime.Now.Date }; FeedbackDA feedbackDA = new FeedbackDA(); if (feedbackDA.InsertFeedback(feedback)) { // Feedback was added successfully Finish(); // Close this activity OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom); } else { string error = "There was a problem saving the record."; RunOnUiThread(() => { //Enabling the controls back DisableEnableControls(true); AlertGenerator.ShowError(error, this); }); } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { //Enabling the controls back DisableEnableControls(true); AlertGenerator.ShowError(error, this); }); } DbConnector.CloseSQLConnection(); // Close connection to the database }); } }
/// <summary> /// Method for setting the user data into the fields /// </summary> private void SetData() { mProgressBar.Visibility = ViewStates.Visible; Task.Factory.StartNew(() => { if (DbConnector.OpenSQLConnection()) { // Connection opened UserDA userDA = new UserDA(); User resultUser = userDA.FindUser(Intent.GetStringExtra("Username")); if (resultUser != null) { // User found RunOnUiThread(() => { if (resultUser.Pic != null) { mUserImg = BitmapFactory.DecodeByteArray(resultUser.Pic, 0, resultUser.Pic.Length); mUserPic.SetImageBitmap(mUserImg); } else { mUserPic.SetImageResource(Resource.Drawable.default_pic); } mTxtUsername.Text = resultUser.Username; mTxtFullName.Text = resultUser.FullName; mTxtEmail.Text = resultUser.Email; mTxtDOB.Text = resultUser.DOB.ToShortDateString(); mProgressBar.Visibility = ViewStates.Gone; }); } else { // User not found string error = "There was a problem when trying to retrieve data."; RunOnUiThread(() => { mProgressBar.Visibility = ViewStates.Gone; AlertGenerator.ShowError(error, this); }); } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { //Enabling the controls back mProgressBar.Visibility = ViewStates.Gone; AlertGenerator.ShowError(error, this); }); } DbConnector.CloseSQLConnection(); // Close connection to the database }); }
public void NoAlerts_ReturnsEmptyList() { List <string> expected = new List <string>(); DateTime date = new DateTime(2018, 3, 10); var result = AlertGenerator.generateAlerts(new Forcast(date, 40, 50, "Nothing")); CollectionAssert.AreEqual(expected, result); }
public void ForcastAndTemp_GeneratesTwoAlerts() { List <string> expected = new List <string> { "Freezing Temperature Alert for Saturday, March 10", "Ice Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result = AlertGenerator.generateAlerts(new Forcast(date, -40, 70, "ice")); }
public void MultipleForcastAlerts() { List <string> expected = new List <string> { "Snow Alert for Saturday, March 10", "Ice Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "ice and snow")); }
public IHttpActionResult GetAlertGenerator(string id) { AlertGenerator alertGenerator = repository.Find(id); if (alertGenerator == null) { return(NotFound()); } return(Ok(alertGenerator)); }
public void LowTempAt32_GeneratesFreezingTempAlert() { List <string> expected = new List <string> { "Freezing Temperature Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result = AlertGenerator.generateAlerts(new Forcast(date, 32, 50, "Nothing")); CollectionAssert.AreEqual(expected, result); }
public void HighTempAt85_GeneratesHighHeatAlert() { List <string> expected = new List <string> { "High Heat Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result = AlertGenerator.generateAlerts(new Forcast(date, 50, 85, "Nothing")); CollectionAssert.AreEqual(expected, result); }
public IHttpActionResult PostAlertGenerator(AlertGenerator alertGenerator) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } repository.Add(alertGenerator); repository.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = alertGenerator.ID }, alertGenerator)); }
public void LowTempBelow32_And_HighTempAbove85_GeneratesTwoAlerts() { List <string> expected = new List <string> { "Freezing Temperature Alert for Saturday, March 10", "High Heat Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result = AlertGenerator.generateAlerts(new Forcast(date, 30, 90, "Nothing")); CollectionAssert.AreEqual(expected, result); }
public IHttpActionResult DeleteAlertGenerator(string id) { AlertGenerator alertGenerator = repository.Find(id); if (alertGenerator == null) { return(NotFound()); } repository.Delete(alertGenerator); repository.SaveChanges(); return(Ok(alertGenerator)); }
/// <summary> /// Handles deletion of the user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DialogFrag_OnDeleteComplete(object sender, DeleteUserDialog.OnDeleteEventArgs e) { mProgressBar.Visibility = ViewStates.Visible; Task.Factory.StartNew(() => { if (DbConnector.OpenSQLConnection()) { // Connection opened User user = new User() { Username = Intent.GetStringExtra("Username"), Password = CryptoHasher.Hash(e.Password) }; UserDA userDA = new UserDA(); if (userDA.DeleteUser(user)) { // User deleted RunOnUiThread(() => MyEventHandler.Trigger(this)); Finish(); // Close the activity OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom); } else { string error = "Invalid password."; RunOnUiThread(() => { //Enabling the controls back mProgressBar.Visibility = ViewStates.Gone; AlertGenerator.ShowError(error, this); }); } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { //Enabling the controls back mProgressBar.Visibility = ViewStates.Gone; AlertGenerator.ShowError(error, this); }); } DbConnector.CloseSQLConnection(); // Close connection to the database }); }
/// <summary> /// Override OnOptionsItemSelected function /// </summary> /// <param name="item"></param> /// <returns></returns> public override bool OnOptionsItemSelected(IMenuItem item) { int id = item.ItemId; if (id == Resource.Id.action_settings) { // Clicked on Settings return(true); } else if (id == Resource.Id.image_from_url) { // Clicked on ImageSearch using (View searchView = item.ActionView) { using (var _searchView = searchView.JavaCast <Android.Support.V7.Widget.SearchView>()) { _searchView.QueryHint = "Add image from url..."; // Set SearchView Hint (Placeholder) text _searchView.MaxWidth = int.MaxValue; // Set the SearchView max width // Get the value of the SearchView _searchView.QueryTextSubmit += (s, e) => { if (mBtnBrowse.Enabled) { LoadImage(null, e.Query); } else { string error = "Please pause the current puzzle before adding a new image."; AlertGenerator.ShowError(error, this); } e.Handled = true; mBtnPlay.RequestFocus(); // Change focus // Close the keyboard View view = CurrentFocus; if (view != null) { KeyboardManager.CloseKeyboard(view, this); // Closing the keyboard on focus change } }; } } return(true); } return(base.OnOptionsItemSelected(item)); }
public void ForcastContainsIce_GeneratesIceAlert() { List <string> expected = new List <string> { "Ice Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result1 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "Ice")); CollectionAssert.AreEqual(expected, result1); var result2 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "black ice")); CollectionAssert.AreEqual(expected, result2); var result3 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "some more ice")); CollectionAssert.AreEqual(expected, result2); }
public void ForcastContainsThunderstorm_GeneratesThunderstormAlert() { List <string> expected = new List <string> { "Thunderstorm Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result1 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "Thunderstorms")); CollectionAssert.AreEqual(expected, result1); var result2 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "Scattered Thunderstorms")); CollectionAssert.AreEqual(expected, result2); var result3 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "Heavy Thunderstorm")); CollectionAssert.AreEqual(expected, result2); }
/// <summary> /// Method for loading the image asynchronously /// </summary> /// <param name="data"></param> /// <param name="url"></param> private async void LoadImage(Intent data) { try { // Call BitmapMaker to draw the selected image into a resampled bitmap Bitmap result = await BitmapMaker.CreateBitmapImage(240, 240, mUserPic.Width, mUserPic.Height, data, this); if (result != null) { mUserImg = result; } } catch { string error = "There was a problem trying to load the image."; AlertGenerator.ShowError(error, this); } mUserPic.SetImageBitmap(mUserImg); // Set the bitmap into the userPic imageView }
public void ForcastContainsSnow_GeneratesSnowAlert() { List <string> expected = new List <string> { "Snow Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result1 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "Snow")); CollectionAssert.AreEqual(expected, result1); var result2 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "light snow")); CollectionAssert.AreEqual(expected, result2); var result3 = AlertGenerator.generateAlerts(new Forcast(date, 50, 70, "Scattered Snow")); CollectionAssert.AreEqual(expected, result2); }
public void LowTempLessThan32_GeneratesFreezingTempAlert() { List <string> expected = new List <string> { "Freezing Temperature Alert for Saturday, March 10" }; DateTime date = new DateTime(2018, 3, 10); var result1 = AlertGenerator.generateAlerts(new Forcast(date, 0, 50, "Nothing")); CollectionAssert.AreEqual(expected, result1); var result2 = AlertGenerator.generateAlerts(new Forcast(date, 20, 70, "Nothing")); CollectionAssert.AreEqual(expected, result2); var result3 = AlertGenerator.generateAlerts(new Forcast(date, -60, -40, "Nothing")); CollectionAssert.AreEqual(expected, result2); }
/// <summary> /// Handles BtnUpdate event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MBtnUpdate_Click(object sender, EventArgs e) { string fullname = mTxtFullName.Text.Trim(); string email = mTxtEmail.Text.Trim(); #region Input validation if (fullname.Length < 1 || email.Length < 1 || mTxtDOB.Text.Length < 1 || mTxtCurrentPwd.Text.Length < 1 || mTxtNewPwd.Text.Length < 1 || mTxtNewConfPwd.Text.Length < 1) { string error = "Please fill all the fields."; AlertGenerator.ShowError(error, this); return; } else if (mTxtNewPwd.Text.Length < 8) { string error = "Password must contain at least 8 characters."; AlertGenerator.ShowError(error, this); return; } else if (mTxtNewPwd.Text != mTxtNewConfPwd.Text) { string error = "Password and Confirm Password do not match."; AlertGenerator.ShowError(error, this); return; } #endregion // Disabling controls while saving the record DisableEnableControls(false); Task.Factory.StartNew(() => { if (DbConnector.OpenSQLConnection()) { // Connection opened byte[] imgBytes = null; if (mUserImg != null) { // Converting the bitmap into a byte array MemoryStream memStream = new MemoryStream(); mUserImg.Compress(Bitmap.CompressFormat.Webp, 100, memStream); imgBytes = memStream.ToArray(); } User user = new User() { Username = mTxtUsername.Text.Trim(), FullName = fullname, Email = email, DOB = DateTime.Parse(mTxtDOB.Text), Password = CryptoHasher.Hash(mTxtNewPwd.Text), Pic = imgBytes }; UserDA userDA = new UserDA(); if (userDA.UpdateUser(user, Intent.GetStringExtra("Username"), CryptoHasher.Hash(mTxtCurrentPwd.Text))) { // User details updated successfully Intent intent = new Intent(this, typeof(LoginActivity)); StartActivity(intent); OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom); Finish(); // Close this activity } else { string error = "Invalid Password."; RunOnUiThread(() => { //Enabling the controls back DisableEnableControls(true); AlertGenerator.ShowError(error, this); }); } } else { // Connection could not be opened string error = "Connection to the database could not be established."; RunOnUiThread(() => { //Enabling the controls back DisableEnableControls(true); AlertGenerator.ShowError(error, this); }); } DbConnector.CloseSQLConnection(); // Close connection to the database }); }
public void Test6() { Assert.AreEqual(AlertGenerator.Spo2Level.ClinicallyAcceptable, AlertGenerator.CheckSpo2(91)); }
public void Test9() { Assert.AreEqual(AlertGenerator.Spo2Level.Hypoxemia, AlertGenerator.CheckSpo2(77)); }
public void Test11() { Assert.AreEqual(AlertGenerator.Spo2Level.LackOfO2, AlertGenerator.CheckSpo2(0)); }
public void Test12() { Assert.AreEqual(AlertGenerator.Spo2Level.InvalidInput, AlertGenerator.CheckSpo2(-90)); }
public void Test11() { Assert.AreEqual(AlertGenerator.Pulse.InvalidInput, AlertGenerator.CheckPulseRate(-45)); }
public void LowTemp_AboveHighTemp_ThrowsException() { DateTime date = new DateTime(2018, 3, 10); var result = AlertGenerator.generateAlerts(new Forcast(date, 70, 60, "Nothing")); }
public void Test4() { Assert.AreEqual(AlertGenerator.Spo2Level.NormalHealthy, AlertGenerator.CheckSpo2(95)); }