Below is code
............................................................................
private LocalGeoprocessingService geoprocessingService;
private Geoprocessor geoprocessorTask;
// Creating the service and starting
public bool CreateNewRoute()
{
try
{
var source = ConfigUtils.ProjectLocation + ConfigurationManager.RouteLayer.SourceLayerName + ".gpk";
geoprocessingService = new LocalGeoprocessingService(source, GPServiceType.SubmitJob);
geoprocessingService.StartAsync((x) =>
{
if (x.Error != null)
Log.Error(x.Error);
});
return true;
}
catch (Exception ex)
{
Log.Error(ex);
return false;
}
}
// Solving route with input locations
public bool SolveRoute()
{
try
{
geoprocessorTask = new Geoprocessor(geoprocessingService.UrlGeoprocessingService + "/Route");
geoprocessorTask.Failed += new EventHandler<TaskFailedEventArgs>(GeoprocessorTaskFailed);
geoprocessorTask.JobCompleted += new EventHandler<JobInfoEventArgs>(GeoprocessorTaskJobCompleted);
routeTask = new RouteTask(geoprocessingService.UrlGeoprocessingService + "/Route");
routeTask.SolveCompleted += new EventHandler<RouteEventArgs>(RouteTaskSolveCompleted);
routeTask.Failed += new EventHandler<TaskFailedEventArgs>(RouteTaskFailed);
List<GPParameter> parameters = new List<GPParameter>();
List<Geometry> inputLocations = new List<Geometry>()
{
new ESRI.ArcGIS.Client.Geometry.MapPoint(routeStartPoint.X, routeStartPoint.Y,esriMap.SpatialReference),
new ESRI.ArcGIS.Client.Geometry.MapPoint(routeEndPoint.X, routeEndPoint.Y,esriMap.SpatialReference)
};
FeatureSet featureSet = new FeatureSet(inputLocations);
featureSet.GeometryType = GeometryType.Point;
featureSet.SpatialReference = esriMap.SpatialReference;
GPFeatureRecordSetLayer gpFeatureRecordSetLayer = new GPFeatureRecordSetLayer("Input_Locations", featureSet);
parameters.Add(gpFeatureRecordSetLayer);
geoprocessorTask.UpdateDelay = 2000;
geoprocessorTask.SubmitJobAsync(parameters);
return true;
}
catch (Exception ex)
{
Log.Error(ex);
return false;
}
}
//Route solved async, only features are returned, no way of deriving route direction objects
private void GeoprocessorTaskJobCompleted(object sender, JobInfoEventArgs e)
{
try
{
geoprocessorTask.GetResultDataCompleted += (s1, e1) =>
{
if (e1.Parameter is GPFeatureRecordSetLayer)
{
GPFeatureRecordSetLayer gpLayer = e1.Parameter as GPFeatureRecordSetLayer;
var gphLayer = (GraphicsLayer)esriMap.Layers["LocalGraphicsLayer"];
gphLayer.ClearGraphics();
int i = 1;
foreach (Graphic graphic in gpLayer.FeatureSet.Features)
{
Symbol sym = new SimpleLineSymbol()
{
Color = ConfigurationManager.RoutingColorBrush,
Width = ConfigurationManager.RoutingWidth,
};
graphic.Symbol = sym;
gphLayer.Graphics.Add(graphic);
}
}
};
geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "Routes");
}
catch (Exception ex)
{
Log.Error(ex);
}
}