protected virtual void RaiseErrorsChanged(DataErrorsChangedEventArgs args) { OnPropertyChanged(Empty.HasErrorsChangedArgs); OnPropertyChanged(Empty.IsValidChangedArgs); OnPropertyChanged(Empty.IndexerPropertyChangedArgs); if (ErrorsChanged != null) { ThreadManager.Invoke(Settings.EventExecutionMode, this, args, RaiseErrorsChangedDelegate); } #if NONOTIFYDATAERROR string ignoreProperty = args.PropertyName ?? string.Empty; lock (_locker) { //Disable validation to prevent cycle var contains = IgnoreProperties.Contains(ignoreProperty); if (!contains) { IgnoreProperties.Add(ignoreProperty); } try { OnPropertyChanged(ignoreProperty); } finally { if (!contains) { IgnoreProperties.Remove(ignoreProperty); } } } #endif }
/// <summary> /// Runs shallow equal on the metadata while ignoring keys starting with '@' /// And replication related properties like replication /// </summary> /// <param name="documentId"></param> /// <param name="origin"></param> /// <param name="external"></param> /// <param name="result">The output metadata incase the metadata are equal</param> /// <returns></returns> protected static bool CheckIfMetadataIsEqualEnoughForReplicationAndMergeHistorires( string documentId, RavenJObject origin, RavenJObject external, out RavenJObject result) { result = null; var keysToCheck = new HashSet <string>(external.Keys.Where(k => !k.StartsWith("@") && !IgnoreProperties.Contains(k))); foreach (var key in origin.Keys.Where(k => !k.StartsWith("@") && !IgnoreProperties.Contains(k))) { var originVal = origin[key]; RavenJToken externalVal; if (external.TryGetValue(key, out externalVal) == false) { return(false); } if (!RavenJTokenEqualityComparer.Default.Equals(originVal, externalVal)) { return(false); } keysToCheck.Remove(key); } if (keysToCheck.Any()) { return(false); } //If we got here the metadata is the same, need to merge histories MergeReplicationHistories(documentId, origin, external, ref result); return(true); }
public override async Task SetParametersAsync(ParameterView parameters) { await base.SetParametersAsync(parameters); if (parameters.GetValueOrDefault <object>(nameof(DataSource)) != null) { rows = (DataSource as IEnumerable).Cast <object>().ToList(); DataType = DataSource.GetType().GetGenericArguments()[0]; if (AutoGenerateColumns && !headerInitilized) { headerInitilized = true; DataType.GetProperties().Where(p => !IgnoreProperties.Contains(p.Name)).Reverse().ToList().ForEach(property => { if (Headers.Any(x => x.Property?.Name == property.Name)) { return; } var attrs = property.GetCustomAttributes(true); var columnConfig = attrs.OfType <TableColumnAttribute>().FirstOrDefault() ?? new TableColumnAttribute() { Text = property.Name }; Headers.Insert(0, new TableHeader() { Eval = row => { var value = property.GetValue(row); if (string.IsNullOrWhiteSpace(columnConfig.Format)) { return(value); } if (value == null) { return(null); } try { return(Convert.ToDateTime(value).ToString(columnConfig.Format)); } catch (InvalidCastException) { throw new BlazuiException("仅日期列支持 Format 参数"); } }, IsCheckBox = property.PropertyType == typeof(bool) || Nullable.GetUnderlyingType(property.PropertyType) == typeof(bool), Property = property, Text = columnConfig.Text, Width = columnConfig.Width }); } ); } SelectedRows = new HashSet <object>(); chkAll?.MarkAsRequireRender(); ResetSelectAllStatus(); } }
internal override void OnPropertyChangedInternal(PropertyChangedEventArgs args) { base.OnPropertyChangedInternal(args); if (IsEntityInitialized && !IgnoreProperties.Contains(args.PropertyName) && !IsDisposed) { OnPropertyChanged(Empty.HasChangesChangedArgs, ExecutionMode.None); } }
public Task ValidateAsync() { EnsureInitialized(); if (IgnoreProperties.Contains(string.Empty)) { return(Empty.Task); } return(Validate(string.Empty)); }
internal override void OnPropertyChangedInternal(PropertyChangedEventArgs args) { base.OnPropertyChangedInternal(args); if (IsEntityInitialized && UpdateChangesOnPropertyChanged && !IgnoreProperties.Contains(args.PropertyName) && !IsDisposed) { OnPropertyChanged("HasChanges"); } }
private ICollection <string> UpdateErrorsInternal([NotNull] string propertyName, [CanBeNull] IEnumerable validatorErrors) { Should.NotBeNull(propertyName, "propertyName"); IList <object> errors; if (validatorErrors is string) { errors = new object[] { validatorErrors } } ; else { errors = validatorErrors == null ? Empty.Array <object>() : validatorErrors.OfType <object>().ToArray(); } var hasErrors = errors.Count != 0; if (hasErrors && IgnoreProperties.Contains(propertyName)) { return(Empty.Array <string>()); } ICollection <string> mappingProperties; PropertyMappings.TryGetValue(propertyName, out mappingProperties); if (mappingProperties == null) { if (hasErrors) { _errors[propertyName] = errors; } else { _errors.Remove(propertyName); } return(new[] { propertyName }); } foreach (string property in mappingProperties) { if (hasErrors) { _errors[property] = errors; } else { _errors.Remove(property); } } return(mappingProperties); }
/// <summary> /// Updates information about errors in the specified property. /// </summary> /// <param name="propertyName">The specified property name.</param> public Task ValidateAsync(string propertyName) { EnsureNotDisposed(); EnsureInitialized(); if (string.IsNullOrEmpty(propertyName)) { return(ValidateAsync()); } if (IgnoreProperties.Contains(propertyName)) { return(Empty.Task); } List <string> properties = null; string singleMap = null; foreach (var item in PropertyMappings) { if (!item.Value.Contains(propertyName)) { continue; } if (singleMap == null) { singleMap = item.Key; } else { if (properties == null) { properties = new List <string> { singleMap } } ; properties.Add(item.Key); } } if (properties != null) { var tasks = new Task[properties.Count]; for (int index = 0; index < properties.Count; index++) { tasks[index] = Validate(properties[index]); } return(ToolkitExtensions.WhenAll(tasks)); } if (singleMap == null) { singleMap = propertyName; } return(Validate(singleMap)); }
public bool HasDesignatedProperties(string Name) { if (OnlyProperties != null) { return(OnlyProperties.Contains(Name)); } if (IgnoreProperties != null) { return(!IgnoreProperties.Contains(Name)); } return(false); }
public virtual void Initialize() { var conventionMap = new List <dynamic>(); var sourceProperties = typeof(TSource).GetProperties(); var destinationProperties = typeof(TDestination).GetProperties(); var propertyMap = new List <PropertyLookup>(); if (CustomActivator == null) { SpecializedActivator = LambdaCompiler.CreateActivator <TDestination>(); } Conventions.Concat(configuration.Conventions).ToList().ForEach(convention => conventionMap.AddRange(convention(sourceProperties, destinationProperties))); conventionMap.ForEach(item => { if (!item.source.CanRead) { throw new MapperException($"Property to read from {item.source.Name} has no getter!"); } if (!item.destination.CanWrite) { throw new MapperException($"Property to write to {item.destination.Name} has no setter"); } if (IgnoreProperties.Contains(item.destination.Name)) { return; } var getter = typeof(PropertyLookup.GetterInvoker <,>).MakeGenericType(typeof(TSource), item.source.PropertyType); var setter = typeof(PropertyLookup.SetterInvoker <,>).MakeGenericType(typeof(TDestination), item.destination.PropertyType); var lookup = new PropertyLookup { Source = Activator.CreateInstance(getter, new object[] { item.source.Name }), Destination = Activator.CreateInstance(setter, new object[] { item.destination.Name }) }; if (item.source.PropertyType != item.destination.PropertyType) { lookup.Converter = CreateTypeConverter(item); } PropertiesSetByConvention.Add(item.destination.Name); propertyMap.Add(lookup); }); map = propertyMap.Distinct().ToList(); //TODO: verify distinct behavior in this case... }
private void HandleValidationInternal(object sender, object message) { var validationMessage = message as AsyncValidationMessage; if (validationMessage != null) { RaiseErrorsChanged(new DataErrorsChangedEventArgs(validationMessage.PropertyName)); OnHandleAsyncValidationMessage(sender, validationMessage); return; } var errorsMessage = message as DataErrorsChangedMessage; if (errorsMessage == null) { return; } OnErrorsChanged(sender, errorsMessage); #if NONOTIFYDATAERROR //To update property error in UI. ThreadManager.InvokeOnUiThreadAsync(() => { string ignoreProperty = errorsMessage.PropertyName ?? string.Empty; lock (_locker) { //Disable validation to prevent cycle var contains = IgnoreProperties.Contains(ignoreProperty); if (!contains) { IgnoreProperties.Add(ignoreProperty); } try { OnPropertyChanged(errorsMessage.PropertyName, ExecutionMode.None); } finally { if (!contains) { IgnoreProperties.Remove(ignoreProperty); } } } }); #endif }
public override async Task SetParametersAsync(ParameterView parameters) { await base.SetParametersAsync(parameters); if (parameters.GetValueOrDefault <object>(nameof(DataSource)) != null) { rows = (DataSource as IEnumerable).Cast <object>().ToList(); DataType = DataSource.GetType().GetGenericArguments()[0]; if (AutoGenerateColumns && !headerInitilized) { headerInitilized = true; DataType.GetProperties().Where(p => !IgnoreProperties.Contains(p.Name)).Reverse().ToList().ForEach(property => { if (Headers.Any(x => x.Property?.Name == property.Name)) { return; } var attrs = property.GetCustomAttributes(true); var text = attrs.OfType <DisplayAttribute>().FirstOrDefault()?.Name; if (string.IsNullOrWhiteSpace(text)) { text = attrs.OfType <DescriptionAttribute>().FirstOrDefault()?.Description; } var width = attrs.OfType <WidthAttribute>().FirstOrDefault()?.Width; Headers.Insert(0, new TableHeader() { Eval = row => { return(property.GetValue(row)); }, IsCheckBox = property.PropertyType == typeof(bool) || Nullable.GetUnderlyingType(property.PropertyType) == typeof(bool), Property = property, Text = text ?? property.Name, Width = width }); } ); } chkAll?.MarkAsRequireRender(); ResetSelectAllStatus(); } }
private void InitilizeHeaders() { if (AutoGenerateColumns && !headerInitilized) { headerInitilized = true; DataType.GetProperties().Where(p => !IgnoreProperties.Contains(p.Name)).Reverse().ToList().ForEach(property => { if (Headers.Any(x => x.Property?.Name == property.Name)) { return; } var attrs = property.GetCustomAttributes(true); if (attrs.OfType <TableIgnoreAttribute>().Any()) { Headers.Add(new TableHeader() { Ignore = true, Property = property }); return; } var columnConfig = attrs.OfType <TableColumnAttribute>().FirstOrDefault() ?? new TableColumnAttribute() { Text = property.Name }; if (columnConfig.Ignore) { Headers.Add(new TableHeader() { Ignore = true, Property = property }); return; } var editorConfig = attrs.OfType <EditorGeneratorAttribute>().FirstOrDefault() ?? new EditorGeneratorAttribute() { Control = typeof(BInput <string>) }; var formConfig = attrs.OfType <FormControlAttribute>().FirstOrDefault(); var propertyConfig = attrs.OfType <PropertyAttribute>().FirstOrDefault(); var tableHeader = new TableHeader() { EvalRaw = row => { object value = property.GetValue(row); return(value); }, SortNo = columnConfig.SortNo, IsCheckBox = property.PropertyType == typeof(bool) || Nullable.GetUnderlyingType(property.PropertyType) == typeof(bool), Property = property, Text = columnConfig.Text, Width = columnConfig.Width, IsEditable = columnConfig.IsEditable }; tableHeader.Eval = displayRender.CreateRenderFactory(tableHeader).CreateRender(tableHeader); if (IsEditable && columnConfig.IsEditable) { InitilizeHeaderEditor(property, editorConfig, tableHeader); } Headers.Insert(0, tableHeader); } ); if (IsEditable) { CreateOperationColumn(); } chkAll?.MarkAsRequireRender(); ResetSelectAllStatus(); } else if (!AutoGenerateColumns && !headerInitilized && Headers.Any()) { headerInitilized = true; foreach (var header in Headers) { if (!CanEdit(header)) { continue; } InitilizeHeaderEditor(header.Property, header.Property.GetCustomAttribute <EditorGeneratorAttribute>() ?? new EditorGeneratorAttribute(), header); } CreateOperationColumn(); Refresh(); } }
public override IList <string> GetDestinationObjectPropertiesNotMapped() { var mappedProperties = new List <string>(); mappedProperties.AddRange(PropertiesSetByConvention); mappedProperties.AddRange(PropertiesSetManually); var objectProperties = typeof(TDestination).GetProperties().Select(x => x.Name); return(objectProperties.Where(property => !mappedProperties.Contains(property) && !IgnoreProperties.Contains(property)).ToList()); }
public virtual IList <string> GetDestinationObjectPropertiesNotMapped() { var mappedProperties = PropertiesSetByConvention; var objectProperties = typeof(TDestination).GetProperties().Select(x => x.Name); return(objectProperties.Where(property => !mappedProperties.Contains(property) && !IgnoreProperties.Contains(property)).ToList()); }