public bool ActivateFor(Row row) { if (ReferenceEquals(null, Target)) return false; attr = Target.GetAttribute<ImageUploadEditorAttribute>(); if (attr == null || attr.DisableDefaultBehavior || attr.EditorType != "MultipleImageUpload") return false; if (!(Target is StringField)) throw new ArgumentException(String.Format( "Field '{0}' on row type '{1}' has a UploadEditor attribute but it is not a String field!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); if (!(row is IIdRow)) throw new ArgumentException(String.Format( "Field '{0}' on row type '{1}' has a UploadEditor attribute but Row type doesn't implement IIdRow!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); var format = attr.FilenameFormat; if (format == null) { format = row.GetType().Name; if (format.EndsWith("Row")) format = format.Substring(0, format.Length - 3); format += "/~"; } this.fileNameFormat = format.Replace("~", SplittedFormat); this.uploadHelper = new UploadHelper((attr.SubFolder.IsEmptyOrNull() ? "" : (attr.SubFolder + "/")) + (this.fileNameFormat)); return true; }
public bool ActivateFor(Row row) { if (row.GetType().GetCustomAttribute<CaptureLogAttribute>() == null) return false; captureLogHandler = (ICaptureLogHandler)Activator.CreateInstance( typeof(CaptureLogHandler<>).MakeGenericType(row.GetType())); return true; }
public bool ActivateFor(Row row) { if (ReferenceEquals(null, Target)) return false; attr = Target.GetAttribute<MasterDetailRelationAttribute>(); if (attr == null) return false; var rowListType = Target.ValueType; if (!rowListType.IsGenericType || rowListType.GetGenericTypeDefinition() != typeof(List<>)) { throw new ArgumentException(String.Format("Field '{0}' in row type '{1}' has a MasterDetailRelationAttribute " + "but its property type is not a generic List (e.g. List<Row>)!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } var rowType = rowListType.GetGenericArguments()[0]; if (rowType.IsAbstract || !typeof(Row).IsAssignableFrom(rowType)) { throw new ArgumentException(String.Format( "Field '{0}' in row type '{1}' has a MasterDetailRelationAttribute " + "but its property type is not a generic list of rows (e.g. List<Row>)!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } rowListFactory = FastReflection.DelegateForConstructor<IList>(rowListType); rowFactory = FastReflection.DelegateForConstructor<Row>(rowType); listHandlerFactory = FastReflection.DelegateForConstructor<IListRequestProcessor>( typeof(ListRequestHandler<>).MakeGenericType(rowType)); saveHandlerFactory = FastReflection.DelegateForConstructor<ISaveRequestProcessor>( typeof(SaveRequestHandler<>).MakeGenericType(rowType)); saveRequestFactory = FastReflection.DelegateForConstructor<ISaveRequest>( typeof(SaveRequest<>).MakeGenericType(rowType)); deleteHandlerFactory = FastReflection.DelegateForConstructor<IDeleteRequestProcessor>( typeof(DeleteRequestHandler<>).MakeGenericType(rowType)); var detailRow = rowFactory(); foreignKeyField = detailRow.FindFieldByPropertyName(attr.ForeignKey) ?? detailRow.FindField(attr.ForeignKey); if (ReferenceEquals(foreignKeyField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for a master detail relation in field '{2}' of row type '{3}'.", attr.ForeignKey, detailRow.GetType().FullName, Target.PropertyName ?? Target.Name, row.GetType().FullName)); return true; }
private static void AddInstance(Dictionary<string, Dictionary<string, Row>> registry, Row row) { try { var connectionKey = GetConnectionKey(row.GetType()); Dictionary<string, Row> connectionRegistry; if (!registry.TryGetValue(connectionKey, out connectionRegistry)) registry[connectionKey] = connectionRegistry = new Dictionary<string, Row>(StringComparer.OrdinalIgnoreCase); string table = row.Table; connectionRegistry.Add(table, row); } catch (Exception ex) { new InvalidOperationException(String.Format("Can't register Row instance in DataSchema: {0}", row.GetType().FullName), ex).Log(); } }
public bool ActivateFor(Row row) { var attr = row.GetType().GetCustomAttributes<UniqueConstraintAttribute>() .Where(x => x.CheckBeforeSave); if (!attr.Any()) return false; this.attrList = attr.ToArray(); return true; }
public bool ActivateFor(Row row) { if (ReferenceEquals(null, Target)) return false; var attr = Target.GetAttribute<NotesEditorAttribute>(); if (attr == null) return false; if (Target.ValueType != typeof(List<NoteRow>)) { throw new ArgumentException(String.Format("Field '{0}' in row type '{1}' has a NotesEditorAttribute " + "but its property type is not a List<NoteRow>!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } return true; }
public bool ActivateFor(Row row) { if (ReferenceEquals(null, Target)) return false; attr = Target.GetAttribute<MasterDetailRelationAttribute>(); if (attr == null) return false; var rowListType = Target.ValueType; if (!rowListType.GetIsGenericType() || rowListType.GetGenericTypeDefinition() != typeof(List<>)) { throw new ArgumentException(String.Format("Field '{0}' in row type '{1}' has a MasterDetailRelationAttribute " + "but its property type is not a generic List (e.g. List<Row>)!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } var rowType = rowListType.GetGenericArguments()[0]; if (rowType.GetIsAbstract() || !typeof(Row).IsAssignableFrom(rowType)) { throw new ArgumentException(String.Format( "Field '{0}' in row type '{1}' has a MasterDetailRelationAttribute " + "but its property type is not a generic list of rows (e.g. List<Row>)!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } rowListFactory = FastReflection.DelegateForConstructor<IList>(rowListType); rowFactory = FastReflection.DelegateForConstructor<Row>(rowType); listHandlerFactory = FastReflection.DelegateForConstructor<IListRequestProcessor>( typeof(ListRequestHandler<>).MakeGenericType(rowType)); saveHandlerFactory = FastReflection.DelegateForConstructor<ISaveRequestProcessor>( typeof(SaveRequestHandler<>).MakeGenericType(rowType)); saveRequestFactory = FastReflection.DelegateForConstructor<ISaveRequest>( typeof(SaveRequest<>).MakeGenericType(rowType)); deleteHandlerFactory = FastReflection.DelegateForConstructor<IDeleteRequestProcessor>( typeof(DeleteRequestHandler<>).MakeGenericType(rowType)); var detailRow = rowFactory(); foreignKeyField = detailRow.FindFieldByPropertyName(attr.ForeignKey) ?? detailRow.FindField(attr.ForeignKey); if (ReferenceEquals(foreignKeyField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for a master detail relation in field '{2}' of row type '{3}'.", attr.ForeignKey, detailRow.GetType().FullName, Target.PropertyName ?? Target.Name, row.GetType().FullName)); this.foreignKeyCriteria = new Criteria(foreignKeyField.PropertyName ?? foreignKeyField.Name); if (!string.IsNullOrEmpty(attr.FilterField)) { this.filterField = detailRow.FindFieldByPropertyName(attr.FilterField) ?? detailRow.FindField(attr.FilterField); if (ReferenceEquals(null, this.filterField)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for a master detail relation as FilterField in field '{2}' of row type '{3}'.", attr.FilterField, detailRow.GetType().FullName, Target.PropertyName ?? Target.Name, row.GetType().FullName)); this.filterCriteria = new Criteria(filterField.PropertyName ?? filterField.Name); this.filterValue = filterField.ConvertValue(attr.FilterValue, CultureInfo.InvariantCulture); if (this.filterValue == null) { this.filterCriteria = this.filterCriteria.IsNull(); this.filterCriteriaT0 = this.filterField.IsNull(); } else { this.filterCriteria = this.filterCriteria == new ValueCriteria(this.filterValue); this.filterCriteriaT0 = this.filterField == new ValueCriteria(this.filterValue); } } this.includeColumns = new HashSet<string>(); if (!string.IsNullOrEmpty(attr.IncludeColumns)) foreach (var s in attr.IncludeColumns.Split(',')) { var col = s.TrimToNull(); if (col != null) this.includeColumns.Add(col); } return true; }
protected void CheckUnassignedRead(Row row) { if (row == null) throw new ArgumentNullException("row"); if (!row.tracking) return; if (!row.trackWithChecks) return; if (row.IsAssigned(this)) return; if (!this.GetIsNull(row)) return; throw new InvalidOperationException(String.Format( "{0} field on {1} is read before assigned a value!", this.Name, row.GetType().Name)); }
public static string GetConnectionKey(Row row) { return GetConnectionKey(row.GetType()); }
public static string GetSchemaName(Row row) { return(GetSchemaName(row.GetType())); }
public bool ActivateFor(Row row) { var attrs = row.GetType().GetCustomAttributes<UpdatableExtensionAttribute>(); if (attrs == null || !attrs.Any()) return false; var sourceByExpression = row.GetFields().ToLookup(x => BracketLocator.ReplaceBrackets(x.Expression.TrimToEmpty(), BracketRemoverDialect.Instance)); this.infoList = attrs.Select(attr => { var info = new RelationInfo(); info.Attr = attr; var rowType = attr.RowType; if (rowType.GetIsAbstract() || !typeof(Row).IsAssignableFrom(rowType)) { throw new ArgumentException(String.Format( "Row type '{1}' has an ExtensionRelation attribute " + "but its specified extension row type '{0}' is not a valid row class!", rowType.FullName, row.GetType().FullName)); } info.RowFactory = FastReflection.DelegateForConstructor<Row>(rowType); info.ListHandlerFactory = FastReflection.DelegateForConstructor<IListRequestProcessor>( typeof(ListRequestHandler<>).MakeGenericType(rowType)); info.SaveHandlerFactory = FastReflection.DelegateForConstructor<ISaveRequestProcessor>( typeof(SaveRequestHandler<>).MakeGenericType(rowType)); info.SaveRequestFactory = FastReflection.DelegateForConstructor<ISaveRequest>( typeof(SaveRequest<>).MakeGenericType(rowType)); info.DeleteHandlerFactory = FastReflection.DelegateForConstructor<IDeleteRequestProcessor>( typeof(DeleteRequestHandler<>).MakeGenericType(rowType)); var thisKey = attr.ThisKey; if (string.IsNullOrEmpty(thisKey)) { if (!(row is IIdRow)) { throw new ArgumentException(String.Format( "Row type '{0}' has an ExtensionRelation attribute " + "but its ThisKey is not specified!", row.GetType().FullName)); } info.ThisKeyField = (Field)(((IIdRow)row).IdField); } else { info.ThisKeyField = row.FindFieldByPropertyName(attr.ThisKey) ?? row.FindField(attr.ThisKey); if (ReferenceEquals(info.ThisKeyField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for an ExtensionRelation attribute", attr.ThisKey, row.GetType().FullName)); } var ext = info.RowFactory(); var otherKey = attr.OtherKey; if (string.IsNullOrEmpty(otherKey)) { info.OtherKeyField = ext.FindField(info.ThisKeyField.Name); if (ReferenceEquals(info.OtherKeyField, null) && ext is IIdRow) info.OtherKeyField = (Field)(((IIdRow)row).IdField); if (ReferenceEquals(info.OtherKeyField, null)) throw new ArgumentException(String.Format( "Row type '{1}' has an ExtensionRelation attribute " + "but its OtherKey is not specified!", row.GetType().FullName)); } else { info.OtherKeyField = ext.FindFieldByPropertyName(attr.OtherKey) ?? ext.FindField(attr.OtherKey); if (ReferenceEquals(info.OtherKeyField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for an ExtensionRelation attribute on '{2}'", attr.OtherKey, ext.GetType().FullName, row.GetType().FullName)); } if (!string.IsNullOrEmpty(attr.FilterField)) { info.FilterField = ext.FindFieldByPropertyName(attr.FilterField) ?? ext.FindField(attr.FilterField); if (ReferenceEquals(info.FilterField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified as FilterField for an ExtensionRelation attribute on '{2}'", attr.OtherKey, ext.GetType().FullName, row.GetType().FullName)); info.FilterValue = info.FilterField.ConvertValue(attr.FilterValue, CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(attr.PresenceField)) { info.PresenceField = ext.FindFieldByPropertyName(attr.PresenceField) ?? ext.FindField(attr.PresenceField); if (ReferenceEquals(info.PresenceField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified as PresenceField as an ExtensionRelation attribute.", attr.PresenceField, row.GetType().FullName)); info.PresenceValue = attr.PresenceValue; } var extFields = ext.GetFields(); var alias = attr.Alias; var aliasPrefix = attr.Alias + "_"; var joinByKey = new HashSet<string>(extFields.Joins.Keys, StringComparer.OrdinalIgnoreCase); Func<string, string> mapAlias = x => { if (x == "t0" || x == "T0") return alias; if (!joinByKey.Contains(x)) return x; return aliasPrefix + x; }; Func<string, string> mapExpression = x => { if (x == null) return null; return JoinAliasLocator.ReplaceAliases(x, mapAlias); }; info.Mappings = new List<Tuple<Field, Field>>(); foreach (var field in extFields) { if (ReferenceEquals(info.OtherKeyField, field)) continue; if (ReferenceEquals(info.FilterField, field)) continue; var expression = field.Expression.TrimToEmpty(); if (string.IsNullOrEmpty(expression)) continue; expression = mapExpression(expression); expression = BracketLocator.ReplaceBrackets(expression, BracketRemoverDialect.Instance); var match = sourceByExpression[expression].FirstOrDefault(); if (ReferenceEquals(null, match)) continue; if (match.IsTableField()) continue; if (ReferenceEquals(info.ThisKeyField, match)) continue; if (field.GetType() != match.GetType()) throw new ArgumentException(String.Format( "Row type '{0}' has an ExtensionRelation attribute to '{1}'." + "Their '{2}' and '{3}' fields are matched but they have different types ({4} and {5})!", row.GetType().FullName, ext.GetType().FullName, field.PropertyName ?? field.Name, match.PropertyName ?? match.Name, field.GetType().Name, match.GetType().Name)); info.Mappings.Add(new Tuple<Field, Field>(match, field)); } if (info.Mappings.Count == 0) throw new ArgumentException(String.Format( "Row type '{0}' has an ExtensionRelation attribute " + "but no view fields could be matched to extension row '{1}'!", row.GetType().FullName, ext.GetType().FullName)); return info; }).ToList(); return true; }
public static string GetConnectionKey(Row row) { return(GetConnectionKey(row.GetType())); }
public bool ActivateFor(Row row) { return row.GetType().GetCustomAttribute<AuditLogAttribute>() != null; }
protected void CheckUnassignedRead(Row row) { if (row == null) { throw new ArgumentNullException("row"); } if (!row.tracking) { return; } if (!row.trackWithChecks) { return; } if (row.IsAssigned(this)) { return; } if (!this.GetIsNull(row)) { return; } throw new InvalidOperationException(String.Format( "{0} field on {1} is read before assigned a value!", this.Name, row.GetType().Name)); }
public override void AsObject(Row row, object value) { if (value == null) { _setValue(row, null); } else { try { _setValue(row, (TValue)value); } catch (InvalidCastException ex) { throw new InvalidCastException($"Invalid cast exception while trying to set the value of {this.Name} field on {row.GetType().Name} as object.", ex); } } if (row.tracking) { row.FieldAssignedValue(this); } }
public bool ActivateFor(Row row) { if (ReferenceEquals(null, Target)) return false; attr = Target.GetAttribute<LinkingSetRelationAttribute>(); if (attr == null) return false; if (!(row is IIdRow)) { throw new ArgumentException(String.Format("Field '{0}' in row type '{1}' has a LinkingSetRelationBehavior " + "but it doesn't implement IIdRow!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } var listType = Target.ValueType; if (!listType.GetIsGenericType() || listType.GetGenericTypeDefinition() != typeof(List<>)) { throw new ArgumentException(String.Format("Field '{0}' in row type '{1}' has a LinkingSetRelationBehavior " + "but its property type is not a generic List (e.g. List<int>)!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } var rowType = attr.RowType; if (rowType.GetIsAbstract() || !typeof(Row).IsAssignableFrom(rowType)) { throw new ArgumentException(String.Format( "Field '{0}' in row type '{1}' has a LinkingSetRelationBehavior " + "but specified row type is not valid row class!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } if (!typeof(IIdRow).IsAssignableFrom(rowType)) { throw new ArgumentException(String.Format( "Field '{0}' in row type '{1}' has a LinkingSetRelationBehavior " + "but specified row type doesn't implement IIdRow!", Target.PropertyName ?? Target.Name, row.GetType().FullName)); } listFactory = FastReflection.DelegateForConstructor<IList>(listType); rowFactory = FastReflection.DelegateForConstructor<Row>(rowType); listHandlerFactory = FastReflection.DelegateForConstructor<IListRequestProcessor>( typeof(ListRequestHandler<>).MakeGenericType(rowType)); saveHandlerFactory = FastReflection.DelegateForConstructor<ISaveRequestProcessor>( typeof(SaveRequestHandler<>).MakeGenericType(rowType)); saveRequestFactory = FastReflection.DelegateForConstructor<ISaveRequest>( typeof(SaveRequest<>).MakeGenericType(rowType)); deleteHandlerFactory = FastReflection.DelegateForConstructor<IDeleteRequestProcessor>( typeof(DeleteRequestHandler<>).MakeGenericType(rowType)); var detailRow = rowFactory(); thisKeyField = detailRow.FindFieldByPropertyName(attr.ThisKey) ?? detailRow.FindField(attr.ThisKey); if (ReferenceEquals(thisKeyField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for a linking set relation in field '{2}' of row type '{3}'.", attr.ThisKey, detailRow.GetType().FullName, Target.PropertyName ?? Target.Name, row.GetType().FullName)); this.thisKeyCriteria = new Criteria(thisKeyField.PropertyName ?? thisKeyField.Name); itemKeyField = detailRow.FindFieldByPropertyName(attr.ItemKey) ?? detailRow.FindField(attr.ItemKey); if (ReferenceEquals(itemKeyField, null)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for a linking set relation in field '{2}' of row type '{3}'.", attr.ItemKey, detailRow.GetType().FullName, Target.PropertyName ?? Target.Name, row.GetType().FullName)); if (!string.IsNullOrEmpty(attr.FilterField)) { this.filterField = detailRow.FindFieldByPropertyName(attr.FilterField) ?? detailRow.FindField(attr.FilterField); if (ReferenceEquals(null, this.filterField)) throw new ArgumentException(String.Format("Field '{0}' doesn't exist in row of type '{1}'." + "This field is specified for a linking set relation as FilterField in field '{2}' of row type '{3}'.", attr.FilterField, detailRow.GetType().FullName, Target.PropertyName ?? Target.Name, row.GetType().FullName)); this.filterCriteria = new Criteria(filterField.PropertyName ?? filterField.Name); this.filterValue = filterField.ConvertValue(attr.FilterValue, CultureInfo.InvariantCulture); if (this.filterValue == null) { this.filterCriteria = this.filterCriteria.IsNull(); this.filterCriteriaT0 = this.filterField.IsNull(); } else { this.filterCriteria = this.filterCriteria == new ValueCriteria(this.filterValue); this.filterCriteriaT0 = this.filterField == new ValueCriteria(this.filterValue); } } return true; }
public bool ActivateFor(Row row) { return row.GetType().GetCustomAttribute<AuditLogAttribute>() != null && row is IIdRow && ((IIdRow)row).IdField.IsIntegerType; }
internal static Dictionary<string, Field> ParseReplaceFields(string fileNameFormat, Row row, Field target) { if (fileNameFormat.IndexOf('|') < 0) return null; var replaceFields = new Dictionary<string, Field>(); int start = 0; while ((start = fileNameFormat.IndexOf('|', start)) >= 0) { var end = fileNameFormat.IndexOf('|', start + 1); if (end <= start + 1) throw new ArgumentException(String.Format( "Field '{0}' on row type '{1}' has a UploadEditor attribute " + "with invalid format string '{2}'!", target.PropertyName ?? target.Name, row.GetType().FullName, fileNameFormat)); var fieldName = fileNameFormat.Substring(start + 1, end - start - 1); var actualName = fieldName; var colon = fieldName.IndexOf(":"); if (colon >= 0) actualName = fieldName.Substring(0, colon); var replaceField = row.FindFieldByPropertyName(actualName) ?? row.FindField(actualName); if (ReferenceEquals(null, replaceField)) { throw new ArgumentException(String.Format( "Field '{0}' on row type '{1}' has a UploadEditor attribute that " + "references field '{2}', but no such field is found!'", target.PropertyName ?? target.Name, row.GetType().FullName, actualName)); } replaceFields['|' + fieldName + '|'] = replaceField; start = end + 1; } return replaceFields; }