ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlToFeatureDefinition.DownloadStyleAsync C# (CSharp) Method

DownloadStyleAsync() private method

Downloads KML file containing style, extracts style and creates feature definitions.
private DownloadStyleAsync ( string styleUrl, System credentials, Action callback, X509Certificate clientCertificate = null ) : void
styleUrl string Style id to locate in file.
credentials System The credentials.
callback Action Callback to execture with the downloaded style
clientCertificate System.Security.Cryptography.X509Certificates.X509Certificate The client certificate.
return void
        private void DownloadStyleAsync(string styleUrl, System.Net.ICredentials credentials, Action<KMLStyle> callback, X509Certificate clientCertificate = null)
        {
            // We can only download KML/KMZ files that are stored remotely, not on the local file system
            if (styleUrl.StartsWith("http://") || styleUrl.StartsWith("https://"))
            {
                // Split style into file URL and style id
                string[] tokens = styleUrl.Split('#');
                if (tokens.Length == 2)
                {
                    // Store current state so event handler can resume
                    DownloadStyleState state = new DownloadStyleState('#' + tokens[1], credentials, callback
            #if !SILVERLIGHT
            , clientCertificate
            #endif
            );
                    WebClient webClient = Utilities.CreateWebClient();

                    if (credentials != null)
                        webClient.Credentials = credentials;
            #if !SILVERLIGHT
                    if (clientCertificate != null)
                        (webClient as CompressResponseWebClient).ClientCertificate = clientCertificate;
            #endif

                    webClient.OpenReadCompleted += StyleDownloaded;
                    webClient.OpenReadAsync(Utilities.PrefixProxy(ProxyUrl, tokens[0]), state);
                    _waitHelper.AddOne();
                    return;
                }
            }

            // Incorrect styleUrl : execute the callback with a null style
            // This will use the default style to process the placemark.
            callback(null);
        }