示例#1
0
        /// <summary>The method called from the regex replace to replace the matched wgInclude() statements.</summary>
        /// <param name="match">The regex match</param>
        /// <param name="workingFolder">The working folder from which to determine relative path's in the include.</param>
        /// <param name="cacheSection">The cache Section.</param>
        /// <param name="minimalOutput">Is the goal to have the most minimal output (true skips lots of comments)</param>
        /// <returns>The contents of the file to replace, with a /* WGINCLUDE [fullFilePath] */ header on top.</returns>
        private static string ReplaceInputs(Match match, string workingFolder, ICacheSection cacheSection, bool minimalOutput)
        {
            var fileOrPath = Path.Combine(workingFolder, match.Groups["fileOrPath"].Value.Trim());
            var inputSpec  = new InputSpec {
                IsOptional = true, Path = fileOrPath
            };

            if (Directory.Exists(fileOrPath))
            {
                inputSpec.SearchPattern = match.Groups["searchPattern"].Value.Trim();
            }

            cacheSection.AddSourceDependency(inputSpec);

            var result = string.Empty;

            foreach (var file in inputSpec.GetFiles())
            {
                if (!minimalOutput)
                {
                    result += "/* WGINCLUDE: {0} */\r\n".InvariantFormat(file);
                }

                result += File.ReadAllText(file) + "\r\n";
            }

            return(result);
        }
示例#2
0
 /// <summary>Gets a unique hash for the input spec.</summary>
 /// <param name="context">The context.</param>
 /// <param name="inputSpec">The input spec.</param>
 /// <returns>The unique hash>.</returns>
 private static string GetInputSpecHash(IWebGreaseContext context, InputSpec inputSpec)
 {
     return
         (inputSpec.GetFiles(context.Configuration.SourceDirectory)
          .ToDictionary(f => f.MakeRelativeToDirectory(context.Configuration.SourceDirectory), context.GetFileHash)
          .ToJson());
 }