Пример #1
0
		public async Task ActivatePanic ()
		{
			try {

				/*                if (MainPage.IsEnabled)      //TODO   Iniciar timer para piscar icone panico se tela Home ativa
                                {


                  //                  HomeView.
                  //                  ((HomeView)MainPage).
                                }*/
				CrossVibrate.Current.Vibration (400);

				Events mySafetyEvent = new Events ();
				mySafetyEvent.Type = "Pânico";
				mySafetyEvent.UserId = Settings.user_Id;
				mySafetyEvent.Date = DateTime.Now;

				if (!Settings.panicActivated) {
					Settings.panicActivated = true;
					mySafetyEvent.Name = "Ativar";
					mySafetyEvent.Id = Guid.NewGuid ().ToString ();
					Settings.panicId = mySafetyEvent.Id;
					if (!locator.IsListening) {
						locator.StartListening (1, 10);
						var panicReceivers = new Repository<PanicContacts> ().GetAllAsync ().Result.Where (pr => pr.Id == Settings.user_Id);

						foreach (var pr in panicReceivers) {
							//                           Console.WriteLine("panicReceiver email: " + pr);
							//  return "PanicReceiver:" + Name + " fone:" + PhoneNumber + " email:" + Email + " sms:" + SendSms + " email:" + SendEmail + " remP:" + IsPanicPermited + " track:" + CanTrackLocation;

							if (pr.SendSms && pr.phoneNumber != null && pr.phoneNumber.Length > 4) {
								enviaSms (pr, mySafetyEvent.Id);
							}

							if (pr.SendEmail && pr.Email != null && pr.Email.Length > 6) {
								//     if (CrossConnectivity.Current.IsConnected)   //TODO se naotiver internet, colocar em lista para envio posterior

								MailAddress from = new MailAddress ("*****@*****.**");
								MailAddress to = new MailAddress (pr.Email);
								MailMessage message = new MailMessage (from, to);
								SmtpClient client = new SmtpClient ("rondaweb.ind.br", 587);
								client.Credentials = new NetworkCredential ("rondaweb", "0df4d421c");
								message.IsBodyHtml = true;
								string html = String.Format (emailHtml, Settings.nome, mySafetyEvent.Id);

								Console.WriteLine ("Email de panico para:" + pr);
								Console.WriteLine (@from.Address + "*" + to.Address);
								client.SendAsync (@from.Address, to.Address, "Panico ativado", html, null);

							}

						}
					}
				} else {
					Settings.panicActivated = false;
					mySafetyEvent.Id = Settings.panicId;   //Eventos entre inicio e fim de um panico,gravados com mesmo Id
					mySafetyEvent.Name = "Desativar";
					if (locator.IsListening)
						locator.StopListening ();
				}

				Console.WriteLine ("Registrando evento panico: " + mySafetyEvent.Name);
				await new Repository<Events> ().CreateAsync (mySafetyEvent);

			} catch (Exception ex) {
				Console.WriteLine ("Ocorreu um erro ao obter coordenadas:" + ex);
			}
		}
Пример #2
0
		private async void SaveEventDatabase (MySafetyDll.MySafety.Message message, Evento evento)
		{

			Events _event = new Events ();
			_event.UserId = Settings.user_Id;
			_event.Id = Guid.NewGuid ().ToString ();
			_event.Type = message.newEvent.ToString ();
			if (evento != null) {
				_event.Date = evento.horario;
				_event.Arg1 = evento.bleAddress;
				_event.Arg2 = evento.evento.ToString ();
			} else {
				_event.Date = DateTime.Now;
			}
			await new Repository<Events> ().CreateAsync (_event);
		}