コード例 #1
0
        /// <summary>
        /// Validates the version spec string.
        /// </summary>
        private void ValidateSelectedVersionSpecString()
        {
            var    value                   = SelectedVersionSpecString;
            string validationMessage       = null;
            string latestVersionSpecOption = _versionSpecToDisplayStringDictionary["H"];

            if (string.IsNullOrEmpty(value) && !SelectedVersionSpecs.Equals(latestVersionSpecOption, StringComparison.OrdinalIgnoreCase))
            {
                validationMessage = "Revision is required!";
            }
            else
            {
                string versionSpecOption;
                // ReSharper disable AssignNullToNotNullAttribute
                _displayStringToVersionSpecDictionary.TryGetValue(SelectedVersionSpecs, out versionSpecOption);
                // ReSharper restore AssignNullToNotNullAttribute

                int tmp;

                if ((versionSpecOption.StartsWith("R")) && (!int.TryParse(value.Trim(), out tmp)))
                {
                    validationMessage = string.Format("{0} version spec is invalid!", SelectedVersionSpecs);
                }
            }

            if (validationMessage != null)
            {
                AddError("SelectedVersionSpecString", validationMessage);
            }
            else
            {
                RemoveError("SelectedVersionSpecString");
            }
        }
        /// <summary>
        /// Validates the version spec string.
        /// </summary>
        private void ValidateSelectedVersionSpecString()
        {
            var    value             = SelectedVersionSpecString;
            string validationMessage = null;
            string latestVersionSpecOption;

            _versionSpecToDisplayStringDictionary.TryGetValue(VersionSpec.Latest.DisplayString, out latestVersionSpecOption);

            if (string.IsNullOrEmpty(value) && !SelectedVersionSpecs.Equals(latestVersionSpecOption, StringComparison.OrdinalIgnoreCase))
            {
                validationMessage = "Version spec is required!";
            }
            else
            {
                string versionSpecOption;
                // ReSharper disable AssignNullToNotNullAttribute
                _displayStringToVersionSpecDictionary.TryGetValue(SelectedVersionSpecs, out versionSpecOption);
                // ReSharper restore AssignNullToNotNullAttribute
                try
                {
                    // ReSharper disable PossibleNullReferenceException
                    if (versionSpecOption.Equals("W", StringComparison.OrdinalIgnoreCase))
                    // ReSharper restore PossibleNullReferenceException
                    {
                        var user = value.Split(';')[1];
                        VersionSpec.ParseSingleSpec(string.Concat(versionSpecOption, value), user);
                    }
                    else
                    {
                        VersionSpec.ParseSingleSpec(string.Concat(versionSpecOption, value), null);
                    }
                }
                catch (Exception)
                {
                    validationMessage = string.Format("{0} version spec is invalid!", SelectedVersionSpecs);
                }
            }

            if (validationMessage != null)
            {
                AddError("SelectedVersionSpecString", validationMessage);
            }
            else
            {
                RemoveError("SelectedVersionSpecString");
            }
        }