Ejemplo n.º 1
0
        /// <summary> Gets version status from github. </summary>
        /// <returns> The current version status. </returns>
        private static VersionStatus GetVersionStatus()
        {
            try
            {
                var interpreter = new InputInterpreter();
                var client      = new GitHubClient(new ProductHeaderValue("butterflow-ui"));
                var releases    = client.Repository.Release.GetAll("wagesj45", "butterflow-ui").Result;

                if (releases.Any())
                {
                    var     latest = releases.First();
                    decimal latestMajor = 0, latestMinor = 0, latestPatch = 0, currentMajor = 0, currentMinor = 0, currentPatch = 0;

                    var regex = new Regex(REGEX_VERSION);
                    foreach (Match match in regex.Matches(latest.TagName))
                    {
                        latestMajor = interpreter.ComputeExpression(match.Groups["Major"].Value);
                        latestMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value);
                        latestPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value);
                    }

                    foreach (Match match in regex.Matches(Assembly.GetExecutingAssembly().GetName().Version.ToString()))
                    {
                        currentMajor = interpreter.ComputeExpression(match.Groups["Major"].Value);
                        currentMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value);
                        currentPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value);
                    }

                    if (latestMajor == currentMajor && latestMinor == currentMinor && latestPatch == currentPatch)
                    {
                        return(VersionStatus.Current);
                    }

                    if (latestMajor >= currentMajor && latestMinor >= currentMinor && latestPatch >= currentPatch)
                    {
                        return(VersionStatus.Behind);
                    }

                    return(VersionStatus.Custom);
                }
            }
            catch (Exception e)
            {
                //There was an issue connecting to Github. This could be caused by a missing network connection.
                //We can safely ignore an error in this process and proceed, falling through to the default connection
                //value of Unknown.
            }

            return(VersionStatus.Unknown);
        }
Ejemplo n.º 2
0
        /// <summary> Gets version status from github. </summary>
        /// <returns> The current version status. </returns>
        private static VersionStatus GetVersionStatus()
        {
            var interpreter = new InputInterpreter();
            var client      = new GitHubClient(new ProductHeaderValue("butterflow-ui"));
            var releases    = client.Repository.Release.GetAll("wagesj45", "butterflow-ui").Result;

            if (releases.Any())
            {
                var     latest = releases.First();
                decimal latestMajor = 0, latestMinor = 0, latestPatch = 0, currentMajor = 0, currentMinor = 0, currentPatch = 0;

                var regex = new Regex(REGEX_VERSION);
                foreach (Match match in regex.Matches(latest.TagName))
                {
                    latestMajor = interpreter.ComputeExpression(match.Groups["Major"].Value);
                    latestMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value);
                    latestPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value);
                }

                foreach (Match match in regex.Matches(Assembly.GetExecutingAssembly().GetName().Version.ToString()))
                {
                    currentMajor = interpreter.ComputeExpression(match.Groups["Major"].Value);
                    currentMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value);
                    currentPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value);
                }

                if (latestMajor == currentMajor && latestMinor == currentMinor && latestPatch == currentPatch)
                {
                    return(VersionStatus.current);
                }

                if (latestMajor >= currentMajor && latestMinor >= currentMinor && latestPatch >= currentPatch)
                {
                    return(VersionStatus.behind);
                }

                return(VersionStatus.custom);
            }

            return(VersionStatus.unknown);
        }