Пример #1
0
 /// <summary>
 /// Initializes a new instances of <see cref="NotificationEventArgs"/> class
 /// </summary>
 /// <param name="updater">The application update details</param>
 public NotificationEventArgs(UpdaterInformation updater)
 {
     this.UpdateInfo = updater;
 }
Пример #2
0
        /// <summary>
        /// Retrieve update information from appcast file
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private async Task <UpdaterInformation> GetUpdateDetilsFromAppCast(CancellationToken token = default(CancellationToken))
        {
            if (token.IsCancellationRequested)
            {
                throw new TaskCanceledException();
            }

            var webRequest = WebRequest.Create(this.AppcastUrl);

            if (this.UpdaterOptions.AppcastFileAuthentication != null)
            {
                webRequest.Headers[HttpRequestHeader.Authorization] = this.UpdaterOptions.AppcastFileAuthentication.ToString();
            }

            webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);

            WebResponse webResponse;

            try
            {
                webResponse = await webRequest.GetResponseAsync().ConfigureAwait(false);
            }
            catch (Exception)
            {
                return(null);
            }

            UpdaterInformation updater;

            using (Stream appCastStream = webResponse?.GetResponseStream())
            {
                if (token.IsCancellationRequested)
                {
                    webResponse?.Close();
                    throw new TaskCanceledException();
                }

                if (appCastStream != null)
                {
                    if (this.ParseUpdateInformation != null)
                    {
                        using (StreamReader streamReader = new StreamReader(appCastStream))
                        {
                            string data = await streamReader.ReadToEndAsync().ConfigureAwait(false);

                            ParseUpdateInfoEventArgs parseArgs = new ParseUpdateInfoEventArgs(data);

                            this.ParseUpdateInformation.Invoke(this, parseArgs);

                            updater = parseArgs.UpdateInfo;
                        }
                    }
                    else
                    {
                        XmlDocument receivedAppCastDocument = new XmlDocument();

                        try
                        {
                            receivedAppCastDocument.Load(appCastStream);

                            XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item");

                            updater = new UpdaterInformation();

                            if (appCastItems != null)
                            {
                                foreach (XmlNode item in appCastItems)
                                {
                                    XmlNode appCastVersion = item.SelectSingleNode("version");

                                    try
                                    {
                                        updater.CurrentVersion = new Version(appCastVersion?.InnerText);
                                    }
                                    catch (Exception)
                                    {
                                        updater.CurrentVersion = null;
                                    }

                                    XmlNode appCastChangeLog = item.SelectSingleNode("changelog");
                                    updater.ChangelogURL = appCastChangeLog?.InnerText;

                                    XmlNode appCastUrl = item.SelectSingleNode("url");
                                    updater.DownloadURL = appCastUrl?.InnerText;

                                    XmlNode umode = item.SelectSingleNode("updatemode");

                                    var updateMode = (EazyUpdateMode)Enum.Parse(typeof(EazyUpdateMode), umode?.InnerText);
                                    if (!Enum.IsDefined(typeof(EazyUpdateMode), updateMode))
                                    {
                                        throw new InvalidDataException(
                                                  $"{updateMode} is not an underlying value of the Mode enumeration.");
                                    }

                                    updater.UpdateMode = updateMode;

                                    XmlNode appArgs = item.SelectSingleNode("args");
                                    updater.InstallerArgs = appArgs?.InnerText;

                                    XmlNode checksum = item.SelectSingleNode("checksum");
                                    updater.HashingAlgorithm = checksum?.Attributes["algorithm"]?.InnerText;
                                    updater.Checksum         = checksum?.InnerText;
                                }
                            }
                        }
                        catch (XmlException)
                        {
                            webResponse?.Close();
                            return(null);
                        }
                    }
                }
                else
                {
                    webResponse?.Close();
                    return(null);
                }
            }

            webResponse?.Close();
            return(updater);
        }