public static Dictionary <string, object> ReadMarkdownAsConceptual(string baseDir, string file) { var filePath = Path.Combine(baseDir, file); var repoInfo = GitUtility.GetGitDetail(filePath); return(new Dictionary <string, object> { ["conceptual"] = File.ReadAllText(filePath), ["type"] = "Conceptual", ["source"] = new SourceDetail() { Remote = repoInfo }, ["path"] = file, }); }
//Function to check if this context option is disabled for string path public override bool IsDisabled(List <string> paths) { //Only allow one file to be selected if (paths.Count != 1) { return(true); } //If file is not asset, disable if (GitUtility.RepoPathToRelativeAssetPath(paths[0]) == null) { return(true); } return(false); }
public static Dictionary <string, object> ReadMarkdownAsConceptual(string baseDir, string file) { var filePath = Path.Combine(baseDir, file); var repoInfo = GitUtility.GetGitDetail(filePath); return(new Dictionary <string, object> { [Constants.PropertyName.Conceptual] = File.ReadAllText(filePath), [Constants.PropertyName.Type] = "Conceptual", [Constants.PropertyName.Source] = new SourceDetail() { Remote = repoInfo }, [Constants.PropertyName.Path] = file, }); }
//Scan attributes for context lists private void BuildContextLists() { stagedContextOptions = new List <ContextOption <string> >(); unstagedContextOptions = new List <ContextOption <string> >(); GitUtility.ForEachTypeWithOrdered <PathContextAttribute>(true, (type, attribute) => { if ((attribute.mode & FilePathMode.Staged) == FilePathMode.Staged) { stagedContextOptions.Add((ContextOption <string>)Activator.CreateInstance(type)); } if ((attribute.mode & FilePathMode.Unstaged) == FilePathMode.Unstaged) { unstagedContextOptions.Add((ContextOption <string>)Activator.CreateInstance(type)); } }); }
public static Dictionary <string, object> ReadMarkdownAsConceptual(string file) { var filePath = EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file); var repoInfo = GitUtility.TryGetFileDetail(filePath); return(new Dictionary <string, object> { [Constants.PropertyName.Conceptual] = EnvironmentContext.FileAbstractLayer.ReadAllText(file), [Constants.PropertyName.Type] = "Conceptual", [Constants.PropertyName.Source] = new SourceDetail { Remote = repoInfo }, [Constants.PropertyName.Path] = file, [Constants.PropertyName.Documentation] = new SourceDetail { Remote = repoInfo } }); }
//Function to check if this context option is disabled for string path public override bool IsDisabled(List <string> paths) { //Only allow one file to be selected if (paths.Count != 1) { return(true); } string absolutePath = GitUtility.RepoPathToAbsolutePath(paths[0]); //Disable if file does not exist (ie moved or deleted) if (!File.Exists(absolutePath)) { return(true); } return(false); }
private static IEnumerable <T> ReadMarkDownCore <T>(string file) where T : IOverrideDocumentViewModel { var content = File.ReadAllText(file); var repoInfo = GitUtility.GetGitDetail(file); var lineIndex = GetLineIndex(content).ToList(); var yamlDetails = YamlHeaderParser.Select(content); if (yamlDetails == null) { yield break; } var sections = from detail in yamlDetails let id = detail.Id from ms in detail.MatchedSections from location in ms.Value.Locations orderby location.StartLocation descending select new { Detail = detail, Id = id, Location = location }; var currentEnd = Coordinate.GetCoordinate(content); foreach (var item in sections) { if (!string.IsNullOrEmpty(item.Id)) { int start = lineIndex[item.Location.EndLocation.Line] + item.Location.EndLocation.Column + 1; int end = lineIndex[currentEnd.Line] + currentEnd.Column + 1; using (var sw = new StringWriter()) { YamlUtility.Serialize(sw, item.Detail.Properties); using (var sr = new StringReader(sw.ToString())) { var vm = YamlUtility.Deserialize <T>(sr); vm.Conceptual = content.Substring(start, end - start + 1); vm.Documentation = new SourceDetail { Remote = repoInfo, StartLine = item.Location.EndLocation.Line, EndLine = currentEnd.Line }; vm.Uid = item.Id; yield return(vm); } } } currentEnd = item.Location.StartLocation; } }
private static void MergeNewFileRepositoryToConfig(BuildJsonConfig config) { GitDetail repoInfoFromBaseDirectory = GitUtility.GetGitDetail(Path.Combine(Environment.CurrentDirectory, config.BaseDirectory)); if (repoInfoFromBaseDirectory != null) { repoInfoFromBaseDirectory.RelativePath = Path.Combine(repoInfoFromBaseDirectory.RelativePath, DocAsCode.Constants.DefaultOverwriteFolderName); } object newFileRepository; if (config.GlobalMetadata.TryGetValue("newFileRepository", out newFileRepository)) { GitDetail repoInfo = null; try { repoInfo = JObject.FromObject(newFileRepository).ToObject <GitDetail>(); } catch (Exception e) { throw new DocumentException($"Unable to convert newFileRepository to GitDetail in globalMetadata: {e.Message}", e); } if (repoInfoFromBaseDirectory != null) { if (repoInfo.RelativePath == null) { repoInfo.RelativePath = repoInfoFromBaseDirectory.RelativePath; } if (repoInfo.RemoteBranch == null) { repoInfo.RemoteBranch = repoInfoFromBaseDirectory.RemoteBranch; } if (repoInfo.RemoteRepositoryUrl == null) { repoInfo.RemoteRepositoryUrl = repoInfoFromBaseDirectory.RemoteRepositoryUrl; } } config.GlobalMetadata["newFileRepository"] = repoInfo; } else { config.GlobalMetadata["newFileRepository"] = repoInfoFromBaseDirectory; } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { var filePath = file.FullPath; var tocViewModel = Utility.LoadSingleToc(filePath); var toc = new TocItemViewModel { Items = tocViewModel }; var repoDetail = GitUtility.GetGitDetail(filePath); var displayLocalPath = repoDetail?.RelativePath ?? filePath; // todo : metadata. return(new FileModel(file, toc) { Uids = new[] { new UidDefinition(file.File, displayLocalPath) }.ToImmutableArray(), LocalPathFromRepoRoot = displayLocalPath, }); }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: var filePath = Path.Combine(file.BaseDir, file.File); var swaggerContent = File.ReadAllText(filePath); var swagger = SwaggerJsonParser.Parse(swaggerContent); swagger.Metadata[DocumentTypeKey] = RestApiDocumentType; swagger.Raw = swaggerContent; var repoInfo = GitUtility.GetGitDetail(filePath); if (repoInfo != null) { swagger.Metadata["source"] = new SourceDetail() { Remote = repoInfo }; } swagger.Metadata = MergeMetadata(swagger.Metadata, metadata); var vm = SwaggerModelConverter.FromSwaggerModel(swagger); var displayLocalPath = repoInfo?.RelativePath ?? filePath.ToDisplayPath(); return(new FileModel(file, vm, serializer: new BinaryFormatter()) { Uids = new[] { new UidDefinition(vm.Uid, displayLocalPath) } .Concat(from item in vm.Children select new UidDefinition(item.Uid, displayLocalPath)) .Concat(from tag in vm.Tags select new UidDefinition(tag.Uid, displayLocalPath)).ToImmutableArray(), LocalPathFromRepoRoot = displayLocalPath, Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, }); case DocumentType.Overwrite: // TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }
private static void MergeGitContributeToConfig(BuildJsonConfig config) { GitDetail repoInfoFromBaseDirectory = GitUtility.GetGitDetail(Path.Combine(Directory.GetCurrentDirectory(), config.BaseDirectory)); if (repoInfoFromBaseDirectory?.RelativePath != null) { repoInfoFromBaseDirectory.RelativePath = Path.Combine(repoInfoFromBaseDirectory.RelativePath, DocAsCode.Constants.DefaultOverwriteFolderName); } object gitRespositoryOpenToPublicContributors; if (config.GlobalMetadata.TryGetValue("_gitContribute", out gitRespositoryOpenToPublicContributors)) { GitDetail repoInfo; try { repoInfo = JObject.FromObject(gitRespositoryOpenToPublicContributors).ToObject <GitDetail>(); } catch (Exception e) { throw new DocumentException($"Unable to convert _gitContribute to GitDetail in globalMetadata: {e.Message}", e); } if (repoInfoFromBaseDirectory != null) { if (repoInfo.RelativePath == null) { repoInfo.RelativePath = repoInfoFromBaseDirectory.RelativePath; } if (repoInfo.RemoteBranch == null) { repoInfo.RemoteBranch = repoInfoFromBaseDirectory.RemoteBranch; } if (repoInfo.RemoteRepositoryUrl == null) { repoInfo.RemoteRepositoryUrl = repoInfoFromBaseDirectory.RemoteRepositoryUrl; } } config.GlobalMetadata["_gitContribute"] = repoInfo; } else { config.GlobalMetadata["_gitContribute"] = repoInfoFromBaseDirectory; } }
public ParseResult Run(MapFileItemViewModel item, IndexerContext context) { if (string.IsNullOrEmpty(context.MarkdownContent) && string.IsNullOrEmpty(context.MarkdownFilePath)) { throw new ArgumentException("Neither Markdown file content nor file path is specified!"); } if (string.IsNullOrEmpty(context.MarkdownContent)) { context.MarkdownContent = File.ReadAllText(context.MarkdownFilePath); } if (!string.IsNullOrEmpty(context.MarkdownFilePath)) { item.Remote = GitUtility.GetGitDetail(context.MarkdownFilePath); } return(new ParseResult(ResultLevel.Success)); }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { var filePath = file.FullPath; var tocViewModel = Utility.LoadSingleToc(filePath); var toc = new TocItemViewModel { Items = tocViewModel }; var repoDetail = GitUtility.TryGetFileDetail(filePath); var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); // todo : metadata. return(new FileModel(file, toc) { Uids = new[] { new UidDefinition(file.File, displayLocalPath) }.ToImmutableArray(), LocalPathFromRoot = displayLocalPath }); }
public static SourceDetail GetSourceDetail(ISymbol symbol) { // For namespace, definition is meaningless if (symbol == null || symbol.Kind == SymbolKind.Namespace) { return(null); } var syntaxRef = symbol.DeclaringSyntaxReferences.LastOrDefault(); if (symbol.IsExtern || syntaxRef == null) { return(new SourceDetail { IsExternalPath = true, Path = symbol.ContainingAssembly?.Name, }); } var syntaxNode = syntaxRef.GetSyntax(); Debug.Assert(syntaxNode != null); if (syntaxNode != null) { var source = new SourceDetail { StartLine = syntaxNode.SyntaxTree.GetLineSpan(syntaxNode.Span).StartLinePosition.Line, Path = syntaxNode.SyntaxTree.FilePath, Name = symbol.Name }; source.Remote = GitUtility.TryGetFileDetail(source.Path); if (source.Remote != null) { source.Path = PathUtility.FormatPath(source.Path, UriKind.Relative, EnvironmentContext.BaseDirectory); } return(source); } return(null); }
protected void FillHeader(ArticleItemYaml yaml, XElement node) { var location = node.NullableElement("location"); if (!location.IsNull()) { string headerPath = location.NullableAttribute("file").NullableValue(); string headerStartlineStr = location.NullableAttribute("line").NullableValue(); int headerStartline = ParseStartline(headerStartlineStr); var info = GitUtility.GetGitInfo(headerPath); string relativePath = GetRelativePath(headerPath, info?.LocalWorkingDirectory); yaml.Header = new SourceDetail { Remote = new GitDetail { RemoteRepositoryUrl = info?.RemoteRepoUrl, RemoteBranch = info?.RemoteBranch, RelativePath = relativePath }, Path = relativePath, StartLine = headerStartline, }; } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { string uid = null; Dictionary <string, object> content = null; var metafile = Path.Combine(file.BaseDir, file.File.TrimEnd('.') + ".meta"); if (File.Exists(metafile)) { content = YamlUtility.Deserialize <Dictionary <string, object> >(metafile); if (content != null) { foreach (var item in metadata) { if (!content.ContainsKey(item.Key)) { content[item.Key] = item.Value; } if (item.Key == Constants.PropertyName.Uid) { uid = item.Value as string; } } } } if (content == null) { content = metadata.ToDictionary(p => p.Key, p => p.Value); } var filePath = Path.Combine(file.BaseDir, file.File); var repoDetail = GitUtility.GetGitDetail(filePath); var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); return(new FileModel(file, content) { Uids = string.IsNullOrEmpty(uid) ? ImmutableArray <UidDefinition> .Empty : ImmutableArray <UidDefinition> .Empty.Add(new UidDefinition(uid, displayLocalPath)), LocalPathFromRepoRoot = repoDetail?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath(), LocalPathFromRoot = displayLocalPath }); }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: var filePath = Path.Combine(file.BaseDir, file.File); var swagger = SwaggerJsonParser.Parse(filePath); swagger.Metadata[DocumentTypeKey] = RestApiDocumentType; swagger.Raw = EnvironmentContext.FileAbstractLayer.ReadAllText(filePath); CheckOperationId(swagger, file.File); var repoInfo = GitUtility.TryGetFileDetail(filePath); if (repoInfo != null) { swagger.Metadata["source"] = new SourceDetail() { Remote = repoInfo }; } swagger.Metadata = MergeMetadata(swagger.Metadata, metadata); var vm = SwaggerModelConverter.FromSwaggerModel(swagger); var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); return(new FileModel(file, vm, serializer: Environment.Is64BitProcess?null: new BinaryFormatter()) { Uids = new[] { new UidDefinition(vm.Uid, displayLocalPath) } .Concat(from item in vm.Children select new UidDefinition(item.Uid, displayLocalPath)) .Concat(from tag in vm.Tags select new UidDefinition(tag.Uid, displayLocalPath)).ToImmutableArray(), LocalPathFromRoot = displayLocalPath }); case DocumentType.Overwrite: // TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors return(OverwriteDocumentReader.Read(file)); default: throw new NotSupportedException(); } }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { var filePath = file.FullPath; var toc = TocHelper.LoadSingleToc(filePath); var repoDetail = GitUtility.TryGetFileDetail(filePath); var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); // Apply metadata to TOC foreach (var pair in metadata) { if (!toc.Metadata.TryGetValue(pair.Key, out var val)) { toc.Metadata[pair.Key] = pair.Value; } } return(new FileModel(file, toc) { LocalPathFromRoot = displayLocalPath }); }
public static SourceDetail GetSourceDetail(ISymbol symbol) { if (symbol == null) { return(null); } var syntaxRef = symbol.DeclaringSyntaxReferences.LastOrDefault(); if (symbol.IsExtern || syntaxRef == null) { return(new SourceDetail { IsExternalPath = true, Path = symbol.ContainingAssembly?.Name, }); } var syntaxNode = syntaxRef.GetSyntax(); Debug.Assert(syntaxNode != null); if (syntaxNode != null) { var source = new SourceDetail { StartLine = syntaxNode.SyntaxTree.GetLineSpan(syntaxNode.Span).StartLinePosition.Line, Path = syntaxNode.SyntaxTree.FilePath, }; source.Remote = GitUtility.GetGitDetail(source.Path); if (source.Remote != null) { source.Path = source.Path.FormatPath(UriKind.Relative, source.Remote.LocalWorkingDirectory); } return(source); } return(null); }
public static string Format(string text) { var customRepoPath = WindowTitleSettings.RepositoryPath; _Tags[BranchKey] = GetBranchName(); if (string.IsNullOrEmpty(customRepoPath)) { GitUtility.TryFindRepositoryDirUpwards(ProjectPath, out customRepoPath); } if (!string.IsNullOrEmpty(customRepoPath)) { _Tags[RepoPathKey] = Path.GetFullPath(customRepoPath).TrimEnd(Path.DirectorySeparatorChar); } _Tags[RepoDirNameKey] = GetRepoDirName(); foreach (var kvp in _Tags) { text = text.Replace(kvp.Key, kvp.Value); } return(text); }
public static void OnlyCopyConf2StreamingAssets() { string srcConfFolder = GetConf(); if (string.IsNullOrEmpty(srcConfFolder)) { return; } DateTime dt1 = System.DateTime.UtcNow; // 拷贝conf文件夹; PackAssetBundleUtlis.CopyFolder(srcConfFolder, string.Format("{0}", bundleBuildFolder)); PackAssetBundleUtlis.CopyFolder(srcConfFolder, string.Format("{0}", ResourceConst.BundleFolder)); DateTime dt2 = System.DateTime.UtcNow; bool result = FileListUtility.BuildFileListByConf(); DateTime dt3 = System.DateTime.UtcNow; //FileListUtility.BuildFileList(true); // 拷贝FileList文件; string fileList = string.Format("{0}/{1}", bundleBuildFolder, ResourceConst.FileListName); string newFileList = string.Format("{0}/{1}", ResourceConst.BundleFolder, ResourceConst.FileListName); PackAssetBundleUtlis.CopyFile(fileList, newFileList); GitUtility.PrintGitToData(); DateTime dt4 = System.DateTime.UtcNow; if (result) { string info = string.Format("Conf打包完成,总时长{0}秒", (dt4 - dt1).TotalSeconds.ToString("f1")); EditorUtility.DisplayDialog("打包完成", info, "好的"); } else { EditorUtility.DisplayDialog("打包失败", "Conf打包失败,详情请看Log!", "马上去看"); } }
public FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { string uid = null; Dictionary <string, object> content = null; var metafile = Path.Combine(file.BaseDir, file.File.TrimEnd('.') + ".meta"); if (File.Exists(metafile)) { content = YamlUtility.Deserialize <Dictionary <string, object> >(metafile); if (content != null) { foreach (var item in metadata) { if (!content.ContainsKey(item.Key)) { content[item.Key] = item.Value; } if (item.Key == "uid") { uid = item.Value as string; } } } } if (content == null) { content = metadata.ToDictionary(p => p.Key, p => p.Value); } var filePath = Path.Combine(file.BaseDir, file.File); var repoDetail = GitUtility.GetGitDetail(filePath); return(new FileModel(file, content) { Uids = string.IsNullOrEmpty(uid) ? ImmutableArray <string> .Empty : ImmutableArray <string> .Empty.Add(uid), LocalPathFromRepoRoot = repoDetail?.RelativePath }); }
private static OverwriteDocumentModel TransformModel(string filePath, YamlHtmlPart part) { if (part == null) { return(null); } var properties = part.YamlHeader; var checkPropertyStatus = CheckRequiredProperties(properties, RequiredProperties, out string checkPropertyMessage); if (!checkPropertyStatus) { throw new InvalidDataException(checkPropertyMessage); } var overriden = RemoveRequiredProperties(properties, RequiredProperties); var repoInfo = GitUtility.TryGetFileDetail(filePath); return(new OverwriteDocumentModel { Uid = properties[Constants.PropertyName.Uid].ToString(), LinkToFiles = new HashSet <string>(part.LinkToFiles), LinkToUids = new HashSet <string>(part.LinkToUids), FileLinkSources = part.FileLinkSources.ToDictionary(p => p.Key, p => p.Value.ToList()), UidLinkSources = part.UidLinkSources.ToDictionary(p => p.Key, p => p.Value.ToList()), Metadata = overriden, Conceptual = part.Conceptual, Documentation = new SourceDetail { Remote = repoInfo, StartLine = part.StartLine, EndLine = part.EndLine, Path = part.SourceFile }, Dependency = part.Origin.Dependency }); }
protected override FileModel LoadArticle(FileAndType file, ImmutableDictionary <string, object> metadata) { var filePath = Path.Combine(file.BaseDir, file.File); var swagger = SwaggerJsonParser.Parse(filePath); swagger.Metadata[DocumentTypeKey] = RestApiDocumentType; swagger.Raw = EnvironmentContext.FileAbstractLayer.ReadAllText(filePath); CheckOperationId(swagger, file.File); var repoInfo = GitUtility.TryGetFileDetail(filePath); if (repoInfo != null) { swagger.Metadata["source"] = new SourceDetail() { Remote = repoInfo }; } swagger.Metadata = MergeMetadata(swagger.Metadata, metadata); var vm = SwaggerModelConverter.FromSwaggerModel(swagger); vm.Metadata[Constants.PropertyName.SystemKeys] = SystemKeys; var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); return(new FileModel(file, vm, serializer: new BinaryFormatter()) { Uids = new[] { new UidDefinition(vm.Uid, displayLocalPath) } .Concat(from item in vm.Children where !string.IsNullOrEmpty(item.Uid) select new UidDefinition(item.Uid, displayLocalPath)) .Concat(from tag in vm.Tags where !string.IsNullOrEmpty(tag.Uid) select new UidDefinition(tag.Uid, displayLocalPath)).ToImmutableArray(), LocalPathFromRoot = displayLocalPath }); }
private static IEnumerable <OverwriteDocumentModel> ReadMarkDownCore(string file) { var content = File.ReadAllText(file); var repoInfo = GitUtility.GetGitDetail(file); var lineIndex = GetLineIndex(content).ToList(); var yamlDetails = YamlHeaderParser.Select(content); var sections = from detail in yamlDetails let id = detail.Id from location in detail.MatchedSection.Locations orderby location.StartLocation descending select new { Detail = detail, Id = id, Location = location }; var currentEnd = Coordinate.GetCoordinate(content); foreach (var item in sections) { if (!string.IsNullOrEmpty(item.Id)) { int start = lineIndex[item.Location.EndLocation.Line] + item.Location.EndLocation.Column + 1; int end = lineIndex[currentEnd.Line] + currentEnd.Column + 1; yield return(new OverwriteDocumentModel { Uid = item.Id, Metadata = item.Detail.Properties, Conceptual = content.Substring(start, end - start), Documentation = new SourceDetail { Remote = repoInfo, StartLine = item.Location.EndLocation.Line, EndLine = currentEnd.Line, Path = Path.GetFullPath(file).ToDisplayPath() } }); } currentEnd = item.Location.StartLocation; } }
static void Pull() { GitUtility.GitPull(); }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { switch (file.Type) { case DocumentType.Article: var filePath = Path.Combine(file.BaseDir, file.File); var swaggerContent = File.ReadAllText(filePath); var swagger = GetModelWithoutRef <SwaggerModel>(swaggerContent); swagger.Metadata[DocumentTypeKey] = RestApiDocumentType; swagger.Raw = swaggerContent; var repoInfo = GitUtility.GetGitDetail(filePath); if (repoInfo != null) { swagger.Metadata["source"] = new SourceDetail() { Remote = repoInfo }; } swagger.Metadata = MergeMetadata(swagger.Metadata, metadata); var vm = RestApiItemViewModel.FromSwaggerModel(swagger); var displayLocalPath = repoInfo?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath(); return(new FileModel(file, vm, serializer: new BinaryFormatter()) { Uids = new UidDefinition[] { new UidDefinition(vm.Uid, displayLocalPath) }.Concat(from item in vm.Children select new UidDefinition(item.Uid, displayLocalPath)).ToImmutableArray(), LocalPathFromRepoRoot = displayLocalPath, Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, }); case DocumentType.Override: var overrides = MarkdownReader.ReadMarkdownAsOverride <RestApiItemViewModel>(file.BaseDir, file.File); if (overrides == null || overrides.Count == 0) { return(null); } displayLocalPath = overrides[0].Documentation?.Remote?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath(); return(new FileModel(file, overrides, serializer: new BinaryFormatter()) { Uids = (from item in overrides select new UidDefinition( item.Uid, displayLocalPath, item.Documentation.StartLine + 1 )).ToImmutableArray(), Properties = { LinkToFiles = new HashSet <string>(), LinkToUids = new HashSet <string>(), }, LocalPathFromRepoRoot = displayLocalPath, }); default: throw new NotSupportedException(); } }
public void TestGitUtility() { var output = GitUtility.GetGitDetail(Environment.CurrentDirectory); Assert.AreEqual("https://capservice.visualstudio.com/DefaultCollection/CAPS/_git/DocAsCode", output.RemoteRepositoryUrl); }
public void Environment_ForBranchName() { var info = GitUtility.TryGetFileDetail(Directory.GetCurrentDirectory()); Assert.Equal("special-branch", info.RemoteBranch); }
public GitPatcherInitVM(ProfileVM profile) : base(profile) { Patcher = new GitPatcherVM(profile); _CanCompleteConfiguration = this.WhenAnyValue(x => x.Patcher.RepoClonesValid) .Select(x => ErrorResponse.Create(x)) .ToGuiProperty(this, nameof(CanCompleteConfiguration), ErrorResponse.Success); PatcherRepos = Observable.Return(Unit.Default) .ObserveOn(RxApp.TaskpoolScheduler) .SelectTask(async _ => { try { var localRepoPath = await GitUtility.CheckOrCloneRepo( GetResponse <string> .Succeed("https://github.com/Mutagen-Modding/Synthesis.Registry"), Paths.RegistryFolder, Log.Logger.Error, CancellationToken.None); if (localRepoPath.Failed) { Error = localRepoPath; return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >()); } using var repo = new Repository(localRepoPath.Value.Local); var master = repo.Branches.Where(b => b.IsCurrentRepositoryHead).FirstOrDefault(); if (master == null) { Error = ErrorResponse.Fail("Could not find master branch"); Log.Logger.Error(Error.Reason); return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >()); } repo.Reset(ResetMode.Hard, repo.Branches[$"{master.RemoteName}/{master.FriendlyName}"].Tip); var listingPath = Path.Combine(repo.Info.WorkingDirectory, Constants.AutomaticListingFileName); if (!File.Exists(listingPath)) { Error = ErrorResponse.Fail("Could not locate listing file"); Log.Logger.Error(Error.Reason); return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >()); } var settings = new JsonSerializerOptions(); settings.Converters.Add(new JsonStringEnumConverter()); var customization = JsonSerializer.Deserialize <MutagenPatchersListing>(File.ReadAllText(listingPath), settings) !; return(customization.Repositories .NotNull() .SelectMany(repo => { var repoVM = new RepositoryStoreListingVM(repo); return repo.Patchers .Select(p => { return new PatcherStoreListingVM(this, p, repoVM); }); }) .AsObservableChangeSet()); } catch (Exception ex) { Log.Logger.Error(ex, "Error downloading patcher listing"); Error = ErrorResponse.Fail(ex); } return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >()); }) .Switch() .Sort(Comparer <PatcherStoreListingVM> .Create((x, y) => x.Name.CompareTo(y.Name))) .Filter(this.WhenAnyValue(x => x.ShowAll) .DistinctUntilChanged() .Select(show => new Func <PatcherStoreListingVM, bool>( (p) => { if (p.Raw.Customization?.Visibility is VisibilityOptions.Visible) { return(true); } else if (p.Raw.Customization?.Visibility is VisibilityOptions.IncludeButHide) { return(show); } else if (p.Raw.Customization?.Visibility is VisibilityOptions.Exclude) { return(false); // just in case. } else { return(true); } }))) .Filter(this.WhenAnyValue(x => x.Search) .Debounce(TimeSpan.FromMilliseconds(350), RxApp.MainThreadScheduler) .Select(x => x.Trim()) .DistinctUntilChanged() .Select(search => { if (string.IsNullOrWhiteSpace(search)) { return(new Func <PatcherStoreListingVM, bool>(_ => true)); } return(new Func <PatcherStoreListingVM, bool>( (p) => { if (p.Name.Contains(search, StringComparison.OrdinalIgnoreCase)) { return true; } if (p.Raw.Customization?.OneLineDescription?.Contains(search, StringComparison.OrdinalIgnoreCase) ?? false) { return true; } return false; })); })) .ToObservableCollection(this); OpenPopulationInfoCommand = ReactiveCommand.Create(() => Utility.NavigateToPath(Constants.ListingRepositoryAddress)); ClearSearchCommand = ReactiveCommand.Create(() => Search = string.Empty); }