本文整理汇总了C#中Microsoft.DocAsCode.Plugins.FileModel类的典型用法代码示例。如果您正苦于以下问题:C# FileModel类的具体用法?C# FileModel怎么用?C# FileModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileModel类属于Microsoft.DocAsCode.Plugins命名空间,在下文中一共展示了FileModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public override void Build(FileModel model, IHostService host)
{
switch (model.Type)
{
case DocumentType.Article:
var restApi = (RestApiRootItemViewModel)model.Content;
BuildItem(host, restApi, model);
if (restApi.Children != null)
{
foreach (var item in restApi.Children)
{
BuildItem(host, item, model);
}
}
if (restApi.Tags != null)
{
foreach (var tag in restApi.Tags)
{
BuildTag(host, tag, model);
}
}
break;
case DocumentType.Overwrite:
BuildItem(host, model);
break;
default:
throw new NotSupportedException();
}
}
示例2: Build
public override void Build(FileModel model, IHostService host)
{
var toc = (TocItemViewModel)model.Content;
BuildCore(toc, model, host);
// todo : metadata.
}
示例3: ValidateToc
private void ValidateToc(TocItemViewModel item, FileModel model, IHostService hostService)
{
if (!PathUtility.IsRelativePath(item.Href)) return;
var file = model.File;
var originalFile = model.OriginalFileAndType.File;
// Special handle for folder ends with '/'
FileAndType originalTocFile = null;
string fileName = Path.GetFileName(item.Href);
if (string.IsNullOrEmpty(fileName))
{
var href = item.Href + "toc.yml";
var absHref = (RelativePath)file + (RelativePath)href;
string tocPath = absHref.GetPathFromWorkingFolder();
if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
{
href = item.Href + "toc.md";
absHref = (RelativePath)file + (RelativePath)href;
tocPath = absHref.GetPathFromWorkingFolder();
if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
{
var error = $"Unable to find either toc.yml or toc.md inside {item.Href}. Make sure the file is included in config file docfx.json!";
Logger.LogError(error, file: model.LocalPathFromRepoRoot);
throw new DocumentException(error);
}
}
Logger.LogInfo($"TOC file {href} inside {item.Href} is used", file: model.LocalPathFromRepoRoot);
item.Href = href;
item.OriginalHref = item.Href;
}
// Set default homepage
SetDefaultHomepage(item, originalTocFile, model);
}
示例4: GetTagsFromOverwriteDocument
public IEnumerable<RestApiTagViewModel> GetTagsFromOverwriteDocument(FileModel overwriteModel, string uid, IHostService host)
{
return OverwriteDocumentReader.Transform<RestApiTagViewModel>(
overwriteModel,
uid,
s => BuildRestApiDocument.BuildTag(host, s, overwriteModel, content => content != null && content.Trim() == Constants.ContentPlaceholder));
}
示例5: BuildCore
private void BuildCore(TocItemViewModel item, FileModel model, IHostService hostService)
{
if (item == null)
{
return;
}
var linkToUids = new HashSet<string>();
var linkToFiles = new HashSet<string>();
if (Utility.IsSupportedRelativeHref(item.Href))
{
linkToFiles.Add(ParseFile(item.Href));
}
if (Utility.IsSupportedRelativeHref(item.Homepage))
{
linkToFiles.Add(ParseFile(item.Homepage));
}
if (!string.IsNullOrEmpty(item.TopicUid))
{
linkToUids.Add(item.TopicUid);
}
model.LinkToUids = model.LinkToUids.Union(linkToUids);
model.LinkToFiles = model.LinkToFiles.Union(linkToFiles);
if (item.Items != null)
{
foreach (var i in item.Items)
{
BuildCore(i, model, hostService);
}
}
}
示例6: GetItemsFromOverwriteDocument
public IEnumerable<ItemViewModel> GetItemsFromOverwriteDocument(FileModel fileModel, string uid, IHostService host)
{
return OverwriteDocumentReader.Transform<ItemViewModel>(
fileModel,
uid,
s => BuildManagedReferenceDocument.BuildItem(host, s, fileModel, content => content != null && content.Trim() == Constants.ContentPlaceholder));
}
示例7: Save
public SaveResult Save(FileModel model)
{
if (model.Type != DocumentType.Article)
{
throw new NotSupportedException();
}
string path = Path.Combine(model.BaseDir, model.File);
try
{
JsonUtility.Serialize(path, model.Content);
}
catch (PathTooLongException e)
{
Logger.LogError($"Path \"{path}\": {e.Message}");
throw;
}
return new SaveResult
{
DocumentType = model.DocumentType ?? "Conceptual",
ModelFile = model.File,
LinkToFiles = model.Properties.LinkToFiles,
LinkToUids = model.Properties.LinkToUids,
};
}
示例8: Save
public override SaveResult Save(FileModel model)
{
if (model.FileAndType != model.OriginalFileAndType)
{
var targetFile = Path.Combine(model.BaseDir, model.File);
Directory.CreateDirectory(Path.GetDirectoryName(targetFile));
File.Copy(
Path.Combine(model.OriginalFileAndType.BaseDir, model.OriginalFileAndType.File),
targetFile,
true);
File.SetAttributes(targetFile, FileAttributes.Normal);
}
var result = new SaveResult
{
DocumentType = "Resource",
ResourceFile = model.File,
};
if (model.Content != null)
{
// For resources, e.g. image.png, file extension is kept
result.FileWithoutExtension = model.File;
}
return result;
}
示例9: BuildItem
private void BuildItem(IHostService host, ItemViewModel item, FileModel model)
{
item.Summary = Markup(host, item.Summary, model);
item.Remarks = Markup(host, item.Remarks, model);
item.Conceptual = Markup(host, item.Conceptual, model);
if (item.Syntax?.Return?.Description != null)
{
item.Syntax.Return.Description = Markup(host, item.Syntax?.Return?.Description, model);
}
var parameters = item.Syntax?.Parameters;
if (parameters != null)
{
foreach (var parameter in parameters)
{
parameter.Description = Markup(host, parameter.Description, model);
}
}
if (item.Exceptions != null)
{
foreach (var exception in item.Exceptions)
{
exception.Description = Markup(host, exception.Description, model);
}
}
}
示例10: Save
public override SaveResult Save(FileModel model)
{
return new SaveResult
{
DocumentType = "Toc",
ModelFile = model.File,
};
}
示例11: Build
public override void Build(FileModel model, IHostService host)
{
if (model.Type != DocumentType.Article && model.Type != DocumentType.Resource)
{
throw new NotSupportedException();
}
// todo : metadata.
}
示例12: Save
public SaveResult Save(FileModel model)
{
return new SaveResult
{
DocumentType = "Conceptual",
ModelFile = model.File,
LinkToFiles = linkToFiles.ToImmutableArray(),
};
}
示例13: UpdateRelativePathAndAddTocMap
private void UpdateRelativePathAndAddTocMap(TocViewModel toc, FileModel model, HashSet<string> links, Dictionary<string, HashSet<string>> tocMap, IHostService hostService)
{
if (toc == null) return;
var file = model.File;
var originalFile = model.OriginalFileAndType.File;
foreach (var item in toc)
{
if (PathUtility.IsRelativePath(item.Href))
{
// Special handle for folder ends with '/'
FileAndType originalTocFile = null;
string fileName = Path.GetFileName(item.Href);
if (string.IsNullOrEmpty(fileName))
{
var href = item.Href + "toc.yml";
var absHref = (RelativePath)file + (RelativePath)href;
string tocPath = absHref.GetPathFromWorkingFolder();
if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
{
href = item.Href + "toc.md";
absHref = (RelativePath)file + (RelativePath)href;
tocPath = absHref.GetPathFromWorkingFolder();
if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
{
var error = $"Unable to find either toc.yml or toc.md inside {item.Href}. Make sure the file is included in config file docfx.json!";
Logger.LogError(error, file: model.LocalPathFromRepoRoot);
throw new DocumentException(error);
}
}
Logger.LogInfo($"TOC file {href} inside {item.Href} is used", file: model.LocalPathFromRepoRoot);
item.Href = href;
item.OriginalHref = item.Href;
}
// Add toc.yml to tocMap before change item.Href to home page
item.Href = ((RelativePath)file + (RelativePath)item.Href).GetPathFromWorkingFolder();
if (item.OriginalHref != null) item.OriginalHref = ((RelativePath)file + (RelativePath)item.OriginalHref).GetPathFromWorkingFolder();
HashSet<string> value;
if (tocMap.TryGetValue(item.Href, out value))
{
value.Add(originalFile);
}
else
{
tocMap[item.Href] = new HashSet<string>(FilePathComparer.OSPlatformSensitiveComparer) { originalFile };
}
links.Add(item.Href);
SetHomepage(item, originalTocFile, model);
}
UpdateRelativePathAndAddTocMap(item.Items, model, links, tocMap, hostService);
}
}
示例14: Save
public override SaveResult Save(FileModel model)
{
return new SaveResult
{
DocumentType = "Toc",
ModelFile = model.File,
TocMap = model.Properties.TocMap,
LinkToFiles = model.Properties.LinkToFiles
};
}
示例15: Save
public override SaveResult Save(FileModel model)
{
return new SaveResult
{
DocumentType = "Toc",
FileWithoutExtension = Path.ChangeExtension(model.File, null),
LinkToFiles = model.LinkToFiles.ToImmutableArray(),
LinkToUids = model.LinkToUids,
};
}