diff --git a/CobXmlSupport/CobXmlSupport.csproj b/CobXmlSupport/CobXmlSupport.csproj
index 2bebbca..59f71c3 100644
--- a/CobXmlSupport/CobXmlSupport.csproj
+++ b/CobXmlSupport/CobXmlSupport.csproj
@@ -32,6 +32,10 @@
4
+
+ False
+ ..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll
+
@@ -90,6 +94,7 @@
ShowCode.cs
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/CobXmlSupport/ShowCode.cs b/CobXmlSupport/ShowCode.cs
index 06f675d..6ff4ae0 100644
--- a/CobXmlSupport/ShowCode.cs
+++ b/CobXmlSupport/ShowCode.cs
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
-
+using Newtonsoft.Json;
namespace CobXmlSupport
@@ -19,6 +19,7 @@ namespace CobXmlSupport
public readonly string CSV = ".csv";
public readonly string DIF = ".dif";
+ public readonly string JSON = ".json";
string oldTxt;
bool bSynch;
@@ -90,75 +91,44 @@ namespace CobXmlSupport
private void btnSynch_Click(object sender, EventArgs e)
{
- Dictionary wrkDic = null;
+ Dictionary wrkDic = null, newDic = null;
string codeComplement = "", fieldCompl = "", codeComplInit = "";
- int actRows = 0;
string inFile = parentWindow.CmbLastFile.Text.Substring(parentWindow.CmbLastFile.Text.LastIndexOf("\\") + 1);
string inPath = parentWindow.CmbLastFile.Text.Substring(0, parentWindow.CmbLastFile.Text.LastIndexOf("\\") + 1);
- //string codeFile = inFile.Substring(0, inFile.LastIndexOf(".")) + CSV;
- string codeFile = inFile.Substring(0, inFile.LastIndexOf(".")) + DIF;
- this.CodeShower.Text = " InPath = " + inPath + "\r\n InFile = " + inFile + "\r\n codeFile = " + codeFile + "\r\n codePath = " + inPath + codeFile + "\r\n -------------- \r\n" + this.CodeShower.Text;
+ // string codeFile = inFile.Substring(0, inFile.LastIndexOf(".")) + DIF;
+ string jsonFile = inFile.Substring(0, inFile.LastIndexOf(".")) + JSON;
+ this.CodeShower.Text = " InPath = " + inPath + "\r\n InFile = " + inFile + "\r\n codeFile = " + jsonFile + "\r\n codePath = " + inPath + jsonFile + "\r\n -------------- \r\n" + this.CodeShower.Text;
- if (File.Exists(inPath + codeFile))
+ if (File.Exists(inPath + jsonFile))
{
- codeComplement = File.ReadAllText(inPath + codeFile);
+ codeComplement = File.ReadAllText(inPath + jsonFile);
}
+
if (codeComplement.Length > 0)
{
-// wrkDic = moveFieldDictionary(codeComplement);
- wrkDic = moveDifFieldDictionary(codeComplement);
+ wrkDic = moveJsonFieldDictionary(codeComplement);
}
+
+ newDic = new Dictionary();
foreach (CobRow cr in parentWindow.RowList)
{
-
if (!cr.isAttribute && !cr.SampleStr.Equals(parentWindow.NOMOVE))
{
-
-
if (wrkDic != null && wrkDic.Count > 0)
{
-
if (wrkDic.TryGetValue(cr.FieldName, out fieldCompl))
{
- cr.MoveCode = deQuote( fieldCompl);
+ cr.MoveCode = fieldCompl;
}
}
- codeComplInit += "-1,0\r\n";
- codeComplInit += "BOT\r\n";
- codeComplInit += "1,0\r\n";
- if (cr.MoveCode == null)
- {
- codeComplInit += enQuote(cr.FieldName) + "\r\n";
- codeComplInit += "1,0\r\n";
- codeComplInit += enQuote(" ") + "\r\n";
- }
- else
- {
- codeComplInit += enQuote(cr.FieldName) + "\r\n";
- codeComplInit += "1,0\r\n";
- codeComplInit += enQuote(cr.MoveCode.Replace("\r\n", "\n")) + "\r\n";
- }
- actRows++;
+
+ newDic.Add(cr.FieldName, cr.MoveCode);
}
}
- codeComplInit = "TABLE\r\n" +
- "0,1\r\n" +
- "\"EXCEL\"\r\n" +
- "VECTORS\r\n" +
- "0"+actRows.ToString()+"\r\n" +
- "\"\"\r\n" +
- "TUPLES\r\n" +
- "0,2\r\n" +
- "\"\"\r\n" +
- "DATA\r\n" +
- "0,0\r\n" +
- "\"\"\r\n" +
- codeComplInit+
- "-1,0\r\n"+
- "EOD\r\n";
-
+ string njsonObj = createJsonFromDic(newDic);
string backupfile;
+
if (S.ettingUserCodeBcup)
{
backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + "." +
@@ -169,23 +139,35 @@ namespace CobXmlSupport
DateTime.Now.Minute.ToString("00") +
DateTime.Now.Second.ToString("00") + DIF;
}
- else {
- backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + ".backup"+DIF;
+ else
+ {
+ backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + ".backup" + JSON;
File.Delete(backupfile);
}
- if (File.Exists(inPath + codeFile))
+ if (File.Exists(inPath + jsonFile))
{
- File.Move(inPath + codeFile, backupfile);//+ DateTime.Now.ToString());
+ File.Move(inPath + jsonFile, backupfile);
}
- //File.WriteAllText(inPath + codeFile, codeComplInit,Encoding.Default);
- File.WriteAllText(inPath + codeFile, codeComplInit);
+ File.WriteAllText(inPath + jsonFile, njsonObj);
refreshWindow();
- this.CodeShower.Text = " InPath = " + inPath + "\r\n InFile = " + inFile + "\r\n codeFile = " + codeFile + "\r\n codePath = " + inPath + codeFile + "\r\n -------------- \r\n" + this.CodeShower.Text;
+ this.CodeShower.Text = " InPath = " + inPath + "\r\n InFile = " + inFile + "\r\n codeFile = " + jsonFile + "\r\n codePath = " + inPath + jsonFile + "\r\n -------------- \r\n" + this.CodeShower.Text;
}
+ private Dictionary moveJsonFieldDictionary(string ccIn)
+ {
+ Dictionary tmpDic = JsonConvert.DeserializeObject>(ccIn);
+ return tmpDic;
+ }
+
+ private string createJsonFromDic(Dictionary wrkDic)
+ {
+ string tmpJson = JsonConvert.SerializeObject(wrkDic);
+ return tmpJson;
+ }
+
private string deQuote(string inString)
{
string tmpStr = "";
@@ -222,7 +204,7 @@ namespace CobXmlSupport
}
else tmpStr += x[i];
}
- return "\""+tmpStr+"\"";
+ return "\"" + tmpStr + "\"";
}
@@ -247,9 +229,9 @@ namespace CobXmlSupport
int rows = 0, rowCount = 0;
Dictionary tmpDic = new Dictionary();
string[] splits = { "\r\n" };
- char[] csplit = {','};
+ char[] csplit = { ',' };
string[] items = inFil.Split(splits, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < items.Count();i++ )
+ for (int i = 0; i < items.Count(); i++)
{
string item = items[i];
switch (item.ToUpper())
@@ -284,7 +266,7 @@ namespace CobXmlSupport
{
if (rowCount < rows)
{
- tmpDic.Add(deQuote(items[i + 2]), items[i+4].Replace("\n", "\r\n"));
+ tmpDic.Add(deQuote(items[i + 2]), items[i + 4].Replace("\n", "\r\n"));
rowCount++;
i = i + 4;
}
@@ -293,7 +275,7 @@ namespace CobXmlSupport
}
case "EOD":
{
- i= items.Count();
+ i = items.Count();
break;
}
}