1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| private void BtnRecupLastMaj_Click(object sender, EventArgs e)
{
RecupLastMaj();
}
private BackgroundWorker bwRecupLastMaj = null;
#region Thread : RecupLastMaj
private void RecupLastMaj()
{
if(bwRecupLastMaj == null)
{
bwRecupLastMaj = new BackgroundWorker();
bwRecupLastMaj.WorkerReportsProgress = true;
bwRecupLastMaj.RunWorkerCompleted += BwRecupLastMajRunWorkerCompleted;
bwRecupLastMaj.ProgressChanged += BwRecupLastMajProgressChanged;
bwRecupLastMaj.DoWork += BwRecupLastMajDoWork;
IsBusy = true;
bwRecupLastMaj.RunWorkerAsync();
}
}
private void BwRecupLastMajDoWork(object sender, DoWorkEventArgs e)
{
e.Result = RecupLastMajFromServiceWeb("setup.exe");
}
private byte[] RecupLastMajFromServiceWeb(string docName)
{
byte[] file = ServiceMiseAjour.GetDocument(docName);
return file;
}
private void BwRecupLastMajProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void BwRecupLastMajRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if(e.Cancelled == true)
{
MessageBox.Show("La récupération du fichier a été annulée.");
} else if(e.Error != null) // Traitement des exceptions
{
MessageBox.Show(e.Error.ToString());
} else
{
SaveLastMaj(e.Result as Byte[]);
}
IsBusy = false;
bwRecupLastMaj = null;
}
private void SaveLastMaj(Byte[] file)
{
if(file == null)
{
MessageBox.Show("Récupération du fichier => ECHEC");
} else
{
if(SaveDocument(file, "MySetup.exe"))
{
MessageBox.Show("sauvegarde du fichier => OK");
} else
{
MessageBox.Show("sauvegarde du fichier => ECHEC");
}
}
}
#endregion Thread : RecupLastMaj |
Partager