Changeset 17828 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateGenerator.cs
- Timestamp:
- 02/01/21 14:37:18 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateGenerator.cs
r17689 r17828 12 12 public class JsonTemplateGenerator { 13 13 14 public static void GenerateTemplate(string path, IOptimizer optimizer) => 15 GenerateTemplate(path, optimizer.Name, optimizer); 14 /// <summary> 15 /// static Function to generate a template. 16 /// </summary> 17 /// <param name="templatePath">the path for the template files</param> 18 /// <param name="optimizer">the optimizer object to serialize</param> 19 /// <param name="rootItem">Root JsonItem for serialization, considers only active JsonItems for serialization</param> 20 public static void GenerateTemplate(string templatePath, IOptimizer optimizer, IJsonItem rootItem) { 21 // clear all runs 22 optimizer.Runs.Clear(); 16 23 17 public static void GenerateTemplate(string path, string templateName, IOptimizer optimizer) => 18 GenerateTemplate(path, templateName, optimizer, JsonItemConverter.Extract(optimizer)); 24 // validation 25 ValidationResult validationResult = rootItem.GetValidator().Validate(); 26 if (!validationResult.Success) 27 throw validationResult.GenerateException(); 19 28 20 public static void GenerateTemplate(string path, string templateName, IOptimizer optimizer, IJsonItem rootItem) {21 29 #region Init 22 30 JObject template = JObject.Parse(Constants.Template); … … 24 32 JArray resultItems = new JArray(); 25 33 IList<IJsonItem> jsonItems = new List<IJsonItem>(); 26 string fullPath = Path.GetFullPath(path); 34 string templateName = Path.GetFileName(templatePath); 35 string templateDirectory = Path.GetDirectoryName(templatePath); 36 27 37 #endregion 28 38 … … 35 45 #region Serialize HL File 36 46 ProtoBufSerializer serializer = new ProtoBufSerializer(); 37 string hlFilePath = Path.Combine( fullPath, templateName + ".hl");47 string hlFilePath = Path.Combine(templateDirectory, $"{templateName}.hl"); 38 48 serializer.Serialize(optimizer, hlFilePath); 39 49 #endregion … … 56 66 57 67 #region Serialize and write to file 58 File.WriteAllText( fullPath + @"\" + templateName + ".json", SingleLineArrayJsonWriter.Serialize(template));68 File.WriteAllText(Path.Combine(templateDirectory, $"{templateName}.json"), SingleLineArrayJsonWriter.Serialize(template)); 59 69 #endregion 60 70 }
Note: See TracChangeset
for help on using the changeset viewer.