Пример #1
0
        private bool TryValidateGSDVersion(GSDEnlistment enlistment, ITracer tracer, ServerGSDConfig config, out string errorMessage, out bool errorIsFatal)
        {
            errorMessage = null;
            errorIsFatal = false;

            using (ITracer activity = tracer.StartActivity("ValidateGSDVersion", EventLevel.Informational))
            {
                Version currentVersion = new Version(ProcessHelper.GetCurrentProcessVersion());

                IEnumerable <ServerGSDConfig.VersionRange> allowedGvfsClientVersions =
                    config != null
                    ? config.AllowedGSDClientVersions
                    : null;

                if (allowedGvfsClientVersions == null || !allowedGvfsClientVersions.Any())
                {
                    errorMessage = "WARNING: Unable to validate your GSD version" + Environment.NewLine;
                    if (config == null)
                    {
                        errorMessage += "Could not query valid GSD versions from: " + Uri.EscapeUriString(enlistment.RepoUrl);
                    }
                    else
                    {
                        errorMessage += "Server not configured to provide supported GSD versions";
                    }

                    return(false);
                }

                foreach (ServerGSDConfig.VersionRange versionRange in config.AllowedGSDClientVersions)
                {
                    if (currentVersion >= versionRange.Min &&
                        (versionRange.Max == null || currentVersion <= versionRange.Max))
                    {
                        activity.RelatedEvent(
                            EventLevel.Informational,
                            "GSDVersionValidated",
                            new EventMetadata
                        {
                            { "SupportedVersionRange", versionRange },
                        });

                        enlistment.SetGSDVersion(currentVersion.ToString());
                        return(true);
                    }
                }

                activity.RelatedError("GSD version {0} is not supported", currentVersion);
            }

            errorMessage = "ERROR: Your GSD version is no longer supported.  Install the latest and try again.";
            errorIsFatal = true;
            return(false);
        }