private void buttonRelease_Click(object sender, EventArgs e) { labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Подключение к серверу"; })); WebReference.WebSDataBrUpdater BrServer = new WebReference.WebSDataBrUpdater(); BrServer.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12; // test.BeginScanEU(EU, AsyncCallGetDataEU, test); BrServer.Url = set.AdressAppServer; BrServer.BeginSystem_Get_Release(AsyncCallGet_Relise, BrServer); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Соединение с сервером"; })); }
void AsyncCallGet_Relise(IAsyncResult res) { try { labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Загрузка файла"; })); WebReference.WebSDataBrUpdater BrServer = res.AsyncState as WebReference.WebSDataBrUpdater; // Trace.Assert(test != null, "Неверный тип объекта"); Byte[] result = BrServer.EndSystem_Get_Release(res); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Сохранение"; })); string FileName = "DataBrCode\\" + DateTime.Now.ToString("yyMMdd-HHmm") + ".zip"; FileStream f = File.Create(FileName); f.Write(result, 0, result.Length); f.Close(); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Файл сохранен"; })); //Раззипуем теперь Unzip(FileName, "DataBrCode\\" + "Release"); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Обновление завершено"; })); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AutoUpdateProcess() { try { //Обновляем по алгоритму,скачиваем, чистим и распаковываем... labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Подключение к серверу"; })); WebReference.WebSDataBrUpdater BrServer = new WebReference.WebSDataBrUpdater(); BrServer.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12; // test.BeginScanEU(EU, AsyncCallGetDataEU, test); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Загрузка файла"; })); BrServer.Url = set.AdressAppServer; Byte[] result = BrServer.System_Get_Release(); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Сохранение"; })); string FileName = "DataBrCode\\" + DateTime.Now.ToString("yyMMdd-HHmm") + ".zip"; FileStream f = File.Create(FileName); f.Write(result, 0, result.Length); f.Close(); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Файл сохранен"; })); //Убиваем процессы KillProcess(); // //Запускаем чистку.. CleanOldRelise(FileName); //Раззипуем теперь Unzip(FileName, "DataBrCode\\" + "Release"); labelloading.BeginInvoke(new Action(() => { labelloading.Text = "Обновление завершено"; })); if (MessageBox.Show("Обновление успешно завершено!", "Обновление", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.OK) { ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = @"DataBrCode\Release\DataBarCode.exe"; processStartInfo.WorkingDirectory = @"DataBrCode\Release\"; Process.Start(processStartInfo); Application.Exit(); } } catch (Exception ex) { MessageBox.Show("Ошибка обновления, запустите в ручном режиме", "Обновление", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } finally { buttonClean.BeginInvoke(new Action(() => { buttonClean.Enabled = true; })); buttonRelease.BeginInvoke(new Action(() => { buttonRelease.Enabled = true; })); buttonExit.BeginInvoke(new Action(() => { buttonExit.Enabled = true; })); } }