From b4e8089efc0bed35baf8faea30b3f77a3f76746a Mon Sep 17 00:00:00 2001 From: tfoman Date: Sat, 10 Oct 2015 17:14:24 +0200 Subject: [PATCH] Extra backup on my local device --- CobXmlSupport/CheckWorkItems.cs | 2 +- CobXmlSupport/CobRow.cs | 15 ++++++--- CobXmlSupport/GenCobCode.cs | 31 ++++++++++-------- CobXmlSupport/Program.cs | 36 ++++++++++++++++++--- CobXmlSupport/ShowCode.cs | 36 +++++++++++++++++---- CobXmlSupport/codeCompleter.cs | 57 ++++++++++++++++++++++++++++----- CobXmlSupport/frmSettings.cs | 3 +- 7 files changed, 141 insertions(+), 39 deletions(-) diff --git a/CobXmlSupport/CheckWorkItems.cs b/CobXmlSupport/CheckWorkItems.cs index 2779196..9b1c070 100644 --- a/CobXmlSupport/CheckWorkItems.cs +++ b/CobXmlSupport/CheckWorkItems.cs @@ -91,7 +91,7 @@ namespace CobXmlSupport try { ShowCode FileWin = new ShowCode(); - FileWin.Parent = null; + FileWin.FormParent = null; //FileWin.Labeltext = usageName; FileWin.Labeltext = fname; FileWin.CodeShower.Text = File.ReadAllText(fname); diff --git a/CobXmlSupport/CobRow.cs b/CobXmlSupport/CobRow.cs index 2a68542..100e17a 100644 --- a/CobXmlSupport/CobRow.cs +++ b/CobXmlSupport/CobRow.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; +using System.Reflection; namespace CobXmlSupport { @@ -54,16 +55,15 @@ namespace CobXmlSupport } } - public string MoveCode { + public string MoveCode { get { return " *" + S.strX(' ', 72 - 15 - this.FieldName.Length) + "------" + this.FieldName + "\r\n" + moveCode + "\r\n *" + S.strX(' ', 72 - 15 - this.FieldName.Length) + "------" + this.FieldName + "\r\n"; - } set{ moveCode = value; - } + } } //Holding code-parts used when generating moves, to structure //Could be a Variable, simple or qualified, could be retreival code. @@ -78,7 +78,7 @@ namespace CobXmlSupport } - public string MoveFromCode { + public string MoveFromCode { get { return " *" + S.strX(' ', 72 - 15 - this.FieldName.Length) + "------" + this.FieldName + "\r\n" + moveFromCode + @@ -86,7 +86,12 @@ namespace CobXmlSupport } set{ 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 //Could be a Variable, simple or qualified, could be retreival code. diff --git a/CobXmlSupport/GenCobCode.cs b/CobXmlSupport/GenCobCode.cs index fb8cc2c..ea2c8e3 100644 --- a/CobXmlSupport/GenCobCode.cs +++ b/CobXmlSupport/GenCobCode.cs @@ -62,7 +62,7 @@ namespace CobXmlSupport ////------------------------- public readonly string NOMOVE = "NoMove"; - private readonly bool MOVEFROM = true; + //private readonly bool MOVEFROM = true; public string FldPref { @@ -252,14 +252,17 @@ namespace CobXmlSupport if (Cc.WorkDicOut.TryGetValue(rw.FieldName, out fieldOutCompl)) { rw.MoveFromCode = fieldOutCompl; + //Debug.WriteLine("Existerarnde fält: " + rw.FieldName + " Kod : " + fieldOutCompl); } else { Cc.WorkDicOut.Add(rw.FieldName, ""); + //Debug.WriteLine("Upplagt fält: " + rw.FieldName); } } 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 @@ -860,7 +863,7 @@ namespace CobXmlSupport string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*"; string slask = ""; genCode = new ShowCode(); - genCode.Parent = this; + genCode.FormParent = this; genCode.Labeltext = "Creating Initialization Code"; savedFile SF = new savedFile(); @@ -915,9 +918,9 @@ namespace CobXmlSupport Dictionary indexNames = new Dictionary(); //string IndVarText = " *--------------------------------------------------*\r\n * Extra indexvariabler för occurs-taggar --------*\r\n *--------------------------------------------------*"; - string slask = ""; + //string slask = ""; genCode = new ShowCode(); - genCode.Parent = this; + genCode.FormParent = this; genCode.Labeltext = "Creating Initialization Code"; savedFile SF = new savedFile(); @@ -986,7 +989,7 @@ namespace CobXmlSupport genCode.CodeShower.Text += " PERFORM VARYING " + indTxt + " FROM 1 BY 1\r\n UNTIL " + 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 slask = ""; genMoves = new ShowCode(); - genMoves.Parent = this; + genMoves.FormParent = this; genMoves.Labeltext = "Creating \"move to\" Code"; // CreateComment(genMoves.CodeShower, "Moves to", "Tommy Öman", "Fordonsdata Nordic AB"); @@ -1521,7 +1524,7 @@ namespace CobXmlSupport string aktIndList = "", slask = "", slask2 = "", struktMove = ""; ; IndexState Is = new IndexState(indexNames, rowList); genExtMoves = new ShowCode(); - genExtMoves.Parent = this; + genExtMoves.FormParent = this; genExtMoves.Labeltext = "Creating \"move to (with loop)\" Code"; savedFile SF = new savedFile(); @@ -1766,7 +1769,7 @@ namespace CobXmlSupport string aktIndList = "", slask = "", slask2 = ""; IndexState Is = new IndexState(indexNames, rowList, false); fromMoves = new ShowCode(); - fromMoves.Parent = this; + fromMoves.FormParent = this; fromMoves.Labeltext = "Creating \"move from\" Code"; savedFile SF = new savedFile(); @@ -1944,7 +1947,7 @@ namespace CobXmlSupport string occParIndRows = ""; IndexState Is = new IndexState(indexNames, rowList, false); fromToMoves = new ShowCode(); - fromToMoves.Parent = this; + fromToMoves.FormParent = this; fromToMoves.Labeltext = "Creating \"move From - To\" Code"; savedFile SF = new savedFile(); @@ -2203,7 +2206,7 @@ namespace CobXmlSupport //Create showing window fromToMoves = new ShowCode(); - fromToMoves.Parent = this; + fromToMoves.FormParent = this; if (!justOut) { fromToMoves.Labeltext = "Created \"move From To\" Code"; @@ -2304,14 +2307,14 @@ namespace CobXmlSupport if (!justOut) { 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"; } } 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("") > -1) //{ @@ -2410,7 +2413,7 @@ namespace CobXmlSupport //Create showing window loadResWords(); fromToMoves = new ShowCode(); - fromToMoves.Parent = this; + fromToMoves.FormParent = this; fromToMoves.Labeltext = "Cobol \"reserved\" Words"; savedFile SF = new savedFile(); @@ -2471,7 +2474,7 @@ namespace CobXmlSupport { //Create showing window fromToMoves = new ShowCode(); - fromToMoves.Parent = this; + fromToMoves.FormParent = this; fromToMoves.BSynch = true; fromToMoves.Labeltext = "Cobol \"CrossRef\" List"; diff --git a/CobXmlSupport/Program.cs b/CobXmlSupport/Program.cs index 07b1a89..69ae45b 100644 --- a/CobXmlSupport/Program.cs +++ b/CobXmlSupport/Program.cs @@ -2,20 +2,48 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Forms; +using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Threading; + namespace CobXmlSupport { static class Program { + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetForegroundWindow(IntPtr hWnd); + /// /// The main entry point for the application. /// [STAThread] static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new GenCobCode()); + bool createdNew = true; + using (Mutex mutex = new Mutex(true, "GenCobCode", out createdNew)) + { + if (createdNew) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + 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; + } + } + } + } } } -} +} \ No newline at end of file diff --git a/CobXmlSupport/ShowCode.cs b/CobXmlSupport/ShowCode.cs index 24e4edf..a12430c 100644 --- a/CobXmlSupport/ShowCode.cs +++ b/CobXmlSupport/ShowCode.cs @@ -17,6 +17,8 @@ namespace CobXmlSupport public partial class ShowCode : Form { + private GenCobCode parentWindow=null; + public readonly string CSV = ".csv"; public readonly string DIF = ".dif"; public readonly string JSON = ".json"; @@ -67,9 +69,8 @@ namespace CobXmlSupport } } - private GenCobCode parentWindow; - public GenCobCode Parent + public GenCobCode FormParent { get { return parentWindow; } set { parentWindow = value; } @@ -104,7 +105,14 @@ namespace CobXmlSupport { codeCompleter Cc = new codeCompleter(parentWindow.CmbLastFile.Text, parentWindow.FldPref); 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(); foreach (CobRow cr in parentWindow.RowList) @@ -127,7 +135,12 @@ namespace CobXmlSupport 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); 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(); // wrkDic = new Dictionary(); @@ -335,7 +354,12 @@ namespace CobXmlSupport 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) diff --git a/CobXmlSupport/codeCompleter.cs b/CobXmlSupport/codeCompleter.cs index 20c4698..b5493d7 100644 --- a/CobXmlSupport/codeCompleter.cs +++ b/CobXmlSupport/codeCompleter.cs @@ -9,6 +9,8 @@ namespace CobXmlSupport { public class codeCompleter { + private readonly string LocBackup = "C:\\CCBackup\\"; + private Dictionary __wrkDicIn = null; private Dictionary __wrkDicOut = null; private string __FieldPrefix; @@ -113,10 +115,10 @@ namespace CobXmlSupport __ccFileOutIdNoSuff = __fileId.Substring(0, __fileId.LastIndexOf(".")) + ".Out" + gPrefix; } - private string backupSuffix() + private string backupSuffix(bool rideOver=false) { string tmpSuff = ""; - if (S.ettingUserCodeBcup) + if (S.ettingUserCodeBcup||rideOver) { tmpSuff = "." + (DateTime.Now.Year - 2000).ToString("00") + @@ -133,6 +135,17 @@ namespace CobXmlSupport 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() { @@ -173,18 +186,31 @@ namespace CobXmlSupport public void Save_In_Dic() { string ccFileInId = __jsonPathId + __ccFileInId; - if (Directory.Exists(__jsonPathId + @"\JsonBackup\")) { } + if (Directory.Exists(__jsonPathId + @"JsonBackup\")) { } 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() == "") { } else { if (File.Exists(ccFileInId)) { + File.Copy(ccFileInId, ccFileInPanikBackup); if (File.Exists(ccFileInBackup)) { File.Delete(ccFileInBackup); @@ -195,21 +221,36 @@ namespace CobXmlSupport } } + public void Save_Out_Dic() { string ccFileOutId = __jsonPathId + __ccFileOutId; - if (Directory.Exists(__jsonPathId + @"\JsonBackup\")) { } + if (Directory.Exists(__jsonPathId + @"JsonBackup\")) { } 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() == "") { } else { if (File.Exists(ccFileOutId)) { + File.Copy(ccFileOutId, ccFileOutPanikBackup); + if (File.Exists(ccFileOutBackup)) { File.Delete(ccFileOutBackup); diff --git a/CobXmlSupport/frmSettings.cs b/CobXmlSupport/frmSettings.cs index dd1d957..9b2f931 100644 --- a/CobXmlSupport/frmSettings.cs +++ b/CobXmlSupport/frmSettings.cs @@ -128,7 +128,8 @@ namespace CobXmlSupport txtUserName.Text = value; } } - public string CompanyName + + public string SettingsCompanyName { get {