Beispiel #1
0
        private async void button7_Click(object sender, EventArgs e)
        {
            button6.Enabled = false;
            button7.Enabled = false;
            DateTime dNow = System.DateTime.Now;

            textBox1.Text      = "" + dNow.ToString("[HH:mm:ss]") + " 更新プログラムを確認しています";
            progressBar1.Style = ProgressBarStyle.Marquee;
            await Task.Delay(1000);

            ApplicationDeployment currentDeploy = ApplicationDeployment.CurrentDeployment;

            currentDeploy.UpdateCompleted += new AsyncCompletedEventHandler(completed);
            dNow           = System.DateTime.Now;
            textBox1.Text += "\r\n" + dNow.ToString("[HH:mm:ss]") + " 更新プログラムが見つかりました";
            dNow           = System.DateTime.Now;
            textBox1.Text += "\r\n" + dNow.ToString("[HH:mm:ss]") + " 更新プログラムをインストールしています";
            dNow           = System.DateTime.Now;
            textBox1.Text += "\r\n" + dNow.ToString("[HH:mm:ss]") + " この画面を閉じないでください";
            await Task.Delay(1000);

            try
            {
                currentDeploy.UpdateAsync();
            }
            catch (DeploymentException exp)
            {
                dNow           = System.DateTime.Now;
                textBox1.Text += "\r\n" + dNow.ToString("\n" + "[HH:mm:ss]") + " エラーが発生しました。\n" + exp.Message;
            }
            finally
            {
            }
        }
Beispiel #2
0
        void DeploymentCheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                _Logger.WarnException("Check for updates failed!", e.Error);
                return;
            }

            if (!e.UpdateAvailable)
            {
                return;
            }

            NewVersion = e.AvailableVersion;
            IsRequired = e.IsUpdateRequired;

            _Logger.Info(string.Format("A new update is available! Old version: {0}, new version: {1}, mandatory: {2}",
                                       _Deployment.CurrentVersion, NewVersion, IsRequired));

            try {
                _Deployment.UpdateAsync();
            }
            catch (Exception exc) {
                _Logger.WarnException("Update failed!", exc);
            }
        }
Beispiel #3
0
        private void btn_update_Click(object sender, RoutedEventArgs e)
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
                System.Deployment.Application.UpdateCheckInfo info = null;
                try
                {
                    ad.UpdateCompleted += new System.ComponentModel.AsyncCompletedEventHandler(ad_UpdateCompleted);
                    //ad_UpdateCompleted is a private method which handles what happens after the update is done
                    //tb_log.Text += "MinimumRequiredVersion" + info.MinimumRequiredVersion;
                    //tb_log.Text += "ActivationUri" + ad.ActivationUri;
                    tb_log.Text += "UpdateLocation" + ad.UpdateLocation;

                    info = ad.CheckForDetailedUpdate();

                    tb_log.Text += "AvailableVersion" + info.AvailableVersion;
                    tb_log.Text += "UpdateAvailable " + info.UpdateAvailable;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    if (info.UpdateAvailable)
                    {
                        //You can create a dialog or message that prompts the user that there's an update. Make sure the user knows that your are updating the application.
                        ad.UpdateAsync();//Updates the application asynchronously
                    }
                }
            }
        }
Beispiel #4
0
 private void UpdateProgram()
 {
     try
     {
         ApplicationDeployment currentDeployment = ApplicationDeployment.CurrentDeployment;
         if (ApplicationDeployment.CurrentDeployment.CheckForUpdate())
         {
             if (MessageBox.Show("發現新的版本,是否確定更新", "更新通知", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
             {
                 currentDeployment.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(obj_UpdateProgressChanged);
                 currentDeployment.UpdateCompleted       += new AsyncCompletedEventHandler(obj_UpdateCompleted);
                 currentDeployment.UpdateAsync();
             }
             else
             {
                 Close();
             }
         }
         else
         {
             Close();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("目前為離線狀態。");
         Close();
     }
 }
Beispiel #5
0
 private void UpdateProgram()
 {
     try
     {
         Program.Logger.Info("[ClickOnce] -- CheckForUpdate");
         ApplicationDeployment currentDeployment = ApplicationDeployment.CurrentDeployment;
         if (ApplicationDeployment.CurrentDeployment.CheckForUpdate())
         {
             if (MessageBox.Show("發現新的版本,是否確定更新", "更新通知", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
             {
                 currentDeployment.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(obj_UpdateProgressChanged);
                 currentDeployment.UpdateCompleted       += new AsyncCompletedEventHandler(obj_UpdateCompleted);
                 currentDeployment.UpdateAsync();
             }
             else
             {
                 Program.Logger.Info("[ClickOnce] -- 使用者取消更新");
                 Close();
             }
         }
         else
         {
             Program.Logger.Info("[ClickOnce] -- 程式已為最新版本:" + Program.Version);
             Close();
         }
     }
     catch (Exception ex)
     {
         Program.Logger.Fatal("[ClickOnce] --" + ex.ToString());
         MessageBox.Show("更新程式失敗:目前為離線狀態。");
         Close();
     }
 }
Beispiel #6
0
        public static void Update()
        {
            try
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

                if (IsAsync)
                {
                    ad.UpdateCompleted       -= CurrentDeployment_UpdateCompleted;
                    ad.UpdateProgressChanged -= CurrentDeployment_UpdateProgressChanged;

                    ad.UpdateCompleted       += CurrentDeployment_UpdateCompleted;
                    ad.UpdateProgressChanged += CurrentDeployment_UpdateProgressChanged;
                    ad.UpdateAsync();
                }
                else
                {
                    IsDownloading = true;
                    ad.Update();
                    IsDownloading = false;
                    OnUpdateChecked(UpdateStateType.Updated);
                }
            }
            catch (DeploymentDownloadException dde)
            {
                OnUpdateChecked(
                    new Exception(
                        "Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " +
                        dde));
                IsDownloading = false;
                return;
            }
        }
Beispiel #7
0
        private void UpdateProgram()
        {
            bool flag = false;

            try
            {
                ApplicationDeployment currentDeployment = ApplicationDeployment.CurrentDeployment;
                if (ApplicationDeployment.CurrentDeployment.CheckForUpdate())
                {
                    Program.Counter++;
                    currentDeployment.UpdateProgressChanged += obj_UpdateProgressChanged;
                    currentDeployment.UpdateCompleted       += obj_UpdateCompleted;
                    currentDeployment.UpdateAsync();
                    flag = true;
                }
            }
            catch (Exception)
            {
                Close();
            }
            if (!flag)
            {
                StartProgram();
                Close();
            }
        }
        protected override async Task <bool> CheckUpdateCore()
        {
            UpdateCheckInfo       info = null;
            ApplicationDeployment ad   = ApplicationDeployment.CurrentDeployment;

            try {
                info = ad.CheckForDetailedUpdate();
            }
            catch (DeploymentDownloadException) {
                return(false);
            }
            catch (InvalidDeploymentException) {
                return(false);
            }
            catch (InvalidOperationException) {
                return(false);
            }
            if (!info.UpdateAvailable)
            {
                return(false);
            }
            bool handled = false;
            AsyncCompletedEventHandler handler = (sender, e) => {
                handled = true;
            };

            ad.UpdateCompleted += handler;
            ad.UpdateAsync();
            while (!handled)
            {
                await Task.Delay(100);
            }
            ad.UpdateCompleted -= handler;
            return(true);
        }
Beispiel #9
0
        private void beginClickOnceUpdate()
        {
            log.Info("Beginning application update...");
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

            ad.UpdateCompleted += new AsyncCompletedEventHandler(update_completed);
            ad.UpdateAsync();
        }
Beispiel #10
0
 private void currentDeploy_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
 {
     if (e.UpdateAvailable)
     {
         ApplicationDeployment current = ApplicationDeployment.CurrentDeployment;
         current.UpdateAsync();
     }
 }
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     btnUpdate.Enabled  = false;
     btnOpnieuw.Enabled = false;
     prev_state         = "";
     lblStatus.Text     = Resources.Updating + "...";
     depl.UpdateAsync();
 }
Beispiel #12
0
 /// <summary>
 /// Handles the LinkClicked event for uxUpdate.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A LinkLabelLinkClickedEventArgs that contains the event data.</param>
 private void uxUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     uxUpdate.Enabled = false;
     if (ApplicationDeployment.IsNetworkDeployed)
     {
         ApplicationDeployment deployment = ApplicationDeployment.CurrentDeployment;
         deployment.UpdateAsync();
     }
 }
Beispiel #13
0
        /// <summary>
        /// Starts the asynchronous update of the application.
        /// </summary>
        private void BeginUpdate()
        {
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

            ad.UpdateCompleted += new AsyncCompletedEventHandler(ad_UpdateCompleted);
            // Indicate progress in the application's status bar.
            ad.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(ad_UpdateProgressChanged);
            ad.UpdateAsync();
        }
Beispiel #14
0
        private void BeginUpdate()
        {
            LogMessage("AutoUpdate: Starting asynch update...");
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

            ad.UpdateCompleted       += new AsyncCompletedEventHandler(ad_UpdateCompleted);
            ad.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(ad_UpdateProgressChanged);

            ad.UpdateAsync();
        }
Beispiel #15
0
        // Show the main application form


        private void BeginUpdate()
        {
            Text = "Güncelleme indiriliyor...";
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

            ad.UpdateCompleted       += ad_UpdateCompleted;
            ad.UpdateProgressChanged += ad_UpdateProgressChanged;

            ad.UpdateAsync();
        }
Beispiel #16
0
        private static void HCMIS_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
        {
            UpdateRunning = false;

            if (e.Error != null)
            {
                XtraMessageBox.Show("An Error occurred:\n" + e.Error.Message, "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                return;
            }

            if (!e.UpdateAvailable)
            {
                XtraMessageBox.Show("No updates found!", "HCMIS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (e.Cancelled)
            {
                XtraMessageBox.Show("Update was cancelled!", "Update Cancelled", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                return;
            }

            if (e.UpdateAvailable)
            {
                if (e.IsUpdateRequired)
                {
                    XtraMessageBox.Show("There is a mandatory update available. Click OK to start installation", "Update Available", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    UpdateRunning = true;
                    HCMIS.UpdateAsync();
                    ShowUpdatingSignOnMainWindow();
                }

                if (XtraMessageBox.Show("Update found! Would you like to download and install the update now?", "Update Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    UpdateRunning = true;
                    HCMIS.UpdateAsync();
                    ShowUpdatingSignOnMainWindow();
                }
            }
        }
Beispiel #17
0
        // NEVER crash the app because of a bad click-once deployment.
        // Kill the update timer if we see problems.  Raise an appropriate event.
        private static void _TimerTick(object sender, EventArgs e)
        {
            if (_isUpdating)
            {
                return;
            }

            _isUpdating = true;

            if (_isFirstCheck)
            {
                _updateTimer.Stop();
                _updateTimer  = null;
                _isFirstCheck = false;
            }

            bool isUpdateAvailable = false;

            try
            {
                UpdateCheckInfo info = ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate();
                if (info != null)
                {
                    isUpdateAvailable = info.UpdateAvailable;
                }

                if (isUpdateAvailable)
                {
                    ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
                    ad.UpdateCompleted += (sender2, e2) => _NotifyUpdateSuccess();

                    ad.UpdateAsync();
                }
                else
                {
                    _isUpdating = false;
                }
            }
            catch (Exception ex)
            {
                _isUpdating = false;
                _NotifyUpdateFailure(new ApplicationUpdateFailedEventArgs {
                    Exception = ex, WasUpdateDetected = isUpdateAvailable
                });
                return;
            }

            if (_updateTimer == null)
            {
                _updateTimer = new DispatcherTimer(_steadyUpdateInterval, DispatcherPriority.ApplicationIdle, _TimerTick, Application.Current.Dispatcher);
                _updateTimer.Start();
            }
        }
Beispiel #18
0
 private void UpdateNow()
 {
     UpToDate = false;
     Checking = true;
     UpdateStatus();
     update.Enabled = false;
     AcceptButton   = close;
     mainLabel.Text = "Installing update...";
     button.Text    = "Installing Update";
     progress.Style = ProgressBarStyle.Marquee;
     deployment.UpdateAsync();
 }
Beispiel #19
0
 public void UpdateAsync(Action <UpdateProgress> updateProgress,
                         Action <UpdateCompletedDetails> updateComplete)
 {
     _applicationDeployment.UpdateProgressChanged += (s, e) =>
     {
         updateProgress(new UpdateProgress(e.BytesCompleted, e.BytesTotal));
     };
     _applicationDeployment.UpdateCompleted += (s, e) =>
     {
         updateComplete(new UpdateCompletedDetails(e.Cancelled, e.Error));
     };
     _applicationDeployment.UpdateAsync();
 }
 private void InstallUpdateSyncWithInfo()
 {
     UpdateCheckInfo info;
     ApplicationDeployment applicationDeployment = ApplicationDeployment.CurrentDeployment;
     info = applicationDeployment.CheckForDetailedUpdate();
     if (!applicationDeployment.IsFirstRun)
     {
         if (info.UpdateAvailable)
         {
             applicationDeployment.UpdateCompleted += applicationDeployment_UpdateCompleted;
             applicationDeployment.UpdateAsync();
         }
     }
 }
        private void BeginUpdate()
        {
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

            ad.UpdateCompleted       += Ad_UpdateCompleted;
            ad.UpdateProgressChanged += Ad_UpdateProgressChanged;
            ad.UpdateAsync();
            UpdateBar.Dispatcher.Invoke(() =>
            {
                UpdateBar.ProgressText    = "0KiB / 0KiB - 0%";
                UpdateBar.Progress        = 0;
                UpdateBar.Display         = true;
                UpdateBar.ShowProgressBar = true;
            });
        }
Beispiel #22
0
 void ad_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
 {
     log.Info("Update Check Complete");
     if (e.UpdateAvailable == true)
     {
         log.Info("Update Available");
         try
         {
             ad.UpdateAsync();
         }
         catch (Exception ex)
         {
             log.Error(ex);
         }
     }
     log.Info("Update Unvailable");
 }
Beispiel #23
0
        public void BeginUpdate()
        {
            //ประกาศตัวแปร beginUpdate เป็นประเภท ApplicationDeployment และกำหนดค่าให้เป็น CurrentDeployment (กล่าวคือโปรแกรมที่ติดตั้งล่าสุด ของเครื่องของ ผู้ใช้งาน)
            ApplicationDeployment beginUpdate = ApplicationDeployment.CurrentDeployment;

            //สร้าง Event beginUpdate_UpdateCompleted
            beginUpdate.UpdateCompleted += new AsyncCompletedEventHandler(beginUpdate_UpdateCompleted);

            //สร้าง Event beginUpdate_UpdateProgressChanged
            beginUpdate.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(beginUpdate_UpdateProgressChanged);

            //เรียกเมธอด UpdateAsync เพื่อ Update แบบอะซิงโครนัส
            beginUpdate.UpdateAsync();

            //เรียกเมธอด showProgrssBar
            //showProgrssBar();
        }
        public void CheckForUpdate(object sender, EventArgs eventargs)
        {
            if (_ClickOnce)
            {
                if (processing)
                {
                    return;
                }
                processing = true;
                try
                {
                    // bool: Persist update to disk?
                    // false: Apply update silently
                    // true: Show prompt and allow user to skip update (not desired)
                    if (Deployment.CheckForUpdate(false))
                    {
                        Deployment.UpdateAsync();
                    }
                    else
                    {
                        processing = false;
                    }
                }
                catch (Exception ex)
                {
                    log.Warn("Check for update failed. " + ex.Message);
                    processing = false;
                }
            }
            else
            {
                if (UpdateManager.Instance.IsWorking)
                {
                    return;
                }

                UpdateManager.Instance.CheckForUpdates();
                if (UpdateManager.Instance.UpdatesAvailable > 0)
                {
                    UpdateManager.Instance.PrepareUpdates();
                }
            }
        }
Beispiel #25
0
        void deployment_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
        {
            if (e.Error == null && e.UpdateAvailable)
            {
                try
                {
                    MainWindow w = this.windows[0];
                    w.updateProgress.Value            = 0;
                    w.UpdateAvailableLabel.Visibility = Visibility.Visible;

                    deployment.UpdateAsync();
                }
                catch (InvalidOperationException ex)
                {
                    Debug.WriteLine(ex.ToString());
                    MainWindow w = this.windows[0];
                    w.UpdateAvailableLabel.Visibility = Visibility.Hidden;
                }
            }
        }
Beispiel #26
0
        void adCheckForUpdateAsyncMin_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show("Could not install application update. Please try again later,  or contact a system administrator.", "Application Update Error");
                return;
            }
            else if (e.Cancelled)
            {
                MessageBox.Show("The application update has been cancelled.", "Application Update Cancelled");
                return;
            }

            adCheckForUpdateAsyncMin = ApplicationDeployment.CurrentDeployment;
            if (e.MinimumRequiredVersion > adCheckForUpdateAsyncMin.CurrentVersion)
            {
                // Launch an install of the minimum required version.
                adCheckForUpdateAsyncMin.UpdateCompleted += new AsyncCompletedEventHandler(adCheckForUpdateAsyncMin_UpdateCompleted);
                adCheckForUpdateAsyncMin.UpdateAsync();
            }
        }
 private void BeginUpdate()
 {
     ADUpdateAsync = ApplicationDeployment.CurrentDeployment;
     ADUpdateAsync.UpdateAsync();
 }
Beispiel #28
0
        public void UpdateApplicationAsync(bool _onBackground)
        {
            if (!ApplicationDeployment.IsNetworkDeployed)
            {
                // not ClickOnce deployed
                labelLoading.Visible = false;
                return;
            }

            if (!CheckForInternetConnection())
            {
                labelLoading.Visible = false;
                //MetroFramework.MetroMessageBox.Show(ownerForm, "No internet connection found!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!_onBackground)
            {
                labelLoading.Visible = true;
            }
            else
            {
                labelLoading.Visible = false;
            }


            // Why use the ThreadPool instead of CheckForUpdateAsync?
            // Some network condition, e.g. Hotel or Guest Wi-Fi, can
            // make ClickOnce throw internally in such a way the exception
            // is tricky to catch. Instead, use CheckForUpdates (sync)
            // and handle the exception directly.
            if (!CheckForUpdateAvailable())
            {
                labelLoading.Visible = false;
                return;
            }


            ThreadPool.QueueUserWorkItem(delegate
            {
                try
                {
                    if (deployment != null)
                    {
                        if (deployment.CheckForUpdate() && pendingUpdate != true)
                        {
                            pendingUpdate = true;
                            deployment.UpdateCompleted +=
                                new AsyncCompletedEventHandler(
                                    deployment_UpdateCompleted);
                            deployment.UpdateAsync();
                        }
                        else
                        {
                            updateOnStart        = false;
                            labelLoading.Visible = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    labelLoading.Visible = false;
                    MessageBox.Show(ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message);
                }
            });
        }
 public void UpdateAsync()
 {
     _deployment.UpdateAsync();
 }
Beispiel #30
0
        private async void MetroWindow_ContentRendered(object sender, EventArgs e)
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ProgressDialogController pd = await this.ShowProgressAsync("Software Update", "Checking for updates...", false);

                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

                pd.SetIndeterminate();

                ad.UpdateProgressChanged += (o, args) => { pd.SetProgress(args.ProgressPercentage / 100f); };
                ad.UpdateCompleted       += (o, args) =>
                {
                    if (args.Error != null)
                    {
                        return;
                    }

                    System.Windows.Forms.Application.Restart();
                    Application.Current.Shutdown();
                };

                UpdateCheckInfo info = await Task.Run(() =>
                {
                    try
                    {
                        return(ad.CheckForDetailedUpdate(false));
                    }
                    catch { }

                    return(null);
                });

                await pd.CloseAsync();

                if (info != null && info.UpdateAvailable)
                {
                    MessageDialogResult res = await this.ShowMessageAsync("Software Update", string.Format("AnySense Studio {0}.{1}.{2} " +
                                                                                                           "is available and is ready to install.",
                                                                                                           info.AvailableVersion.Major,
                                                                                                           info.AvailableVersion.Minor,
                                                                                                           info.AvailableVersion.Build),
                                                                          MessageDialogStyle.AffirmativeAndNegative,
                                                                          new MetroDialogSettings()
                    {
                        AffirmativeButtonText = "Install Now",
                        NegativeButtonText    = "Later"
                    });

                    if (res == MessageDialogResult.Affirmative)
                    {
                        pd = await this.ShowProgressAsync("Software Update", "Updating...", false);

                        try { ad.UpdateAsync(); }
                        catch { }

                        return;
                    }
                }

                Title += string.Format(" (Version {0}.{1}.{2})", ad.CurrentVersion.Major, ad.CurrentVersion.Minor, ad.CurrentVersion.Build);
            }

            DataContext = new MainViewModel();
        }