/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this Model</param> /// <exception cref="OrderFieldBadFormatException">throws an exception if one of the parameters doesn't match the expected format</exception> public void Validate(Validations validationType = Validations.Weak) { if (validationType == Validations.Weak) { if (string.IsNullOrEmpty(FirstName) && string.IsNullOrEmpty(LastName)) { throw new Exceptions.OrderFieldBadFormatException("Both First name and last name are missing or empty - at least one should be specified"); } } else { InputValidators.ValidateValuedString(FirstName, "First Name"); InputValidators.ValidateValuedString(LastName, "Last Name"); } // optional fields validations if (!string.IsNullOrEmpty(Email)) { InputValidators.ValidateEmail(Email); } if (OrdersCount.HasValue) { InputValidators.ValidateZeroOrPositiveValue(OrdersCount.Value, "Orders Count"); } if (CreatedAt.HasValue) { InputValidators.ValidateDateNotDefault(CreatedAt.Value, "Created At"); } if (UpdatedAt.HasValue) { InputValidators.ValidateDateNotDefault(UpdatedAt.Value, "Updated At"); } if (VerifiedEmailAt.HasValue) { InputValidators.ValidateDateNotDefault(VerifiedEmailAt.Value, "Verified Email At"); } if (VerifiedPhoneAt.HasValue) { InputValidators.ValidateDateNotDefault(VerifiedPhoneAt.Value, "Verified Phone At"); } if (FirstPurchaseAt.HasValue) { InputValidators.ValidateDateNotDefault(FirstPurchaseAt.Value, "First Purchase At"); } if (Social != null) { Social.ToList().ForEach(item => item.Validate(validationType)); } if (Address != null) { Address.Validate(validationType); } }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType"></param> /// <exception cref="OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public void Validate(Validations validationType = Validations.Weak) { if (validationType != Validations.Weak) { InputValidators.ValidateAvsResultCode(AvsResultCode); InputValidators.ValidateCvvResultCode(CvvResultCode); InputValidators.ValidateCreditCard(CreditCardNumber); } InputValidators.ValidateValuedString(CreditCardBin, "Credit Card Bin"); InputValidators.ValidateValuedString(CreditCardCompany, "Credit Card Company"); }
public void Validate(Validations validationType = Validations.Weak) { InputValidators.ValidateValuedString(FulfillmentId, "Fulfillment Id"); InputValidators.ValidateDateNotDefault(CreatedAt.Value, "Created At"); InputValidators.ValidateObjectNotNull(Status, "Status"); if (LineItems != null) { LineItems.ToList().ForEach(item => item.Validate(validationType)); } }
/// <summary> /// Deserialize the source string from either json or yaml and populate the rules /// object. /// </summary> /// <param name="source"></param> private void PopulateRules(string source) { // Is it valid json? if (InputValidators.IsValidJson(source)) { // Deserialize directly Rules = JsonConvert.DeserializeObject <dynamic>(source); } else { throw new Exception("Grammar file doesn't seem to be valid JSON!"); } }
public void Validate(Validations validationType = Validations.Weak) { InputValidators.ValidateObjectNotNull(ExternalStatus, "External Status"); if (DecidedAt != null) { InputValidators.ValidateDateNotDefault(DecidedAt.Value, "Decided At"); } if (Currency != null) { InputValidators.ValidateCurrency(Currency); } }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this model</param> /// <exception cref="OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public virtual void Validate(Validations validationType = Validations.Weak) { InputValidators.ValidateValuedString(Title, "Title"); InputValidators.ValidateZeroOrPositiveValue(Price.GetValueOrDefault(), "Price"); InputValidators.ValidatePositiveValue(QuantityPurchased.GetValueOrDefault(), "Quantity Purchased"); // optional fields validations if (ProductId != null) { InputValidators.ValidateValuedString(ProductId, "Product Id"); } Seller?.Validate(validationType); }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this model</param> /// <exception cref="OrderFieldBadFormatException">throws an exception if one of the parameters doesn't match the expected format</exception> public virtual void Validate(Validations validationType = Validations.Weak) { // optional fields validations if (!string.IsNullOrEmpty(Phone)) { InputValidators.ValidatePhoneNumber(Phone); } if (!string.IsNullOrEmpty(CountryCode)) { InputValidators.ValidateCountryOrProvinceCode(CountryCode); } if (!string.IsNullOrEmpty(ProvinceCode)) { InputValidators.ValidateCountryOrProvinceCode(ProvinceCode); } }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this model</param> /// <exception cref="OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); if (validationType == Validations.All) { InputValidators.ValidateValuedString(FirstName, "First Name"); InputValidators.ValidateValuedString(LastName, "Last Name"); InputValidators.ValidatePhoneNumber(Phone); // make sure phone exists and has a value (addition to validation of BaseAddress) } InputValidators.ValidateValuedString(Address1, "Address 1"); InputValidators.ValidateValuedString(City, "City"); if (string.IsNullOrEmpty(Country) && string.IsNullOrEmpty(CountryCode)) { throw new OrderFieldBadFormatException("Both Country or Country Code fields are missing - at least one should be speicified"); } }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level to use on this Model</param> /// <exception cref="OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public void Validate(Validations validationType = Validations.Weak) { // optional fields validations if (!string.IsNullOrEmpty(Email)) { InputValidators.ValidateEmail(Email); } if (!string.IsNullOrEmpty(Phone)) { InputValidators.ValidatePhoneNumber(Phone); } Social?.Validate(validationType); if (Social == null && string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Phone)) { throw new OrderFieldBadFormatException("All recipient fields are missing - at least one should be specified"); } }
/// <summary> /// Deserialize the source string from either json or yaml and populate the rules /// object. /// </summary> /// <param name="source"></param> public static JObject PopulateRules(string source) { // Is it valid json? if (InputValidators.IsValidJson(source)) { // Deserialize directly return(JsonConvert.DeserializeObject <dynamic>(source)); } // Is it valid yaml? else if (InputValidators.IsValidYaml(source)) { // Deserialize yaml var deserializer = new Deserializer(); var yamlObject = deserializer.Deserialize(new StringReader(source)); return(PopulateRules(yamlObject)); } else { throw new Exception("Grammar file doesn't seem to be valid JSON or YAML!"); } }
internal ExtendedBuilder(string message, IConsole console, params ConsoleKey[] @params) : base(console) { this.RenderQuestion(message, this, this, Console); this.Parse(value => { return(value); }); InputValidators.Add( value => { return(@params.Any(p => p == value)); }, value => { string keys = " Press : "; foreach (var key in @params) { keys += $"[{(char)key}] "; } return(keys); }); }
internal PagedRawListBuilder(RawListBuilder <TResult> listBuilder, int pageSize) : base(listBuilder.Console) { Choices = listBuilder.Choices; Console = listBuilder.Console; Confirm = listBuilder.Confirm; Convert = listBuilder.Convert; Default = listBuilder.Default; ResultValidators = listBuilder.ResultValidators; RenderQuestion = listBuilder.RenderQuestion; this.RenderRawChoices(this, this, Console); DisplayError = listBuilder.DisplayError; this.Input(Console, ConsoleKey.LeftArrow, ConsoleKey.RightArrow, ConsoleKey.Enter); Input.AllowTypeFn = value => { return(char.IsNumber(value)); }; this.Parse(value => { return(Paging.CurrentPage[value.To <int>() - 1]); }); InputValidators.Add(value => { return(string.IsNullOrEmpty(value) == false || Default.HasDefault); }, "Empty line"); InputValidators.Add(value => { return(value.ToN <int>().HasValue); }, value => { return($"Cannot parse {value} to {typeof(TResult)}"); }); InputValidators.Add( value => { var index = value.To <int>(); return(index > 0 && index <= Paging.CurrentPage.Count); }, value => { return($"Chosen number must be between 1 and {Paging.CurrentPage.Count} "); }); OnKey = listBuilder.OnKey; this.Paging(listBuilder.Choices, pageSize); }
public async Task <PlayerFound> PlayerExists(string region, string playerName, string realm) { InputValidators.ValidateRealmName(realm); InputValidators.ValidatePlayerName(playerName); realm = BlizzardService.FormatRealmName(realm); var regionEnum = GameRegionUtilities.GetGameRegionFromString(region); var locatedPlayer = await this.playerCache.GetPlayer(regionEnum, playerName, realm); if (locatedPlayer == null) { return(new PlayerFound() { Found = false }); } return(new PlayerFound() { Found = true, PlayerDetails = locatedPlayer }); }
/// <summary> /// Deserialize the source string from either json or yaml and populate the rules /// object. /// </summary> /// <param name="source"></param> private void PopulateRules(string source) { // Is it valid json? if (InputValidators.IsValidJson(source)) { // Deserialize directly Rules = JsonConvert.DeserializeObject <dynamic>(source); } // Is it valid yaml? else if (InputValidators.IsValidYaml(source)) { // Deserialize yaml var deserializer = new Deserializer(); var yamlObject = deserializer.Deserialize(new StringReader(source)); // Reserialize the yaml as json into the Rules object var rules = JsonConvert.SerializeObject(yamlObject); Rules = JsonConvert.DeserializeObject <dynamic>(rules); } else { throw new Exception("Grammar file doesn't seem to be valid JSON or YAML!"); } }
public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); InputValidators.ValidateObjectNotNull(Fulfillments, "Fulfillments"); Fulfillments.ToList().ForEach(item => item.Validate(validationType)); }
/*private async void registerall() * { * var accidents = new List<accident>(); * * using (var ctx = new EmployeeEntity()) * accidents = ctx.accidents.ToList(); * * foreach(var item in accidents) * { * var birthDate = DataCalc.getBirthDate(item.curp); * int dias = DataCalc.daysLived(birthDate, item.fecha_accidente); * var biorritmoFisico = CalcularBiorritmo(dias, BiorytmDays.biorritmo_fisico); * var biorritmoEmocional = CalcularBiorritmo(dias, BiorytmDays.biorritmo_emocional); * var biorritmoIntelectual = CalcularBiorritmo(dias, BiorytmDays.biorritmo_intelectual); * var biorritmoIntuicional = CalcularBiorritmo(dias, BiorytmDays.biorritmo_intuicional); * * using (var ctx = new EmployeeEntity()) * { * var some = ctx.accidents.Where(x => x.curp == item.curp).First(); * some.residuo_fisico = biorritmoFisico; * some.residuo_emocional = biorritmoEmocional; * some.residuo_intelectual = biorritmoIntelectual; * some.residuo_intuicional = biorritmoIntuicional; * ctx.SaveChanges(); * } * * } * * * }*/ private async void btnRegister_Click(object sender, RoutedEventArgs e) { bool errors = false; if (string.IsNullOrEmpty(vm.curp)) { lblErrorCurp.Content = "El CURP no puede ser vacio"; lblErrorCurp.Visibility = Visibility.Visible; errors = true; } if (vm.curp.Length != 18) { lblErrorCurp.Content = "El CURP debe ser a 18 digitos"; lblErrorCurp.Visibility = Visibility.Visible; errors = true; } if (tbFechaAccidente.SelectedDate == null) { lblErrorDate.Content = "La fecha del accidente no puede ser vacia"; lblErrorDate.Visibility = Visibility.Visible; errors = true; } if (!InputValidators.validateCURP(vm.curp)) { lblErrorCurp.Content = "Ingresa un CURP valido"; lblErrorCurp.Visibility = Visibility.Visible; errors = true; } if (errors) { return; } employee empleado = new employee(); using (var ctx = new EmployeeEntity()) empleado = ctx.employees.Where(x => x.curp == vm.curp).FirstOrDefault(); if (empleado == null) { lblErrorCurp.Content = "No hay un empleado registrado con ese CURP"; lblErrorCurp.Visibility = Visibility.Visible; return; } DateTime fecha_nacimiento = DataCalc.getBirthDate(vm.curp); int dias = DataCalc.daysLived(fecha_nacimiento); var biorritmoFisico = CalcularBiorritmo(dias, 23); var biorritmoEmocional = CalcularBiorritmo(dias, 28); var biorritmoIntelectual = CalcularBiorritmo(dias, 33); var biorritmoIntuicional = CalcularBiorritmo(dias, 38); try { var createCommand = new RegisterAccidentCommand(vm.curp, vm.fecha_accidente, biorritmoFisico, biorritmoEmocional, biorritmoIntelectual, biorritmoIntuicional); await _mediator.Send(createCommand); MessageBox.Show("Accidente registrado con exito"); } catch (Exception ex) { MessageBox.Show("Ha ocurrido un error al registrar el accidente" + ex.Message); return; } Close(); }
public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); InputValidators.ValidateDateNotDefault(CancelledAt.Value, "Cancelled At"); InputValidators.ValidateValuedString(CancelReason, "Cancel Reason"); }
public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); InputValidators.ValidateObjectNotNull(Refunds, "Refunds"); Refunds.ToList().ForEach(item => item.Validate(validationType)); }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Should use weak validations or strong</param> /// <exception cref="Exceptions.OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public void Validate(Validations validationType = Validations.Weak) { InputValidators.ValidateZeroOrPositiveValue(Price.GetValueOrDefault(), "Price"); InputValidators.ValidateValuedString(Title, "Title"); }
public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); // All properties are optional, so we only validated when they're filled. if (LineItems != null) { LineItems.ToList().ForEach(item => item.Validate(validationType)); } if (ShippingAddress != null) { ShippingLines.ToList().ForEach(item => item.Validate(validationType)); } if (PaymentDetails != null && PaymentDetails.Length > 0) { PaymentDetails.ToList().ForEach(item => item.Validate(validationType)); } if (NoChargeAmount != null) { NoChargeAmount.Validate(validationType); } if (validationType == Validations.Weak) { if (BillingAddress != null) { BillingAddress.Validate(validationType); } else if (ShippingAddress != null) { ShippingAddress.Validate(validationType); } } else { if (BillingAddress != null) { BillingAddress.Validate(validationType); } if (ShippingAddress != null) { ShippingAddress.Validate(validationType); } } if (Customer != null) { Customer.Validate(validationType); } if (!string.IsNullOrEmpty(Email)) { InputValidators.ValidateEmail(Email); } if (!string.IsNullOrEmpty(CustomerBrowserIp)) { InputValidators.ValidateIp(CustomerBrowserIp); } if (!string.IsNullOrEmpty(Currency)) { InputValidators.ValidateCurrency(Currency); } if (TotalPrice.HasValue) { InputValidators.ValidateZeroOrPositiveValue(TotalPrice.Value, "Total Price"); } if (CreatedAt != null) { InputValidators.ValidateDateNotDefault(CreatedAt.Value, "Created At"); } if (UpdatedAt != null) { InputValidators.ValidateDateNotDefault(UpdatedAt.Value, "Updated At"); } if (DiscountCodes != null && DiscountCodes.Length > 0) { DiscountCodes.ToList().ForEach(item => item.Validate(validationType)); } if (TotalPriceUsd.HasValue) { InputValidators.ValidateZeroOrPositiveValue(TotalPriceUsd.Value, "Total Price USD"); } if (TotalDiscounts.HasValue) { InputValidators.ValidateZeroOrPositiveValue(TotalDiscounts.Value, "Total Discounts"); } if (ClosedAt.HasValue) { InputValidators.ValidateDateNotDefault(ClosedAt.Value, "Closed At"); } if (Decision != null) { Decision.Validate(validationType); } }
public void Validate(Validations validationType = Validations.Weak) { InputValidators.ValidateObjectNotNull(ErrorCode, "Error Code"); }
public virtual void Validate(Validations validationType = Validations.Weak) { InputValidators.ValidateValuedString(Id, "Merchant Order ID"); }
protected AbstractOrder(string merchantOrderId) { InputValidators.ValidateValuedString(merchantOrderId, "Merchant Order ID"); Id = merchantOrderId; }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="isWeak">Should use weak validations or strong</param> /// <exception cref="OrderFieldBadFormatException">throws an exception if one of the parameters doesn't match the expected format</exception> public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); InputValidators.ValidateObjectNotNull(LineItems, "Line Items"); LineItems.ToList().ForEach(item => item.Validate(validationType)); InputValidators.ValidateObjectNotNull(ShippingLines, "Shipping Lines"); ShippingLines.ToList().ForEach(item => item.Validate(validationType)); if (PaymentDetails == null && NoChargeAmount == null) { throw new Exceptions.OrderFieldBadFormatException("Both PaymentDetails and NoChargeDetails are missing - at least one should be specified"); } if (PaymentDetails != null) { PaymentDetails.Validate(validationType); } else { NoChargeAmount.Validate(validationType); } if (validationType == Validations.Weak) { if (BillingAddress == null && ShippingAddress == null) { throw new Exceptions.OrderFieldBadFormatException("Both shipping and billing addresses are missing - at least one should be specified"); } if (BillingAddress != null) { BillingAddress.Validate(validationType); } else { ShippingAddress.Validate(validationType); } } else { InputValidators.ValidateObjectNotNull(BillingAddress, "Billing Address"); BillingAddress.Validate(validationType); InputValidators.ValidateObjectNotNull(ShippingAddress, "Shipping Address"); ShippingAddress.Validate(validationType); } InputValidators.ValidateObjectNotNull(Customer, "Customer"); Customer.Validate(validationType); InputValidators.ValidateEmail(Email); InputValidators.ValidateIp(CustomerBrowserIp); InputValidators.ValidateCurrency(Currency); InputValidators.ValidateZeroOrPositiveValue(TotalPrice.Value, "Total Price"); InputValidators.ValidateValuedString(Gateway, "Gateway"); InputValidators.ValidateDateNotDefault(CreatedAt.Value, "Created At"); InputValidators.ValidateDateNotDefault(UpdatedAt.Value, "Updated At"); // optional fields validations if (DiscountCodes != null && DiscountCodes.Length > 0) { DiscountCodes.ToList().ForEach(item => item.Validate(validationType)); } if (TotalPriceUsd.HasValue) { InputValidators.ValidateZeroOrPositiveValue(TotalPriceUsd.Value, "Total Price USD"); } if (TotalDiscounts.HasValue) { InputValidators.ValidateZeroOrPositiveValue(TotalDiscounts.Value, "Total Discounts"); } if (ClosedAt.HasValue) { InputValidators.ValidateDateNotDefault(ClosedAt.Value, "Closed At"); } }
private async void btnAdd_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(vm.curp)) { lblErrorCurp.Content = "El CURP no puede ser vacio"; lblErrorCurp.Visibility = Visibility.Visible; return; } if (vm.curp.Length != 18) { lblErrorCurp.Content = "El CURP debe ser a 18 digitos"; lblErrorCurp.Visibility = Visibility.Visible; return; } if (!InputValidators.validateCURP(vm.curp)) { lblErrorCurp.Content = "Ingresa un CURP valido"; lblErrorCurp.Visibility = Visibility.Visible; return; } using (var ctx = new EmployeeEntity()) { var result = ctx.employees.Where(x => x.curp == vm.curp).Select(x => x.curp).FirstOrDefault(); if (result != null) { lblErrorCurp.Content = "Ya existe un empleado registrado con ese CURP"; lblErrorCurp.Visibility = Visibility.Visible; return; } } vm.fecha_nacimiento = DataCalc.getBirthDate(vm.curp); DateTime fecha_nacimiento = DataCalc.getBirthDate(vm.curp); int livedDays = DataCalc.daysLived(fecha_nacimiento); if (livedDays < 0) { lblErrorCurp.Content = "Error: La edad maxima 100"; lblErrorCurp.Visibility = Visibility.Visible; return; } var createCommand = new CreateEmployeeCommand(vm.curp, vm.fecha_nacimiento, tbFechaAccidente.SelectedDate); try { await _mediator.Send(createCommand); } catch (Exception) { MessageBox.Show("Ha ocurrido un error al registrar al empleado"); return; } if (tbFechaAccidente.SelectedDate != null) { vm.fecha_accidente = tbFechaAccidente.SelectedDate ?? DateTime.Now; var biorritmoFisico = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_fisico); var biorritmoEmocional = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_emocional); var biorritmoIntelectual = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_intelectual); var biorritmoIntuicional = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_intuicional); var registerAccident = new RegisterAccidentCommand(vm.curp, vm.fecha_accidente, biorritmoFisico, biorritmoEmocional, biorritmoIntelectual, biorritmoIntuicional); await _mediator.Send(registerAccident); } var response = $"{vm.curp} registrado con exito"; MessageBox.Show(response); Close(); }
private void SpaceNotAllowedTextBox_PreviewKeyDown(object sender, KeyEventArgs e) { e.Handled = InputValidators.SpaceNotAllowed(e); }
private void TextBox_PreviewExecuted(object sender, ExecutedRoutedEventArgs e) { e.Handled = InputValidators.PasteNotAllowed(e); }
private void IntegerTextBoxChecker_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !InputValidators.NumbersOnly(e.Text); }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Validation level of the model</param> /// <exception cref="OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public override void Validate(Validations validationType = Validations.Weak) { base.Validate(validationType); InputValidators.ValidateObjectNotNull(Decision, "Decision"); Decision.Validate(validationType); }
/// <summary> /// Validates the objects fields content /// </summary> /// <param name="validationType">Should use weak validations or strong</param> /// <exception cref="OrderFieldBadFormatException"> /// throws an exception if one of the parameters doesn't match the expected /// format /// </exception> public void Validate(Validations validationType = Validations.Weak) { InputValidators.ValidateValuedString(Gateway, "Gateway"); InputValidators.ValidateZeroOrPositiveValue(Amount, "Amount"); }