Get PortalItem status

423
3
09-23-2022 05:49 AM
TomGeo
by
Occasional Contributor III

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?

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
Tags (3)
0 Kudos
3 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Have you tried CanCreateLayer from LayerFactory?

					if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
						LayerFactory.Instance.CreateLayer(currentItem, MapView.Active.Map);
0 Kudos
TomGeo
by
Occasional Contributor III

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.

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
GKmieliauskas
Esri Regular Contributor

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

0 Kudos