public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { var entityValue = propertyMetadata.GetValue<TimeSpan>(entity); switch (SelectedCondition) { case Condition.EqualTo: return entityValue == Value; case Condition.NotEqualTo: return entityValue != Value; case Condition.GreaterThan: return entityValue > Value; case Condition.LessThan: return entityValue < Value; case Condition.GreaterThanOrEqualTo: return entityValue >= Value; case Condition.LessThanOrEqualTo: return entityValue <= Value; default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } }
public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { bool entityValue = propertyMetadata.GetValue<bool>(entity); switch (SelectedCondition) { case Condition.EqualTo: return entityValue == Value; default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } }
public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { var entityValue = propertyMetadata.GetValue<string>(entity); switch (SelectedCondition) { case Condition.Contains: return entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) != -1; case Condition.EndsWith: return entityValue != null && entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase); case Condition.EqualTo: return entityValue == Value; case Condition.GreaterThan: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) > 0; case Condition.GreaterThanOrEqualTo: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) >= 0; case Condition.IsEmpty: return entityValue == string.Empty; case Condition.IsNull: return entityValue == null; case Condition.LessThan: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) < 0; case Condition.LessThanOrEqualTo: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) <= 0; case Condition.NotEqualTo: return entityValue != Value; case Condition.NotIsEmpty: return entityValue != string.Empty; case Condition.NotIsNull: return entityValue != null; case Condition.StartsWith: return entityValue != null && entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase); default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public bool IsToManyRelationProperty(IPropertyMetadata property, out Type relatedContract) { Type elementType; var isCollection = property.ClrType.IsCollectionType(out elementType); if ( isCollection && IsDataObjectContract(elementType) ) { relatedContract = elementType; return true; } else { relatedContract = null; return false; } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void WriteScalarPropertyConfiguration(IPropertyMetadata property, Operand<EntityTypeConfiguration<TT.TImpl>> typeConfig) { var m = _method; using ( TT.CreateScope<TT.TValue>(property.ClrType) ) { //typeConfig.Func<Expression<Func<TT.TImpl, TT.TValue>>, PrimitivePropertyConfiguration>(x => x.Property<TT.TValue>, WriteNewPropertyExpression(property).CastTo<Expression<Func<TT.TImpl, TT.TValue>>>()) } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void WriteOneToManyPropertyConfiguration(IPropertyMetadata property, Operand<EntityTypeConfiguration<TT.TImpl>> typeConfig) { throw new NotImplementedException(); }
public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { if (IsNullable) { var entityValue = propertyMetadata.GetValue <TValue?>(entity); switch (SelectedCondition) { case Condition.EqualTo: return(object.Equals(entityValue, Value)); case Condition.NotEqualTo: return(!object.Equals(entityValue, Value)); case Condition.GreaterThan: return(entityValue != null && _comparer.Compare(entityValue.Value, Value) > 0); case Condition.LessThan: return(entityValue != null && _comparer.Compare(entityValue.Value, Value) < 0); case Condition.GreaterThanOrEqualTo: return(entityValue != null && _comparer.Compare(entityValue.Value, Value) >= 0); case Condition.LessThanOrEqualTo: return(entityValue != null && _comparer.Compare(entityValue.Value, Value) <= 0); case Condition.IsNull: return(entityValue == null); case Condition.NotIsNull: return(entityValue != null); default: throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition)); } } else { var entityValue = propertyMetadata.GetValue <TValue>(entity); switch (SelectedCondition) { case Condition.EqualTo: return(object.Equals(entityValue, Value)); case Condition.NotEqualTo: return(!object.Equals(entityValue, Value)); case Condition.GreaterThan: return(_comparer.Compare(entityValue, Value) > 0); case Condition.LessThan: return(_comparer.Compare(entityValue, Value) < 0); case Condition.GreaterThanOrEqualTo: return(_comparer.Compare(entityValue, Value) >= 0); case Condition.LessThanOrEqualTo: return(_comparer.Compare(entityValue, Value) <= 0); default: throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition)); } } }
/// <summary> /// Get converter for a type. /// </summary> /// <param name="metadata">Property metadata.</param> /// <returns></returns> public static TypeConverter GetConverter(IPropertyMetadata metadata) { if (metadata == null) throw new ArgumentNullException("metadata"); TypeConverter converter; if (metadata.Type == CustomDataType.Other) converter = GetConverter(metadata.CustomType); else converter = GetConverter(metadata.Type); if (converter == null) converter = TypeDescriptor.GetConverter(metadata.ClrType); return converter; }
private void WhenRequiredFieldIsNotBlankAndSubmitButtonIsClicked(IPropertyMetadata metadata) { this.NewTest(); var propertyId = this.GetPropertyId(metadata); var humanFieldName = this.GetHumanFieldName(metadata); var value = metadata.PropertyInfo.GetValue(this.ViewModel, null); var s = this.Scenario(); s[string.Format("Given I am on the registration page")] = p => this.NavigateToRegistrationPage(); s[string.Format("And I have entered my {0}", humanFieldName)] = p => this.Page.SetElement(metadata, value); s[string.Format("When I submit my registration")] = p => this.Page.Submit(); s[string.Format("Then I will not see required validation message for my {0}", humanFieldName)] = p => this.GetRequiredValidationMesssage(metadata).Displayed.Should().BeFalse(); s.Execute(); }
public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { var entityValue = propertyMetadata.GetValue <string>(entity); if (entityValue is null && propertyMetadata.Type.IsEnumEx()) { var entityValueAsObject = propertyMetadata.GetValue(entity); if (entityValueAsObject != null) { entityValue = entityValueAsObject.ToString(); } } switch (SelectedCondition) { case Condition.Contains: return(entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) != -1); case Condition.DoesNotContain: return(entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) == -1); case Condition.EndsWith: return(entityValue != null && entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase)); case Condition.DoesNotEndWith: return(entityValue != null && !entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase)); case Condition.EqualTo: return(entityValue == Value); case Condition.GreaterThan: return(string.Compare(entityValue, Value, StringComparison.OrdinalIgnoreCase) > 0); case Condition.GreaterThanOrEqualTo: return(string.Compare(entityValue, Value, StringComparison.OrdinalIgnoreCase) >= 0); case Condition.IsEmpty: return(entityValue == string.Empty); case Condition.IsNull: return(entityValue is null); case Condition.LessThan: return(string.Compare(entityValue, Value, StringComparison.OrdinalIgnoreCase) < 0); case Condition.LessThanOrEqualTo: return(string.Compare(entityValue, Value, StringComparison.OrdinalIgnoreCase) <= 0); case Condition.NotEqualTo: return(entityValue != Value); case Condition.NotIsEmpty: return(entityValue != string.Empty); case Condition.NotIsNull: return(entityValue != null); case Condition.StartsWith: return(entityValue != null && entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase)); case Condition.DoesNotStartWith: return(entityValue != null && !entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase)); case Condition.Matches: return(entityValue != null && _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value)) && _regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue)); case Condition.DoesNotMatch: return(entityValue != null && _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value)) && !_regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue)); default: throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition)); } }
public CustomField(IPropertyMetadata property, Type customFieldType) : base(property) { CustomType = customFieldType ?? throw new ArgumentNullException(nameof(customFieldType)); }
private PropertyImpl(IPropertyMetadata metadata, Item parent) { _metadata = metadata; Parent = parent; }
private PropertyImpl(IPropertyMetadata metadata, Object parent) { _metadata = metadata; Parent = parent; }
protected virtual async Task UpdateProperty(IValueProvider valueProvider, T entity, IPropertyMetadata property) { bool handled = false; bool hasValue = valueProvider.ContainsKey(property.ClrName); object value; if (hasValue) { if (property.IsFileUpload) { value = valueProvider.GetValue <ISelectedFile>(property.ClrName); } else if (property.Type == CustomDataType.Password) { value = valueProvider.GetValue <string>(property.ClrName); } else { value = valueProvider.GetValue(property.ClrName, property.ClrType); } var arg = new EntityPropertyUpdateEventArgs <T>(entity, valueProvider, property, value); await RaiseAsyncEvent(EntityPropertyUpdateEvent, arg); handled = arg.IsHandled; } else { value = property.GetValue(entity); } if (!handled) { if (value != null && !property.ClrType.IsAssignableFrom(value.GetType())) { throw new NotImplementedException("未处理的属性“" + property.Name + "”。"); } ValidationContext validationContext = new ValidationContext(entity, Context.DomainContext, null); validationContext.MemberName = property.ClrName; validationContext.DisplayName = property.Name; var error = property.GetAttributes <ValidationAttribute>().Select(t => t.GetValidationResult(value, validationContext)).Where(t => t != ValidationResult.Success).ToArray(); if (error.Length > 0) { throw new ValidationException(string.Join(",", error.Select(t => t.ErrorMessage))); } if (hasValue) { property.SetValue(entity, value); } } }
private Task Service_EntityQuery(IDomainExecutionContext context, EntityQueryEventArgs <T> e) { List <EntitySearchItem> searchItems = new List <EntitySearchItem>(); var valueProvider = context.DomainContext.GetRequiredService <IValueProvider>(); if (!valueProvider.GetValue <bool>("Search")) { return(Task.CompletedTask); } IQueryable <T> queryable = e.Queryable; var keys = valueProvider.Keys.Where(t => t.StartsWith("Search.", StringComparison.OrdinalIgnoreCase)).Select(t => t.Substring(7).Split('.')).GroupBy(t => t[0], t => t.Length == 1 ? "" : "." + t[1]).ToArray(); for (int i = 0; i < keys.Length; i++) { string propertyName = keys[i].Key; IPropertyMetadata property = Service.Metadata.SearchProperties.FirstOrDefault(t => t.ClrName.Equals(propertyName, StringComparison.OrdinalIgnoreCase)); if (property == null) { continue; } EntitySearchItem searchItem = new EntitySearchItem(); string[] options = keys[i].ToArray(); switch (property.Type) { case CustomDataType.Date: case CustomDataType.DateTime: for (int a = 0; a < options.Length; a++) { if (options[a].Equals(".Start", StringComparison.OrdinalIgnoreCase)) { DateTime start; if (!DateTime.TryParse(valueProvider.GetValue <string>("Search." + keys[i].Key + options[a]), out start)) { continue; } searchItem.MorethanDate = start; ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(Expression.GreaterThanOrEqual(Expression.Property(parameter, property.ClrName), Expression.Constant(start)), parameter)); } else if (options[a].Equals(".End", StringComparison.OrdinalIgnoreCase)) { DateTime end; if (!DateTime.TryParse(valueProvider.GetValue <string>("Search." + keys[i].Key + options[a]), out end)) { continue; } if (property.Type == CustomDataType.Date) { end = end.AddDays(1); } searchItem.LessthanDate = end; ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(Expression.LessThanOrEqual(Expression.Property(parameter, property.ClrName), Expression.Constant(end)), parameter)); } } break; case CustomDataType.Boolean: case CustomDataType.Gender: if (options[0] == "") { bool result; if (!bool.TryParse(valueProvider.GetValue <string>("Search." + keys[i].Key), out result)) { continue; } searchItem.Equal = result; ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(Expression.Equal(Expression.Property(parameter, property.ClrName), Expression.Constant(result)), parameter)); } break; case CustomDataType.Currency: case CustomDataType.Integer: case CustomDataType.Number: for (int a = 0; a < options.Length; a++) { if (options[a].Equals(".Start", StringComparison.OrdinalIgnoreCase)) { double start; if (!double.TryParse(valueProvider.GetValue <string>("Search." + keys[i].Key + options[a]), out start)) { continue; } searchItem.Morethan = start; ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(Expression.GreaterThanOrEqual(Expression.Property(parameter, property.ClrName), Expression.Constant(start)), parameter)); } else if (options[a].Equals(".End", StringComparison.OrdinalIgnoreCase)) { double end; if (!double.TryParse(valueProvider.GetValue <string>("Search." + keys[i].Key + options[a]), out end)) { continue; } searchItem.Lessthan = end; ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(Expression.LessThanOrEqual(Expression.Property(parameter, property.ClrName), Expression.Constant(end)), parameter)); } } break; case CustomDataType.Other: if (property.CustomType == "Enum") { object result; try { result = Enum.Parse(property.ClrType, valueProvider.GetValue <string>("Search." + keys[i].Key)); } catch { continue; } searchItem.Enum = new EnumConverter(property.ClrType).ConvertToString(result); ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(Expression.Equal(Expression.Property(parameter, property.ClrName), Expression.Constant(result)), parameter)); } else if (property.CustomType == "Entity") { searchItem.Contains = valueProvider.GetValue <string>("Search." + keys[i].Key); if (searchItem.Contains == null) { continue; } var isId = valueProvider.GetValue <bool?>("Search." + keys[i].Key + ".Id"); ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); if (isId.HasValue && isId.Value) { var keyProperty = EntityDescriptor.GetMetadata(property.ClrType).KeyProperty; var id = keyProperty.Converter.ConvertFrom(searchItem.Contains); Expression expression = Expression.Property(Expression.Property(parameter, property.ClrName), keyProperty.ClrName); expression = Expression.Equal(expression, Expression.Constant(id)); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(expression, parameter)); } else { Expression expression = Expression.Property(Expression.Property(parameter, property.ClrName), EntityDescriptor.GetMetadata(property.ClrType).DisplayProperty.ClrName); expression = Expression.Call(expression, typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), Expression.Constant(searchItem.Contains)); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(expression, parameter)); } } break; default: if (property.ClrType == typeof(string)) { searchItem.Contains = valueProvider.GetValue <string>("Search." + keys[i].Key); if (searchItem.Contains == null) { continue; } ParameterExpression parameter = Expression.Parameter(Service.Metadata.Type); Expression expression = Expression.Property(parameter, property.ClrName); expression = Expression.Call(expression, typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), Expression.Constant(searchItem.Contains)); queryable = queryable.Where <T>(Expression.Lambda <Func <T, bool> >(expression, parameter)); } break; } if (searchItem.Contains != null || searchItem.Enum != null || searchItem.Equal.HasValue || searchItem.Lessthan.HasValue || searchItem.LessthanDate.HasValue || searchItem.Morethan.HasValue || searchItem.MorethanDate.HasValue) { searchItem.Name = property.Name; } if (searchItem.Name != null) { searchItems.Add(searchItem); } e.Queryable = queryable; } context.DomainContext.DataBag.SearchItem = searchItems.ToArray(); return(Task.CompletedTask); }
private PropertyState?GetPropertyState(IPropertyMetadata property) => _formState.GetPropertyState(property, false);
/// <summary> /// Executa um comando de insert no banco de dados. /// </summary> /// <param name="commandText">Texto do comando a ser executado.</param> /// <param name="action">Informação da ação de persistência.</param> /// <param name="transaction">Transação do comando.</param> /// <param name="primaryKeyMappings">Dicionário que mapeia ids virtuais para reais.</param> /// <returns>Retorna resultado da ação de persistência.</returns> protected virtual PersistenceActionResult ExecuteInsertCommand(string commandText, PersistenceAction action, IPersistenceTransactionExecuter transaction, Dictionary <int, int> primaryKeyMappings) { var trans = (PersistenceTransactionExecuter)transaction; var typeMetadata = TypeSchema.GetTypeMetadata(action.EntityFullName); bool hasRowVersion = typeMetadata.IsVersioned; var onlyResultProperties = typeMetadata.GetVolatileProperties().Where(f => action.Parameters.Count(g => g.Name == f.Name) == 0); int onlyResultCount = onlyResultProperties.Count(); int parameterCount = action.Parameters.Count + onlyResultCount; if (hasRowVersion) { parameterCount++; } var resultParameters = new PersistenceParameter[action.Parameters.Count + onlyResultCount]; var parameters = new GDAParameter[parameterCount + onlyResultCount]; for (int i = 0; i < action.Parameters.Count; i++) { parameters[i] = CreateParameter('?' + action.Parameters[i].Name, action.Parameters[i].Value); if (action.Parameters[i].DbType != DbType.AnsiString) { parameters[i].DbType = action.Parameters[i].DbType; } resultParameters[i] = action.Parameters[i]; } int index = action.Parameters.Count; foreach (var property in onlyResultProperties) { parameters[index] = CreateParameter('?' + property.Name, "", 0, System.Data.ParameterDirection.InputOutput); resultParameters[index] = new PersistenceParameter(property.Name, ""); index++; } if (hasRowVersion) { parameters[index] = CreateParameter('?' + DataAccessConstants.RowVersionPropertyName, action.RowVersion, 0, System.Data.ParameterDirection.Output); } int affectedRows = 0; try { var da = new DataAccess(trans.Transaction.ProviderConfiguration); affectedRows = da.ExecuteCommand(trans.Transaction, CommandType.Text, action.CommandTimeout, commandText, parameters); } catch (Exception ex) { Exception ex2 = ex; if (ex.InnerException is System.Data.Common.DbException || ex.InnerException is DataException) { ex2 = ex.InnerException; } ex = new DataException(ResourceMessageFormatter.Create(() => Properties.Resources.Exception_ExecuteDatabaseCommand, ex2.Message).Format(), ex2); action.NotifyError(ex); return(new PersistenceActionResult() { Success = false, AffectedRows = affectedRows, ActionId = action.ActionId, FailureMessage = ex.Message, RowVersion = (hasRowVersion) ? (long)parameters[parameters.Length - 1].Value : 0 }); } var keyRepository = GetKeyRepository(trans.ProviderName); if (keyRepository.IsPosCommand(action.EntityFullName)) { IPropertyMetadata identityMetadata = typeMetadata.GetKeyProperties().FirstOrDefault(); if (identityMetadata != null && identityMetadata.ParameterType == Schema.PersistenceParameterType.IdentityKey) { for (int i = 0; i < parameters.Length; i++) { if (action.Parameters[i].Name == identityMetadata.Name) { int identityValue = 0; var key = keyRepository.GetPrimaryKey(transaction, typeMetadata.FullName); if (key is int) { identityValue = (int)key; } else if (key is uint) { identityValue = (int)(uint)key; } else { identityValue = Convert.ToInt32(key); } parameters[i].Value = identityValue; var virtualIdValue = action.Parameters[i].Value; int virtualId = 0; if (virtualIdValue is int) { virtualId = (int)virtualIdValue; } else if (virtualIdValue is uint) { virtualId = (int)(uint)virtualIdValue; } else { virtualId = Convert.ToInt32(virtualIdValue); } action.Parameters[i].Value = identityValue; primaryKeyMappings.Add(virtualId, identityValue); break; } } } } action.NotifyExecution(); return(new PersistenceActionResult() { Success = true, AffectedRows = affectedRows, Parameters = resultParameters, ActionId = action.ActionId, RowVersion = (hasRowVersion) ? (long)parameters[parameters.Length - 1].Value : 0 }); }
/// <summary> /// Initialize. /// </summary> /// <param name="context">Entity descriptor context.</param> /// <param name="property">Property metadata.</param> public EntityValueConverterContext(EntityDescriptorContext context, IPropertyMetadata property) { _Context = context; Property = property; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public bool IsKeyProperty(IPropertyMetadata property) { return (property.Name.EqualsIgnoreCase("Id") || property.HasContractAttribute<PropertyContract.KeyAttribute>()); }
public Relation(Type relatedEntity, IPropertyMetadata property, IReadOnlyList <IElement> relatedElements) { RelatedEntity = relatedEntity ?? throw new ArgumentNullException(nameof(relatedEntity)); Property = property ?? throw new ArgumentNullException(nameof(property)); RelatedElements = relatedElements ?? throw new ArgumentNullException(nameof(relatedElements)); }
private IWebElement GetRequiredValidationMesssage(IPropertyMetadata metadata) { var elementId = (metadata.PropertyInfo.Name + "-required-validation-message").ToHtmlNamingConvention(); var element = this.Page.Find.Element(By.Id(elementId)); return element; }
public ObjectToValueConverter(IPropertyMetadata propertyMetadata) { _propertyMetadata = propertyMetadata; }
public bool IsModified(IPropertyMetadata property) { return(GetPropertyState(property) !.IsModified); }
public ElementConfig(IPropertyMetadata id, params IExpressionMetadata[] labels) { IdProperty = id ?? throw new ArgumentNullException(nameof(id)); DisplayProperties = labels?.ToList() ?? throw new ArgumentNullException(nameof(labels)); }
public bool IsValid(IPropertyMetadata property) { return(!GetPropertyState(property) !.GetValidationMessages().Any()); }
private object MapPropertyFromObject(object source, PropertyInfo sourceProperty, IPropertyMetadata viewModelProperty, CultureInfo culture) { return(MapProperty( sourceProperty.Get(source), sourceProperty.PropertyType, viewModelProperty.PropertyType, viewModelProperty.SourcePropertyName, viewModelProperty.FormattableProperty || viewModelProperty.LocalizableEnumProperty, culture)); }
public bool WasValidated(IPropertyMetadata property) { return(GetPropertyState(property) !.WasValidated); }
public void AddValidationMessage(IPropertyMetadata property, string message) { GetPropertyState(property, true) !.AddMessage(message); GetPropertyState(property, true) !.WasValidated = true; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private IOperand<LambdaExpression> WriteNewPropertyExpression(IPropertyMetadata property) { throw new NotImplementedException(); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public bool IsToOneRelationProperty(IPropertyMetadata property) { return IsDataObjectContract(property.ClrType); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void WriteRelationPropertyConfiguration(IPropertyMetadata property, Operand<EntityTypeConfiguration<TT.TImpl>> typeConfig) { if ( property.Relation.RelationKind == RelationKind.ManyToOne && property.Relation.ThisPartyKind == RelationPartyKind.Dependent ) { WriteManyToOnePropertyConfiguration(property, typeConfig); } else if ( property.Relation.RelationKind == RelationKind.OneToMany && property.Relation.ThisPartyKind == RelationPartyKind.Principal ) { WriteOneToManyPropertyConfiguration(property, typeConfig); } }
public abstract bool CalculateResult(IPropertyMetadata propertyMetadata, object entity);
private PropertyImpl(IPropertyMetadata metadata, Item parent) { this.metadata = metadata; this.Parent = parent; }
private string GetLabel(IPropertyMetadata metadata) { var name = metadata.Display.GetName(); if (string.IsNullOrWhiteSpace(name)) { name = metadata.PropertyInfo.Name.Dehumanize(); } return name; }
public void NotifyPropertyIncludedInForm(IPropertyMetadata property) { GetPropertyState(property); }
public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { var entityValue = propertyMetadata.GetValue<string>(entity); if (entityValue == null && propertyMetadata.Type.IsEnumEx()) { var entityValueAsObject = propertyMetadata.GetValue(entity); if (entityValueAsObject != null) { entityValue = entityValueAsObject.ToString(); } } switch (SelectedCondition) { case Condition.Contains: return entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) != -1; case Condition.DoesNotContain: return entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) == -1; case Condition.EndsWith: return entityValue != null && entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase); case Condition.DoesNotEndWith: return entityValue != null && !entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase); case Condition.EqualTo: return entityValue == Value; case Condition.GreaterThan: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) > 0; case Condition.GreaterThanOrEqualTo: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) >= 0; case Condition.IsEmpty: return entityValue == string.Empty; case Condition.IsNull: return entityValue == null; case Condition.LessThan: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) < 0; case Condition.LessThanOrEqualTo: return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) <= 0; case Condition.NotEqualTo: return entityValue != Value; case Condition.NotIsEmpty: return entityValue != string.Empty; case Condition.NotIsNull: return entityValue != null; case Condition.StartsWith: return entityValue != null && entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase); case Condition.DoesNotStartWith: return entityValue != null && !entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase); case Condition.Matches: return entityValue != null && _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value)) && _regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue); case Condition.DoesNotMatch: return entityValue != null && _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value)) && !_regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue); default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } }
/// <summary> /// Render a property editor. /// </summary> /// <param name="helper">A htmlhelper.</param> /// <param name="property">Property metadata.</param> /// <param name="value">Property value.</param> public static MvcHtmlString Editor(this HtmlHelper helper, IPropertyMetadata property, object value) { if (helper == null) throw new ArgumentNullException("helper"); if (property == null) throw new ArgumentNullException("property"); MvcEditorModel model = new MvcEditorModel(); model.Metadata = property; model.Value = value; if (property.Type == CustomDataType.Other) return helper.Partial(property.CustomType + "Editor", model); else return helper.Partial(property.Type.ToString() + "Editor", model); }
public void NotifyPropertyFinished(IPropertyMetadata property) { GetPropertyState(property) !.IsBusy = false; OnValidationStateChanged?.Invoke(this, new ValidationStateChangedEventArgs()); }
private string GetHumanFieldName(IPropertyMetadata metadata) { return this.GetLabel(metadata).ToLower(); }
protected virtual void MergeProtected(IPropertyMetadata baseMetadata) { }
private string GetPropertyId(IPropertyMetadata metadata) { return metadata.PropertyInfo.Name; }
public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { if (IsNullable) { var entityValue = propertyMetadata.GetValue <int?>(entity); switch (SelectedCondition) { case Condition.EqualTo: return(entityValue == Value); case Condition.NotEqualTo: return(entityValue != Value); case Condition.GreaterThan: return(entityValue > Value); case Condition.LessThan: return(entityValue < Value); case Condition.GreaterThanOrEqualTo: return(entityValue >= Value); case Condition.LessThanOrEqualTo: return(entityValue <= Value); case Condition.IsNull: return(entityValue == null); case Condition.NotIsNull: return(entityValue != null); default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } } else { var entityValue = propertyMetadata.GetValue <int>(entity); switch (SelectedCondition) { case Condition.EqualTo: return(entityValue == Value); case Condition.NotEqualTo: return(entityValue != Value); case Condition.GreaterThan: return(entityValue > Value); case Condition.LessThan: return(entityValue < Value); case Condition.GreaterThanOrEqualTo: return(entityValue >= Value); case Condition.LessThanOrEqualTo: return(entityValue <= Value); default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } } }
private void WhenRequiredFieldIsNotBlankAndExited(IPropertyMetadata metadata) { this.NewTest(); IWebElement element = null; var propertyId = this.GetPropertyId(metadata); var humanFieldName = this.GetHumanFieldName(metadata); var value = metadata.PropertyInfo.GetValue(this.ViewModel, null); var s = this.Scenario(); s[string.Format("Given I am on the registration page")] = p => { this.NavigateToRegistrationPage(); element = this.Page.GetElement(metadata); }; s[string.Format("And I have not entered my {0}", humanFieldName)] = p => { element.Click(); element.SendKeys(value.ToString()); }; s[string.Format("When I exit the control")] = p => element.SendKeys("\t"); s[string.Format("Then I will see validation message that {0} is required", humanFieldName)] = p => this.GetRequiredValidationMesssage(metadata).Displayed.Should().BeFalse(); s.Execute(); }
public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity) { if (IsNullable) { var entityValue = propertyMetadata.GetValue(entity); double doubleValue = 0d; if (entityValue != null) { doubleValue = Convert.ToDouble(entityValue); } switch (SelectedCondition) { case Condition.EqualTo: return entityValue != null && doubleValue == Value; case Condition.NotEqualTo: return entityValue != null && doubleValue != Value; case Condition.GreaterThan: return entityValue != null && doubleValue > Value; case Condition.LessThan: return entityValue != null && doubleValue < Value; case Condition.GreaterThanOrEqualTo: return entityValue != null && doubleValue >= Value; case Condition.LessThanOrEqualTo: return entityValue != null && doubleValue <= Value; case Condition.IsNull: return entityValue == null; case Condition.NotIsNull: return entityValue != null; default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } } else { var entityValue = propertyMetadata.GetValue(entity); var doubleValue = Convert.ToDouble(entityValue); switch (SelectedCondition) { case Condition.EqualTo: return doubleValue == Value; case Condition.NotEqualTo: return doubleValue != Value; case Condition.GreaterThan: return doubleValue > Value; case Condition.LessThan: return doubleValue < Value; case Condition.GreaterThanOrEqualTo: return doubleValue >= Value; case Condition.LessThanOrEqualTo: return doubleValue <= Value; default: throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition)); } } }
internal ExpressionFieldSetup(FieldConfig field, IPropertyMetadata expression) : base(field) { Expression = PropertyMetadataHelper.GetExpressionMetadata(expression ?? throw new ArgumentNullException(nameof(expression))); DisplayType = field.DisplayType; }
public CollectionDataValidator(IPropertyMetadata property) { _property = property; }