Merge branch 'master' of https://tfomancode.visualstudio.com/defaultcollection/_git/CobXml
This commit is contained in:
@ -32,6 +32,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<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.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@ -90,6 +94,7 @@
|
||||
<DependentUpon>ShowCode.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
|
||||
@ -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<string, string> wrkDic = null;
|
||||
Dictionary<string, string> 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<string, string>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
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++;
|
||||
cr.MoveCode = fieldCompl;
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
newDic.Add(cr.FieldName, cr.MoveCode);
|
||||
}
|
||||
}
|
||||
|
||||
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<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)
|
||||
{
|
||||
string tmpStr = "";
|
||||
|
||||
Reference in New Issue
Block a user