Hi,
/// <summary>
/// Geo Route class to get the class using ThinkGeo Routing Software
/// </summary>
public static class GeoRoute
{
private static FeatureSource featureSource;
private static RoutingSource routingSource;
/// <summary>
/// Assign Source
/// </summary>
/// <param name="freatureSource"></param>
/// <param name="routingSource"></param>
public static void AssignSource(string freatureSourcePath, string routingSourcePath)
{
featureSource = new ShapeFileFeatureSource(freatureSourcePath);
routingSource = new RtgRoutingSource(routingSourcePath);
}
/// <summary>
/// Get Driving Distance
/// </summary>
/// <param name="startingAddress">Starting Address</param>
/// <param name="listOfAddress">List of Address</param>
/// <returns>
public static List<DrivingDistance> drivingDistance(Coordinate startingAddress, List<GeoCodedAddress> listOfAddress)
{
List<DrivingDistance> drivingDistance = new List<DrivingDistance>();
try
{
featureSource.Open();
routingSource.Open();
RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource);
// Loop throught Address
foreach (GeoCodedAddress coord in listOfAddress)
{
routingEngine.RoutingSource = routingSource;
try
{
if (coord.latitude.Equals(0.00) || coord.latitude.Equals(0.00))
{
drivingDistance.Add(new DrivingDistance(coord.workAssignmentID, coord.address, 0, false));
}
else
{
double distance = routingEngine.GetRoute(new PointShape(startingAddress.Longitude, startingAddress.Latitude),
new PointShape(coord.longtitude, coord.latitude)).Distance;
drivingDistance.Add(new DrivingDistance(coord.workAssignmentID, coord.address, (distance * 0.621371192), true));
}
}
catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
drivingDistance.Add(new DrivingDistance(coord.workAssignmentID, coord.address, 0, false)); }
}
featureSource.Close();
routingSource.Close();
return drivingDistance;
}
catch (Exception) { return null; }
}
}
/// <summary>
/// Driving Distance class to that holds that driving distance
/// </summary>
[Serializable]
public class DrivingDistance
{
public string workAssignmentID { get; set; }
public string address {get; set;}
public double miles {get; set;}
public bool valid { get; set; }
public DrivingDistance(string address, double miles, bool valid)
{
this.address = address;
this.miles = miles;
this.valid = valid;
}
// Added by JC on 4/21/2010
public DrivingDistance(string workAssignmentID, string address, double miles, bool valid)
{
this.workAssignmentID = workAssignmentID;
this.address = address;
this.miles = miles;
this.valid = valid;
}
}
I build a class that gets driving distance between from starting point to mutiple locations. However, we are getting errors such as "ObjectDisposedException was unhandled" and "Can't access a closed file" when mutiple users login on our test server. It even crash our IIS server. Who would I dispose the objects propertly in my code. Thanks.