Extra backup on my local device

This commit is contained in:
2015-10-10 17:14:24 +02:00
parent 46e6585495
commit b4e8089efc
7 changed files with 141 additions and 39 deletions

View File

@ -91,7 +91,7 @@ namespace CobXmlSupport
try try
{ {
ShowCode FileWin = new ShowCode(); ShowCode FileWin = new ShowCode();
FileWin.Parent = null; FileWin.FormParent = null;
//FileWin.Labeltext = usageName; //FileWin.Labeltext = usageName;
FileWin.Labeltext = fname; FileWin.Labeltext = fname;
FileWin.CodeShower.Text = File.ReadAllText(fname); FileWin.CodeShower.Text = File.ReadAllText(fname);

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection;
namespace CobXmlSupport namespace CobXmlSupport
{ {
@ -59,7 +60,6 @@ namespace CobXmlSupport
return " *" + S.strX(' ', 72 - 15 - this.FieldName.Length) + "------" + this.FieldName + "\r\n" + return " *" + S.strX(' ', 72 - 15 - this.FieldName.Length) + "------" + this.FieldName + "\r\n" +
moveCode + moveCode +
"\r\n *" + S.strX(' ', 72 - 15 - this.FieldName.Length) + "------" + this.FieldName + "\r\n"; "\r\n *" + S.strX(' ', 72 - 15 - this.FieldName.Length) + "------" + this.FieldName + "\r\n";
} }
set{ set{
moveCode = value; moveCode = value;
@ -86,6 +86,11 @@ namespace CobXmlSupport
} }
set{ set{
moveFromCode = value; moveFromCode = value;
// Debug för att se var datat fyll på
//StackTrace stackTrace = new StackTrace();
//MethodBase methBase = stackTrace.GetFrame(1).GetMethod();
//Debug.WriteLine("MoveFromCode -> "+ methBase.Name.ToString() + " calls MoveFromCode saving " + value);
// Debug för att se var datat fyll på
} }
} }
//Holding code-parts used when generating moves, from structure //Holding code-parts used when generating moves, from structure

View File

@ -62,7 +62,7 @@ namespace CobXmlSupport
////------------------------- ////-------------------------
public readonly string NOMOVE = "NoMove"; public readonly string NOMOVE = "NoMove";
private readonly bool MOVEFROM = true; //private readonly bool MOVEFROM = true;
public string FldPref public string FldPref
{ {
@ -252,14 +252,17 @@ namespace CobXmlSupport
if (Cc.WorkDicOut.TryGetValue(rw.FieldName, out fieldOutCompl)) if (Cc.WorkDicOut.TryGetValue(rw.FieldName, out fieldOutCompl))
{ {
rw.MoveFromCode = fieldOutCompl; rw.MoveFromCode = fieldOutCompl;
//Debug.WriteLine("Existerarnde fält: " + rw.FieldName + " Kod : " + fieldOutCompl);
} }
else else
{ {
Cc.WorkDicOut.Add(rw.FieldName, ""); Cc.WorkDicOut.Add(rw.FieldName, "");
//Debug.WriteLine("Upplagt fält: " + rw.FieldName);
} }
} }
if (rw.Move_FromCode == null) { rw.MoveFromCode = " "; } if (rw.Move_FromCode == null) { rw.MoveFromCode = " "; }
Cc.WorkDicOut[rw.FieldName] = rw.Move_FromCode; Cc.WorkDicOut[rw.FieldName] = rw.Move_FromCode;
FieldList.Add(rw.FieldName, objNr++); FieldList.Add(rw.FieldName, objNr++);
} }
// Prefill with possibly filled out code // Prefill with possibly filled out code
@ -860,7 +863,7 @@ namespace CobXmlSupport
string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*"; string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*";
string slask = ""; string slask = "";
genCode = new ShowCode(); genCode = new ShowCode();
genCode.Parent = this; genCode.FormParent = this;
genCode.Labeltext = "Creating Initialization Code"; genCode.Labeltext = "Creating Initialization Code";
savedFile SF = new savedFile(); savedFile SF = new savedFile();
@ -915,9 +918,9 @@ namespace CobXmlSupport
Dictionary<string, string> indexNames = new Dictionary<string, string>(); Dictionary<string, string> indexNames = new Dictionary<string, string>();
//string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*"; //string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*";
string slask = ""; //string slask = "";
genCode = new ShowCode(); genCode = new ShowCode();
genCode.Parent = this; genCode.FormParent = this;
genCode.Labeltext = "Creating Initialization Code"; genCode.Labeltext = "Creating Initialization Code";
savedFile SF = new savedFile(); savedFile SF = new savedFile();
@ -986,7 +989,7 @@ namespace CobXmlSupport
genCode.CodeShower.Text += " PERFORM VARYING " + indTxt + " FROM 1 BY 1\r\n UNTIL " + genCode.CodeShower.Text += " PERFORM VARYING " + indTxt + " FROM 1 BY 1\r\n UNTIL " +
indTxt + "\r\n > " + tmpQfh.qualCobRow.occNum.ToString() + "\r\n"; // +tmpQfh.indexRedText; indTxt + "\r\n > " + tmpQfh.qualCobRow.occNum.ToString() + "\r\n"; // +tmpQfh.indexRedText;
if (tmpQfh.qualCobRow.isOccurs) slask = ""; //if (tmpQfh.qualCobRow.isOccurs) slask = "";
} }
} }
@ -1471,7 +1474,7 @@ namespace CobXmlSupport
string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*"; string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*";
string slask = ""; string slask = "";
genMoves = new ShowCode(); genMoves = new ShowCode();
genMoves.Parent = this; genMoves.FormParent = this;
genMoves.Labeltext = "Creating \"move to\" Code"; genMoves.Labeltext = "Creating \"move to\" Code";
// CreateComment(genMoves.CodeShower, "Moves to", "Tommy Öman", "Fordonsdata Nordic AB"); // CreateComment(genMoves.CodeShower, "Moves to", "Tommy Öman", "Fordonsdata Nordic AB");
@ -1521,7 +1524,7 @@ namespace CobXmlSupport
string aktIndList = "", slask = "", slask2 = "", struktMove = ""; ; string aktIndList = "", slask = "", slask2 = "", struktMove = ""; ;
IndexState Is = new IndexState(indexNames, rowList); IndexState Is = new IndexState(indexNames, rowList);
genExtMoves = new ShowCode(); genExtMoves = new ShowCode();
genExtMoves.Parent = this; genExtMoves.FormParent = this;
genExtMoves.Labeltext = "Creating \"move to (with loop)\" Code"; genExtMoves.Labeltext = "Creating \"move to (with loop)\" Code";
savedFile SF = new savedFile(); savedFile SF = new savedFile();
@ -1766,7 +1769,7 @@ namespace CobXmlSupport
string aktIndList = "", slask = "", slask2 = ""; string aktIndList = "", slask = "", slask2 = "";
IndexState Is = new IndexState(indexNames, rowList, false); IndexState Is = new IndexState(indexNames, rowList, false);
fromMoves = new ShowCode(); fromMoves = new ShowCode();
fromMoves.Parent = this; fromMoves.FormParent = this;
fromMoves.Labeltext = "Creating \"move from\" Code"; fromMoves.Labeltext = "Creating \"move from\" Code";
savedFile SF = new savedFile(); savedFile SF = new savedFile();
@ -1944,7 +1947,7 @@ namespace CobXmlSupport
string occParIndRows = ""; string occParIndRows = "";
IndexState Is = new IndexState(indexNames, rowList, false); IndexState Is = new IndexState(indexNames, rowList, false);
fromToMoves = new ShowCode(); fromToMoves = new ShowCode();
fromToMoves.Parent = this; fromToMoves.FormParent = this;
fromToMoves.Labeltext = "Creating \"move From - To\" Code"; fromToMoves.Labeltext = "Creating \"move From - To\" Code";
savedFile SF = new savedFile(); savedFile SF = new savedFile();
@ -2203,7 +2206,7 @@ namespace CobXmlSupport
//Create showing window //Create showing window
fromToMoves = new ShowCode(); fromToMoves = new ShowCode();
fromToMoves.Parent = this; fromToMoves.FormParent = this;
if (!justOut) if (!justOut)
{ {
fromToMoves.Labeltext = "Created \"move From To\" Code"; fromToMoves.Labeltext = "Created \"move From To\" Code";
@ -2304,14 +2307,14 @@ namespace CobXmlSupport
if (!justOut) if (!justOut)
{ {
fromToMoves.CodeShower.Text += " TO " + tmpQfh.ToExpString(); fromToMoves.CodeShower.Text += " TO " + tmpQfh.ToExpString();
if (tmpQfh.qualCobRow.MoveFromCode != null && tmpQfh.qualCobRow.Move_FromCode.Trim().Length > 0) if (tmpQfh.qualCobRow.Move_FromCode != null && tmpQfh.qualCobRow.Move_FromCode.Trim().Length > 0)
{ {
fromToMoves.CodeShower.Text += tmpQfh.qualCobRow.MoveFromCode + "\r\n"; fromToMoves.CodeShower.Text += tmpQfh.qualCobRow.MoveFromCode + "\r\n";
} }
} }
else else
{ {
if (tmpQfh.qualCobRow.MoveFromCode != null && tmpQfh.qualCobRow.Move_FromCode.Trim().Length > 0) if (tmpQfh.qualCobRow.Move_FromCode != null && tmpQfh.qualCobRow.Move_FromCode.Trim().Length > 0)
{ {
//if (tmpQfh.qualCobRow.MoveFromCode.IndexOf("<?>") > -1 || tmpQfh.qualCobRow.MoveFromCode.IndexOf("<NYPOST>") > -1) //if (tmpQfh.qualCobRow.MoveFromCode.IndexOf("<?>") > -1 || tmpQfh.qualCobRow.MoveFromCode.IndexOf("<NYPOST>") > -1)
//{ //{
@ -2410,7 +2413,7 @@ namespace CobXmlSupport
//Create showing window //Create showing window
loadResWords(); loadResWords();
fromToMoves = new ShowCode(); fromToMoves = new ShowCode();
fromToMoves.Parent = this; fromToMoves.FormParent = this;
fromToMoves.Labeltext = "Cobol \"reserved\" Words"; fromToMoves.Labeltext = "Cobol \"reserved\" Words";
savedFile SF = new savedFile(); savedFile SF = new savedFile();
@ -2471,7 +2474,7 @@ namespace CobXmlSupport
{ {
//Create showing window //Create showing window
fromToMoves = new ShowCode(); fromToMoves = new ShowCode();
fromToMoves.Parent = this; fromToMoves.FormParent = this;
fromToMoves.BSynch = true; fromToMoves.BSynch = true;
fromToMoves.Labeltext = "Cobol \"CrossRef\" List"; fromToMoves.Labeltext = "Cobol \"CrossRef\" List";

View File

@ -2,20 +2,48 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
namespace CobXmlSupport namespace CobXmlSupport
{ {
static class Program static class Program
{ {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "GenCobCode", out createdNew))
{
if (createdNew)
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new GenCobCode()); Application.Run(new GenCobCode());
} }
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}
} }
} }

View File

@ -17,6 +17,8 @@ namespace CobXmlSupport
public partial class ShowCode : Form public partial class ShowCode : Form
{ {
private GenCobCode parentWindow=null;
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"; public readonly string JSON = ".json";
@ -67,9 +69,8 @@ namespace CobXmlSupport
} }
} }
private GenCobCode parentWindow;
public GenCobCode Parent public GenCobCode FormParent
{ {
get { return parentWindow; } get { return parentWindow; }
set { parentWindow = value; } set { parentWindow = value; }
@ -104,7 +105,14 @@ namespace CobXmlSupport
{ {
codeCompleter Cc = new codeCompleter(parentWindow.CmbLastFile.Text, parentWindow.FldPref); codeCompleter Cc = new codeCompleter(parentWindow.CmbLastFile.Text, parentWindow.FldPref);
string fieldCompl = ""; string fieldCompl = "";
this.CodeShower.Text = " InPath = " + Cc.PathId + "\r\n InFile = " + Cc.FileId + "\r\n codeFile = " + Cc.CcFileInId + "\r\n codePath = " + Cc.PathId + Cc.CcFileInId + "\r\n -------------- \r\n" + this.CodeShower.Text; this.CodeShower.Text = " InPath = " +
Cc.PathId + "\r\n InFile = " +
Cc.FileId + "\r\n codeFile = " +
Cc.CcFileInId + "\r\n codePath = " +
Cc.PathId +
Cc.CcFileInId + "\r\n -------------- \r\n" +
this.CodeShower.Text;
Cc.TryFill_In_Dic(); Cc.TryFill_In_Dic();
foreach (CobRow cr in parentWindow.RowList) foreach (CobRow cr in parentWindow.RowList)
@ -127,7 +135,12 @@ namespace CobXmlSupport
refreshWindow("IN"); refreshWindow("IN");
this.CodeShower.Text = " InPath = " + Cc.PathId + "\r\n InFile = " + Cc.FileId + "\r\n codeFile = " + Cc.CcFileInId + "\r\n codePath = " + Cc.PathId + Cc.CcFileInId + "\r\n -------------- \r\n" + this.CodeShower.Text; this.CodeShower.Text = " InPath = " +
Cc.PathId + "\r\n InFile = " +
Cc.FileId + "\r\n codeFile = " +
Cc.CcFileInId + "\r\n codePath = " +
Cc.PathId +
Cc.CcFileInId + "\r\n -------------- \r\n" + this.CodeShower.Text;
} }
@ -311,7 +324,13 @@ namespace CobXmlSupport
{ {
codeCompleter Cc = new codeCompleter(parentWindow.CmbLastFile.Text, parentWindow.FldPref); codeCompleter Cc = new codeCompleter(parentWindow.CmbLastFile.Text, parentWindow.FldPref);
string fieldCompl = ""; string fieldCompl = "";
this.CodeShower.Text = " InPath = " + Cc.PathId + "\r\n InFile = " + Cc.FileId + "\r\n codeFile = " + Cc.CcFileOutId + "\r\n codePath = " + Cc.PathId + Cc.CcFileOutId + "\r\n -------------- \r\n" + this.CodeShower.Text; this.CodeShower.Text = " InPath = " +
Cc.PathId + "\r\n InFile = " +
Cc.FileId + "\r\n codeFile = " +
Cc.CcFileOutId + "\r\n codePath = " +
Cc.PathId +
Cc.CcFileOutId + "\r\n -------------- \r\n" + this.CodeShower.Text;
Cc.TryFill_Out_Dic(); Cc.TryFill_Out_Dic();
// wrkDic = new Dictionary<string, string>(); // wrkDic = new Dictionary<string, string>();
@ -335,7 +354,12 @@ namespace CobXmlSupport
refreshWindow("OUT"); refreshWindow("OUT");
this.CodeShower.Text = " InPath = " + Cc.PathId + "\r\n InFile = " + Cc.FileId + "\r\n codeFile = " + Cc.CcFileOutId + "\r\n codePath = " + Cc.PathId + Cc.CcFileOutId + "\r\n -------------- \r\n" + this.CodeShower.Text; this.CodeShower.Text = " InPath = " +
Cc.PathId + "\r\n InFile = " +
Cc.FileId + "\r\n codeFile = " +
Cc.CcFileOutId + "\r\n codePath = " +
Cc.PathId +
Cc.CcFileOutId + "\r\n -------------- \r\n" + this.CodeShower.Text;
} }
private void btnSaveAktualText_Click(object sender, EventArgs e) private void btnSaveAktualText_Click(object sender, EventArgs e)

View File

@ -9,6 +9,8 @@ namespace CobXmlSupport
{ {
public class codeCompleter public class codeCompleter
{ {
private readonly string LocBackup = "C:\\CCBackup\\";
private Dictionary<string, string> __wrkDicIn = null; private Dictionary<string, string> __wrkDicIn = null;
private Dictionary<string, string> __wrkDicOut = null; private Dictionary<string, string> __wrkDicOut = null;
private string __FieldPrefix; private string __FieldPrefix;
@ -113,10 +115,10 @@ namespace CobXmlSupport
__ccFileOutIdNoSuff = __fileId.Substring(0, __fileId.LastIndexOf(".")) + ".Out" + gPrefix; __ccFileOutIdNoSuff = __fileId.Substring(0, __fileId.LastIndexOf(".")) + ".Out" + gPrefix;
} }
private string backupSuffix() private string backupSuffix(bool rideOver=false)
{ {
string tmpSuff = ""; string tmpSuff = "";
if (S.ettingUserCodeBcup) if (S.ettingUserCodeBcup||rideOver)
{ {
tmpSuff = "." + tmpSuff = "." +
(DateTime.Now.Year - 2000).ToString("00") + (DateTime.Now.Year - 2000).ToString("00") +
@ -133,6 +135,17 @@ namespace CobXmlSupport
return tmpSuff; return tmpSuff;
} }
private string SafeBackPath()
{
return LocBackup +
"BC"+
(DateTime.Now.Year - 2000).ToString("00") +
DateTime.Now.Month.ToString("00") +
DateTime.Now.Day.ToString("00") +
"\\";
}
public void TryFill_In_Dic() public void TryFill_In_Dic()
{ {
@ -173,18 +186,31 @@ namespace CobXmlSupport
public void Save_In_Dic() public void Save_In_Dic()
{ {
string ccFileInId = __jsonPathId + __ccFileInId; string ccFileInId = __jsonPathId + __ccFileInId;
if (Directory.Exists(__jsonPathId + @"\JsonBackup\")) { } if (Directory.Exists(__jsonPathId + @"JsonBackup\")) { }
else else
{ {
Directory.CreateDirectory(__jsonPathId + @"\JsonBackup\"); Directory.CreateDirectory(__jsonPathId + @"JsonBackup\");
} }
string ccFileInBackup = __jsonPathId + @"\JsonBackup\" + __ccFileInIdNoSuff + backupSuffix();
//Panik-backup
if (Directory.Exists(SafeBackPath())) { }
else
{
Directory.CreateDirectory(SafeBackPath());
}
string ccFileInPanikBackup = SafeBackPath() + __ccFileInIdNoSuff + backupSuffix(true);
//Panik-backup
string ccFileInBackup = __jsonPathId + @"JsonBackup\" + __ccFileInIdNoSuff + backupSuffix();
if (__filePathId.Trim() == "") { } if (__filePathId.Trim() == "") { }
else else
{ {
if (File.Exists(ccFileInId)) if (File.Exists(ccFileInId))
{ {
File.Copy(ccFileInId, ccFileInPanikBackup);
if (File.Exists(ccFileInBackup)) if (File.Exists(ccFileInBackup))
{ {
File.Delete(ccFileInBackup); File.Delete(ccFileInBackup);
@ -195,21 +221,36 @@ namespace CobXmlSupport
} }
} }
public void Save_Out_Dic() public void Save_Out_Dic()
{ {
string ccFileOutId = __jsonPathId + __ccFileOutId; string ccFileOutId = __jsonPathId + __ccFileOutId;
if (Directory.Exists(__jsonPathId + @"\JsonBackup\")) { } if (Directory.Exists(__jsonPathId + @"JsonBackup\")) { }
else else
{ {
Directory.CreateDirectory(__jsonPathId + @"\JsonBackup\"); Directory.CreateDirectory(__jsonPathId + @"JsonBackup\");
} }
string ccFileOutBackup = __jsonPathId + @"\JsonBackup\" + __ccFileOutIdNoSuff + backupSuffix();
//Panik-backup
if (Directory.Exists(SafeBackPath())) { }
else
{
Directory.CreateDirectory(SafeBackPath());
}
string ccFileOutPanikBackup = SafeBackPath() + __ccFileOutIdNoSuff + backupSuffix(true);
//Panik-backup
string ccFileOutBackup = __jsonPathId + @"JsonBackup\" + __ccFileOutIdNoSuff + backupSuffix();
if (__filePathId.Trim() == "") { } if (__filePathId.Trim() == "") { }
else else
{ {
if (File.Exists(ccFileOutId)) if (File.Exists(ccFileOutId))
{ {
File.Copy(ccFileOutId, ccFileOutPanikBackup);
if (File.Exists(ccFileOutBackup)) if (File.Exists(ccFileOutBackup))
{ {
File.Delete(ccFileOutBackup); File.Delete(ccFileOutBackup);

View File

@ -128,7 +128,8 @@ namespace CobXmlSupport
txtUserName.Text = value; txtUserName.Text = value;
} }
} }
public string CompanyName
public string SettingsCompanyName
{ {
get get
{ {