/// <summary>
        /// Create ArcGisDynamicProvider, capabilities will be parsed automatically
        /// </summary>
        /// <param name="url">url to map service example: http://url/arcgis/rest/services/test/MapServer</param>        
        public ArcGisDynamicProvider(string url)
        {
            Url = url;

            Capabilities = new Capabilities
            {
                fullExtent = new Extent { xmin = 0, xmax = 0, ymin = 0, ymax = 0 },
                initialExtent = new Extent { xmin = 0, xmax = 0, ymin = 0, ymax = 0 }
            };

            var capabilitiesHelper = new CapabilitiesHelper();
            capabilitiesHelper.CapabilitiesReceived += CapabilitiesHelperCapabilitiesReceived;
            capabilitiesHelper.CapabilitiesFailed += CapabilitiesHelperCapabilitiesFailed;
            capabilitiesHelper.GetCapabilities(url);

            timeOut = 10000;
        }
 /// <summary>
 /// Create ArcGisDynamicProvider based on a given capabilities file
 /// </summary>
 /// <param name="url">url to map service example: http://url/arcgis/rest/services/test/MapServer</param>
 /// <param name="capabilities"></param>
 public ArcGisDynamicProvider(string url, Capabilities capabilities)
 {
     Url = url;
     Capabilities = capabilities;
     timeOut = 10000;            
 }
        private static string GetFormat(Capabilities capabilities)
        {
            //png | png8 | png24 | jpg | pdf | bmp | gif | svg | png32 (png32 only supported from 9.3.1 and up)
            if (capabilities.supportedImageFormatTypes == null)//Not all services return supported types, use png
                return "png";

            var supportedTypes = capabilities.supportedImageFormatTypes.ToLower();

            if (supportedTypes.Contains("png32"))
                return "png32";
            if (supportedTypes.Contains("png24"))
                return "png24";
            if (supportedTypes.Contains("png8"))
                return "png8";
            if (supportedTypes.Contains("png"))
                return "png";

            return "jpg";
        }
        /// <summary>
        /// Generate BruTile TileSchema based on ArcGIS Capabilities
        /// </summary>
        /// <returns>TileSchema, returns null if service is not tiled</returns>
        public static ITileSchema GetTileSchema(Capabilities capabilities)
        {
            //TODO: Does this belong in Mapsui.Providers?

            if (capabilities.tileInfo == null)
                return null;

            var schema = new TileSchema();
            var count = 0;

            foreach (var lod in capabilities.tileInfo.lods)
            {
                schema.Resolutions.Add(new Resolution { Id = count.ToString(), UnitsPerPixel = lod.resolution });
                count++;
            }

            schema.Height = capabilities.tileInfo.cols;
            schema.Width = capabilities.tileInfo.rows;
            schema.Extent = new BruTile.Extent(capabilities.fullExtent.xmin, capabilities.fullExtent.ymin, capabilities.fullExtent.xmax, capabilities.fullExtent.ymax);
            schema.OriginX = capabilities.tileInfo.origin.x;
            schema.OriginY = capabilities.tileInfo.origin.y;
            schema.Name = "ESRI";
            schema.Format = capabilities.tileInfo.format;            
            schema.Axis = AxisDirection.InvertedY;
            schema.Srs = string.Format("EPSG:{0}", capabilities.tileInfo.spatialReference.wkid);

            return schema;
        }