/// <summary>
/// Downloads and updates the premium data file.
/// </summary>
internal static LicenceKeyResults Download(string[] licenceKeys)
{
var status = LicenceKeyResults.InProgress;
WebClient client = new WebClient();
var compressedTempFile = WebProvider.GetTempFileName();
var uncompressedTempFile = String.Format("{0}.new", Manager.BinaryFilePath);
try
{
// Wait until any other threads have finished executing.
_autoDownloadUpdateSignal.WaitOne();
// Download the data file to the compressed temporary file.
status = DownloadFile(client, Manager.BinaryFilePath, compressedTempFile, licenceKeys);
// Validate the MD5 hash of the download.
if (status == LicenceKeyResults.InProgress)
{
status = CheckedDownloadedFileMD5(client, compressedTempFile);
}
// Decompress the data file ready to create the data set.
if (status == LicenceKeyResults.InProgress)
{
status = Decompress(compressedTempFile, uncompressedTempFile);
}
// Validate that the data file can be used to create a provider.
if (status == LicenceKeyResults.InProgress)
{
status = ValidateDownloadedFile(uncompressedTempFile);
}
// Activate the data file downloaded for future use.
if (status == LicenceKeyResults.InProgress)
{
status = ActivateDownloadedFile(client, uncompressedTempFile);
}
}
catch (Exception)
{
status = LicenceKeyResults.GenericFailure;
}
finally
{
File.Delete(compressedTempFile);
File.Delete(uncompressedTempFile);
client.Dispose();
_autoDownloadUpdateSignal.Set();
}
return(status);
}