public IEnumerable<SystemReference> Load(string rootPath, SystemReference reference) { if (reference == null) { throw new ArgumentNullException("reference"); } rootPath = rootPath.Reslash(); // Ensure we have the root path separate from the reference var rootIndex = reference.Path.IndexOf(rootPath, StringComparison.OrdinalIgnoreCase); var relativePath = reference.Path; if (rootIndex >= 0) { relativePath = relativePath.Substring(rootIndex+rootPath.Length); } var results = Parse(rootPath, relativePath, reference.Name); if (!results.Any()) { yield return reference;//.ToSystemReference(rootPath); } CheckForCircularReferences(results); // Return the files in the correct order var processed = new List<Reference>(); var loops = 0; var maxLoops = results.Count; while (results.Any()) { if (loops++ > maxLoops) { throw new StackOverflowException(); } var noDependencies = results .Where(x => x.Value.Count(v => !processed.Contains(v)) == 0) .ToList(); if (!noDependencies.Any()) { throw new Exception("Unable to add order, there aren't any files that don't have a dependency"); } for (int index = 0; index < noDependencies.Count; index++) { var noDependency = noDependencies[index]; processed.Add(noDependency.Key); results.Remove(noDependency.Key); if (index == noDependencies.Count - 1) { noDependency.Key.Wait = true; } yield return noDependency.Key; } } }
public string GenerateReference(SystemReference reference) { var relativePath = reference.RelativePath(true); var wait = reference.Wait ? ".wait()" : ""; return reference.Name.EndsWith("-module") ? string.Format(".script(\"/hotglue.axd{0}&name={2}\"){1}", relativePath, wait, string.Join("&name=", reference.ReferenceNames)) : string.Format(".script(\"/hotglue.axd{0}\"){1}", relativePath, wait); }
public string GenerateReference(SystemReference reference) { var relativePath = reference.RelativePath(true); return reference.Name.EndsWith("-module") ? string.Format("<script src=\"/hotglue.axd{0}&name={1}\"></script>", relativePath, string.Join("&name=", reference.ReferenceNames)) : string.Format("<script src=\"/hotglue.axd{0}\"></script>", relativePath) + Environment.NewLine; }
public static string Reference( HelperContext context, HelperOptions options, string root, IEnumerable<string> names) { var package = Package.Build(context.Configuration, root); var references = new List<SystemReference>(); if (context.Debug) { foreach (var name in names) { var cleanedName = name.Reslash(); string file = cleanedName.StartsWith("/") ? cleanedName.Substring(1) : Path.Combine(context.Configuration.ScriptPath.Reslash(), cleanedName).Reslash(); file = file.StartsWith("/") ? file.Substring(1) : file; cleanedName = file.Substring(file.LastIndexOf("/", StringComparison.Ordinal) + 1); var reference = new SystemReference(new DirectoryInfo(root), new FileInfo(Path.Combine(root, file)), cleanedName); references.AddRange(context.Locator.Load(root, reference)); } return package.GenerateReferences(references, options); } foreach (var name in names) { var appName = name + "-glue"; var appDirectory = new DirectoryInfo(root); var appFile = new FileInfo(Path.Combine(root + context.Configuration.ScriptPath, appName)); var appReference = new SystemReference(appDirectory, appFile, appName) { Type = Model.Reference.TypeEnum.App }; references.Add(appReference); } return package.GenerateReferences(references, options); }
public static string Compile(string rootPath, string filePath, string fileName) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException("rootPath"); } if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } var config = LoadedConfiguration.Load(HotGlueConfiguration.Default()); var locator = new GraphReferenceLocator(config); var directoryInfo = new DirectoryInfo(rootPath); var fileInfo = new FileInfo(Path.Combine(filePath, fileName)); var reference = new SystemReference(directoryInfo, fileInfo, fileName); var references = locator.Load(rootPath, reference); var package = Package.Build(config, rootPath); return package.Compile(references); }
public SystemReference Clone(string suffix) { var clone = new SystemReference { ReferenceNames = ReferenceNames, SystemPath = SystemPath, Name = Name + suffix, Extension = Extension, Path = Path, Type = Type, Wait = Wait }; return clone; }
public static SystemReference Build(Reference.TypeEnum type, string fullPath, string rootPath, string keys) { var name = System.IO.Path.GetFileName(fullPath).RealFileName(); var directory = System.IO.Path.GetDirectoryName(fullPath); var reference = new SystemReference(new DirectoryInfo(rootPath), new FileInfo(System.IO.Path.Combine(directory, name)), name) { Type = type }; foreach (var key in keys.Split(',')) { reference.ReferenceNames.Add(key); } return reference; }
// recursive function private void Parse(DirectoryInfo rootDirectory, String relativePath, RelativeReference relativeReference, ref Dictionary<SystemReference, IList<RelativeReference>> references) { String currentPath = Path.Combine(rootDirectory.FullName, relativePath); SystemReference systemReference = null; var modifiedPath = Regex.Replace(relativeReference.ReferenceName, "^~/", "/"); var referenceIsAbsolutePath = !string.IsNullOrEmpty(relativeReference.ReferenceName) && (modifiedPath[0] == '/'); var filePath = referenceIsAbsolutePath ? Path.Combine(rootDirectory.FullName, modifiedPath.Substring(1)) : Path.Combine(currentPath, relativeReference.ReferenceName); var fileReference = new FileInfo(filePath); // Doesn't really exist, just create the system reference and return if (relativeReference.Type == Reference.TypeEnum.Generated) { systemReference = new SystemReference(rootDirectory, fileReference, relativeReference.ReferenceName) { Type = relativeReference.Type }; relativeReference.UpdateFromSystemReference(systemReference); if (!references.ContainsKey(systemReference)) { references.Add(systemReference, new List<RelativeReference>()); } return; } if (fileReference.Exists) { systemReference = new SystemReference(rootDirectory, fileReference, relativeReference.ReferenceName) { Type = relativeReference.Type }; } if (systemReference == null) { throw new FileNotFoundException(String.Format("Unable to find the file: '{0}' in the current path: '{1}'.", relativeReference.Name, filePath)); } relativeReference.UpdateFromSystemReference(systemReference); // We check for library references here rather than below, because we have the actual file path now if (relativeReference.Type == Reference.TypeEnum.Library) { if (!references.ContainsKey(systemReference)) { references.Add(systemReference, new List<RelativeReference>()); } return; } var newRelativeReferences = GetReferences(systemReference, ref references); foreach (var reference in newRelativeReferences) { Parse(rootDirectory, systemReference.Path, reference, ref references); } }
private IList<RelativeReference> GetReferences(SystemReference reference, ref Dictionary<SystemReference, IList<RelativeReference>> references) { if (references.ContainsKey(reference)) { // Duplicates within the different files with different types CheckForDuplicateReference(reference, references.Keys); // if its not a duplicate reference type, but has a different reference name, add it to the collection var existing = references.Single(x => x.Key.Equals(reference)); if (!existing.Key.ReferenceNames.Contains(reference.ReferenceNames.Single())) { existing.Key.ReferenceNames.Add(reference.ReferenceNames.Single()); } return new List<RelativeReference>(); // already parsed file } references.Add(reference, new List<RelativeReference>()); var text = File.ReadAllText(reference.FullPath); var currentReferences = new List<RelativeReference>(); foreach (var findReference in _configuration.FindReferences) { currentReferences.AddRange(findReference.Parse(text)); } var list = references[reference]; foreach (var currentReference in currentReferences.OrderBy(r => r.Index)) { // find any duplicate references for the same type in the file and remove. // look off the full referenced name and not the internal equals name if (!list.Any(x => x.ReferenceName.Equals(currentReference.ReferenceName, StringComparison.OrdinalIgnoreCase))) { list.Add(currentReference); } else { // Duplicates within the same file with different types CheckForDuplicateReference(currentReference, list); } } return list; }
public void ShouldMatch(SystemReference[] good, List<SystemReference> generated) { generated.Count.ShouldBe(good.Length); // check in list for (int index = 0; index < good.Length; index++) { var reference = good[index]; generated.Contains(reference).ShouldBe(true); ShouldMatch(reference, generated[index]); } }
public SystemReference BuildReference(string path, string name, Reference.TypeEnum type) { var root = new DirectoryInfo("../../"); var reference = new SystemReference(root, new FileInfo(Path.Combine(root.FullName, configuration.ScriptPath + path + "/" + name)), name) { Type = type }; return reference; }