Guys, thanks for the response and I completely understand where you are coming from. I am definitely not advocating breaking API compatibility. I bring up this issue so that you can rethink your exception strategy in some cases as this issue has been brought up before. I also do understand the philosophy behind Microsoft's approach of raising exceptions to report errors but you guys may be doing it too much, considering that raising of exceptions are typically more expensive than simply returning a true false in cases where one can easily recover.
This particular case of throwing an exception when the map goes outside of valid extent, IMHO, is not necessarily. I probably takes away resources that could be used to do other useful work, and provides no usefulness to the API. I was catching these exceptions and showing a dialog box each time for info purposes and at one point, I had about 20 of these boxes open and had to shut down the app. So the exceptions did not help here but stole away resources. Also, MapClick and MouseMove event handling will be common scenarios so why would you expose data within these event arguments that is invalid, cannot easily be validated, and could easily cause exceptions to be thrown? This must impact performance, no?
Again, maybe it is just a matter of documentation. BaseShape.Validate(ShapeValidationMode) is great but it has passed most of the shapes i have run through it, so it is hard to see what exactly it does
Anyways, this is what I am doing to while waiting for better validation...Something like this would not be hard for you smart folks to quickly implement.
internal static EnhancedShapeValidationResult GetBuffer(BaseShape geom, double tolerance, GeographyUnit geoUnit, DistanceUnit distUnit)
{
var result = new EnhancedShapeValidationResult();
result.Shape = geom;
var validation = geom.Validate(ShapeValidationMode.Simple);
if (validation != null && validation.IsValid)
{
try
{
result.Shape = geom.Buffer(tolerance, geoUnit, distUnit);
result.IsValid = true;
result.OriginalIsValid = true;
}
catch (Exception ex)
{
// geometry is not valid
switch (geoUnit)
{
case GeographyUnit.DecimalDegree:
result.Shape = ValidateShape(geom);
result.IsValid = true;
result.OriginalIsValid = false;
break;
default:
//result.Shape = ValidateShape(geom);
result.IsValid = false;
result.OriginalIsValid = false;
result.ValidationErrors = string.Format("Provided geometry for buffer operation is not valid. Validation for {0} not implemented.", geom.GetType().ToString());
//DialogBox.ShowExceptionModelessly(MessageBoxImage.Warning, string.Format( "Provided geometry for buffer operation is not valid. Validation for {0} not implemented.", geom.GetType().ToString()), ex);
break;
}
}
}
return result;
}
#region Validations for Decimal Degrees
public static BaseShape ValidateShape(BaseShape shape)
{
var point = shape as PointShape;
if (point != null)
return ValidatePointShape(point);
// TODO: Add other Shapes...
return point;
}
public static PointShape ValidatePointShape(PointShape point)
{
if (point != null)
{
if (point.X > 180)
point.X = 180;
else if (point.X < -180)
point.X = -180;
if (point.Y > 90)
point.Y = 90;
else if (point.Y < -90)
point.Y = -90;
}
return point;
}
// TODO: Add nother shape validation methods
#endregion
public class EnhancedShapeValidationResult
{
public BaseShape Shape { get; set; }
public bool IsValid { get; set; }
public bool OriginalIsValid { get; set; }
public string ValidationErrors { get; set; }
}