using Hermes; using Newtonsoft.Json; using System; using System.IO; namespace VisionCommon { public class PatternBlockParamExt : ICloneable { private const string FILE_NAME = "PatternBlockParamExt.json"; public int PatternId1 { get; set; } = -1; public int PatternId2 { get; set; } = -1; public object Clone() { return new PatternBlockParamExt() { PatternId1 = PatternId1, PatternId2 = PatternId2, }; } public static bool Exists(string dirPath) { string filePath = Path.Combine(dirPath, FILE_NAME); return File.Exists(filePath); } public static PatternBlockParamExt Load(string dirPath) { string filePath = Path.Combine(dirPath, FILE_NAME); if (File.Exists(filePath)) { return JsonConvert.DeserializeObject( File.ReadAllText(filePath), typeof(PatternBlockParamExt)) as PatternBlockParamExt; } return new PatternBlockParamExt(); } public static int Save(string dirPath, PatternBlockParamExt PatternBlockParam) { string filePath = Path.Combine(dirPath, FILE_NAME); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } using (var fs = File.Create(filePath)) using (var sw = new StreamWriter(fs)) using (var jtw = new JsonTextWriter(sw) { Formatting = Formatting.Indented, Indentation = 2, }) { (new JsonSerializer()).Serialize(jtw, PatternBlockParam); } return E1.OK; } } }