protected virtual void Save(object obj, string comment, string fileName) { if (obj == null || string.IsNullOrEmpty(fileName)) { return; } var fullFileName = fileName + Constants.Constants.YamlExtension; string sdpymlfilePath = Path.Combine(StepUtility.GetSDPYmlOutputPath(_outputFolder), fullFileName); YamlUtility.Serialize(sdpymlfilePath, obj, comment); }
protected virtual void Save(object obj, string comment, string fileName, string memberType) { if (obj == null || string.IsNullOrEmpty(fileName)) { return; } string sdpymlfilePath = ""; string fullFileName = "", fullFileNameWithType = ""; fullFileName = fileName + Constants.Constants.YamlExtension; fullFileNameWithType = (fileName + '(' + (memberType == null ? "unknown" : memberType.ToLower()) + ')') + Constants.Constants.YamlExtension; sdpymlfilePath = Path.Combine(StepUtility.GetSDPYmlOutputPath(_outputFolder), fullFileName); if (File.Exists(sdpymlfilePath)) { sdpymlfilePath = Path.Combine(StepUtility.GetSDPYmlOutputPath(_outputFolder), fullFileNameWithType); } YamlUtility.Serialize(sdpymlfilePath, obj, comment); }
public Task RunAsync(BuildContext context) { var config = context.GetSharedObject(Constants.Config) as ConfigModel; if (config == null) { throw new ApplicationException(string.Format("Key: {0} doesn't exist in build context", Constants.Config)); } string sdpYmlFolder = StepUtility.GetSDPYmlOutputPath(config.OutputPath); if (!Directory.Exists(sdpYmlFolder)) { throw new ApplicationException(string.Format("SDPYmlOutputPath: {0} doesn't exist.", sdpYmlFolder)); } var inputPaths = config.InputPaths; foreach (var inputPath in inputPaths) { try { var tocFilePath = Path.Combine(inputPath, "toc.yml"); if (!File.Exists(tocFilePath)) { throw new ApplicationException(string.Format("toc.yml: toc.yml doesn't exist in the {0} directory.", inputPath)); } var content = File.ReadAllText(tocFilePath, Encoding.UTF8); TocYaml toc; using (StringReader reader = new StringReader(content)) { toc = YamlUtility.Deserialize <TocYaml>(reader); } TocExpression javaTocExpression = new TocExpression(config.OutputPath); javaTocExpression.Interpreter(toc, context); ConsoleLogger.WriteLine( new LogEntry { Phase = StepName, Level = LogLevel.Info, Message = $"Succeed to interpret Merf file: Toc.yml.", }); } catch (Exception ex) { ConsoleLogger.WriteLine( new LogEntry { Phase = StepName, Level = LogLevel.Error, Message = $"Fail to interpret Merf file: Toc.yml.Exception: {ex}" }); throw; } } return(Task.FromResult(1)); }
public Task RunAsync(BuildContext context) { var config = context.GetSharedObject(Constants.Config) as ConfigModel; if (config == null) { throw new ApplicationException(string.Format("Key: {0} doesn't exist in build context", Constants.Config)); } string sdpYmlFolder = StepUtility.GetSDPYmlOutputPath(config.OutputPath); if (Directory.Exists(sdpYmlFolder)) { Directory.Delete(sdpYmlFolder, recursive: true); } Directory.CreateDirectory(sdpYmlFolder); var inputPaths = config.InputPaths; foreach (var inputPath in inputPaths) { Directory.EnumerateFiles(inputPath, "*.yml").AsParallel().ForAll( p => { var filename = Path.GetFileNameWithoutExtension(p); try { var content = File.ReadAllText(p, Encoding.UTF8); if (filename != "toc") { PageModel pageModel; using (StringReader reader = new StringReader(content)) { pageModel = YamlUtility.Deserialize <PageModel>(reader); } List <AbstractExpression> expressions = new List <AbstractExpression>(); expressions.Add(new PackageExpression(config.OutputPath, filename)); expressions.Add(new TypeExpress(config.OutputPath, filename)); expressions.Add(new EnumExpression(config.OutputPath, filename)); if (pageModel == null) { return; } foreach (var expression in expressions) { if (!expression.Interpret(pageModel, context)) { break; } } ConsoleLogger.WriteLine( new LogEntry { Phase = StepName, Level = LogLevel.Info, Message = $"Succeed to interpret Merf file: {filename}.yml.", }); } } catch (Exception ex) { var sb = new StringBuilder(); sb.Append($"Fail to interpret Merf file: {filename}.yml."); sb.AppendLine(" "); sb.Append($"Exception: { ex}"); ConsoleLogger.WriteLine( new LogEntry { Phase = StepName, Level = LogLevel.Error, Message = sb.ToString() }); } }); } return(Task.FromResult(1)); }