public Classifier(ITextBuffer buffer) { this.buffer = buffer; fileNode = GlobalServices.GetFileNodeForBuffer(buffer); if (fileNode != null) fileNode.Recompiled += SourceRecompiled; }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } var treeDepth = file.GetTreeDepth(); if (treeDepth != 0) { var parent = file.Parent; var pathToParent = file.FileDepth != treeDepth ? $"./{parent.Name}.html" : $"../{parent.Name}.html"; var result = $"<a href=\"{pathToParent}\">{parent.Title}</a>"; var currentPath = file.FileDepth != treeDepth ? "../" : "../../"; while (parent.Parent != null) { parent = parent.Parent; pathToParent = $"{currentPath}{parent.Name}.html"; result = $"<a href=\"{pathToParent}\">{parent.Title}</a> <span>></span> {result}"; currentPath = $"../{currentPath}"; } file.Contents = file.Contents.Replace("{{breadcrumbs}}", result); } return(file); }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } var pattern = @"{{render (?<title>.*)}}"; var matches = Regex.Matches(file.Contents, pattern); if (matches.Count == 0) { return(file); } foreach (Match match in matches) { var partialTitle = match.Groups["title"].Value; if (this.partials.Any(p => p.Title == partialTitle)) { var partial = this.partials.Where(p => p.Title == partialTitle).First(); file.Contents = file.Contents.Replace( match.Value, partial.Contents ); } } return(file); }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } var currentDepth = file.FileDepth; var relativePath = string.Empty; if (currentDepth == 0) { relativePath = "./"; } else { while (currentDepth > 0) { relativePath += "../"; currentDepth--; } } file.Contents = file.Contents.Replace("{{relative-root}}", relativePath); return(file); }
/// <summary> /// Initializes a new instance of the <see cref="FileLinkedListBase" /> class. /// </summary> /// <param name="path">The file path.</param> /// <param name="root">The root node.</param> protected FileLinkedListBase (string path, IFileNode root) { FilePath = path; Root = root; }
public BooTypeAndMemberDropdownBars(BooLanguageService service, IFileNode fileNode) : base(service) { this.service = service; isDirty = true; fileNode.Recompiled += SourceRecompiled; barManager = new DropdownBarsManager(fileNode); }
public void Start(IFileNode[] fileNodes, IFileNodeBackupService backupService) { Progress = 1; Reporter(1, null); var fileCount = fileNodes.Select(f => backupService.CountExportFiles(f)).Sum(); Delta = 98.0 / Math.Max(fileCount, 1); Downloader.Downloading += OnDownloading; }
public VSMDBooCodeProvider(ReferenceContainerNode refs, IFileNode file) { _provider = new VSBooCodeProvider(GetReferences(refs).ToArray(), file); _references = refs; _file = file; refs.OnChildAdded += RefsOnOnChildListChanged; refs.OnChildRemoved += RefsOnOnChildListChanged; }
public Tagger(ITextBuffer buffer) { this.buffer = buffer; fileNode = GlobalServices.GetFileNodeForBuffer(buffer); if (fileNode != null) { fileNode.Recompiled += SourceRecompiled; } }
internal void SubmitForCompile(IFileNode file) { if (projectManager.IsCodeFile(file.Url) && file.ItemName == "Compile") { lock (compileList) { compileList.Add(file); } } }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate) { return(file); } if (!file.Contents.Contains("{{progress}}")) { return(file); } var numExercises = new Dictionary <int, int>(); numExercises.Add(1, 46); numExercises.Add(2, 97); numExercises.Add(3, 82); numExercises.Add(4, 79); numExercises.Add(5, 52); var divs = string.Empty; foreach (KeyValuePair <int, int> kvp in numExercises) { for (var i = 1; i <= kvp.Value; i++) { var style = "link"; var link = string.Empty; if (this.statistics.ContainsKey(kvp.Key) && this.statistics[kvp.Key].ContainsKey(i)) { if (this.statistics[kvp.Key][i].Completed == true) { style += " done"; } else { style += " half"; } var href = $"{this.statistics[kvp.Key][i].Link}#Exercise {kvp.Key}.{i}"; link = $"<a class=\"problem-link\" href=\"{href}\"></a>"; } divs += $"<div class=\"{style}\" title=\"Exercise {kvp.Key}.{i}\">{link}</div>\n"; } } var contents = $"<div id=\"vis\">{Environment.NewLine}{divs}{Environment.NewLine}</div>"; file.Contents = file.Contents.Replace("{{progress}}", contents); return(file); }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } file.Contents = Regex.Replace(file.Contents, @"{{\w+}}", string.Empty); return(file); }
private void PostProcessRecursively(IFileNode node) { foreach (var transformer in this.postTransformers) { node = transformer.Transform(node); } for (var i = 0; i < node.Children.Count; i++) { this.PostProcessRecursively(node.Children[i]); } }
public static TextSpan GetTextSpan(this Node node, IFileNode fileNode) { var start = fileNode.MapPosition(node.LexicalInfo.Line, node.LexicalInfo.Column); var end = fileNode.MapPosition(node.EndSourceLocation.Line, node.EndSourceLocation.Column); return new TextSpan { iStartLine = start.Line, iStartIndex = start.Column, iEndLine = end.Line, iEndIndex = end.Column }; }
public BooSource(BooLanguageService service, string filePath, IVsTextLines buffer, Microsoft.VisualStudio.Package.Colorizer colorizer) : base(service, buffer, colorizer) { projectManager = GlobalServices.GetProjectManagerForFile(filePath); fileNode = projectManager.GetFileNode(filePath); fileNode.ShowMessages(); fileNode.Recompiled += (sender, eventArgs) => service.Invoke( new Action<BooLanguageService>(SynchronizeDropDowns), new object[] {service} ); }
public void Backup(IFileNode fileNode, string destinationDirectory) { EnsureIsNotBusy(); try { BackupRecursively(fileNode, destinationDirectory); } finally { Finish(); } }
public BooSource(BooLanguageService service, string filePath, IVsTextLines buffer, Microsoft.VisualStudio.Package.Colorizer colorizer) : base(service, buffer, colorizer) { projectManager = GlobalServices.GetProjectManagerForFile(filePath); fileNode = projectManager.GetFileNode(filePath); fileNode.ShowMessages(); fileNode.Recompiled += (sender, eventArgs) => service.Invoke( new Action <BooLanguageService>(SynchronizeDropDowns), new object[] { service } ); }
public static TextSpan GetTextSpan(this Node node, IFileNode fileNode) { var start = fileNode.MapPosition(node.LexicalInfo.Line, node.LexicalInfo.Column); var end = fileNode.MapPosition(node.EndSourceLocation.Line, node.EndSourceLocation.Column); return(new TextSpan { iStartLine = start.Line, iStartIndex = start.Column, iEndLine = end.Line, iEndIndex = end.Column }); }
public IFileNode Transform(IFileNode file) { foreach (KeyValuePair <string, string> kvp in file.Keys) { file.Contents = file.Contents.Replace($"{{{{{kvp.Key}}}}}", kvp.Value); } foreach (KeyValuePair <string, string> kvp in file.Sections) { file.Contents = file.Contents.Replace($"{{{{{kvp.Key}}}}}", kvp.Value); } return(file); }
private void WriteOutput(IFileNode file) { if (!file.IsDraft) { var path = Path.Join(this.outputDirectory, file.RelativePath); Directory.CreateDirectory(path); this.fileIO.CreateFile(Path.Join(path, file.FullName), file.Contents); } foreach (var child in file.Children) { this.WriteOutput(child); } }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } var pattern = @"<h3 id=""\w+ \d+\.\d+"" class=""(?<tag>\w+-\w+)"">Exercise (?<title>\d+\.\d+)</h3>"; var matches = Regex.Matches(file.Contents, pattern); if (matches.Count == 0) { return(file); } foreach (Match match in matches) { var title = match.Groups["title"].Value; var chapter = int.Parse(title.Split('.').First()); var problem = int.Parse(title.Split('.').Last()); if (!this.statistics.ContainsKey(chapter)) { this.statistics.Add(chapter, new Dictionary <int, Statistic>()); } var tag = match.Groups["tag"].Value; if (tag == "completed-true") { this.statistics[chapter].Add(problem, new Statistic { Completed = true, Link = file.FullName }); } else { this.statistics[chapter].Add(problem, new Statistic { Completed = false, Link = file.FullName }); } } return(file); }
void AddNodeToTorrent(HtmlNode node, IResourceInfo torrent, IFileNode parentNode) { if (node == null) { return; } var nodes = node.SelectNodes("li"); foreach (var li in nodes) { var cls = li.Attributes["class"].Value; if (cls == "branch") { var bnode = new FileNode() { IsDirectory = true, Name = li.SelectSingleNode("span/text()").InnerText }; if (parentNode == null) { torrent.Add(bnode); } else { parentNode.Children.Add(bnode); } AddNodeToTorrent(li.SelectSingleNode("ul"), torrent, bnode); } else { var lnode = new FileNode() { IsDirectory = false, Name = li.SelectSingleNode("span[1]/text()").InnerText, SizeString = li.SelectSingleNode("span[2]/text()").InnerText }; if (parentNode == null) { torrent.Add(lnode); } else { parentNode.Children.Add(lnode); } } } }
/// <summary> /// Backs up the descendants of the given node into the specified directory. /// The name of the given folder will not be part of the created directory structure. /// </summary> public void BackupContents(IFileNode fileNode, string destinationDirectory) { EnsureIsNotBusy(); try { FileSystem.Directory.CreateDirectory(destinationDirectory); foreach (var childNode in fileNode.Children) { BackupRecursively(childNode, destinationDirectory); } } finally { Finish(); } }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } if (string.IsNullOrEmpty(file.Prev) && string.IsNullOrEmpty(file.Next)) { return(file); } var leftLink = string.Empty; var rightLink = string.Empty; var pages = file.GetSiblings(); if (!string.IsNullOrEmpty(file.Prev)) { var prevPage = pages.Where(p => p.Title == file.Prev).FirstOrDefault(); if (prevPage != null) { leftLink = $"<a href=\"{prevPage.Name}.html\" title=\"{prevPage.Title}\">Previous</a>"; } } else { leftLink = "<span> </span>"; } if (!string.IsNullOrEmpty(file.Next)) { var nextPage = pages.Where(p => p.Title == file.Next).FirstOrDefault(); if (nextPage != null) { rightLink = $"<a href=\"{nextPage.Name}.html\" title=\"{nextPage.Title}\">Next</a>"; } } else { rightLink = "<span> </span>"; } file.Contents += $"{Environment.NewLine}{Environment.NewLine}<div style=\"display: flex; justify-content: space-between\">{leftLink} {rightLink}</div>"; return(file); }
public int GetTreeDepth() { var depth = 0; IFileNode currentNode = this; if (currentNode.Parent == null) { return(depth); } while (currentNode.Parent != null) { currentNode = currentNode.Parent; depth++; } return(depth); }
public IFileNode Transform(IFileNode file) { if (file.UsesTemplate) { if (this.templates.Any(f => f.Name == file.TemplateName)) { file.Contents = this.templates .Where(f => f.Name == file.TemplateName) .First() .Contents .Replace("{{content}}", file.Contents.Trim()); file.TemplateName = string.Empty; } } return(file); }
public IFileNode Transform(IFileNode file) { if (file.Extension != ".md") { return(file); } if (file.IsPartial || file.IsTemplate) { return(file); } var sections = BuildPageSectionsFromContents(file.Contents); var rendered = RenderSections(sections); file.Contents = CombineSecions(rendered); file.FullName = $"{file.Name}.html"; return(file); }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } var tagRegex = new Regex(@"{{posts(\s""(?<path>[^""]*)"")?}}"); var matches = tagRegex.Matches(file.Contents); foreach (Match match in matches) { var specifiedTitle = match.Groups["path"]?.Value; var parent = string.IsNullOrWhiteSpace(specifiedTitle) ? file : this.pages.Where(p => p.Title == specifiedTitle).FirstOrDefault(); var posts = parent.Children.OrderBy(f => f.FullName).Reverse().ToList(); var result = string.Empty; foreach (var post in posts) { if (post.IsDraft) { continue; } var path = parent == file ? post.Name + ".html" : parent.RelativePath + "/" + post.Name + ".html"; var date = post.Keys["date"]; result += $"- <small>[{date}]</small> [{post.Title}]({path}){Environment.NewLine}"; } file.Contents = tagRegex.Replace(file.Contents, result); } return(file); }
private void ProcessTree(IFileNode root) { for (var i = 0; i < this.templates.Count; i++) { foreach (var transformer in this.transformers) { this.templates[i] = transformer.Transform(this.templates[i]); } } for (var i = 0; i < this.partials.Count; i++) { foreach (var transformer in this.transformers) { this.partials[i] = transformer.Transform(this.partials[i]); } } this.ProcessRecursively(root); this.PostProcessRecursively(root); }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } var pattern = "<pre><code>\\s*"; var matches = Regex.Matches(file.Contents, pattern); if (matches.Count == 0) { return(file); } foreach (Match match in matches) { var trimmed = match.Value.Trim(); file.Contents = file.Contents.Replace(match.Value, trimmed); } return(file); }
/// <summary> /// 加载内容 /// </summary> public override void LookupTorrentContents(IResourceInfo torrent) { var url = GetDetailUrl(torrent); var htmlContext = NetworkClient.Create <string>(HttpMethod.Get, url, _referUrl).Send(); if (!htmlContext.IsValid()) { return; } var html = htmlContext.Result.SearchStringTag("<div class=\"files\">", "<p>Please note"); if (string.IsNullOrEmpty(html)) { return; } var m = Regex.Match(html, @"<(ul|li|/ul)(\s*class=""t"")?>(([^<]+?)(\s*<span>([^<]+)</span>\s*)?)?\s*(?=<)", RegexOptions.Singleline | RegexOptions.IgnoreCase); var isTorrentSelfSkiped = false; //是否已经跳过种子本身 var nodesChain = new Stack <IFileNode>(); IFileNode parentNode = null; //当前父节点 IFileNode lastNode = null; //最后的节点 while (m.Success) { if (!isTorrentSelfSkiped) { isTorrentSelfSkiped = m.Groups[1].Value == "li"; } else if (m.Groups[1].Value == "/ul") { parentNode = nodesChain.Count > 0 ? nodesChain.Pop() : null; } else if (m.Groups[1].Value == "ul") { //开始文件夹列表 nodesChain.Push(parentNode); parentNode = lastNode; } else if (m.Groups[1].Value == "li" && !m.Groups[3].Success) { //文件夹的开始节点,忽略 } else if (m.Groups[2].Success) { //文件夹节点 var node = new FileNode() { IsDirectory = true, Name = m.Groups[4].Value }; lastNode = node; if (parentNode == null) { torrent.Add(node); } else { parentNode.Children.Add(node); } } else { //文件节点 var node = new FileNode() { IsDirectory = false, Name = m.Groups[4].Value, SizeString = m.Groups[6].Value ?? "" }; lastNode = node; if (parentNode == null) { torrent.Add(node); } else { parentNode.Children.Add(node); } } m = m.NextMatch(); } }
public int CountExportFiles(IFileNode fileNode) { DryRunFileSystem mockFileSystem = new DryRunFileSystem(); DryRunDriveService mockDriveService = new DryRunDriveService(); IFileSystem oldFileSystem = FileSystem; IDriveService oldDriveService = Downloader.DriveService; try { Downloader.DriveService = mockDriveService; Downloader.FileSystem = mockFileSystem; Backup(fileNode, null); return ((DryRunFileBase)mockFileSystem.File).CreateCount; } finally { Downloader.DriveService = oldDriveService; Downloader.FileSystem = oldFileSystem; } }
public IFileNode Transform(IFileNode file) { if (file.IsTemplate || file.IsPartial) { return(file); } var codeBlock = "<pre><code class=\"scheme(-run)?\">(?<contents>.*?)</code></pre>"; var matches = Regex.Matches(file.Contents, codeBlock, RegexOptions.Singleline); foreach (Match match in matches) { var contents = match.Groups["contents"].Value; var newContents = contents; var functions = new string[] { @"(?<pre>\(define\s+\()(?<fn>[^\s\)]+)(?<post>\s+)" // function define }; foreach (var fn in functions) { newContents = Regex.Replace( newContents, fn, "${pre}<span class=\"fn\">${fn}</span>${post}"); } var keywords = new string[] { @"(?<pre>\()(?<kw>define)(?<post>\s)", // define @"(?<pre>\()(?<kw>\+)(?<post>\s)", // + @"(?<pre>\()(?<kw>-)(?<post>\s)", // - @"(?<pre>\()(?<kw>\*)(?<post>\s)", // * @"(?<pre>\()(?<kw>/)(?<post>\s)", // / @"(?<pre>\()(?<kw>cond)(?<post>\s)", // cond @"(?<pre>\()(?<kw>if)(?<post>\s)", // if @"(?<pre>\()(?<kw>else)(?<post>\s)", // else @"(?<pre>\()(?<kw>and)(?<post>\s)", // and @"(?<pre>\()(?<kw>or)(?<post>\s)", // or @"(?<pre>\()(?<kw>=)(?<post>\s)", // = @"(?<pre>\()(?<kw><)(?<post>\s)", // > @"(?<pre>\()(?<kw>>)(?<post>\s)", // < @"(?<pre>\()(?<kw><=)(?<post>\s)", // >= @"(?<pre>\()(?<kw>>=)(?<post>\s)", // <= @"(?<pre>\()(?<kw>lambda)(?<post>\s)", // <= }; foreach (var keyword in keywords) { newContents = Regex.Replace( newContents, keyword, "${pre}<span class=\"keyword\">${kw}</span>${post}"); } var numbers = new string[] { @"(?<pre>\b)(?<nm>\d+\.?\d*)(?<post>\b)" }; foreach (var number in numbers) { newContents = Regex.Replace( newContents, number, "${pre}<span class=\"nm\">${nm}</span>${post}"); } var brackets = @"(?<brace>[\(\)])"; newContents = Regex.Replace(newContents, brackets, "<span class=\"brace\">${brace}</span>"); file.Contents = file.Contents.Replace(contents, newContents); } return(file); }
public DropdownBarsManager(IFileNode file) { this.file = file; }
public void SubmitForCompile(IFileNode file) { compilerManager.SubmitForCompile(file); }
private IFileNode ReadInput(string relativePath, int fileDepth, IFileNode parent) { var currentPath = Path.Join(this.sourceDirectory, relativePath); var localFiles = this.fileIO.GetFiles(currentPath); var subdirectories = this.fileIO.GetDirectories(Path.Join(this.sourceDirectory, relativePath)); var localNodes = new List <IFileNode>(); foreach (var filename in localFiles) { var filePath = Path.Join(currentPath, filename); var contents = this.fileIO.ReadFile(filePath); var fileNode = new FileNode { FullName = filename, Contents = contents, FileDepth = fileDepth, RelativePath = relativePath, }; if (this.fixedFiles.Contains(fileNode.Extension)) { // ignore from our tree, // just copy it to the output directly Directory.CreateDirectory(Path.Join(this.outputDirectory, relativePath)); File.Copy(filePath, Path.Join(this.outputDirectory, relativePath, filename)); } else if (fileNode.IsTemplate) { this.templates.Add(fileNode); } else if (fileNode.IsPartial) { this.partials.Add(fileNode); } else { if (fileNode.Name == "index") { if (parent != null) { fileNode.Parent = parent; parent.Children.Add(fileNode); } parent = fileNode; } localNodes.Add(fileNode); this.pages.Add(fileNode); } } // Need this separately, in case a file is read before the index. foreach (var file in localNodes) { if (file.Name != "index") { file.Parent = parent; parent.Children.Add(file); } } foreach (var directory in subdirectories) { var path = Path.Join(relativePath, directory); this.ReadInput(path, fileDepth + 1, parent); } return(parent); }
public VSBooCodeProvider(string[] references, IFileNode baseFileNode) : base(references) { _baseFileNode = baseFileNode; }
private void BackupRecursively(IFileNode fileNode, string destinationDirectory) { if (CancelRequested) { return; } if (fileNode.IsFolder()) { string subDirectory = FileSystem.Path.Combine(destinationDirectory, fileNode.Name); FileSystem.Directory.CreateDirectory(subDirectory); foreach (var childNode in fileNode.Children) { if (CancelRequested) { return; } BackupRecursively(childNode, subDirectory); } } else { Downloader.DownloadFile(fileNode, destinationDirectory); } }