本文整理汇总了C#中BundleResponse类的典型用法代码示例。如果您正苦于以下问题:C# BundleResponse类的具体用法?C# BundleResponse怎么用?C# BundleResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BundleResponse类属于命名空间,在下文中一共展示了BundleResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
/// <summary>
/// Processes the specified bundle of LESS files.
/// </summary>
/// <param name="context"> </param>
/// <param name="bundle">The LESS bundle.</param>
public void Process(BundleContext context, BundleResponse bundle)
{
if (bundle == null)
throw new ArgumentNullException("bundle");
context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();
var parser = new Parser();
var engine = new LessEngine(parser);
var content = new StringBuilder();
foreach (var file in bundle.Files)
{
// set current file path
SetCurrentFilePath(parser, file.FullName);
var text = File.ReadAllText(file.FullName);
var css = engine.TransformToCss(text, file.FullName);
content.AppendLine(css);
// content.Append(engine.TransformToCss(text, file.FullName));
// content.AppendLine();
AddFileDependencies(parser);
}
bundle.Content = content.ToString();
bundle.ContentType = "text/css";
}
示例2: Process
public override void Process(BundleResponse bundle)
{
var compiler = new CoffeeScriptEngine();
bundle.Content = compiler.Compile(bundle.Content);
base.Process(bundle);
}
示例3: Process
public void Process(BundleContext context, BundleResponse response)
{
var compiler = new HandlebarsCompiler();
var templates = new Dictionary<string, string>();
var server = context.HttpContext.Server;
foreach (var bundleFile in response.Files)
{
var filePath = server.MapPath(bundleFile.VirtualFile.VirtualPath);
var bundleRelativePath = GetRelativePath(server, bundleFile, filePath);
var templateName = namer.GenerateName(bundleRelativePath, bundleFile.VirtualFile.Name);
var template = File.ReadAllText(filePath);
var compiled = compiler.Precompile(template, false);
templates[templateName] = compiled;
}
StringBuilder javascript = new StringBuilder();
foreach (var templateName in templates.Keys)
{
javascript.AppendFormat("Ember.TEMPLATES['{0}']=", templateName);
javascript.AppendFormat("Ember.Handlebars.template({0});", templates[templateName]);
}
var Compressor = new JavaScriptCompressor();
var compressed = Compressor.Compress(javascript.ToString());
response.ContentType = "text/javascript";
response.Cacheability = HttpCacheability.Public;
response.Content = compressed;
}
示例4: Process
public virtual void Process(BundleContext context, BundleResponse response)
{
var file = VirtualPathUtility.GetFileName(context.BundleVirtualPath);
if (!context.BundleCollection.UseCdn)
{
return;
}
if (string.IsNullOrWhiteSpace(ContainerName))
{
throw new Exception("ContainerName Not Set");
}
var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
var conn = CloudStorageAccount.Parse(connectionString);
var cont = conn.CreateCloudBlobClient().GetContainerReference(ContainerName);
cont.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
var blob = cont.GetBlockBlobReference(file);
blob.Properties.ContentType = response.ContentType;
blob.UploadText(response.Content);
var uri = string.IsNullOrWhiteSpace(CdnHost) ? blob.Uri.AbsoluteUri.Replace("http:", "").Replace("https:", "") : string.Format("{0}/{1}/{2}", CdnHost, ContainerName, file);
using (var hashAlgorithm = CreateHashAlgorithm())
{
var hash = HttpServerUtility.UrlTokenEncode(hashAlgorithm.ComputeHash(Encoding.Unicode.GetBytes(response.Content)));
context.BundleCollection.GetBundleFor(context.BundleVirtualPath).CdnPath = string.Format("{0}?v={1}", uri, hash);
}
}
示例5: Process
/// <summary>
/// The process.
/// </summary>
/// <param name="context">
/// The context.
/// </param>
/// <param name="bundleResponse">
/// The bundle response.
/// </param>
/// <exception cref="ArgumentNullException">
/// Argument NULL Exception
/// </exception>
public void Process(BundleContext context, BundleResponse bundleResponse)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (bundleResponse == null)
{
throw new ArgumentNullException("bundleResponse");
}
context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();
IEnumerable<BundleFile> bundleFiles = bundleResponse.Files;
bundleResponse.Content = Process(ref bundleFiles);
// set bundle response files back (with imported ones)
if (context.EnableOptimizations)
{
bundleResponse.Files = bundleFiles;
}
bundleResponse.ContentType = "text/css";
}
示例6: Process
public void Process(BundleContext context, BundleResponse response)
{
var config = new DotlessConfiguration();
// config.Plugins.Add(new BuildNumberPluginConfigurator());
response.Content = Less.Parse(response.Content, config);
response.ContentType = "text/css";
}
示例7: Process
public override void Process(BundleContext context, BundleResponse response)
{
var compressor = new CssCompressor();
response.Content = compressor.Compress(response.Content);
response.ContentType = ContentTypes.Css;
}
示例8: TransformUrls
private void TransformUrls(BundleContext context, BundleResponse response)
{
response.Content = String.Empty;
var builder = new StringBuilder();
foreach (var cssFileInfo in response.Files)
{
if (cssFileInfo.VirtualFile == null) continue;
string content;
using (var streamReader = new StreamReader(cssFileInfo.VirtualFile.Open())) { content = streamReader.ReadToEnd(); }
if (content.IsNullOrWhiteSpace()) continue;
var matches = _pattern.Matches(content);
if (matches.Count > 0)
{
foreach (Match match in matches)
{
var cssRelativeUrl = match.Groups[2].Value;
var rootRelativeUrl = TransformUrl(context, cssRelativeUrl, cssFileInfo);
var quote = match.Groups[1].Value;
var replace = String.Format("url({0}{1}{0})", quote, rootRelativeUrl);
content = content.Replace(match.Groups[0].Value, replace);
}
}
builder.AppendLine(content);
}
response.ContentType = "text/css";
response.Content = builder.ToString();
}
示例9: Process
public void Process(BundleContext context, BundleResponse response)
{
Assert.ArgumentNotNull(response, "response");
response.Content = new CssCompressor().Compress(response.Content);
response.ContentType = "text/css";
}
示例10: Process
public void Process(BundleContext context, BundleResponse response)
{
var builder = new StringBuilder();
foreach (var file in response.Files)
{
var path =
context.HttpContext.Server.MapPath(
file.IncludedVirtualPath);
var fileInfo = new FileInfo(path);
if (!fileInfo.Exists)
{
continue;
}
var content = ResolveImports(fileInfo);
builder.AppendLine(
_configuration.Web
? dotless.Core.LessWeb.Parse(content, _configuration)
: dotless.Core.Less.Parse(content, _configuration));
}
response.ContentType = ContentType.Css;
response.Content = builder.ToString();
}
示例11: Process
public void Process(BundleContext context, BundleResponse response)
{
var output = new StringBuilder();
var errors = new StringBuilder();
var applicationFolder = context.HttpContext.Server.MapPath(@"~/");
var nodejs = Path.GetFullPath(applicationFolder + @"..\nodejs");
foreach (var file in response.Files)
{
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo
{
FileName = Path.Combine(nodejs, "node.exe"),
Arguments = Path.Combine(nodejs, @"node_modules\less\bin\lessc") + " " + file.FullName,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = applicationFolder,
};
process.OutputDataReceived += (sender, e) => output.AppendLine(e.Data);
process.ErrorDataReceived += (sender, e) => { if (!String.IsNullOrWhiteSpace(e.Data)) errors.AppendLine(e.Data); };
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
}
if (!String.IsNullOrEmpty(errors.ToString())) throw new LessParsingException(errors.ToString());
response.ContentType = "text/css";
response.Content = output.ToString();
}
示例12: Process
/// <summary>
/// Transforms the content in the <see cref="T:System.Web.Optimization.BundleResponse" /> object.
/// </summary>
/// <param name="context">The bundle context.</param>
/// <param name="response">The bundle response.</param>
public void Process(BundleContext context, BundleResponse response)
{
if (!context.EnableInstrumentation)
{
Manager.Process(response.Files.Select(x => new Asset(x.IncludedVirtualPath)).ToList<IAsset>(), context, response);
}
}
示例13: Process
public void Process(BundleContext context, BundleResponse response)
{
var sharedLessFile = CreateSharedLessFile(response.Files);
response.Content = GenerateCss(sharedLessFile, context);
response.ContentType = "text/css";
}
示例14: Process
public virtual void Process(BundleContext context, BundleResponse response)
{
#if DEBUG
// set BundleContext.UseServerCache to false in order to process all bundle request and generate dynamic response
context.UseServerCache = false;
response.Cacheability = HttpCacheability.NoCache;
#endif
var contentBuilder = new StringBuilder();
contentBuilder.AppendLine("// Created on: " + DateTime.Now.ToString(CultureInfo.InvariantCulture));
contentBuilder.AppendLine("require(['angular'], function(angular) {");
contentBuilder.AppendLine(" angular.module('bundleTemplateCache', []).run(['$templateCache', function($templateCache) {");
contentBuilder.AppendLine(" $templateCache.removeAll();");
foreach (BundleFile file in response.Files)
{
string fileId = VirtualPathUtility.ToAbsolute(file.IncludedVirtualPath);
string filePath = HttpContext.Current.Server.MapPath(file.IncludedVirtualPath);
string fileContent = File.ReadAllText(filePath);
contentBuilder.AppendFormat(" $templateCache.put({0},{1});" + Environment.NewLine,
JsonConvert.SerializeObject(fileId),
JsonConvert.SerializeObject(fileContent));
}
contentBuilder.AppendLine(" }]);");
contentBuilder.AppendLine("});");
response.Content = contentBuilder.ToString();
response.ContentType = "text/javascript";
}
示例15: Process
public void Process(BundleContext context, BundleResponse response)
{
string content = response.get_Content();
StringBuilder stringBuilder = new StringBuilder();
char[] chrArray = new char[1];
chrArray[0] = '\n';
string[] strArrays = content.Split(chrArray);
for (int i = 0; i < (int)strArrays.Length; i++)
{
string str = strArrays[i];
Match match = Regex.Match(str, "url\\([\\\"\\'](.*)\\?embed[\\\"\\']\\)");
if (match.Success)
{
string str1 = match.Result("$1");
str1 = ConvertCssUrlsToDataUris.CleanPath(str1);
try
{
str1 = HttpContext.Current.Server.MapPath(str1);
}
catch (ArgumentException argumentException)
{
throw new Exception(string.Concat("Illegal Characters : ", str1));
}
stringBuilder.AppendLine(str.Replace(match.Result("$0"), this.GetDataUri(str1)));
stringBuilder.AppendLine(str.Replace("background", "*background"));
}
else
{
stringBuilder.Append(str);
}
}
response.set_ContentType("text/css");
response.set_Content(stringBuilder.ToString());
}