예제 #1
0
        public async Task <GitHubRelease> GetReleaseAsync(string releaseId = "latest")
        {
            if (string.IsNullOrWhiteSpace(Repository))
            {
                throw new ArgumentException($"{nameof(Repository)} cannot be null or white space as it is used by GitHub to allow API calls through. See https://developer.github.com/v3/#user-agent-required");
            }

            var apiUrl = GetReleaseApiUrl(releaseId);

            _httpClient.DefaultRequestHeaders.Accept.Clear();

            // https://developer.github.com/v3/#user-agent-required
            _httpClient.DefaultRequestHeaders.Add("User-Agent", Repository);

            var jsonString = await _httpClient.GetStringAsync(apiUrl);

            return(GitHubRelease.CreateFromJson(jsonString));
        }
예제 #2
0
        private async void CheckForUpdateAsync(object state)
        {
            if (!(state is CheckForUpdateParams))
            {
                throw new ArgumentException($"{nameof(state)} must be of type {nameof(CheckForUpdateParams)} (current is {state.GetType().Name})");
            }

            var args = (CheckForUpdateParams)state;

            try
            {
                var release = await GetReleaseAsync();

                if (args.CurrentVersion != release.Version)
                {
                    args.Callback?.Invoke(release);

                    UpdateUrl       = release.HtmlUrl;
                    UpdateAvailable = true;
                    Update          = release;
                }
                else
                {
                    UpdateUrl       = null;
                    UpdateAvailable = false;
                    Update          = null;
                }

                LastChecked = DateTime.Now;
            }
            catch (Exception e)
            {
                // If the handler is defined, invoke it, otherwise silently swallow these exceptions
                UnhandledException?.Invoke(this, e);
            }
        }