Adding a feature layer via Geodatabase

174
6
05-15-2018 09:43 AM
Highlighted
New Contributor

I'm using the following code to open a connection to a feature server and adding a feature layer to the current map:

var serviceUrl = @"http://url-of-feature-server/FeatureServer";
var layerId = "0";
var map = MapView.Active.Map;

using (var geoDb = new Geodatabase(new ServiceConnectionProperties(new Uri(serviceUrl)))
{
  var defNames = geoDb.GetDefinitions<FeatureClassDefinition>()
    .Select(def => def.GetName()).ToArray();
  var id = int.Parse(layerId);
  Debug.Assert(defNames.Length > id);
  if (defNames.Length > id)
  {
    using (var featureClass = geoDb.OpenDataset<FeatureClass>(defNames[id]))
    {
      featureLayer = LayerFactory.Instance.CreateFeatureLayer(featureClass, map);
      featureLayer.SetDisplayCacheType(DisplayCacheType.None);
      featureLayer.SetDisplayCacheMaxAge(TimeSpan.Zero);
    }
  }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This works fine the 1st time this code gets executed.  If the feature server has N feature layers then defNames gets N definitions.

If the feature server gains a new layer, one would expect that the next time this code gets executed defNames would have N + 1 items.  However it still returns N definitions.  Using Fiddler, I can see that ArcGIS performs HTTP requests (to get feature definitions, metadata, etc.) the 1st time the Geodatabase object is created.  Subsequent creations of new Geodatabase objects (using the same service URL) does not make any other HTTP requests, even when geoDb object was disposed via "using", as if it was being cached by ArcGIS.  

I would like to ensure that every time I create a new Geodatabase object that it has the most recent feature definitions and ArcGIS doesn't cache anything.  How would one do that?

Additionally, I've noticed that SetDisplayCacheType(DisplayCacheType.None) does not seem to apply or update the layer's properties (checking via Layer->Properties->Cache).

Reply
0 Kudos
6 Replies
Highlighted
Esri Contributor

Thanks Mark. We've added this as an issue for our next release after 2.2.

Reply
0 Kudos
Highlighted
New Contributor

Thanks Charles. Do you have any recommendations for work arounds in the meantime? Is there any way to force Pro to refresh the available layers in a service? Are there any flags that we could set in the service/layer metadata?

Reply
0 Kudos
Highlighted
Esri Contributor

Hi James, unfortunately, there is no workaround.

Reply
0 Kudos
Highlighted
New Contributor

Hey Charles. I'm just checking up on this to see if you have any update on a fix for this.

Thanks,

-James

Reply
0 Kudos
Highlighted
Esri Regular Contributor

James,

This will be fixed in Pro 2.3, expected early 2019.

--Rich

Reply
0 Kudos
Highlighted
New Contributor

Thanks Rich.

Reply
0 Kudos