Beispiel #1
0
        public string ExtractVersion(string versionPatternOrSeedFilePath, string packageId, string queryString, string sourcesDirectory)
        {
            var versionPattern = string.Empty;

            #region Validate Parameters

            if (string.IsNullOrWhiteSpace(versionPatternOrSeedFilePath))
            {
                throw new ArgumentNullException(versionPatternOrSeedFilePath);
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(packageId);
            }

            if (string.IsNullOrWhiteSpace(sourcesDirectory))
            {
                throw new ArgumentNullException(sourcesDirectory);
            }

            if (string.IsNullOrWhiteSpace(queryString))
            {
                throw new ArgumentNullException(queryString);
            }

            #endregion

            //var regex = new Regex(@"^(\d+\.)?((\d+|[a-zA-Z])\.)?((\d+|[a-zA-Z])\.)?(\*|\d+|[a-zA-Z])$");

            var regex =
                new Regex(
                    @"^(\d+)?(\.((\d{1,5})|([a-zA-Z]{1,4})))?(\.((\d{1,5})|([a-zA-Z]{1,9})))?(\.((\d)+|(\d+[a-zA-Z0-9+-]*)|([a-zA-Z]{1,9})|([a-zA-Z]{1,9})([-|+][a-zA-Z0-9+-]*)|(\*)))?$");

            var match = regex.Match(versionPatternOrSeedFilePath);

            // Was the value passed in actually an version pattern)
            if (match.Success)
            {
                // Write to the log

                versionPattern = versionPatternOrSeedFilePath;
            }
            else //
            {
                // full path or do i have to create one?
                var seedFilePath = Path.IsPathRooted(versionPatternOrSeedFilePath)
                                        ? versionPatternOrSeedFilePath
                                        : Path.Combine(sourcesDirectory, versionPatternOrSeedFilePath);

                if (File.Exists(seedFilePath))
                {
                    var xPathQuery = string.Format(queryString, packageId);

                    var xmlGetElement = new XmlGetElement();

                    versionPattern = xmlGetElement.GetXmlElementValue(seedFilePath, xPathQuery, "", "");
                }
            }

            return(versionPattern);
        }
        public string ExtractVersion(string versionPatternOrSeedFilePath, string packageId, string queryString, string sourcesDirectory)
        {
            var versionPattern = string.Empty;

            #region Validate Parameters

            if (string.IsNullOrWhiteSpace(versionPatternOrSeedFilePath))
            {
                throw new ArgumentNullException(versionPatternOrSeedFilePath);
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(packageId);
            }

            if (string.IsNullOrWhiteSpace(sourcesDirectory))
            {
                throw new ArgumentNullException(sourcesDirectory);
            }

            if (string.IsNullOrWhiteSpace(queryString))
            {
                throw new ArgumentNullException(queryString);
            }

            #endregion

            //var regex = new Regex(@"^(\d+\.)?((\d+|[a-zA-Z])\.)?((\d+|[a-zA-Z])\.)?(\*|\d+|[a-zA-Z])$");

            var regex =
                new Regex(
                    @"^(\d+)?(\.((\d{1,5})|([a-zA-Z]{1,4})))?(\.((\d{1,5})|([a-zA-Z]{1,9})))?(\.((\d)+|(\d+[a-zA-Z0-9+-]*)|([a-zA-Z]{1,9})|([a-zA-Z]{1,9})([-|+][a-zA-Z0-9+-]*)|(\*)))?$");

            var match = regex.Match(versionPatternOrSeedFilePath);

            // Was the value passed in actually an version pattern)
            if (match.Success)
            {
                // Write to the log

                versionPattern = versionPatternOrSeedFilePath;
            }
            else //
            {
                // full path or do i have to create one?
                var seedFilePath = Path.IsPathRooted(versionPatternOrSeedFilePath)
                                        ? versionPatternOrSeedFilePath
                                        : Path.Combine(sourcesDirectory, versionPatternOrSeedFilePath);

                if (File.Exists(seedFilePath))
                {
                    var xPathQuery = string.Format(queryString, packageId);

                    var xmlGetElement = new XmlGetElement();

                    versionPattern = xmlGetElement.GetXmlElementValue(seedFilePath, xPathQuery, "", "");
                }
            }

            return versionPattern;
        }