private static LinksModel BuildLinks(IEnumerable <string> paths, string relatedTo) { LinksModel result = new LinksModel(); foreach (string path in paths) { PathTypeEnum type = path.GetPathType(); switch (type) { case PathTypeEnum.Directory: result.Directories.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathOpenUri(path))); break; case PathTypeEnum.File: result.Files.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathOpenUri(path))); break; case PathTypeEnum.NonExistent: result.NonExists.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathUri(path))); break; } } return(result); }
public Task ExecuteAsync(IDictionary <string, string> arguments) { if (!arguments.TryGetValue(ActionParameters.ADDRESS, out string address) || string.IsNullOrWhiteSpace(address)) { return(Task.CompletedTask); } Uri uri = TryToBuildUri(address); if (uri == null) { return(Task.CompletedTask); } if (string.Equals(uri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase)) { actionService.ExecuteAsync(ActionBuilder.PathUri(uri.LocalPath)); } else if (string.Equals(uri.Scheme, ActionConstants.ACTION_SCHEMA, StringComparison.OrdinalIgnoreCase)) { actionService.ExecuteAsync(uri.OriginalString); } else { return(UriOpenAction.ExecuteAsync(uri.OriginalString)); } return(Task.CompletedTask); }
public Task <OutputModel> ProcessAsync(OutputModel data) { if (!data.Flags.Contains(TransformationFlags.GIT_STATUS)) { return(Task.FromResult(data)); } string line = data.Output; Match match; if (data.Flags.Contains(TransformationFlags.GIT_UNTRACKED)) { match = untrackedFileRegex.Match(line); } else { if (line.StartsWith("Untracked files", StringComparison.OrdinalIgnoreCase)) { data.Flags.Add(TransformationFlags.GIT_UNTRACKED); return(Task.FromResult(data)); } match = fileRegex.Match(line); } if (!match.Success) { return(Task.FromResult(data)); } Group fileGroup = match.Groups["path"]; string path = fileGroup.Value; if (!path.IsValidPath()) { return(Task.FromResult(data)); } Func <string, bool> pathCheckFunc = path.EndsWith("/") ? (Func <string, bool>)Directory.Exists : File.Exists; string fullPath = Path.Combine(PathConstants.RELATIVE_CURRENT_DIRECTORY, path); if (!pathCheckFunc(fullPath)) { return(Task.FromResult(data)); } fullPath = fullPath.GetFullConsolidatedPath(); AnsiStringBuilder builder = new AnsiStringBuilder(); builder.Append(line.Substring(0, fileGroup.Index)); builder.AppendLink(path, ActionBuilder.PathUri(fullPath)); int endIndex = fileGroup.Index + fileGroup.Length; if (endIndex < line.Length) { builder.Append(line.Substring(endIndex)); } data.Output = builder.ToString(); return(Task.FromResult(data)); }
public Task <OutputModel> ProcessAsync(OutputModel data) { if (!data.Flags.Contains(TransformationFlags.GET_CHILD_ITEM)) { return(Task.FromResult(data)); } string text = data.Output; string itemPath; int index; if (data.Flags.Contains(TransformationFlags.GET_CHILD_ITEM_NAME)) { itemPath = text.TrimEnd(); index = 0; } else if (data.Properties.TryGetValue(TransformationProperties.INDEX, out object value)) { index = (int)value; if (text.Length <= index) { return(Task.FromResult(data)); } itemPath = text.Substring(index).TrimEnd(); } else { if (text.StartsWith("Mode", StringComparison.OrdinalIgnoreCase) && text.Contains("Name")) { int indexOfName = text.LastIndexOf("Name"); data.Properties[TransformationProperties.INDEX] = indexOfName; } return(Task.FromResult(data)); } if (string.IsNullOrWhiteSpace(itemPath)) { return(Task.FromResult(data)); } string parentPath = data.Input.ParsedInput.Tokens .Skip(1) .FirstOrDefault(t => !string.Equals(t, "-name", StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(parentPath)) { parentPath = PathConstants.RELATIVE_CURRENT_DIRECTORY; } string path = Path.Combine(parentPath, itemPath); if (path.GetPathType() == PathTypeEnum.NonExistent) { return(Task.FromResult(data)); } string fullPath = path.GetFullConsolidatedPath(); AnsiStringBuilder builder = new AnsiStringBuilder(); builder.Append(text.Substring(0, index)); builder.AppendLink(itemPath, ActionBuilder.PathUri(fullPath)); int endIndex = index + itemPath.Length; if (endIndex < text.Length) { builder.Append(text.Substring(endIndex)); } data.Output = builder.ToString(); return(Task.FromResult(data)); }