Example #1
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
                    }
                }
            }
        }
        private static void HandleCheckForUpdateCompleted(UpdateCheckInfo e)
        {
            if (e.UpdateAvailable)
            {
                Logger.InfoFormat("An update is vailable ({0})...", ToVersionString(e.AvailableVersion));
                ApplicationDeployment.CurrentDeployment.Update();

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("An update was found and installed. The application needs to be restarted to use the new version.");
                sb.AppendLine();
                sb.AppendLine("Current version: " + GetVersion());
                sb.AppendLine("New version: " + ToVersionString(e.AvailableVersion));
                sb.AppendLine("Update size: " + e.UpdateSizeBytes + " bytes");
                sb.AppendLine();
                sb.AppendLine("Do you want to restart the application to update now?");

                // Get a form so we can invoke on the thread
                Form form = Application.OpenForms.Count > 0 ? Application.OpenForms[0] : null;
                if (form != null)
                {
                    form.Invoke((Action)(() => {
                        if (MessageBox.Show(form, sb.ToString(), "Update available!", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            Application.Restart();
                    }));
                }
            }
            else
            {
                Logger.InfoFormat("No update available...");
            }
        }
Example #3
0
        private void frmAviso_Load(object sender, EventArgs e)
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
                #region Check se tem update
                try
                {
                    info = ad.CheckForDetailedUpdate();
                }
                catch (DeploymentDownloadException dde)
                {
                    throw new Exception("A nova versão não pode ser baixada agora. \n\nVerifique sua conexão com a Internet ou tente novamente mais tarde. Erro: " + dde.Message);

                }
                catch (InvalidDeploymentException ide)
                {
                    throw new Exception("O arquivo está indisponível ou corrompido. Erro: " + ide.Message);

                }
                catch (InvalidOperationException ioe)
                {
                    throw new Exception("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
                }
                #endregion
                if (info.UpdateAvailable)
                {
                    string sVersaoAtual = ad.CurrentVersion.ToString();
                    lblDisponivel.Text = string.Format(lblDisponivel.Text, sVersaoAtual);

                    if (!objBelVersionamento.VersaoDisponivelIgualLiberada(sVersaoAtual))
                    {
                        if (objBelVersionamento.VerificaAtualizacaoDisponivel())
                        {
                            this.Size = new Size(250, 115);
                            lblAviso.Text = Environment.NewLine + "Mantenha seu sistema atualizado!";
                        }
                        else
                        {
                            this.Size = new Size(250, 144);
                            btnAtualizar.Visible = false;
                            lblAviso.Text = Environment.NewLine
                                            + "A versão acima já foi publicada, "
                                            + "mas é necessário algumas atualizações "
                                            + "na estrutura do sistema.!"
                                            + Environment.NewLine
                                            + "Favor entrar em contato com o suporte para liberação da versão!";
                        }
                    }
                }
                else
                {
                    lblDisponivel.Text = string.Format(lblDisponivel.Text, belStatic.sVersaoAtual.ToString());
                    this.Size = new Size(250, 100);
                    btnAtualizar.Visible = false;
                    lblAviso.Text = Environment.NewLine + "Sistema Atualizado !!";
                }
            }
            btnAtualizar.Focus();
        }
Example #4
0
        private bool checkForUpdate()
        {
            bool returnValue = false;

            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

                try
                {
                    updateStatus("Checking with Server");
                    _info = ad.CheckForDetailedUpdate();

                    updateStatus(string.Format("Installed version: {0}", ad.CurrentVersion));

                    if (_info.UpdateAvailable)
                    {
                        returnValue = true;

                        updateStatus(string.Format("Latest version: {0}", _info.AvailableVersion));

                        if (_info.IsUpdateRequired)
                            updateStatus("Update is required");
                        else
                            updateStatus("Your current version is obsolete and should be updated");

                        updateStatus(string.Format("Size of the update: {0} kb", _info.UpdateSizeBytes / 1024));
                    }
                    else
                    {
                        updateStatus(string.Format("Latest version: {0}", ad.CurrentVersion));
                        updateStatus("Your current version is the latest");
                    }

                }
                catch (DeploymentDownloadException dde)
                {
                    updateStatus("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
                    returnValue = false;
                }
                catch (InvalidDeploymentException ide)
                {
                    updateStatus("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
                    returnValue = false;
                }
                catch (InvalidOperationException ioe)
                {
                    updateStatus("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
                    returnValue = false;
                }

            }
            else
                updateStatus("This app is not a ClickOnce application");

            return returnValue;
        }
Example #5
0
 public static bool CheckUpdate()
 {
    try
    {
       if(ApplicationDeployment.IsNetworkDeployed)
       {
          var upInfo = ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate();
          if(upInfo != null)
          {
             UpdateInfo = upInfo;
             return upInfo.UpdateAvailable;
          }
       }
    }
    catch
    {
    }
    return false;
 }
 private UpdateResult SuccessResult(UpdateCheckInfo info)
 {
     return new UpdateResult
                {
                    Success = true,
                    Updated = true,
                    Message = string.Format(Properties.Resources.Deployment_Success,
                                            _applicationName,
                                            info.AvailableVersion)
                };
 }
Example #7
0
        /// <summary>
        /// Starts the ClickOnce updating.
        /// </summary>
        public void StartUpdating()
        {
            if (!ApplicationDeployment.IsNetworkDeployed)
            {
                return;
            }
            UpdateProgress("Checking for updates.");

            // http://blogs.msdn.com/b/ukadc/archive/2010/09/16/taming-clickonce-taking-charge-of-updates.aspx
            // Why use the ThreadPool instead of CheckForUpdateAsync?
            // Some network conditions, 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.
            ThreadPool.QueueUserWorkItem(delegate
                                             {
                                                 try
                                                 {
                                                     var deployment = ApplicationDeployment.CurrentDeployment;

                                                     // http://msdn.microsoft.com/en-us/library/ms404263(VS.80).aspx
                                                     try
                                                     {
                                                         versionInfo = deployment.CheckForDetailedUpdate();
                                                     }
                                                     catch (DeploymentDownloadException dde)
                                                     {
                                                         MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
                                                         return;
                                                     }
                                                     catch (InvalidDeploymentException ide)
                                                     {
                                                         MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
                                                         return;
                                                     }
                                                     catch (InvalidOperationException ioe)
                                                     {
                                                         MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
                                                         return;
                                                     }

                                                     if (versionInfo.UpdateAvailable)
                                                     {
                                                         UpdateProgress("Update Found.");
                                                         if (versionInfo.IsUpdateRequired)
                                                         {
                                                             // Display a message that the app MUST reboot. Display the minimum required version.
                                                             MessageBox.Show("This application has detected a mandatory update from your current " +
                                                                             "version to version " + versionInfo.MinimumRequiredVersion +
                                                                             ". The application will now install the update and restart.",
                                                                             "Update Available", MessageBoxButtons.OK,
                                                                             MessageBoxIcon.Information);
                                                         }

                                                         deployment.CheckForUpdateProgressChanged += deployment_CheckForUpdateProgressChanged;
                                                         deployment.UpdateCompleted += deployment_UpdateCompleted;
                                                         deployment.UpdateAsync();
                                                     }
                                                     else
                                                     {
                                                         UpdateProgress("No updates.");
                                                     }
                                                 }
                                                 catch (Exception ex)
                                                 {
                                                     Trace.WriteLine(ex.Message);
                                                 }
                                             });
        }
        private static void CheckForUpdates(UpdateCheckInfo info, bool auto)
        {
            try
            {
                if (!ApplicationDeployment.IsNetworkDeployed)
                {
                    if (!auto)
                        Popup.Show(
                            "This application was not installed via ClickOnce and cannot be updated automatically.");
                    return;
                }

                if (info == null)
                {
                    if (!auto)
                        Popup.Show(
                            "An error occurred while trying to check for updates.", image: MessageBoxImage.Error);
                    return;
                }

                Settings.Default.LastUpdateCheck = DateTime.Now;
                if (info.UpdateAvailable && !(Settings.Default.UpdateBranch != UpdateBranch.Beta &&
                                              info.AvailableVersion.Minor == Settings.Default.BetaVersion) &&
                    !(AssemblyInfo.Version.Major != ForgetUpdateVersion.Major &&
                      ForgetUpdateVersion.Major == info.AvailableVersion.Major))
                {
                    if (auto && info.AvailableVersion == ForgetUpdateVersion)
                        return;
                    var ad = ApplicationDeployment.CurrentDeployment;
                    ad.UpdateCompleted += delegate
                    {
                        var args = new List<string>();
                        if (auto && Settings.Default.AutoUpdate)
                            args.Add("updatingsilent");
                        else
                            args.Add("updating");
                        AppHelper.RestartApplication(args);
                    };
                    if (auto && Settings.Default.AutoUpdate)
                    {
                        try
                        {
                            ad.UpdateAsync();
                        }
                        catch
                        {
                            // ignored
                        }
                        return;
                    }

                    if (auto)
                    {
                        if (Settings.Default.UpdateWaiting != info.AvailableVersion)
                        {
                            Settings.Default.UpdateWaiting = info.AvailableVersion;
                            TrayIconHelper.ShowBalloon(
                                $"Update available ({info.AvailableVersion})\nClick to view details",
                                BalloonIcon.Info);
                        }
                    }
                    else
                    {
                        App.UpdateScheduler?.Stop();

                        var updateDialog = new UpdatePrompt(info.AvailableVersion, info.IsUpdateRequired);
                        updateDialog.ShowDialog();
                        updateDialog.Activate();

                        switch (updateDialog.SelectedUpdateMode)
                        {
                            case UpdatePrompt.UpdateMode.RemindNever:
                                Settings.Default.ForgetUpdateVersion = info.AvailableVersion;
                                break;
                            case UpdatePrompt.UpdateMode.UpdateNow:
                                try
                                {
                                    var progressDialog = new UpdateProgress(info.AvailableVersion);
                                    ad.UpdateProgressChanged +=
                                        delegate(object sender, DeploymentProgressChangedEventArgs args)
                                        {
                                            if (args.State == DeploymentProgressState.DownloadingApplicationFiles)
                                                progressDialog.CurrentProgress = args.ProgressPercentage;
                                        };
                                    progressDialog.Show();
                                    progressDialog.Activate();
                                    ad.UpdateAsync();
                                }
                                catch (DeploymentDownloadException dde)
                                {
                                    Popup.Show(
                                        "Cannot download the latest version of this application.\n\nPlease check your network connection, or try again later.\n\nError: " +
                                        dde, image: MessageBoxImage.Error);
                                }
                                break;
                        }

                        App.UpdateScheduler?.Start();
                    }
                }
                else
                {
                    if (!auto)
                        Popup.Show(
                            $"You have the latest version ({AssemblyInfo.Version}).");
                }
            }
            catch (Exception)
            {
                if (!auto)
                    throw;
            }
        }
 private void ProcessUpdateCheckResult(UpdateCheckInfo info, ActivationDescription actDesc)
 {
     if (this._subState.IsShellVisible)
     {
         AssemblyManifest deployManifest = actDesc.DeployManifest;
         DefinitionIdentity deployId = info.UpdateAvailable ? deployManifest.Identity : null;
         this._subStore.SetPendingDeployment(this._subState, deployId, DateTime.UtcNow);
     }
 }