/// <summary> /// Создает объект, если в потоке /// </summary> /// <returns>Объект UnitOfWork</returns> public IUnitOfWork Create() { if (_local == null || _local.Disposed) { _local = new FileUnitOfWork(); } _local.InstanceCount += 1; return _local; }
public void ProcessDocument(HtmlDocument document, string documentPath, FileUnitOfWork unitOfWork) { Argument.NotNull("document", document); Argument.NotNullOrEmpty("documentPath", documentPath); var references = this.handler.SelectReferences(document); var bundles = new List <BundledSequence>(); var sequence = new List <HtmlNode>(); foreach (var reference in references) { var shouldProcess = IsLocalPath(this.handler.GetPath(reference)) && !reference.Attributes.Contains("data-bundled"); if (shouldProcess) { sequence.Add(reference); } else if (sequence.Count > 0) { bundles.Add(BundleSequence(sequence, documentPath, unitOfWork)); sequence = new List <HtmlNode>(); } } if (sequence.Count > 0) { bundles.Add(BundleSequence(sequence, documentPath, unitOfWork)); } foreach (var bundle in bundles) { var bundleNode = ReplaceNodesInDocumentWithBundleNode(bundle); unitOfWork.RequestFile( this.handler.FileExtension, bundle.Content, path => this.handler.SetPath(bundleNode, GetRelativePath(documentPath, path)) ); } }
private BundledSequence BundleSequence(IList <HtmlNode> sequence, string documentPath, FileUnitOfWork unitOfWork) { var parentPath = Path.GetDirectoryName(documentPath); var settings = new OptimizationSettings { BundleTable = new BundleCollection(), ApplicationPath = parentPath }; var paths = sequence.Select(r => this.handler.GetPath(r)).ToArray(); var bundle = new Bundle("~/stub") .Include(paths.Select(p => "~/" + p).ToArray()); bundle.Transforms.Add(this.handler.Transform); settings.BundleTable.Add(bundle); var response = Optimizer.BuildBundle(bundle.Path, settings); foreach (var path in paths) { unitOfWork.RequestDelete(Path.Combine(parentPath, path)); } return(new BundledSequence(sequence, response.Content)); }