I recently experienced that while trying to create a layer from one of our portal services my AGP crashed. Turned out that the service I requested to create the layer from was stopped on the server.
To avoid that, I would like to check on the PortalItem (Item) status, but I do not seem to have the possibility to do so (Item Class Members). Fingers crossed I am only looking at the wrong place.
Can I check the PortalItem status?
Hi,
Have you tried CanCreateLayer from LayerFactory?
if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
LayerFactory.Instance.CreateLayer(currentItem, MapView.Active.Map);
Yes, I tried that, but it's still causing an exception right after
Item curItem = ItemFactory.Instance.Create(curService);
if(LayerFactory.Instance.CanCreateLayerFrom(curItem))
{
Layer newLayer = LayerFactory.Instance.CreateLayer(new Uri(curService, UriKind.Absolute), activeMapView.Map, 0);
}
Also when trying to show the service as a layer in the Map Viewer at the portal, the error message returned by the viewer is: The layer cannot be added to the map.
It worked some time ago. So you could place CreateLayer in try/catch block and make return with message on exception:
Item curItem = ItemFactory.Instance.Create(curService);
try {
Layer newLayer = LayerFactory.Instance.CreateLayer(new Uri(curService, UriKind.Absolute), activeMapView.Map, 0);
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
return;
}
It is not elegant way but it works