public ObservationResponse GetIdObservacao(ObservationRequest model) { var command = string.Format("select max(itemobs) as ultimo from obsrr where registro={0} and item={1} and parte = 0", model.Registro, model.Item); var response = RrBD.GetIdObservacao(command, model.UserId, model.PasswordBD, model.Url); return(response); }
async void SendNotification() { try { HttpResponseMessage response = await NotificationRequest.GetNotPulledNotifications(); if (response.IsSuccessStatusCode) { string response_content = await response.Content.ReadAsStringAsync(); List <AppUserNotification> user_notifications = JsonConvert.DeserializeObject <List <AppUserNotification> >(response_content); if (user_notifications.Any()) { foreach (AppUserNotification user_notification in user_notifications) { HttpResponseMessage responseOb = await ObservationRequest.GetObservationById(user_notification.Observation); if (responseOb.IsSuccessStatusCode) { string response_contentOb = await responseOb.Content.ReadAsStringAsync(); RequestObservation observation = JsonConvert.DeserializeObject <RequestObservation>(response_contentOb); string title = "🚨 Good news! 🚨"; string message = "💰 Your observed product: " + observation.Product.Title + " is now available for: €" + user_notification.Notified_price + " 💰"; notificationManager.SendNotification(title, message); } else { if (responseOb.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Try Again!", "No connection with the server", "OK"); } if (responseOb.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } } } } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Try Again!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } } catch (Exception ex) { Console.WriteLine("No notification"); } }
private async void FillPage() { List <OutputNotification> output_list = new List <OutputNotification>(); HttpResponseMessage response = await NotificationRequest.GetAllNotifications(); if (response.IsSuccessStatusCode) { string response_content = await response.Content.ReadAsStringAsync(); List <AppUserNotification> notifications_list = JsonConvert.DeserializeObject <List <AppUserNotification> >(response_content); foreach (AppUserNotification notification in notifications_list) { HttpResponseMessage responseOb = await ObservationRequest.GetObservationById(notification.Observation); if (responseOb.IsSuccessStatusCode) { string response_contentOb = await responseOb.Content.ReadAsStringAsync(); RequestObservation observation = JsonConvert.DeserializeObject <RequestObservation>(response_contentOb); if (observation != null) { OutputNotification output_value = new OutputNotification(observation, notification); output_list.Add(output_value); } } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Attention!!!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } } Notifications = output_list; MyCollectionView.ItemsSource = Notifications; } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Attention!!!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } }
public bool InsertObservacao(ObservationRequest model) { var command = string.Format("insert into obsrr values({0}, {1}, 0, {2}, '{3}', '{4}', '{5}', '{6}')", model.Registro, model.Item, model.IdObservacao, model.Texto, DateTime.Today.ToShortDateString(), DateTime.Today.ToShortTimeString(), model.Usuario); var response = RrBD.InsertObservacao(command, model.UserId, model.PasswordBD, model.Url); return(response); }
public void CreateTest() { using (var context = new TrafficLightContext(ContextOptions)) { var controller = new ObservationsController(context, new SequencesService(), new ObservationsService(context)); ObservationRequest request = new ObservationRequest() { Sequence = sequence.Id, Observation = new UserObservation() { Color = sequence.StartColor, Numbers = new string[2] { "1110111", "0011101" } } }; string firstResponseJson = controller.Create(request).Result; var responseType = new { status = "", response = new { start = new int[1], missing = new string[1] } }; var firstResponse = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(firstResponseJson, responseType); Thread.Sleep(1000); request.Observation.Numbers[1] = "0010000"; var secondResponseJson = controller.Create(request).Result; var secondResponse = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(secondResponseJson, responseType); Thread.Sleep(1000); request.Observation.Numbers = null; request.Observation.Color = "red"; var redResponseJson = controller.Create(request).Result; var redResponse = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(redResponseJson, responseType); Assert.NotNull(firstResponse.response); Assert.NotNull(firstResponse.response.missing); Assert.Equal(new int[4] { 2, 8, 82, 88 }, firstResponse.response.start); Assert.Equal(2, firstResponse.response.missing.Length); Assert.Equal("1000000", firstResponse.response.missing[1]); Assert.Equal("0000000", firstResponse.response.missing[0]); Assert.Equal("ok", firstResponse.status); Assert.NotNull(secondResponse.response); Assert.NotNull(secondResponse.response.missing); Assert.Equal("1000010", secondResponse.response.missing[1]); Assert.Equal("ok", secondResponse.status); Assert.NotNull(redResponse.response); Assert.NotNull(redResponse.response.missing); Assert.Equal("1000010", redResponse.response.missing[1]); Assert.Equal("ok", redResponse.status); } }
private void ProcessObservationReport(IResultInstancePayloadChoice payloadChoice) { // Observation Report Lab Result. ObservationReport report = (ObservationReport)payloadChoice; // id = Report ID [1..1] Console.WriteLine("Report ID = (root={0}, extension={1})\n", report.Id.Root, report.Id.Extension); // ObservationLabReportType code [1..1] // FIXME - TM: the raw code value below is not the correct type and throws a ClassCastException // String reportTypeCode = report.Code.CodeValue; // String reportTypeCodeSystem = report.Code.CodeSystem; // Console.WriteLine("Report Type: = (code={0}, codeSystem={1})\n", reportTypeCode, reportTypeCodeSystem); // title [1..1] Console.WriteLine("Report Title:= {0}\n", report.Title); // text [0..1] specialization = ED.DOCORREF //TODO - Uncomment the next two lines once CR5 release is provided //EncapsulatedData ed = report.getRenderedReport(); //Console.WriteLine("Report Text:= {0}\n", ed.getContent().toString()); // statusCode Console.WriteLine("Report Status:= {0}\n", report.StatusCode.ToString()); //effectiveTime Console.WriteLine("Report Date:= {0}\n", report.EffectiveTime.ToString()); //confidentialityCode [0..2] // Who requested this lab test? foreach (IFulfillmentChoice choice in report.InFulfillmentOfFulfillmentChoice) { Console.WriteLine("fulfillmentChoice is {0}\n", choice.GetType().Name); if (typeof(ObservationRequest) == choice.GetType()) { ObservationRequest observationRequest = (ObservationRequest)choice; Identifier ii = observationRequest.Id; Console.WriteLine("infulfillmentOf/observationRequest/id:= (root={0} extension={1})\n", ii.Root, ii.Extension); } } }
async private void InsertObservation(object sender, EventArgs e) { string result = await DisplayPromptAsync("What's your desired price?", "Insert a threshold price", keyboard : Keyboard.Numeric); string email; if (result != null) { try { email = await SecureStorage.GetAsync("email"); RequestObservation observation = new RequestObservation(Page_product, result, email); string json = JsonConvert.SerializeObject(observation); HttpResponseMessage response = await ObservationRequest.InsertObservation(json); if (response.IsSuccessStatusCode) { string response_content = await response.Content.ReadAsStringAsync(); await DisplayAlert("Success!", "Observation successful", "OK"); } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Try Again!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } } catch (Exception ex) { await DisplayAlert("Error!", "Something went wrong", "OK"); } } }
private async void FillPage() { HttpResponseMessage response = await ObservationRequest.GetAllUserObservation(); if (response.IsSuccessStatusCode) { string response_content = await response.Content.ReadAsStringAsync(); CompleteObservations = JsonConvert.DeserializeObject <List <RequestObservation> >(response_content); MyCollectionView.ItemsSource = CompleteObservations; } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Attention!!!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } }
/// <summary> /// Функция добавления очередного наблюдения /// </summary> /// <param name="request">Данные наблюдения</param> /// <returns>Результат рассчета</returns> public BaseResponse Add(ObservationRequest request) { return(TaskSolver.Instance.Add(request)); }
public override void OnDone() { if (Data != null) { RegistroDeReforma registroDeReforma = (RegistroDeReforma)Data; if (string.IsNullOrEmpty(registroDeReforma.NumeroRR)) { Program.Main.ShowMessage("Favor inserir um Registro de Reforma (RR)"); return; } if ((registroDeReforma.ListaDeImagens == null || !registroDeReforma.ListaDeImagens.Any()) && string.IsNullOrWhiteSpace(registroDeReforma.Observacao)) { Program.Main.ShowMessage("É necessário inserir ao menos uma imagem ou uma observação para continuar"); return; } var task = new GenericTask() .WithPreExecuteProcess((b) => { Program.Main.ShowLoading(); }).WithBackGroundProcess((b, t) => { try { if (registroDeReforma.ListaDeImagens != null && registroDeReforma.ListaDeImagens.Any()) { InserirImagensServidor(registroDeReforma); } if (!string.IsNullOrWhiteSpace(registroDeReforma.Observacao)) { var request = new ObservationRequest(); request.Item = Convert.ToInt32(registroDeReforma.NumeroItem); request.Registro = Convert.ToInt32(registroDeReforma.NumeroRR); request.PasswordBD = ConfigurationBase.Instance.PasswordBD; request.Url = ConfigurationBase.Instance.ApiUrl; request.UserId = ConfigurationBase.Instance.UserIdBD; var observationResponse = RrApi.Instance.GetIdObservacao(request); if (observationResponse.Success) { var idObservation = observationResponse.IdObservation + 1; request.Texto = registroDeReforma.Observacao; request.Usuario = ConfigurationBase.Instance.UserAPP; request.IdObservacao = idObservation; var responseObservacao = RrApi.Instance.InsertObservacao(request); if (!responseObservacao) { throw new Exception("Ocorreu um erro ao inserir informações de observação"); } } else { throw new Exception("Ocorreu um erro ao buscar informações da obseração"); } } } catch (Exception ex) { Program.Main.ShowMessage(ex.Message, ToastLength.Long, Base.Enums.ToastMessageType.Error); } }).WithPosExecuteProcess((b, t) => { var wizard = Program.Main.Navigate <CadastroRRFragment>(); wizard.Data = new RegistroDeReforma(); Program.Main.ShowMessage("Cadastros de imagens realizado com sucesso", ToastLength.Long, Base.Enums.ToastMessageType.Success); Program.Main.HideLoading(); }).Execute(); } }
private async void UpdateOrDelete(object sender, EventArgs e) { Button button = (Button)sender; string observation_product = (string)button.CommandParameter; string action = await DisplayActionSheet("What would you like to do?", "Cancel", null, "Update Observation", "Delete Observation"); if (action == "Delete Observation") { HttpResponseMessage response = await ObservationRequest.DeleteObservation(observation_product); if (response.IsSuccessStatusCode) { try { RequestObservation obs_to_remove = CompleteObservations.Find(RequestObservation => RequestObservation.Product.Id == observation_product); CompleteObservations.Remove(obs_to_remove); Console.WriteLine(CompleteObservations); MyCollectionView.ItemsSource = null; MyCollectionView.ItemsSource = CompleteObservations; await DisplayAlert("Success!", "Observation removed", "OK"); } catch (Exception ex) { await DisplayAlert("Error!", "Something went wrong", "OK"); } } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Attention!!!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } } else if (action == "Update Observation") { RequestObservation obs_to_update = CompleteObservations.Find(RequestObservation => RequestObservation.Product.Id == observation_product); string threshold_price = await DisplayPromptAsync("What's your desired price?", "Insert a threshold price", keyboard : Keyboard.Numeric); ModifyObservation update_observation = new ModifyObservation(obs_to_update.Email, obs_to_update.Product.Id, threshold_price); string json = JsonConvert.SerializeObject(update_observation); HttpResponseMessage response = await ObservationRequest.UpdateObservation(json, observation_product); if (response.IsSuccessStatusCode) { int index = CompleteObservations.FindIndex(RequestObservation => RequestObservation.Product.Id == observation_product); CompleteObservations[index].Threshold_price = string.Format("{0:f2}", threshold_price); MyCollectionView.ItemsSource = null; MyCollectionView.ItemsSource = CompleteObservations; await DisplayAlert("Success!", "Observation updated", "OK"); } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Attention!!!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } } }
public async Task <string> Create(ObservationRequest observation) { string msg = _observationsService.CheckObservationValid(observation); if (msg != "ok") { return(JsonConvert.BadRequestJson(msg)); } Sequence sequence = _db.Sequences.Find(observation.Sequence); if (sequence is null) { return(JsonConvert.BadRequestJson("The sequence isn't found")); } if (sequence.IsOver) { return(JsonConvert.BadRequestJson("The red observation should be the last")); } Observation newObservation = new Observation(); Observation preObservation = _db.Observations.AsEnumerable().Reverse().FirstOrDefault(o => o.SequenceId == observation.Sequence); if (observation.Observation.Color == "red") { if (preObservation is null) { return(JsonConvert.BadRequestJson("There isn't enough data")); } if (_sequencesService.ToInt(preObservation.Numbers) == 1) { newObservation.Color = observation.Observation.Color; } else { return(JsonConvert.BadRequestJson("No solutions found")); } GoodResponse redResponse = new GoodResponse() { Response = new { start = new int[1] { sequence.StartClock }, missing = sequence.NickedBrokenNumbers } }; newObservation.SequenceId = observation.Sequence; newObservation.Id = $"{observation.Sequence}red"; _db.Entry(sequence).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _db.Entry(newObservation).State = Microsoft.EntityFrameworkCore.EntityState.Added; await _db.SaveChangesAsync(); return(JsonConvert.Json(redResponse)); } try { newObservation.SequenceId = observation.Sequence; _sequencesService.SetObservationClocks(ref newObservation, ref sequence, _sequencesService.GetCurrentClockFromPre(preObservation.Numbers), observation.Observation.Numbers); sequence.StartClocks = _sequencesService.GetClosestValuesFromArray(sequence.StartClocks, observation.Observation.Numbers); } catch (NullReferenceException) { newObservation = new Observation(); string[] curClock = new string[0]; if (sequence.StartColor == "red") { curClock = _sequencesService.ConvertClocks(sequence.MaxClock); } else { curClock = _sequencesService.ConvertClocks(sequence.StartClock); } if (!_sequencesService.GetTrueClockValide(observation.Observation.Numbers, sequence.BrokenNumbers, curClock)) { return("bad request"); } _sequencesService.SetObservationClocks(ref newObservation, ref sequence, curClock, observation.Observation.Numbers); sequence.StartClocks = _sequencesService.GetClosestValues(observation.Observation.Numbers); } GoodResponse response = new GoodResponse() { Response = new { start = sequence.StartClocks, missing = sequence.NickedBrokenNumbers } }; newObservation.SequenceId = observation.Sequence; newObservation.Id = $"{newObservation.SequenceId}{newObservation.Numbers[0]}{newObservation.Numbers[1]}"; _db.Entry(sequence).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _db.Entry(newObservation).State = Microsoft.EntityFrameworkCore.EntityState.Added; await _db.SaveChangesAsync(); return(JsonConvert.Json(response)); }