public object BeforeCall(string operationName, object[] inputs) { var tokenValidator = new TokenValidator(new TokenRepository(new BankDbContext())); if (inputs[0] == null) { throw new FaultException("Token can't be empty"); } var token = inputs[0] as string; if (string.IsNullOrEmpty(token) || string.IsNullOrWhiteSpace(token)) { throw new FaultException("Token can't be empty"); } if (!tokenValidator.IsValid(token)) { var fault = new TokenFault { Message = "Invalid or expired token", Token = token }; throw new FaultException <TokenFault>(fault, "Token Fault"); } return(null); }
public IActionResult GetByTitle(string title) { var token = Request.Headers["Authorization"].ToString(); TokenValidator validator = new TokenValidator(); string resultValid = validator.IsValid(token); var entity = _blogPostAppService.GetByTitle(title, Convert.ToInt32(resultValid)); return(Ok(entity)); }
public bool ValidateToken() { var token = HttpContext.Current.Request.Headers["Token"]; ITokenValidator validator = new TokenValidator(); if (validator.IsValid(token)) { return(true); } return(false); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var token = HttpContext.Current.Request.Headers["Token"]; if (token != null) { return(TokenValidator.IsValid(token)); } else { return(false); } }
public string Test() { var token = HttpContext.Current.Request.Headers["Token"]; TokenValidator validator = new TokenValidator(); if (validator.IsValid(token)) { return("Your token worked!"); } else { return("Your token failed!"); } }
private async void Save() { try { if (SelectedOperator == null) { Alert.Show("Debe seleccionar un operador", "Aceptar"); return; } if (string.IsNullOrWhiteSpace(OperatorPassword)) { Alert.Show("Debe ingresar el password del operador", "Aceptar"); return; } UserDialogs.Instance.ShowLoading("Validando operador...", MaskType.Black); ApiSrv = new Services.ApiService(ApiConsult.ApiAuth); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { TokenPbAuth = TokenGet; LoginPb loginPb = new LoginPb { Username = this.SelectedOperator.IdUser, Password = this.OperatorPassword }; Response resultValidateOperator = await ApiSrv.AuthenticateProbath(TokenPbAuth.Key, loginPb); if (!resultValidateOperator.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultValidateOperator.Message); return; } else { OperatorObject operatorObject = JsonConvert.DeserializeObject <OperatorObject>(Crypto.DecodeString(resultValidateOperator.Data)); if (!operatorObject.IsValid) { UserDialogs.Instance.HideLoading(); Alert.Show(AlertMessages.UserInvalid); return; } else { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.ShowLoading("Validando instancias...", MaskType.Black); ApiSrv = new Services.ApiService(ApiConsult.ApiMenuB); if (!TokenValidator.IsValid(TokenMenuB)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { TokenMenuB = TokenGet; } } } StringBuilder Instances = new StringBuilder(); StringBuilder InstancesRunning = new StringBuilder(); foreach (InstanceRunningItem instanceRunningItem in InstanceRunningItems) { Instances.Append(instanceRunningItem.IdInstance); Instances.Append(","); if (string.Compare(instanceRunningItem.RunningDisplay, "SI") == 0) { InstancesRunning.Append(instanceRunningItem.IdInstance); InstancesRunning.Append(","); } } if (!AppHelper.UserIsSupervisor(operatorObject)) { OperatorChangeUserIsInAllInstancesQueryValues operatorChangeUserIsInAllInstancesQueryValues = new OperatorChangeUserIsInAllInstancesQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, Instances = Instances.ToString() }; Response resultOperatorChangeUserIsInAllInstances = await ApiSrv.GetOperatorChangeUserIsInAllInstances(TokenMenuB.Key, operatorChangeUserIsInAllInstancesQueryValues); if (!resultOperatorChangeUserIsInAllInstances.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { UserInInstances = JsonConvert.DeserializeObject <List <OperatorChangeUserIsInAllInstances> >(Crypto.DecodeString(resultOperatorChangeUserIsInAllInstances.Data)); if (!UserInInstances[0].UserIsInAllInstances) { UserDialogs.Instance.HideLoading(); Alert.Show(string.Format("Usted no tiene permisos para ejecutar en todas las instancias que tiene asignada el operador: {0}", PbUser.IdUser), "Aceptar"); return; } } } if (InstancesRunning.Length > 0) { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.ShowLoading("Cambiando al operador seleccionado...", MaskType.Black); ApiSrv = new Services.ApiService(ApiConsult.ApiMenuB); if (!TokenValidator.IsValid(TokenMenuB)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { TokenMenuB = TokenGet; } } } //string MyIp; //foreach (IPAddress iPAddress in Dns.GetHostAddresses(Dns.GetHostName())) //{ // MyIp = iPAddress.ToString(); //} OperatorChangeQueryValues operatorChangeQueryValues = new OperatorChangeQueryValues() { IdLog = this.LogItem.IdLog, NewIdUser = operatorObject.IdUser, Instances = Instances.ToString(), OldIdUser = PbUser.IdUser, StartDate = ConvertStartDateToSp(this.LogItem.ExecutionDateTime), ClientIp = "127.0.0.1" }; Response resultOperatorChange = await ApiSrv.GetOperatorChange(TokenMenuB.Key, operatorChangeQueryValues); if (!resultOperatorChange.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { OperatorChanges = JsonConvert.DeserializeObject <List <OperatorChange> >(Crypto.DecodeString(resultOperatorChange.Data)); if (!OperatorChanges[0].IsSuccess) { UserDialogs.Instance.HideLoading(); Alert.Show(string.Format("Ocurrió un error al intentar cambiar el operador actual por: {0}", operatorObject.IdUser), "Aceptar"); return; } this.SelectedOperator = null; this.OperatorPassword = string.Empty; UserDialogs.Instance.HideLoading(); Alert.Show(string.Format("Cambio de operador satisfactorio!"), "Aceptar"); } } else { UserDialogs.Instance.HideLoading(); Alert.Show(string.Format("No hay instancias en ejecución!"), "Aceptar"); } } } } } } catch //(Exception ex) { Toast.ShowError(AlertMessages.Error); } }
private async void Graph() { if (this.TemplateSelected == null) { Alert.Show("Debe seleccionar una plantilla!"); return; } try { UserDialogs.Instance.ShowLoading("Obteniendo datos del reporte...", MaskType.Black); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } LogExecutionResultQueryValues logExecutionResultQueryValues = new LogExecutionResultQueryValues() { IdTemplate = this.TemplateSelected.IdTemplate, StartDate = (this.StartDateValue == null ? DateTime.Now : this.StartDateValue.SelectedDate), EndDate = (this.EndDateValue == null ? DateTime.Now : this.EndDateValue.SelectedDate), Executions = (string.IsNullOrEmpty(this.Executions) ? 100 : Convert.ToInt32(this.Executions)), Monday = this.WeekDays.Monday, Tuesday = this.WeekDays.Tuesday, Wednesday = this.WeekDays.Wednesday, Thursday = this.WeekDays.Thursday, Friday = this.WeekDays.Friday, Saturday = this.WeekDays.Saturday, Sunday = this.WeekDays.Sunday }; Response resultGetResults = await ApiSrv.LogExecutionGetResults(TokenGet.Key, logExecutionResultQueryValues); if (!resultGetResults.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { LogExecutionResults = JsonConvert.DeserializeObject <List <LogExecutionResult> >(Crypto.DecodeString(resultGetResults.Data)); if (LogExecutionResults.Count == 0) { UserDialogs.Instance.HideLoading(); Alert.Show("No hay datos para mostrar!"); return; } UserDialogs.Instance.HideLoading(); MainViewModel.GetInstance().LogExecutionChart = new LogExecutionChartViewModel(true, LogExecutionResults); await Application.Current.MainPage.Navigation.PushModalAsync(new LogExecutionChartPage()); } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError("Ocurrió un error."); } }
private async void SelectedLotItemChange() { try { if (this.LotSelected == null) { if (this.CommandSelected != null) { this.CommandSelected = null; } return; } UserDialogs.Instance.ShowLoading("Obteniendo comandos...", MaskType.Black); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } LotAndCommandCommandQueryValues lotAndCommandCommandQueryValues = new LotAndCommandCommandQueryValues() { IdLot = this.LotSelected.IdLot }; Response resultGetCommands = await ApiSrv.LotAndCommandGetCommands(TokenGet.Key, lotAndCommandCommandQueryValues); if (!resultGetCommands.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { LotAndCommandCommands = JsonConvert.DeserializeObject <List <LotAndCommandCommand> >(Crypto.DecodeString(resultGetCommands.Data)); if (PickerCommandItems == null) { PickerCommandItems = new ObservableCollection <PickerCommandItem>(); } else { PickerCommandItems.Clear(); } foreach (LotAndCommandCommand lotAndCommandCommand in LotAndCommandCommands) { PickerCommandItems.Add(new PickerCommandItem() { IdCommand = lotAndCommandCommand.IdCommand, NameCommand = lotAndCommandCommand.Command }); } UserDialogs.Instance.HideLoading(); } } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); } }
private async void Report() { if (this.TemplateSelected == null) { Alert.Show("Debe seleccionar una plantilla!"); return; } if (this.LogSelected == null) { Alert.Show("Debe seleccionar una bitácora!"); return; } try { UserDialogs.Instance.ShowLoading("Obteniendo datos del reporte...", MaskType.Black); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } LotAndCommandResultQueryValues lotAndCommandResultQueryValues = new LotAndCommandResultQueryValues() { IdTemplate = this.TemplateSelected.IdTemplate, IdLog = this.LogSelected.IdLog, IdLot = (this.LotSelected != null ? this.LotSelected.IdLot : 0), IdCommand = (this.CommandSelected != null ? this.CommandSelected.IdCommand : 0), StartDate = (this.StartDateValue == null ? DateTime.Now : this.StartDateValue.SelectedDate), EndDate = (this.EndDateValue == null ? DateTime.Now : this.EndDateValue.SelectedDate), Executions = (string.IsNullOrEmpty(this.Executions) ? 100 : Convert.ToInt32(this.Executions)), Monday = this.WeekDays.Monday, Tuesday = this.WeekDays.Tuesday, Wednesday = this.WeekDays.Wednesday, Thursday = this.WeekDays.Thursday, Friday = this.WeekDays.Friday, Saturday = this.WeekDays.Saturday, Sunday = this.WeekDays.Sunday }; Response resultGetResults = await ApiSrv.LotAndCommandGetResults(TokenGet.Key, lotAndCommandResultQueryValues); if (!resultGetResults.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { LotAndCommandResults = JsonConvert.DeserializeObject <List <LotAndCommandResult> >(Crypto.DecodeString(resultGetResults.Data)); if (LotAndCommandResults.Count == 0) { UserDialogs.Instance.HideLoading(); Alert.Show("No hay datos para mostrar!"); return; } if (LotAndCommandReportItem == null) { LotAndCommandReportItem = new ObservableCollection <LotAndCommandReportItem>(); } else { LotAndCommandReportItem.Clear(); } foreach (LotAndCommandResult lotAndCommandResult in LotAndCommandResults) { LotAndCommandReportItem.Add(new LotAndCommandReportItem() { IdTemplate = lotAndCommandResult.IdTemplate, Template = lotAndCommandResult.Template, IdLog = lotAndCommandResult.IdLog, Log = lotAndCommandResult.Log, Instance = lotAndCommandResult.Instance, IdLot = lotAndCommandResult.IdLot, Lot = lotAndCommandResult.Lot, IdCommand = lotAndCommandResult.IdCommand, Command = lotAndCommandResult.Command, IdCommandGroup = lotAndCommandResult.IdCommandGroup, CommandGroup = lotAndCommandResult.CommandGroup, IdEnvironment = lotAndCommandResult.IdEnvironment, Environment = lotAndCommandResult.Environment, ExecutionTime = lotAndCommandResult.ExecutionTime, StartDate = lotAndCommandResult.StartDate, StartTime = lotAndCommandResult.StartTime, EndDate = lotAndCommandResult.EndDate, IdStatus = lotAndCommandResult.IdStatus, Status = lotAndCommandResult.Status, StartDateString = (lotAndCommandResult.StartDate != null) ? ((DateTime)lotAndCommandResult.StartDate).ToString(DateTimeFormatString.LatinDate24Hours) : "", StartTimeString = (lotAndCommandResult.StartTime != null) ? ((DateTime)lotAndCommandResult.StartTime).ToString(DateTimeFormatString.Time24Hour) : "", EndDateString = (lotAndCommandResult.EndDate != null) ? ((DateTime)lotAndCommandResult.EndDate).ToString(DateTimeFormatString.LatinDate24Hours) : "" }); } UserDialogs.Instance.HideLoading(); MainViewModel.GetInstance().LotAndCommandReport = new LotAndCommandReportViewModel(true, LotAndCommandReportItem); await Application.Current.MainPage.Navigation.PushModalAsync(new LotAndCommandReportPage()); } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError("Ocurrió un error."); } }
private async void SelectedTemplateItemChange() { try { if (this.TemplateSelected == null) { return; } UserDialogs.Instance.ShowLoading("Obteniendo lotes...", MaskType.Black); this.EventSelected = new PickerEventItem(); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } LogExecutionDelayLotQueryValues logExecutionDelayLotQueryValues = new LogExecutionDelayLotQueryValues() { IdLog = this.TemplateSelected.IdTemplate }; Response resultGetLots = await ApiSrv.LogExecutionDelayGetLots(TokenGet.Key, logExecutionDelayLotQueryValues); if (!resultGetLots.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { LogExecutionDelayLots = JsonConvert.DeserializeObject <List <LogExecutionDelayLot> >(Crypto.DecodeString(resultGetLots.Data)); if (PickerLotItems == null) { PickerLotItems = new ObservableCollection <PickerLotItem>(); } else { PickerLotItems.Clear(); } foreach (LogExecutionDelayLot logExecutionDelayLot in LogExecutionDelayLots) { PickerLotItems.Add(new PickerLotItem() { IdLot = logExecutionDelayLot.IdLot, NameLot = logExecutionDelayLot.Lot }); } UserDialogs.Instance.HideLoading(); } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); } }
private async void Delete() { try { if (IsLoadingData) { return; } if (this.SelectedObservation.IdObsv == 0) { Alert.Show(AlertMessages.Delete); return; } bool result = await Confirm.Show("Desea eliminar la observación"); if (result) { IsLoadingData = true; UserDialogs.Instance.ShowLoading(AlertMessages.Deleting, MaskType.Black); if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } ObservationDelQueryValues QueryValuesDel = new ObservationDelQueryValues() { IdObsv = this.SelectedObservation.IdObsv }; Response resultObservationsDel = await ApiSrv.DelObservations(TokenGet.Key, QueryValuesDel); if (!resultObservationsDel.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { ObservationDel = JsonConvert.DeserializeObject <List <ObservationDel> >(Crypto.DecodeString(resultObservationsDel.Data)); if (!ObservationDel[0].Result) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.NoSuccess); } else { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.ShowLoading(AlertMessages.UpdatingList, MaskType.Black); ObservationGetQueryValues QueryValuesGet; if (this.LotAndCommandData.HasData) { QueryValuesGet = new ObservationGetQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = this.LotAndCommandData.IdInstance, IdLot = this.LotAndCommandData.IdLot, IdCommand = this.LotAndCommandData.IdCommand }; } else { QueryValuesGet = new ObservationGetQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = 0, IdLot = 0, IdCommand = 0 }; } Response resultObservationsGet = await ApiSrv.GetObservations(TokenGet.Key, QueryValuesGet); if (!resultObservationsGet.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { Observations = JsonConvert.DeserializeObject <List <ObservationGet> >(Crypto.DecodeString(resultObservationsGet.Data)); ObservationItems.Clear(); foreach (ObservationGet observationGet in Observations) { ObservationItems.Add(new ObservationItem() { IdObsv = observationGet.IdObsv, DateObsv = observationGet.DateObsv, NameObsv = observationGet.NameObsv, IdUser = observationGet.IdUser, DetailObsv = observationGet.DetailObsv, DateObsvString = observationGet.DateObsv.ToString(DateTimeFormatString.LatinDate) }); } UserDialogs.Instance.HideLoading(); } Toast.ShowSuccess(AlertMessages.Success); this.Name = string.Empty; this.Details = string.Empty; this.SelectedObservation = new ObservationItem(); } } IsLoadingData = false; } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); } }
private async void Save() { try { if (IsLoadingData) { return; } if (String.IsNullOrWhiteSpace(this.Name)) { Alert.Show("Debe ingresar un nombre para la observación"); return; } if (String.IsNullOrWhiteSpace(this.Details)) { Alert.Show("Debe ingresar un detalle para la observación"); return; } bool result = await Confirm.Show("Desea guardar los cambios de la observación"); if (result) { IsLoadingData = true; if (this.SelectedObservation.IdObsv != 0) { UserDialogs.Instance.ShowLoading(AlertMessages.Updating, MaskType.Black); if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } ObservationModQueryValues QueryValuesMod; if (this.LotAndCommandData.HasData) { QueryValuesMod = new ObservationModQueryValues() { IdObsv = this.SelectedObservation.IdObsv, IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = this.LotAndCommandData.IdInstance, IdLot = this.LotAndCommandData.IdLot, IdCommand = this.LotAndCommandData.IdCommand, NameObsv = this.Name, DetailObsv = this.Details }; } else { QueryValuesMod = new ObservationModQueryValues() { IdObsv = this.SelectedObservation.IdObsv, IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = 0, IdLot = 0, IdCommand = 0, NameObsv = this.Name, DetailObsv = this.Details }; } Response resultObservationsMod = await ApiSrv.ModObservations(TokenGet.Key, QueryValuesMod); if (!resultObservationsMod.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { ObservationMod = JsonConvert.DeserializeObject <List <ObservationMod> >(Crypto.DecodeString(resultObservationsMod.Data)); switch (ObservationMod[0].ResultModObservation) { case AddOrModResult.OK: UserDialogs.Instance.HideLoading(); UserDialogs.Instance.ShowLoading(AlertMessages.UpdatingList, MaskType.Black); ObservationGetQueryValues QueryValuesGet; if (this.LotAndCommandData.HasData) { QueryValuesGet = new ObservationGetQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = this.LotAndCommandData.IdInstance, IdLot = this.LotAndCommandData.IdLot, IdCommand = this.LotAndCommandData.IdCommand }; } else { QueryValuesGet = new ObservationGetQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = 0, IdLot = 0, IdCommand = 0 }; } Response resultObservationsGet = await ApiSrv.GetObservations(TokenGet.Key, QueryValuesGet); if (!resultObservationsGet.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { Observations = JsonConvert.DeserializeObject <List <ObservationGet> >(Crypto.DecodeString(resultObservationsGet.Data)); ObservationItems.Clear(); foreach (ObservationGet observationGet in Observations) { ObservationItems.Add(new ObservationItem() { IdObsv = observationGet.IdObsv, DateObsv = observationGet.DateObsv, NameObsv = observationGet.NameObsv, IdUser = observationGet.IdUser, DetailObsv = observationGet.DetailObsv, DateObsvString = observationGet.DateObsv.ToString(DateTimeFormatString.LatinDate) }); } UserDialogs.Instance.HideLoading(); } Toast.ShowSuccess(AlertMessages.Success); this.SelectedObservation = new ObservationItem(); this.Name = string.Empty; this.Details = string.Empty; break; case AddOrModResult.ERROR: UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.NoSuccess); break; case AddOrModResult.EXISTING_DATA: UserDialogs.Instance.HideLoading(); Alert.Show(AlertMessages.Existing); break; } } } else { UserDialogs.Instance.ShowLoading(AlertMessages.Adding, MaskType.Black); if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } ObservationAddQueryValues QueryValuesAdd; if (this.LotAndCommandData.HasData) { QueryValuesAdd = new ObservationAddQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = this.LotAndCommandData.IdInstance, IdLot = this.LotAndCommandData.IdLot, IdCommand = this.LotAndCommandData.IdCommand, NameObsv = this.Name, DetailObsv = this.Details }; } else { QueryValuesAdd = new ObservationAddQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = 0, IdLot = 0, IdCommand = 0, NameObsv = this.Name, DetailObsv = this.Details }; } Response resultObservationsAdd = await ApiSrv.AddObservations(TokenGet.Key, QueryValuesAdd); if (!resultObservationsAdd.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { ObservationAdd = JsonConvert.DeserializeObject <List <ObservationAdd> >(Crypto.DecodeString(resultObservationsAdd.Data)); switch (ObservationAdd[0].ResultAddObservation) { case AddOrModResult.OK: UserDialogs.Instance.HideLoading(); UserDialogs.Instance.ShowLoading(AlertMessages.UpdatingList, MaskType.Black); ObservationGetQueryValues QueryValuesGet; if (this.LotAndCommandData.HasData) { QueryValuesGet = new ObservationGetQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = this.LotAndCommandData.IdInstance, IdLot = this.LotAndCommandData.IdLot, IdCommand = this.LotAndCommandData.IdCommand }; } else { QueryValuesGet = new ObservationGetQueryValues() { IdLog = this.LogItem.IdLog, IdUser = PbUser.IdUser, IdInstance = 0, IdLot = 0, IdCommand = 0 }; } Response resultObservationsGet = await ApiSrv.GetObservations(TokenGet.Key, QueryValuesGet); if (!resultObservationsGet.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { Observations = JsonConvert.DeserializeObject <List <ObservationGet> >(Crypto.DecodeString(resultObservationsGet.Data)); ObservationItems.Clear(); foreach (ObservationGet observationGet in Observations) { ObservationItems.Add(new ObservationItem() { IdObsv = observationGet.IdObsv, DateObsv = observationGet.DateObsv, NameObsv = observationGet.NameObsv, IdUser = observationGet.IdUser, DetailObsv = observationGet.DetailObsv, DateObsvString = observationGet.DateObsv.ToString(DateTimeFormatString.LatinDate) }); } UserDialogs.Instance.HideLoading(); } Toast.ShowSuccess(AlertMessages.Success); this.Name = string.Empty; this.Details = string.Empty; break; case AddOrModResult.ERROR: UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.NoSuccess); break; case AddOrModResult.EXISTING_DATA: UserDialogs.Instance.HideLoading(); Alert.Show(AlertMessages.Existing); break; } } } IsLoadingData = false; } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); } }
private async void LogFinishedCheckedChange() { try { if (!this.LogFinished) { UserDialogs.Instance.ShowLoading("Obteniendo bitácoras...", MaskType.Black); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } OperationsLogLogQueryValues operationsLogLogQueryValues = new OperationsLogLogQueryValues() { Finished = false }; Response resultLogs = await ApiSrv.OperationsLogGetLogs(TokenGet.Key, operationsLogLogQueryValues); if (!resultLogs.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { OperationsLogLogs = JsonConvert.DeserializeObject <List <OperationsLogLog> >(Crypto.DecodeString(resultLogs.Data)); if (PickerLogItems == null) { PickerLogItems = new ObservableCollection <PickerLogItem>(); } else { PickerLogItems.Clear(); } foreach (OperationsLogLog item in OperationsLogLogs) { PickerLogItems.Add(new PickerLogItem() { IdLog = item.IdLog, NameDisplay = item.NameLog }); UserDialogs.Instance.HideLoading(); } } } } else { UserDialogs.Instance.ShowLoading("Obteniendo bitácoras...", MaskType.Black); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } OperationsLogLogQueryValues operationsLogLogQueryValues = new OperationsLogLogQueryValues() { Finished = true }; Response resultLogs = await ApiSrv.OperationsLogGetLogs(TokenGet.Key, operationsLogLogQueryValues); if (!resultLogs.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { OperationsLogLogs = JsonConvert.DeserializeObject <List <OperationsLogLog> >(Crypto.DecodeString(resultLogs.Data)); if (PickerLogItems == null) { PickerLogItems = new ObservableCollection <PickerLogItem>(); } else { PickerLogItems.Clear(); } foreach (OperationsLogLog item in OperationsLogLogs) { PickerLogItems.Add(new PickerLogItem() { IdLog = item.IdLog, NameDisplay = item.NameLog }); UserDialogs.Instance.HideLoading(); } } } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); } }
private async void Report() { if (this.LogItemSelected == null) { Alert.Show("Debe seleccionar una bitácora!"); return; } try { UserDialogs.Instance.ShowLoading("Obteniendo datos del reporte...", MaskType.Black); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenGet)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } } } OperationsLogResultQueryValues operationsLogResultQueryValues = new OperationsLogResultQueryValues() { IdLog = this.LogItemSelected.IdLog, IdUser = (this.OperatorItemSelected != null ? this.OperatorItemSelected.IdUser : ""), IdStatus = (this.StatusItemSelected != null ? this.StatusItemSelected.IdStatus : ""), IdEnvironment = (this.EnvironmentItemSelected != null ? this.EnvironmentItemSelected.IdEnvironment : 0), IdService = (this.ServiceItemSelected != null ? this.ServiceItemSelected.IdService : 0), IdLot = (this.LotItemSelected != null ? this.LotItemSelected.IdLot : 0), IdCommand = (this.CommandItemSelected != null ? this.CommandItemSelected.IdCommand : 0), StartDateFrom = (this.StartDateFromValue == null ? DateTime.Now : this.StartDateFromValue.SelectedDate), StartDateTo = (this.StartDateToValue == null ? DateTime.Now : this.StartDateToValue.SelectedDate), EndDateFrom = (this.EndDateFromValue == null ? DateTime.Now : this.EndDateFromValue.SelectedDate), EndDateTo = (this.EndDateToValue == null ? DateTime.Now : this.EndDateToValue.SelectedDate), }; Response resultGetResults = await ApiSrv.OperationsLogGetResults(TokenGet.Key, operationsLogResultQueryValues); if (!resultGetResults.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { OperationsLogResults = JsonConvert.DeserializeObject <List <OperationsLogResult> >(Crypto.DecodeString(resultGetResults.Data)); if (OperationsLogResults.Count == 0) { UserDialogs.Instance.HideLoading(); Alert.Show("No hay datos para mostrar!"); return; } if (OperationsLogReportItems == null) { OperationsLogReportItems = new ObservableCollection <OperationsLogReportItem>(); } else { OperationsLogReportItems.Clear(); } foreach (OperationsLogResult item in OperationsLogResults) { OperationsLogReportItems.Add(new OperationsLogReportItem() { IdLog = item.IdLog, IdInstance = item.IdInstance, IdLot = item.IdLot, IdCommand = item.IdCommand, IdUser = item.IdUser, Environment = item.Environment, Service = item.Service, CodeCommand = item.CodeCommand, NameCommand = item.NameCommand, Product = item.Product, StartDate = (item.StartDate != null) ? ((DateTime)item.StartDate) : new DateTime(), EndDate = (item.EndDate != null) ? ((DateTime)item.EndDate) : new DateTime(), Duration = item.Duration, Status = item.Status, IPClient = item.IPClient, NameLog = item.NameLog, InstanceNumber = item.InstanceNumber, CodeLot = item.CodeLot, NameLot = item.NameLot, Source = item.Source, Critical = item.Critical, StartDateString = (item.StartDate != null) ? ((DateTime)item.StartDate).ToString(DateTimeFormatString.LatinDate24Hours) : "", EndDateString = (item.EndDate != null) ? ((DateTime)item.EndDate).ToString(DateTimeFormatString.LatinDate24Hours) : "" }); } UserDialogs.Instance.HideLoading(); MainViewModel.GetInstance().OperationsLogReport = new OperationsLogReportViewModel(true, OperationsLogReportItems); await Application.Current.MainPage.Navigation.PushModalAsync(new OperationsLogReportPage()); } } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError("Ocurrió un error."); } }
private async void LotSelectedItemChange() { try { if (this.LotSelected == null) { this.NameLot = "Seleccione un lote..."; return; } this.NameLot = this.LotSelected.NameLot; UserDialogs.Instance.ShowLoading("Obteniendo comandos...", MaskType.Black); //ApiSrv = new Services.ApiService(ApiConsult.ApiAuth); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenMenuB)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { TokenMenuB = TokenGet; } } } LogInquirieGetCommandsQueryValues logInquirieGetCommandsQueryValues = new LogInquirieGetCommandsQueryValues() { IdLot = this.LotSelected.IdLot }; Response resultGetCommands = await ApiSrv.LogInquirieGetCommands(TokenMenuB.Key, logInquirieGetCommandsQueryValues); if (!resultGetCommands.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { Commands = JsonConvert.DeserializeObject <List <LogInquiriesCommand> >(Crypto.DecodeString(resultGetCommands.Data)); if (CommandItems == null) { CommandItems = new ObservableCollection <PickerCommandItem>(); } else { CommandItems.Clear(); } foreach (LogInquiriesCommand logInquiriesCommand in Commands) { CommandItems.Add(new PickerCommandItem() { IdCommand = logInquiriesCommand.IdCommand, NameCommand = logInquiriesCommand.Command, NameDisplay = (logInquiriesCommand.Command.Length > 20) ? logInquiriesCommand.Command.Substring(0, 20) + "..." : logInquiriesCommand.Command, CodeCommand = logInquiriesCommand.Command.Split('-')[0].Trim() }); } UserDialogs.Instance.HideLoading(); } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); } }
private async void Search() { try { if (this.LotSelected == null) { Alert.Show("Debe seleccionar por lo menos un lote."); return; } UserDialogs.Instance.ShowLoading("Obteniendo bitácoras...", MaskType.Black); if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!TokenValidator.IsValid(TokenMenuB)) { if (!await ApiIsOnline()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { if (!await GetTokenSuccess()) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { TokenMenuB = TokenGet; } } } LogInquirieGetLogsQueryValues logInquirieGetLogsQueryValues = new LogInquirieGetLogsQueryValues() { IdLog = this.LogItem.IdLog, IdLot = this.LotSelected.IdLot, IdCommand = (this.CommandSelected != null) ? this.CommandSelected.IdCommand : -1 }; Response resultGetLogs = await ApiSrv.LogInquirieGetLogs(TokenMenuB.Key, logInquirieGetLogsQueryValues); if (!resultGetLogs.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); return; } else { Logs = JsonConvert.DeserializeObject <List <LogInquiriesResult> >(Crypto.DecodeString(resultGetLogs.Data)); if (ResultLogInquirieItems == null) { ResultLogInquirieItems = new ObservableCollection <ResultLogInquirieItem>(); } else { ResultLogInquirieItems.Clear(); } foreach (LogInquiriesResult logInquiriesResult in Logs) { ResultLogInquirieItems.Add(new ResultLogInquirieItem() { IdLog = this.LogItem.IdLog, NameLog = this.LogItem.NameLog, NameInstance = logInquiriesResult.NameInstance, StartHour = (logInquiriesResult.StartTime != null) ? ((DateTime)logInquiriesResult.StartTime).ToString(DateTimeFormatString.Time24Hour) : "", Pause = (logInquiriesResult.Pause) ? "SI" : "NO", IdLot = logInquiriesResult.IdLot, NameLot = logInquiriesResult.Lot, IdCommand = logInquiriesResult.IdCommand, NameCommand = logInquiriesResult.Command, Status = logInquiriesResult.Status, StatusColor = GetStatusColor.ByIdStatus(logInquiriesResult.IdStatus), StatusResult = logInquiriesResult.Result, StartDateTime = (logInquiriesResult.DateStart != null) ? ((DateTime)logInquiriesResult.DateStart).ToString(DateTimeFormatString.Time24Hour) : "", EndDateTime = (logInquiriesResult.DateEnd != null) ? ((DateTime)logInquiriesResult.StartTime).ToString(DateTimeFormatString.Time24Hour) : "" }); } UserDialogs.Instance.HideLoading(); } } this.ResultIsVisible = true; UserDialogs.Instance.HideLoading(); } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError(AlertMessages.Error); } }