Example #1
0
        private bool ResolveEnvironmentVariables(IPatternResolutionContext context, StringBuilder resultBuilder)
        {
            Match match;
            do
            {
                match = envVarsRegex.Match(resultBuilder.ToString());

                if (match.Success)
                {
                    string value = context.GetEnvironmentVariable(match.Groups[1].Captures[0].Value);
                    if (value == null)
                    {
                        log.InfoFormat("Failed to resolve FS repository pattern {0}: environment variable {1} does not exists", pattern, match.Value);
                        return false;
                    }
                    else
                    {
                        resultBuilder.Remove(match.Index, match.Length);
                        resultBuilder.Insert(match.Index, value);
                    }
                }
            } while (match.Success);
            
            return true;
        }
        /// <summary>
        /// Resolves the given context using all the available patterns, checking their
        /// resolution in the file system as well.
        /// </summary>
        /// <param name="context">Resolution context</param>
        /// <returns>Returns the path to the dependency if resolution succeeded. Otherwise it returns <c>null</c>.</returns>
        public string Resolve(IPatternResolutionContext context)
        {
            Contract.Requires(context != null);

            foreach (RepositoryPattern pattern in patterns)
            {
                string res = pattern.Resolve(context);

                if (res != null)
                {
                    log.DebugFormat("Trying resolved FS repository path: {0}", res);

                    if (fsAccess.Exists(res))
                        return res;
                    else
                        log.DebugFormat("FS repository path `{0}` is invalid", res);
                }
            }
            return null;
        }
        /// <summary>
        /// Resolves the given context using all the available patterns, checking their
        /// resolution in the file system as well.
        /// </summary>
        /// <param name="context">Resolution context</param>
        /// <returns>Returns the path to the dependency if resolution succeeded. Otherwise it returns <c>null</c>.</returns>
        public PatternResolution Resolve(IPatternResolutionContext context)
        {
            Contract.Requires(context != null);

            var logLines = new StringBuilder();

            foreach (RepositoryPattern pattern in patterns)
            {
                string res = pattern.Resolve(context);

                if (res != null)
                {
                    logLines.AppendFormat("Trying resolved FS repository path: {0}\n", res);

                    if (fsAccess.Exists(res))
                        return PatternResolution.Success(res);
                    else
                        logLines.AppendFormat("FS repository path `{0}` is invalid\n", res);
                }
            }

            return PatternResolution.Failure(logLines.ToString());
        }
Example #4
0
        /// <summary>
        /// Tries to resolve the pattern using the given context
        /// </summary>
        /// <param name="context">The context to get variables from</param>
        /// <returns>Returns the resolved path to the dependency, or <c>null</c> if
        /// the resolution is not possible.</returns>
        public string Resolve(IPatternResolutionContext context)
        {
            Contract.Requires(context != null);

            var resultBuilder = new StringBuilder(pattern);

            if (!ResolveEnvironmentVariables(context, resultBuilder)) 
                return null;

            resultBuilder.Replace("%NAME", context.DependencyName);
            resultBuilder.Replace("%FILENAME", context.FileName);
            resultBuilder.Replace("%EXT", context.Extension);
            if (!string.IsNullOrEmpty(context.Version))
                resultBuilder.Replace("%VERSION", context.Version);
            else
            {                
                if (resultBuilder.ToString().IndexOf("%VERSION", System.StringComparison.InvariantCulture) >= 0)
                    // Pattern requires version but we don't have it
                    return null;
            }

            return resultBuilder.ToString();
        }