Save extra code to json
This commit is contained in:
@ -32,6 +32,10 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
@ -90,6 +94,7 @@
|
|||||||
<DependentUpon>ShowCode.cs</DependentUpon>
|
<DependentUpon>ShowCode.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
<None Include="packages.config" />
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
|||||||
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
|
||||||
namespace CobXmlSupport
|
namespace CobXmlSupport
|
||||||
@ -18,6 +19,7 @@ namespace CobXmlSupport
|
|||||||
|
|
||||||
public readonly string CSV = ".csv";
|
public readonly string CSV = ".csv";
|
||||||
public readonly string DIF = ".dif";
|
public readonly string DIF = ".dif";
|
||||||
|
public readonly string JSON = ".json";
|
||||||
|
|
||||||
string oldTxt;
|
string oldTxt;
|
||||||
bool bSynch;
|
bool bSynch;
|
||||||
@ -89,75 +91,44 @@ namespace CobXmlSupport
|
|||||||
|
|
||||||
private void btnSynch_Click(object sender, EventArgs e)
|
private void btnSynch_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> wrkDic = null;
|
Dictionary<string, string> wrkDic = null, newDic = null;
|
||||||
string codeComplement = "", fieldCompl = "", codeComplInit = "";
|
string codeComplement = "", fieldCompl = "", codeComplInit = "";
|
||||||
int actRows = 0;
|
|
||||||
string inFile = parentWindow.CmbLastFile.Text.Substring(parentWindow.CmbLastFile.Text.LastIndexOf("\\") + 1);
|
string inFile = parentWindow.CmbLastFile.Text.Substring(parentWindow.CmbLastFile.Text.LastIndexOf("\\") + 1);
|
||||||
string inPath = parentWindow.CmbLastFile.Text.Substring(0, 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;
|
||||||
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 = " + 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;
|
||||||
|
|
||||||
if (File.Exists(inPath + codeFile))
|
if (File.Exists(inPath + jsonFile))
|
||||||
{
|
{
|
||||||
codeComplement = File.ReadAllText(inPath + codeFile);
|
codeComplement = File.ReadAllText(inPath + jsonFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codeComplement.Length > 0)
|
if (codeComplement.Length > 0)
|
||||||
{
|
{
|
||||||
// wrkDic = moveFieldDictionary(codeComplement);
|
wrkDic = moveJsonFieldDictionary(codeComplement);
|
||||||
wrkDic = moveDifFieldDictionary(codeComplement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newDic = new Dictionary<string, string>();
|
||||||
foreach (CobRow cr in parentWindow.RowList)
|
foreach (CobRow cr in parentWindow.RowList)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!cr.isAttribute && !cr.SampleStr.Equals(parentWindow.NOMOVE))
|
if (!cr.isAttribute && !cr.SampleStr.Equals(parentWindow.NOMOVE))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (wrkDic != null && wrkDic.Count > 0)
|
if (wrkDic != null && wrkDic.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (wrkDic.TryGetValue(cr.FieldName, out fieldCompl))
|
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++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
codeComplInit = "TABLE\r\n" +
|
newDic.Add(cr.FieldName, cr.MoveCode);
|
||||||
"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;
|
string backupfile;
|
||||||
|
|
||||||
if (S.ettingUserCodeBcup)
|
if (S.ettingUserCodeBcup)
|
||||||
{
|
{
|
||||||
backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + "." +
|
backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + "." +
|
||||||
@ -168,22 +139,35 @@ namespace CobXmlSupport
|
|||||||
DateTime.Now.Minute.ToString("00") +
|
DateTime.Now.Minute.ToString("00") +
|
||||||
DateTime.Now.Second.ToString("00") + DIF;
|
DateTime.Now.Second.ToString("00") + DIF;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + ".backup"+DIF;
|
{
|
||||||
|
backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + ".backup" + JSON;
|
||||||
File.Delete(backupfile);
|
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);
|
File.WriteAllText(inPath + jsonFile, njsonObj);
|
||||||
|
|
||||||
refreshWindow();
|
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<string, string> moveJsonFieldDictionary(string ccIn)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> tmpDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(ccIn);
|
||||||
|
return tmpDic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string createJsonFromDic(Dictionary<string, string> wrkDic)
|
||||||
|
{
|
||||||
|
string tmpJson = JsonConvert.SerializeObject(wrkDic);
|
||||||
|
return tmpJson;
|
||||||
|
}
|
||||||
|
|
||||||
private string deQuote(string inString)
|
private string deQuote(string inString)
|
||||||
{
|
{
|
||||||
string tmpStr = "";
|
string tmpStr = "";
|
||||||
@ -220,7 +204,7 @@ namespace CobXmlSupport
|
|||||||
}
|
}
|
||||||
else tmpStr += x[i];
|
else tmpStr += x[i];
|
||||||
}
|
}
|
||||||
return "\""+tmpStr+"\"";
|
return "\"" + tmpStr + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -245,9 +229,9 @@ namespace CobXmlSupport
|
|||||||
int rows = 0, rowCount = 0;
|
int rows = 0, rowCount = 0;
|
||||||
Dictionary<string, string> tmpDic = new Dictionary<string, string>();
|
Dictionary<string, string> tmpDic = new Dictionary<string, string>();
|
||||||
string[] splits = { "\r\n" };
|
string[] splits = { "\r\n" };
|
||||||
char[] csplit = {','};
|
char[] csplit = { ',' };
|
||||||
string[] items = inFil.Split(splits, StringSplitOptions.RemoveEmptyEntries);
|
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];
|
string item = items[i];
|
||||||
switch (item.ToUpper())
|
switch (item.ToUpper())
|
||||||
@ -282,7 +266,7 @@ namespace CobXmlSupport
|
|||||||
{
|
{
|
||||||
if (rowCount < rows)
|
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++;
|
rowCount++;
|
||||||
i = i + 4;
|
i = i + 4;
|
||||||
}
|
}
|
||||||
@ -291,7 +275,7 @@ namespace CobXmlSupport
|
|||||||
}
|
}
|
||||||
case "EOD":
|
case "EOD":
|
||||||
{
|
{
|
||||||
i= items.Count();
|
i = items.Count();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user