public override Exceptional<IObject> Aggregate(IEnumerable<DBObjectStream> myDBObjects, TypeAttribute myTypeAttribute, DBContext myDBContext, params Functions.ParameterValue[] myParameters) { var foundFirstMax = false; var aggregateResult = myTypeAttribute.GetADBBaseObjectType(myDBContext.DBTypeManager); foreach (var dbo in myDBObjects) { var attrResult = dbo.GetAttribute(myTypeAttribute, myTypeAttribute.GetDBType(myDBContext.DBTypeManager), myDBContext); if (attrResult.Failed()) { return attrResult; } var attr = attrResult.Value; if (attr != null && attr is ADBBaseObject && aggregateResult.IsValidValue((attr as ADBBaseObject).Value)) { if (foundFirstMax == false) { aggregateResult.Value = (attr as ADBBaseObject).Value; foundFirstMax = true; } else { if (aggregateResult.CompareTo((attr as ADBBaseObject).Value) < 0) { aggregateResult.Value = (attr as ADBBaseObject).Value; } } } else { return new Exceptional<IObject>(new Error_AggregateIsNotValidOnThisAttribute(myTypeAttribute.Name)); } } return new Exceptional<IObject>(aggregateResult); }
public override Exceptional<IObject> Aggregate(IEnumerable<DBObjectStream> myDBObjects, TypeAttribute myTypeAttribute, DBContext myDBContext, params Functions.ParameterValue[] myParameters) { var aggregateResult = myTypeAttribute.GetADBBaseObjectType(myDBContext.DBTypeManager); foreach (var dbo in myDBObjects) { var attrResult = dbo.GetAttribute(myTypeAttribute, myTypeAttribute.GetDBType(myDBContext.DBTypeManager), myDBContext); if (attrResult.Failed()) { return attrResult; } var attr = attrResult.Value; if (attr != null && attr is ADBBaseObject && aggregateResult.IsValidValue((attr as ADBBaseObject).Value)) { aggregateResult.Add((attr as ADBBaseObject)); } else if (attr != null) // if null, this value will be skipped { return new Exceptional<IObject>(new Error_AggregateIsNotValidOnThisAttribute(myTypeAttribute.Name)); } } return new Exceptional<IObject>(aggregateResult); }