Ejemplo n.º 1
0
 protected virtual void OnServiceDetailsDownloadCompleted(ServiceDetailsDownloadCompletedEventArgs args)
 {
     if (ServiceDetailsDownloadCompleted != null)
     {
         ServiceDetailsDownloadCompleted(this, args);
     }
 }
        protected async override void OnServiceDetailsDownloadCompleted(ServiceDetailsDownloadCompletedEventArgs args)
        {
            // Workaround for the fact that DataContractJsonSerializer doesn't call the default contructor
            // http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx
            if (ServiceInfo != null && ServiceInfo.SpatialReference != null)
            {
                if (ServiceInfo.SpatialReference.WKID == default(int))
                {
                    ServiceInfo.SpatialReference.WKID = -1;
                }
            }

            Uri finalUrl = new Uri(string.Format("{0}/layers?f=json", Uri));

            if (webClient == null)
            {
                webClient = new ArcGISWebClient();
            }
            webClient.ProxyUrl = ProxyUrl;

            try
            {
                ArcGISWebClient.DownloadStringCompletedEventArgs result =
                    await webClient.DownloadStringTaskAsync(finalUrl, args);

                processResult(result);
            }
            catch
            {
                base.OnServiceDetailsDownloadCompleted(args);
            }
        }
        private void processResult(ArcGISWebClient.DownloadStringCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }
            ServiceDetailsDownloadCompletedEventArgs eventArgs = e.UserState as ServiceDetailsDownloadCompletedEventArgs;

            if (e.Error != null)
            {
                base.OnServiceDetailsDownloadCompleted(eventArgs);
                return;
            }

            string    json = e.Result;
            Exception ex   = Utils.CheckJsonForException(json);

            if (ex != null) // if the service is pre-10.x then it doesn't support /layers operation
            {
                base.OnServiceDetailsDownloadCompleted(eventArgs);
                return;
            }

            try
            {
                AllLayersResponse response = JsonSerializer.Deserialize <AllLayersResponse>(e.Result);
                _layersInService = response.Layers;
                if (_layersInService != null)
                {
                    _notSupportedLayerIds = new List <int>();
                    foreach (MapServiceLayerInfo mapServiceLayerInfo in _layersInService)
                    {
                        if (Utility.RasterLayer.Equals(mapServiceLayerInfo.Type) || Utility.ImageServerLayer.Equals(mapServiceLayerInfo.Type))
                        {
                            _notSupportedLayerIds.Add(mapServiceLayerInfo.ID);
                        }
                    }
                }
            }
            catch (Exception)
            {
                // Ok to swallow
            }
            base.OnServiceDetailsDownloadCompleted(eventArgs);
        }