private async Task DownloadFileAsync2(Uri uri, string name)
{
try
{
var file = Path.Combine(Dispatcher.Invoke(() => TempPath), name);
if (File.Exists(file))
File.Delete(file);
using (var webClient = new WebClient { Credentials = CredentialCache.DefaultNetworkCredentials })
await webClient.DownloadFileTaskAsync(uri, file);
//Saves the template for later, when exporting the translation.
if (name.EndsWith("en.xaml"))
_resourceTemplate = File.ReadAllText(file);
using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var dictionary = (ResourceDictionary)XamlReader.Load(fs, new ParserContext { XmlSpace = "preserve" });
//var dictionary = new ResourceDictionary();
dictionary.Source = new Uri(Path.GetFullPath(file), UriKind.Absolute);
_resourceList.Add(dictionary);
if (name.EndsWith("en.xaml"))
Application.Current.Resources.MergedDictionaries.Add(dictionary);
}
}
catch (Exception ex)
{
Dispatcher.Invoke(() => Dialog.Ok("Translator", "Translator - Downloading File", ex.Message));
}
}