public static void WritePage(ModelIndex page) { string intendedFilePath = page.Links.Self; (new FileInfo(intendedFilePath)).Directory.Create(); ConvertLinks(page); string indexJsonString = JsonSerializer.Serialize(page, ParsingUtils.DefaultJsonSerializerOptions); Outputs.WriteToFile(intendedFilePath, indexJsonString); Outputs.WriteOut($"Created index page: {intendedFilePath}"); }
public static async Task <int> RepoExpand(DirectoryInfo localRepo) { if (localRepo == null) { localRepo = new DirectoryInfo(Path.GetFullPath(".")); } var repoProvider = new RepoProvider(localRepo.FullName); if (!localRepo.Exists) { Outputs.WriteError($"Invalid target repository directory: {localRepo.FullName}."); return(ReturnCodes.InvalidArguments); } foreach (string file in Directory.EnumerateFiles(localRepo.FullName, "*.json", new EnumerationOptions { RecurseSubdirectories = true })) { if (file.ToLower().EndsWith(".expanded.json")) { continue; } try { var modelFile = new FileInfo(file); string dtmi = ParsingUtils.GetRootId(modelFile); if (string.IsNullOrEmpty(dtmi)) { continue; } List <string> expandedModel = await repoProvider.ExpandModel(dtmi); string formattedJson = Outputs.FormatExpandedListAsJson(expandedModel); string createPath = DtmiConventions.GetModelUri(dtmi, new Uri(localRepo.FullName), true).AbsolutePath; Outputs.WriteToFile(createPath, formattedJson); Outputs.WriteOut($"Created: {createPath}"); } catch (Exception e) { Outputs.WriteError($"Failure expanding model file: {file}, {e.Message}"); return(ReturnCodes.ProcessingError); } } return(ReturnCodes.Success); }
public static void Import(string modelContent, DirectoryInfo repository) { string rootId = ParsingUtils.GetRootId(modelContent); string createPath = DtmiConventions.GetModelUri(rootId, new Uri(repository.FullName)).AbsolutePath; Outputs.WriteOut($"- Importing model \"{rootId}\"..."); if (File.Exists(createPath)) { Outputs.WriteOut( $"- Skipping \"{rootId}\". Model file already exists in repository.", ConsoleColor.DarkCyan); return; } (new FileInfo(createPath)).Directory.Create(); Outputs.WriteToFile(createPath, modelContent); }
public static async Task <int> Export(string dtmi, FileInfo modelFile, string repo, FileInfo outputFile) { // Check that we have either model file or dtmi if (string.IsNullOrWhiteSpace(dtmi) && modelFile == null) { string invalidArgMsg = "Please specify a value for --dtmi"; Outputs.WriteError(invalidArgMsg); return(ReturnCodes.InvalidArguments); } var repoProvider = new RepoProvider(repo); try { if (string.IsNullOrWhiteSpace(dtmi)) { dtmi = ParsingUtils.GetRootId(modelFile); if (string.IsNullOrWhiteSpace(dtmi)) { Outputs.WriteError("Model is missing root @id"); return(ReturnCodes.ValidationError); } } List <string> expandedModel = await repoProvider.ExpandModel(dtmi); string formattedJson = Outputs.FormatExpandedListAsJson(expandedModel); Outputs.WriteOut(formattedJson); Outputs.WriteToFile(outputFile, formattedJson); } catch (RequestFailedException requestEx) { Outputs.WriteError(requestEx.Message); return(ReturnCodes.ResolutionError); } catch (System.Text.Json.JsonException jsonEx) { Outputs.WriteError($"Parsing json-ld content. Details: {jsonEx.Message}"); return(ReturnCodes.InvalidArguments); } return(ReturnCodes.Success); }