Ejemplo n.º 1
0
        /// <summary>
        /// Downloads the file at <see cref="linkToVersionXml"/> and attempts to deserialize it into <see cref="Sys.LastCheckedVersion"/>.
        /// Uses the download queue so this happens asynchronously. <see cref="UpdateCheckCompleted"/> is raised when the download is complete.
        /// </summary>
        public void CheckForUpdates()
        {
            string path = Path.Combine(Sys.PathToTempFolder, "version.xml");

            Directory.CreateDirectory(Sys.PathToTempFolder);

            DownloadItem download = new DownloadItem()
            {
                Links = new List <string>()
                {
                    LocationUtil.FormatHttpUrl(linkToVersionXml)
                },
                SaveFilePath = path,
                Category     = DownloadCategory.AppUpdate,
                ItemName     = $"{ResourceHelper.Get(StringKey.CheckingForUpdatesAt)} {linkToVersionXml}"
            };

            download.IProc = new Install.InstallProcedureCallback(e =>
            {
                bool success = (e.Error == null && e.Cancelled == false);

                if (success)
                {
                    try
                    {
                        Sys.LastCheckedVersion = Util.Deserialize <AvailableUpdate>(path);
                    }
                    catch (Exception ex)
                    {
                        Sys.LastCheckedVersion = Sys.LastCheckedVersion ?? new AvailableUpdate(); // if currently null then initialize new instance
                        Sys.Message(new WMessage()
                        {
                            Text = $"{ResourceHelper.Get(StringKey.FailedToCheckForUpdatesAt)} {linkToVersionXml}: {ex.Message}", LoggedException = ex
                        });
                    }
                }
                else
                {
                    Sys.LastCheckedVersion = Sys.LastCheckedVersion ?? new AvailableUpdate();
                    Sys.Message(new WMessage()
                    {
                        Text = $"{ResourceHelper.Get(StringKey.FailedToCheckForUpdatesAt)} {linkToVersionXml}", LoggedException = e.Error
                    });
                }

                UpdateCheckCompleted?.Invoke(success);
            });

            Sys.Downloads.AddToDownloadQueue(download);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Raises the UpdateCheckCompleted event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual Task OnUpdateCheckCompleted(UpdateCheckEventArgs e)
 {
     UpdateCheckCompleted?.Invoke(this, e);
     return(Task.FromResult(false));
 }