From 0a2bc54fe9ff167f0e19bff32cb31b43237e619e Mon Sep 17 00:00:00 2001 From: tfoman Date: Wed, 23 Sep 2015 00:04:49 +0200 Subject: [PATCH] Dont save nonexisting fields in json-files --- CobXmlSupport/GenCobCode.cs | 31 +++++++++++++++++++++++++++++++ CobXmlSupport/codeCompleter.cs | 2 ++ 2 files changed, 33 insertions(+) diff --git a/CobXmlSupport/GenCobCode.cs b/CobXmlSupport/GenCobCode.cs index 737c45a..6e9a713 100644 --- a/CobXmlSupport/GenCobCode.cs +++ b/CobXmlSupport/GenCobCode.cs @@ -215,6 +215,8 @@ namespace CobXmlSupport Cc = new codeCompleter(cmbLastFile.Text, txtPrefix.Text); Cc.TryFill_In_Dic(); Cc.TryFill_Out_Dic(); + Dictionary FieldList = new Dictionary(); + int objNr = 0; string fieldInCompl = "", fieldOutCompl = ""; foreach (CobRow rw in rowList) @@ -258,6 +260,7 @@ namespace CobXmlSupport } if (rw.Move_FromCode == null) { rw.MoveFromCode = " "; } Cc.WorkDicOut[rw.FieldName] = rw.Move_FromCode; + FieldList.Add(rw.FieldName,objNr++); } // Prefill with possibly filled out code if (chkWrap.Checked) @@ -272,7 +275,35 @@ namespace CobXmlSupport //Debug.WriteLine(rw.TagName); //Debug.WriteLine(rw.Hirarchy); } + string[] jkeys = Cc.WorkDicIn.Keys.ToArray(); + foreach (string jkey in jkeys) + { + int item; + if (!FieldList.TryGetValue(jkey,out item)) + { + string checktxt = ""; + Cc.WorkDicIn.TryGetValue(jkey, out checktxt); + if (checktxt.Trim().Length == 0) + { + Cc.WorkDicIn.Remove(jkey); + } + } + } Cc.Save_In_Dic(); + string[] jkeysOut = Cc.WorkDicOut.Keys.ToArray(); + foreach (string jkey in jkeysOut) + { + int item; + if (!FieldList.TryGetValue(jkey, out item)) + { + string checktxt = ""; + Cc.WorkDicOut.TryGetValue(jkey, out checktxt); + if (checktxt.Trim().Length == 0) + { + Cc.WorkDicOut.Remove(jkey); + } + } + } Cc.Save_Out_Dic(); if (rowList.Count > 0) diff --git a/CobXmlSupport/codeCompleter.cs b/CobXmlSupport/codeCompleter.cs index 19790f9..20c4698 100644 --- a/CobXmlSupport/codeCompleter.cs +++ b/CobXmlSupport/codeCompleter.cs @@ -24,6 +24,8 @@ namespace CobXmlSupport public codeCompleter() { + __wrkDicIn = null; + __wrkDicOut = null; __FieldPrefix = ""; __filePathId = ""; __fileId = "";