Exemple #1
0
        /// <summary>
        /// Downloads update and installs the update
        /// </summary>
        /// <param name="update">The update xml info</param>
        private void DownloadUpdate(ApplicationUpdateXml update)
        {
            //webClients = new List<WebClient>();
            webClient = new WebClient();

            //var filecount = update.Applications.Select(n => n.Files.Count);

            //for (int i = 0; i < filecount.Sum(n => n); i++)
            //    webClients.Add(new WebClient());

            // Set up backgroundworker to download files
            bgWorker                     = new BackgroundWorker();
            bgWorker.DoWork             += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
            bgWorker.RunWorkerAsync();
        }
Exemple #2
0
        private void CheckForUpdate()
        {
            try
            {
                eventLog.WriteEntry("Enter checking update" + DateTime.Now.ToString());
                // Update the service state to Start Pending.
                ServiceStatus serviceStatus = new ServiceStatus();
                serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
                serviceStatus.dwWaitHint     = 100000;
                SetServiceStatus(this.ServiceHandle, ref serviceStatus);

                eventLog.WriteEntry("Checking for update xml" + DateTime.Now.ToString());

                ApplicationUpdateXml updateXML = ApplicationUpdateHelper.HasUpdate(this);

                eventLog.WriteEntry("Found update xml" + DateTime.Now.ToString() + updateXML.ToString());

                if (updateXML != null)
                {
                    update = updateXML;
                    eventLog.WriteEntry(String.Format("App Version {0}", this.applicationInfo.ApplicationAssembly.GetName().Version.ToString()));
                    eventLog.WriteEntry(String.Format("update version {0}", update.Version));
                    eventLog.WriteEntry("Is newer" + DateTime.Now.ToString() + update.IsNewerThan(this.applicationInfo.ApplicationAssembly.GetName().Version).ToString());

                    // Check if the update is not null and is a newer version than the current application
                    if (update != null && update.IsNewerThan(this.applicationInfo.ApplicationAssembly.GetName().Version))
                    {
                        eventLog.WriteEntry("download update" + DateTime.Now.ToString());
                        this.DownloadUpdate(update); // Do the update
                        eventLog.WriteEntry("updated downloaded" + DateTime.Now.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                eventLog.WriteEntry("CheckForUpdate Excption " + DateTime.Now.ToString() + ex.ToString());
                timer.Stop();
            }
        }