private void loadEntityManyToManyField(IEntityField _attribute, PropertyInfo _property) { EntityManyToManyFieldAttribute _oneToManyAttribute = (EntityManyToManyFieldAttribute)_attribute; _modelProperties.Add(new ModelProperty(_property, _oneToManyAttribute)); _modelAttributes[_modelo.GetType().Name + "." + _property.Name] = _attribute.FieldName; }
public Required(IEntityField <T> field) { // TODO: Move all arguments checking to attributes and run them in a "decorator". Raise.ArgumentNullException.IfIsNull(field, nameof(field)); Field = field; }
public override void SetValue(string propertyName, object value) { IEntityField field = EntityType.GetField(propertyName); _values[field.Index] = Parse(field.Type, value); OnPropertyChanged(); }
public GreaterThan(IEntityField <TEntity> field, TValue value) { Raise.ArgumentNullException.IfIsNull(field, nameof(field)); Raise.ArgumentNullException.IfIsNull(value, nameof(value)); Field = field; Value = value; }
private void loadEntityKeyField(IEntityField _attribute, PropertyInfo _property) { EntityKeyFieldAttribute _featureAttribute = (EntityKeyFieldAttribute)_attribute; _modelProperties.Add(new ModelProperty(_property, _featureAttribute)); _modelAttributes[_modelo.GetType().Name + "." + _property.Name] = _featureAttribute.FieldName; _KeyField = _attribute.FieldName; //TODO: Incluir validação para lançar exceção caso não tenha entity key field }
public MaxLength(IEntityField <TEntity> field, int length) { Raise.ArgumentNullException.IfIsNull(field, nameof(field)); // TODO: Make obvious for the end user that the field has to be IEnumerable. Raise.ArgumentException.IfNot(field.Type.GetInterfaces().Contains(typeof(IEnumerable)), nameof(field)); Field = field; Length = length; }
public virtual IXlsxFieldsMap <TEntity> Add(string column, IEntityField <TEntity> field) { if (Has(column)) { map[column] = field; } else { map.Add(column, field); } return(this); }
private static object GetDefaultValue(IEntityField field) { if (field.Type == typeof(IDbRef)) return DbContext.Current.CreateDbRef(field.DbRefTable, Guid.Empty); if (field.AllowNull) return null; if (field.Type.IsValueType) return Activator.CreateInstance(field.Type); if (field.Type == typeof(string)) return string.Empty; throw new Exception("Unknown type: " + field.Type); }
private static object GetDefaultValue(IEntityField field) { if (field.Type == typeof(IDbRef)) { return(DbContext.Current.CreateDbRef(field.DbRefTable, Guid.Empty)); } if (field.AllowNull) { return(null); } if (field.Type.IsValueType) { return(Activator.CreateInstance(field.Type)); } if (field.Type == typeof(string)) { return(string.Empty); } throw new Exception("Unknown type: " + field.Type); }
public EntityFieldMemberDescriptor(IEntityFields entityFields, int index) : base(entityFields[index].Name) { _entityField = entityFields[index]; }
public ModelProperty(PropertyInfo PropertyInfo, IEntityField Attribute) { _property = PropertyInfo; _attribute = Attribute; }
public FieldSerializationInfo(IEntityField field) { this.Field = field; }
public virtual IProcessingResult <IEnumerable <IXlsxParsedRow <T> > > Parse(Stream stream) { Raise.ArgumentNullException.IfIsNull(stream, nameof(stream)); var parsedEntities = new List <IXlsxParsedRow <T> >(); var errors = new List <IError>(); using (var spreadsheetDocument = SpreadsheetDocument.Open(stream, false)) { IProcessingResult <IXlsxParserConfig <T> > configBuildingResult = configFactory.Create(spreadsheetDocument); if (configBuildingResult.Errors != null && configBuildingResult.Errors.Any()) { return(new ProcessingResult <IEnumerable <IXlsxParsedRow <T> > >(Enumerable.Empty <IXlsxParsedRow <T> >(), configBuildingResult.Errors)); } IXlsxParserConfig <T> config = configBuildingResult.Result; var firstRow = config.FirstRow; var lastRow = config.LastRow; var firstColumn = XlsxColumnAddressConverter.ToInt(config.FirstColumn); var lastColumn = XlsxColumnAddressConverter.ToInt(config.LastColumn); var firstSheet = config.FirstSheet; var lastSheet = config.LastSheet; var fieldsMap = config.FieldsMap; var typeAccessor = config.TypeAccessor; var valueConverter = config.ValueConverter; WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart; SharedStringTable sharedStringTable = workbookPart.GetPartsOfType <SharedStringTablePart>() .FirstOrDefault()? .SharedStringTable; string[] sharedStrings = sharedStringTable? .Select(x => x.InnerText)? .ToArray(); sharedStringTable = null; var sheets = workbookPart.Workbook.Descendants <Sheet>(); int sheetIndex = 1; foreach (var sheet in sheets) { if (sheetIndex < firstSheet) { sheetIndex++; continue; } string currentSheetName = sheet.Name; WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id); Worksheet worksheet = worksheetPart.Worksheet; SheetData sheetData = worksheet.GetFirstChild <SheetData>(); var rows = sheetData.Elements <Row>(); var rowIndex = 0; foreach (var row in rows) { var rowNumber = rowIndex + 1; if (rowNumber < firstRow) { rowIndex++; continue; } T entity = (T)Activator.CreateInstance(typeof(T)); bool entityHasErrors = false; var cells = row.Elements <Cell>(); var cellIndex = 0; foreach (var cell in cells) { string cellAddress; int columnNumber; string column; if (!string.IsNullOrEmpty(cell.CellReference)) { cellAddress = cell.CellReference; column = cellAddress.Replace(rowNumber.ToString(), string.Empty); columnNumber = XlsxColumnAddressConverter.ToInt(column); } else { columnNumber = cellIndex + 1; column = XlsxColumnAddressConverter.ToString(columnNumber); cellAddress = $"{column}{rowNumber}"; } if (columnNumber < firstColumn) { cellIndex++; continue; } if (!fieldsMap.Has(column)) { cellIndex++; continue; } IEntityField <T> entityField = fieldsMap[column]; string rawValue = cell.InnerText; if (cell.DataType != null && cell.DataType.Value == CellValues.SharedString) { rawValue = sharedStrings[int.Parse(rawValue)]; } else if (cell.CellFormula != null) { if (cell.CellValue == null) { return(new ProcessingResult <IEnumerable <IXlsxParsedRow <T> > >(Enumerable.Empty <IXlsxParsedRow <T> >(), new[] { new XlsxProtectedViewError() })); } rawValue = cell.CellValue?.InnerText; } if (cell.DataType != null && cell.DataType.Value == CellValues.Error) { if (entityField.Type.GetTypeInfo().IsValueType ? Activator.CreateInstance(entityField.Type) != null : false) { errors.Add(new XlsxCellValueError(entityField.Description, cellAddress, currentSheetName, cell.CellValue.InnerText)); entityHasErrors = true; } else { rawValue = string.Empty; } } if (valueConverter.TryConvert(rawValue, entityField.Type, out object value)) { typeAccessor[entity, entityField.Name] = value; } else { errors.Add(new XlsxDataTypeError(entityField.Description, cellAddress, currentSheetName)); entityHasErrors = true; } if (columnNumber == lastColumn) { break; } cellIndex++; } if (!entityHasErrors) { parsedEntities.Add(new XlsxParsedRow <T>(rowNumber, currentSheetName, entity)); } if (rowNumber == lastRow) { break; } rowIndex++; } if (sheetIndex == lastSheet) { break; } sheetIndex++; } } return(new ProcessingResult <IEnumerable <IXlsxParsedRow <T> > >(parsedEntities, errors)); }
public LeafElement Add(IEntityField entityField) { Fields.Add(entityField); return(this); }
public override object GetValue(string propertyName) { IEntityField field = EntityType.GetField(propertyName); return(_values[field.Index] ?? GetDefaultValue(field)); }
private void loadEntityField(IEntityField _attribute, PropertyInfo _property) { _modelProperties.Add(new ModelProperty(_property, _attribute)); _modelAttributes[_modelo.GetType().Name + "." + _property.Name] = _attribute.FieldName; }
private void loadEntityShapeField(IEntityField _attribute, PropertyInfo _property) { _modelProperties.Add(new ModelProperty(_property, _attribute)); _modelAttributes[_modelo.GetType().Name + ".Shape"] = "Geometry"; }