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);
}