示例#1
0
        private void SetVersionStatus()
        {
            if (_serverVersion == null)
            {
                VersionStatus = "(Unable to get version information)";
            }
            else if (LocalVersion.CompareTo(_serverVersion) > 0)
            {
                VersionStatus = string.Format("(Ahead of {1} Version - {0} )", _serverVersion.ToString(3), ServerVersionType);
            }
            else if (LocalVersion.CompareTo(_serverVersion) == 0)
            {
                VersionStatus = string.Format("(Latest {0} Version)", ServerVersionType);
            }
            else
            {
                VersionStatus = string.Format("(New {1} Version available - {0})", _serverVersion.ToString(3), ServerVersionType);
            }

            NotifyOfPropertyChange(() => VersionStatus);
        }
示例#2
0
        /// <summary>
        /// Determines whether an update is available.
        /// </summary>
        /// <returns>True if an update is available otherwise false.</returns>
        public async Task <bool> IsUpdateAvailable()
        {
            try
            {
                var client  = new RestClient(Properties.Settings.Default.APIUrl);
                var request =
                    new RestRequest(
                        $"/repos/{Properties.Settings.Default.RepoOwner}/{Properties.Settings.Default.RepoName}/releases/latest",
                        Method.GET)
                {
                    RequestFormat = DataFormat.Json,
                };
                var result = await client.ExecuteGetTaskAsync(request);

                if (result.StatusCode != HttpStatusCode.OK)
                {
                    Debug.WriteLine("Couldn't get latest release from repo. Result code was " + result.StatusCode);
                    return(false);
                }

                var json = JObject.Parse(result.Content);
                RemoteVersion = ParseVersion(json["tag_name"].ToString());
                var config = Environment.Is64BitOperatingSystem ? "x64" : "x86";
                foreach (var child in json["assets"].Children())
                {
                    if (child["name"].ToString().Contains(Properties.Settings.Default.AssetName + config))
                    {
                        _downloadUrl = child["browser_download_url"].ToString();
                        break;
                    }
                }
                return(LocalVersion.CompareTo(RemoteVersion) < 0);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Couldn't get latest release from repo. Error: " + ex);
            }

            return(false);
        }