Exemple #1
0
        private void WatchChanges(BundleCacheItem cacheValue, List <string> files, string bundleRelativePath)
        {
            lock (cacheValue.WatchDisposeHandles)
            {
                foreach (var file in files)
                {
                    var watchDisposeHandle = WebContentFileProvider.Watch(file).RegisterChangeCallback(_ =>
                    {
                        lock (cacheValue.WatchDisposeHandles)
                        {
                            cacheValue.WatchDisposeHandles.ForEach(h => h.Dispose());
                            cacheValue.WatchDisposeHandles.Clear();
                        }

                        BundleCache.Remove(bundleRelativePath);
                        DynamicFileProvider.Delete("/wwwroot/" + bundleRelativePath); //TODO: get rid of wwwroot!
                    }, null);

                    cacheValue.WatchDisposeHandles.Add(watchDisposeHandle);
                }
            }
        }
Exemple #2
0
        protected string RenderDebug(string name = null)
        {
            string content = null;

            DependentFiles.Clear();

            var modifiedGroupBundles = BeforeRenderDebug();
            var sb = new StringBuilder();

            foreach (var groupBundleKVP in modifiedGroupBundles)
            {
                var groupBundle = groupBundleKVP.Value;
                var attributes  = GetAdditionalAttributes(groupBundle);
                var assets      = groupBundle.Assets;

                DependentFiles.AddRange(GetFiles(assets));
                foreach (var asset in assets)
                {
                    var inputFile = GetInputFile(asset);
                    var files     = inputFile.TryResolve(allowedExtensions);

                    if (asset.IsEmbeddedResource)
                    {
                        var tsb = new StringBuilder();

                        foreach (var fn in files)
                        {
                            tsb.Append(ReadFile(fn) + "\n\n\n");
                        }

                        var renderer      = new FileRenderer(fileWriterFactory);
                        var processedFile = ExpandAppRelativePath(asset.LocalPath);
                        renderer.Render(tsb.ToString(), FileSystem.ResolveAppRelativePathToFileSystem(processedFile));
                        sb.AppendLine(FillTemplate(groupBundle, processedFile));
                    }
                    else if (asset.RemotePath != null)
                    {
                        sb.AppendLine(FillTemplate(groupBundle, ExpandAppRelativePath(asset.LocalPath)));
                    }
                    else
                    {
                        foreach (var file in files)
                        {
                            var    relativePath = FileSystem.ResolveFileSystemPathToAppRelative(file);
                            string path;
                            if (HttpContext.Current == null)
                            {
                                path = (asset.LocalPath.StartsWith("~") ? "" : "/") + relativePath;
                            }
                            else
                            {
                                if (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/"))
                                {
                                    path = HttpRuntime.AppDomainAppVirtualPath + relativePath;
                                }
                                else
                                {
                                    path = HttpRuntime.AppDomainAppVirtualPath + "/" + relativePath;
                                }
                            }
                            sb.AppendLine(FillTemplate(groupBundle, path));
                        }
                    }
                }
            }

            foreach (var cntnt in arbitrary)
            {
                sb.AppendLine(string.Format(tagFormat, cntnt));
            }

            content = sb.ToString();

            if (bundleCache.ContainsKey(name))
            {
                bundleCache.Remove(name);
            }
            bundleCache.Add(name, content, DependentFiles);

            return(content);
        }