Exemplo n.º 1
0
        public async Task Check(bool notifyNoFound, bool isPreRelease)
        {
            try
            {
                var updater = new GitHubRelease(Owner, Repo);
                var url     = updater.AllReleaseUrl;

                var json = await GetAsync(url);

                var releases      = JsonSerializer.Deserialize <List <Release> >(json);
                var latestRelease = VersionUtil.GetLatestRelease(releases, isPreRelease);
                if (VersionUtil.CompareVersion(latestRelease.tag_name, Version) > 0)
                {
                    LatestVersionNumber = latestRelease.tag_name;
                    LatestVersionUrl    = latestRelease.html_url;
                    NewVersionFound?.Invoke(this, new EventArgs());
                }
                else
                {
                    LatestVersionNumber = latestRelease.tag_name;
                    if (notifyNoFound)
                    {
                        NewVersionNotFound?.Invoke(this, new EventArgs());
                    }
                }
            }
            catch
            {
                if (notifyNoFound)
                {
                    NewVersionFoundFailed?.Invoke(this, new EventArgs());
                }
            }
        }
Exemplo n.º 2
0
        public async void Check(bool notifyNoFound, bool isPreRelease)
        {
            try
            {
                var updater = new GitHubRelease(Owner, Repo);
                var url     = updater.AllReleaseUrl;

                var json = await GetAsync(url, true);

                var releases      = JsonConvert.DeserializeObject <List <Release> >(json);
                var latestRelease = VersionUtil.GetLatestRelease(releases, isPreRelease);
                if (VersionUtil.CompareVersion(latestRelease.tag_name, Version) > 0)
                {
                    LatestVersionNumber = latestRelease.tag_name;
                    LatestVersionUrl    = latestRelease.html_url;
                    NewVersionFound?.Invoke(this, new EventArgs());
                }
                else
                {
                    LatestVersionNumber = latestRelease.tag_name;
                    if (notifyNoFound)
                    {
                        NewVersionNotFound?.Invoke(this, new EventArgs());
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                if (notifyNoFound)
                {
                    NewVersionFoundFailed?.Invoke(this, new EventArgs());
                }
            }
        }
Exemplo n.º 3
0
        public void Check(bool notifyNoFound, bool isPreRelease)
        {
            try
            {
                var updater = new GitHubRelease(Owner, Repo);
                var url     = updater.AllReleaseUrl;

                var json = WebUtil.DownloadString(WebUtil.CreateRequest(url));

                var releases      = JsonConvert.DeserializeObject <List <Release> >(json);
                var latestRelease = VersionUtil.GetLatestRelease(releases, isPreRelease);
                if (VersionUtil.CompareVersion(latestRelease.tag_name, Version) > 0)
                {
                    LatestVersionNumber = latestRelease.tag_name;
                    LatestVersionUrl    = latestRelease.html_url;
                    NewVersionFound?.Invoke(this, new EventArgs());
                }
                else
                {
                    LatestVersionNumber = latestRelease.tag_name;
                    if (notifyNoFound)
                    {
                        NewVersionNotFound?.Invoke(this, new EventArgs());
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error(e.ToString());
                if (notifyNoFound)
                {
                    NewVersionFoundFailed?.Invoke(this, new EventArgs());
                }
            }
        }
Exemplo n.º 4
0
        public async void Check(bool isPreRelease)
        {
            try
            {
                var updater = new GitHubRelease(Owner, Repo);
                var url     = updater.AllReleaseUrl;

                var json = await WebUtil.DownloadStringAsync(WebUtil.CreateRequest(url));

                var releases      = JsonConvert.DeserializeObject <List <Release> >(json);
                var latestRelease = VersionUtil.GetLatestRelease(releases, isPreRelease);
                LatestVersionNumber      = latestRelease.tag_name;
                LatestVersionUrl         = latestRelease.html_url;
                LatestVersionDownloadUrl = latestRelease.assets[0].browser_download_url;
                Logging.Info($"Github 最新发布版本: {latestRelease.tag_name}");
                if (VersionUtil.CompareVersion(latestRelease.tag_name, Version) > 0)
                {
                    Logging.Info($"发现新版本");
                    NewVersionFound?.Invoke(this, new EventArgs());
                }
                else
                {
                    Logging.Info("目前是最新版本");
                    NewVersionNotFound?.Invoke(this, new EventArgs());
                }
            }
            catch (Exception e)
            {
                if (e is WebException)
                {
                    Logging.Warning($"获取新版本失败: {e.Message}");
                }
                else
                {
                    Logging.Warning(e.ToString());
                }

                NewVersionFoundFailed?.Invoke(this, new EventArgs());
            }
        }