diff --git a/Classes/Enums/LogPrefixEnum.cs b/Classes/Enums/LogPrefixEnum.cs index 8fc03a9..bbeac69 100644 --- a/Classes/Enums/LogPrefixEnum.cs +++ b/Classes/Enums/LogPrefixEnum.cs @@ -11,6 +11,7 @@ enum LogPrefixEnum Sort_System, Security_System, Template_System, + Language_System, About_View, @@ -19,6 +20,6 @@ enum LogPrefixEnum Invoice_View, MainWindow_View, Notebook_View, - Setting_View, + Setting_View } } diff --git a/Classes/EnvironmentsVariable.cs b/Classes/EnvironmentsVariable.cs index 3426ab3..0033060 100644 --- a/Classes/EnvironmentsVariable.cs +++ b/Classes/EnvironmentsVariable.cs @@ -25,7 +25,7 @@ public class EnvironmentsVariable public static string UILanguage = "English"; public static string[] PossibleUILanguages = { "English", "German" }; - public const string PROGRAM_VERSION = "1.4.3.0"; + public const string PROGRAM_VERSION = "1.4.4.0"; public const string PROGRAM_LICENSE = "License: Open source"; // Placeholder public static string ConfigVersion; public const string PROGRAM_SUPPORTEDFORMAT = ".pdf"; diff --git a/Classes/GlobalUsing.cs b/Classes/GlobalUsing.cs index 94c3ae9..a96f834 100644 --- a/Classes/GlobalUsing.cs +++ b/Classes/GlobalUsing.cs @@ -24,4 +24,5 @@ global using System.Threading.Tasks; global using System.Windows.Data; global using System.Windows.Input; -global using System.Windows.Threading; \ No newline at end of file +global using System.Windows.Threading; +global using System.Security.Cryptography; \ No newline at end of file diff --git a/Classes/LanguageManager.cs b/Classes/LanguageManager.cs index e428d74..61b8b38 100644 --- a/Classes/LanguageManager.cs +++ b/Classes/LanguageManager.cs @@ -14,6 +14,8 @@ public static void Init() }; Application.Current.Resources.MergedDictionaries.Add(dict); + + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Language_System, "Language system has been initialized."); } } } diff --git a/Core/BackUpSystem.cs b/Core/BackUpSystem.cs index caa4dd5..739998a 100644 --- a/Core/BackUpSystem.cs +++ b/Core/BackUpSystem.cs @@ -8,6 +8,8 @@ public class BackUpSystem public void CheckBackUpCount() { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, "CheckBackUpCount has been called."); + try { //get all files in the backup folder @@ -18,14 +20,24 @@ public void CheckBackUpCount() //if its zero or negativ => no files to delete int hasToDeleteCounter = files.Length - EnvironmentsVariable.MaxCountBackUp; - if (hasToDeleteCounter > 0) - //delete the oldest files - for (int i = 0; i < hasToDeleteCounter; i++) - try { File.Delete(files[i]); } catch { } + + if (!(hasToDeleteCounter > 0)) + return; + + + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, "CheckBackUpCount has been found " + hasToDeleteCounter + " files to delete."); + //delete the oldest files + for (int i = 0; i < hasToDeleteCounter; i++) + try + { + File.Delete(files[i]); + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, "CheckBackUpCount has been deleted the file: (autobackup overflow)" + files[i]); + } + catch { } } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, "CheckBackUpCount has been failed. err: " + ex.Message); } } @@ -33,7 +45,10 @@ public bool BackUp(string backupFilePath, BackUpView backUpMgr = null) { bool wasPerformedCorrectly = false; InvoiceSystem iSys = new InvoiceSystem(); - + + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, "BackUp has been called."); + DateTime start = DateTime.Now; + try { //set the main window for the progress bar @@ -125,15 +140,21 @@ public bool BackUp(string backupFilePath, BackUpView backUpMgr = null) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, "BackUp has been failed. err: " + ex.Message); return false; } + DateTime stop = DateTime.Now; + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"BackUp has been finished. Took: {(stop - start).TotalMilliseconds} ms, that is in seconds: {(stop - start).TotalSeconds} s"); + return wasPerformedCorrectly; } public bool Restore(string backupFilePath, BackUpView backUpMgr = null) { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, "Restore has been called."); + DateTime start = DateTime.Now; + //set the main window for the progress bar if (backUpMgr != null) _backUpMgrView = backUpMgr; @@ -277,7 +298,7 @@ public bool Restore(string backupFilePath, BackUpView backUpMgr = null) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, "Error while restoring, err: " + ex.Message); wasPerformedCorrectly = false; } @@ -287,7 +308,11 @@ public bool Restore(string backupFilePath, BackUpView backUpMgr = null) //delete all temp files foreach (string file in allTempFiles) - try { File.Delete(file); } catch { } + try + { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.BackUp_System, $"Deleting temp file: {file}"); + File.Delete(file); + } catch { } //must be, if the backup is from a older version (v1.2.3.2 or older) int noteCount = 0; @@ -295,6 +320,8 @@ public bool Restore(string backupFilePath, BackUpView backUpMgr = null) if (backUp.Notebook != null) noteCount = backUp.Notebook.Notebook.Count; + DateTime stop = DateTime.Now; + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"Restore has been finished. Took: {(stop - start).TotalMilliseconds} ms, that is in seconds: {(stop - start).TotalSeconds} s"); //show the results MessageBox.Show($"{backUp.EntityCount - (invoice_AlreadyExistCounter + invoice_WasOverwrittenCounter)} {Application.Current.Resources["invoicesWereRestored"] as string}" + Environment.NewLine + @@ -308,11 +335,15 @@ public bool Restore(string backupFilePath, BackUpView backUpMgr = null) $"{Application.Current.Resources["fromTotal"] as string} {noteCount} {Application.Current.Resources["notes"] as string}", Application.Current.Resources["recoveryCompleted"] as string, MessageBoxButton.OK); + return wasPerformedCorrectly; } public bool SaveAs(string backupFilePath, string newPath) { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"SaveAs() has been called"); + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"Save as: {backupFilePath} to {newPath}"); + //return if the backup not exist if (!File.Exists(backupFilePath)) { @@ -329,13 +360,15 @@ public bool SaveAs(string backupFilePath, string newPath) //saves the backup to the new path File.Copy(backupFilePath, newPath); - LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.BackUp_System, ""); - + return true; } public async IAsyncEnumerable GetBackUps() { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"GetBackUps() has been called"); + DateTime start = DateTime.Now; + BackUpSystem buSys = new BackUpSystem(); //get all files in the backup folder @@ -354,10 +387,16 @@ public async IAsyncEnumerable GetBackUps() //yield the result yield return backUpMetaData; } + + DateTime stop = DateTime.Now; + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"GetBackUps() has been finished. Took: {(stop - start).TotalMilliseconds} ms, that is in seconds: {(stop - start).TotalSeconds} s"); } private BackUpInfoModel GetBackUpMetaData(string file) { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"GetBackUpMetaData() has been called"); + DateTime start = DateTime.Now; + try { LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.BackUp_System, $"Get meta data from backup file: {file}"); @@ -391,11 +430,14 @@ private BackUpInfoModel GetBackUpMetaData(string file) //get file path backUpMetaData.BackUpPath = file; + DateTime stop = DateTime.Now; + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"GetBackUpMetaData() has been finished. Took: {(stop - start).TotalMilliseconds} ms"); + return backUpMetaData; } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, $"The BackUp file is corrupted, abort the process! {file} Error: {ex.Message}"); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, $"The BackUp file is corrupted, abort the process! {file} err: {ex.Message}"); return new BackUpInfoModel { }; } @@ -403,6 +445,8 @@ private BackUpInfoModel GetBackUpMetaData(string file) public static string GetFileSize(string path) { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"GetFileSize() has been called"); + long size = new FileInfo(path).Length; string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB @@ -416,15 +460,18 @@ public static string GetFileSize(string path) public bool Delete(string backUpPath) { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.BackUp_System, $"Delete() has been called"); + //delete the backup try { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.BackUp_System, $"Delete backup file: {backUpPath}"); File.Delete(backUpPath); return true; } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.BackUp_System, "Could not delete the backup file! err:" + ex.Message); return false; } } diff --git a/Core/ConfigSystem.cs b/Core/ConfigSystem.cs index 659570b..61d70a9 100644 --- a/Core/ConfigSystem.cs +++ b/Core/ConfigSystem.cs @@ -4,6 +4,8 @@ public class ConfigSystem { public void Init() { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Config_System, "Config init has been started."); + try { string json = String.Empty; @@ -39,19 +41,21 @@ public void Init() EnvironmentsVariable.MoneyUnit = config.MoneyUnit; EnvironmentsVariable.CreateABackupEveryTimeTheProgramStarts = config.CreateABackupEveryTimeTheProgramStarts; EnvironmentsVariable.MaxCountBackUp = config.MaxCountBackUp; + //if the owner starts this program with an older config version, then by default there is NULL, and the program would crash at init if (config.ColumnVisibility is not null) EnvironmentsVariable.ColumnVisibility = config.ColumnVisibility; - Save(); + SaveIntoJsonFile(); + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Config_System, "Config init has been finished."); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Config_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Config_System, "Config init has been failed. err: " + ex.Message); } } - public void Save() + public void SaveIntoJsonFile() { ConfigModel config = new ConfigModel() { @@ -66,8 +70,17 @@ public void Save() MaxCountBackUp = EnvironmentsVariable.MaxCountBackUp, ColumnVisibility = EnvironmentsVariable.ColumnVisibility }; - - File.WriteAllText(EnvironmentsVariable.PathConfig + EnvironmentsVariable.ConfigJsonFileName, JsonConvert.SerializeObject(config, Formatting.Indented)); + + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Config_System, "SaveIntoJsonFile() has been called"); + + try + { + File.WriteAllText(EnvironmentsVariable.PathConfig + EnvironmentsVariable.ConfigJsonFileName, JsonConvert.SerializeObject(config, Formatting.Indented)); + } + catch (Exception ex) + { + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Config_System, $"Error saving changes to the config file, err: {ex.Message}"); + } } } } diff --git a/Core/InvoiceSystem.cs b/Core/InvoiceSystem.cs index aad1dec..b5e1724 100644 --- a/Core/InvoiceSystem.cs +++ b/Core/InvoiceSystem.cs @@ -8,11 +8,18 @@ public void Init() { //set the flag to false EnvironmentsVariable.IsInvoiceInitFinish = false; + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, "set EnvironmentsVariable.IsInvoiceInitFinish to false"); + + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Invoice_System, "Initializing the invoices..."); EnvironmentsVariable.AllInvoices.Clear(); + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, "Loading the invoices from the json file..."); + string json = File.ReadAllText(EnvironmentsVariable.PathInvoices + EnvironmentsVariable.InvoicesJsonFileName); + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, "Finished, loading the invoices from the json file"); + if (!(json.Equals("[]") || String.IsNullOrWhiteSpace(json) || json.Equals("null"))) EnvironmentsVariable.AllInvoices = JsonConvert.DeserializeObject>(json); @@ -21,10 +28,11 @@ public void Init() //set the flag to true EnvironmentsVariable.IsInvoiceInitFinish = true; + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, "set EnvironmentsVariable.IsInvoiceInitFinish to true"); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while initializing the invoices, err: " + ex.Message); } } @@ -37,14 +45,17 @@ public void AddInvoice(InvoiceModel newInvoice, string filePath, string newPath) MessageBox.Show(Application.Current.Resources["fileDoNotExist"] as string); return; } + EnvironmentsVariable.AllInvoices.Add(newInvoice); + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, $"start FileCp filePath: {filePath} newPath: {newPath}"); File.Copy(filePath, newPath); + SaveIntoJsonFile(); LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Invoice_System, $"A new invoice has been added. [{newInvoice.FileID}]"); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while adding a new invoice, err: " + ex.Message); } } @@ -66,7 +77,7 @@ public void EditInvoice(InvoiceModel oldInvoice, InvoiceModel newInvoice) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while editing a invoice, err: " + ex.Message); } } @@ -88,7 +99,7 @@ public void RemoveInvoice(InvoiceModel oldInvoice) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while deleting a invoice, err: " + ex.Message); } } @@ -96,17 +107,21 @@ public void SaveAs(InvoiceModel invoice, string path) { try { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Invoice_System, $"A invoice has been saved as. ID: [{invoice.FileID}] Path: [{path}]"); File.Copy(EnvironmentsVariable.PathInvoices + invoice.FileID + EnvironmentsVariable.PROGRAM_SUPPORTEDFORMAT, path); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while saving a invoice as, err: " + ex.Message); } } public bool CheckIfInvoiceExist(string filePath) { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, $"CheckIfInvoiceExist() was called"); + bool existAlready = false; + try { string hashID = SecuritySystem.GetMD5HashFromFile(filePath); @@ -120,7 +135,7 @@ public bool CheckIfInvoiceExist(string filePath) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while checking if the invoice exist, err: " + ex.Message); } return existAlready; @@ -128,9 +143,21 @@ public bool CheckIfInvoiceExist(string filePath) public bool CheckIfInvoicesDataHasChanged(InvoiceModel backupInvoice) { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, $"CheckIfInvoicesDataHasChanged() was called"); + bool hasChanged = false; - var invoice = EnvironmentsVariable.AllInvoices.Find(x => x.FileID.Equals(backupInvoice.FileID)); + InvoiceModel invoice; + + try + { + invoice = EnvironmentsVariable.AllInvoices.Find(x => x.FileID.Equals(backupInvoice.FileID)); + } + catch (Exception ex) + { + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while getting the invoice, err: " + ex.Message); + return false; + } if (invoice.Reference != backupInvoice.Reference) hasChanged = true; @@ -164,6 +191,8 @@ public bool CheckIfInvoicesDataHasChanged(InvoiceModel backupInvoice) public void OverrideInvoice(InvoiceModel invoice) { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, $"OverrideInvoice() was called"); + try { //find the invoice in the list @@ -184,14 +213,23 @@ public void OverrideInvoice(InvoiceModel invoice) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, "Error while overriding a invoice, err: " + ex.Message); } } private void SaveIntoJsonFile() { - File.WriteAllText(EnvironmentsVariable.PathInvoices + EnvironmentsVariable.InvoicesJsonFileName, JsonConvert.SerializeObject(EnvironmentsVariable.AllInvoices, Formatting.Indented)); + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Invoice_System, $"SaveIntoJsonFile() was called"); + + try + { + File.WriteAllText(EnvironmentsVariable.PathInvoices + EnvironmentsVariable.InvoicesJsonFileName, JsonConvert.SerializeObject(EnvironmentsVariable.AllInvoices, Formatting.Indented)); + } + catch (Exception ex) + { + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Invoice_System, $"Error while saving the invoices into the json file, err: {ex.Message}"); + } } } } diff --git a/Core/LoggerSystem.cs b/Core/LoggerSystem.cs index 95102d8..b2169c6 100644 --- a/Core/LoggerSystem.cs +++ b/Core/LoggerSystem.cs @@ -51,6 +51,7 @@ private static string GetEnumPrefixAsString(LogPrefixEnum prefix) LogPrefixEnum.Notebook_System => "Notebook-System", LogPrefixEnum.Sort_System => "Sort-System", LogPrefixEnum.Security_System => "Security-System", + LogPrefixEnum.Language_System => "Language-System", LogPrefixEnum.About_View => "About-View", LogPrefixEnum.BackUp_View => "BackUp-View", LogPrefixEnum.SaveAs_View => "SaveAs-View", diff --git a/Core/NotebookSystem.cs b/Core/NotebookSystem.cs index a7a8e0a..5080cff 100644 --- a/Core/NotebookSystem.cs +++ b/Core/NotebookSystem.cs @@ -6,16 +6,20 @@ public void Init() { try { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Notebook_System, "Notebook init has been started."); + EnvironmentsVariable.Notebook.Notebook.Clear(); string json = File.ReadAllText(EnvironmentsVariable.PathNotebook + EnvironmentsVariable.NotebooksJsonFileName); if (!(json.Equals("[]") || String.IsNullOrWhiteSpace(json) || json.Equals("null"))) EnvironmentsVariable.Notebook = JsonConvert.DeserializeObject(json); + + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Notebook_System, "Notebook system has been initialized."); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, "Error initializing Notebook System, err: " + ex.Message); } } @@ -30,7 +34,7 @@ public void AddNote(NoteModel newNote) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, "Error adding note, err: " + ex.Message); } } @@ -48,7 +52,7 @@ public void EditNote(NoteModel editNote) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, "Error editing note, err: " + ex.Message); } } @@ -63,25 +67,36 @@ public void RemoveNote(NoteModel oldNote) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, "Error removing note, err: " + ex.Message); } } public bool CheckIfNoteExist(NoteModel note) { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Notebook_System, "CheckIfNoteExist() has been called"); return EnvironmentsVariable.Notebook.Notebook.Exists(x => x.Id == note.Id); } public bool CheckIfNoteHasChanged(NoteModel note) { - NoteModel noteFromList = EnvironmentsVariable.Notebook.Notebook.Find(x => x.Id == note.Id); + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Notebook_System, "CheckIfNoteHasChanged() has been called"); + NoteModel noteFromList = EnvironmentsVariable.Notebook.Notebook.Find(x => x.Id == note.Id); return noteFromList.Name != note.Name || noteFromList.Value != note.Value; } private void SaveIntoJsonFile() { - File.WriteAllText(EnvironmentsVariable.PathNotebook + EnvironmentsVariable.NotebooksJsonFileName, JsonConvert.SerializeObject(EnvironmentsVariable.Notebook, Formatting.Indented)); + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Notebook_System, "SaveIntoJsonFile() has been called"); + + try + { + File.WriteAllText(EnvironmentsVariable.PathNotebook + EnvironmentsVariable.NotebooksJsonFileName, JsonConvert.SerializeObject(EnvironmentsVariable.Notebook, Formatting.Indented)); + } + catch (Exception ex) + { + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_System, $"Error saving changes to the notebook file, err: {ex.Message}"); + } } } } diff --git a/Core/SecuritySystem.cs b/Core/SecuritySystem.cs index 7658d43..b5d885e 100644 --- a/Core/SecuritySystem.cs +++ b/Core/SecuritySystem.cs @@ -4,31 +4,33 @@ class SecuritySystem { public static string GetMD5HashFromFile(string path) { - using var md5 = System.Security.Cryptography.MD5.Create(); - using var stream = System.IO.File.OpenRead(path); + using var md5 = MD5.Create(); + using var stream = File.OpenRead(path); try { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Security_System, $"Get MD5 Hash from file: {path}"); return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant(); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Security_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Security_System, "Error while getting MD5 Hash from file, err:" + ex.Message); throw new Exception(ex.Message); } } public static string GetMD5HashFromByteArray(byte[] bytes) { - using var md5 = System.Security.Cryptography.MD5.Create(); + using var md5 = MD5.Create(); try { + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Security_System, "Get MD5 Hash from byte array"); return BitConverter.ToString(md5.ComputeHash(bytes)).Replace("-", "").ToLowerInvariant(); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Security_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Security_System, "Error while getting MD5 Hash from byte array, err:" + ex.Message); throw new Exception(ex.Message); } } diff --git a/Core/SortSystem.cs b/Core/SortSystem.cs index 5719fce..a95979e 100644 --- a/Core/SortSystem.cs +++ b/Core/SortSystem.cs @@ -43,6 +43,9 @@ public void Sort() { try { + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Sort_System, $"Start sorting invoices"); + DateTime startTime = DateTime.Now; + EnvironmentsVariable.FilteredInvoices = allInvoices .Where(x => x.Reference.ToLower().Contains(filterReference) || String.IsNullOrEmpty(filterReference)) .Where(x => x.InvoiceNumber.ToLower().Contains(filterInvoiceNumber) || String.IsNullOrEmpty(filterInvoiceNumber)) @@ -55,10 +58,12 @@ public void Sort() .Where(x => x.MoneyTotal == filterMoneyTotal || filterMoneyTotal == double.MinValue) .Where(x => x.Tags.Select(y => y.ToLower()).Contains(filterTags.ToLower()) || String.IsNullOrEmpty(filterTags)) .ToList(); + + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Sort_System, $"Stop sorting invoices took {(DateTime.Now - startTime).TotalMilliseconds} ms"); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Sort_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Sort_System, $"Error while sorting invoices {ex.Message}"); } } } diff --git a/Core/TemplateSystem.cs b/Core/TemplateSystem.cs index 7a001cf..ab1aafb 100644 --- a/Core/TemplateSystem.cs +++ b/Core/TemplateSystem.cs @@ -12,10 +12,12 @@ public void Init() if (!(json.Equals("[]") || String.IsNullOrWhiteSpace(json) || json.Equals("null"))) EnvironmentsVariable.AllTemplates = JsonConvert.DeserializeObject>(json); + + LoggerSystem.Log(LogStateEnum.Info, LogPrefixEnum.Template_System, "Template System Initialized Successfully."); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, $"Error initializing Template System: {ex.Message}"); } } @@ -29,7 +31,7 @@ public void AddTemplate(TemplateModel newTemplate) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, $"Error adding template: {ex.Message}"); } } @@ -47,7 +49,7 @@ public void EditTemplate(string oldTemplateName, TemplateModel newTemplate) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, $"Error editing template: {ex.Message}"); } } @@ -62,13 +64,22 @@ public void RemoveTemplate(TemplateModel oldTemplate) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, $"Error deleting template: {ex.Message}"); } } - + private void SaveIntoJsonFile() { - File.WriteAllText(EnvironmentsVariable.PathTemplates + EnvironmentsVariable.TemplatesJsonFileName, JsonConvert.SerializeObject(EnvironmentsVariable.AllTemplates, Formatting.Indented)); + LoggerSystem.Log(LogStateEnum.Debug, LogPrefixEnum.Template_System, "SaveIntoJsonFile() has been called"); + + try + { + File.WriteAllText(EnvironmentsVariable.PathTemplates + EnvironmentsVariable.TemplatesJsonFileName, JsonConvert.SerializeObject(EnvironmentsVariable.AllTemplates, Formatting.Indented)); + } + catch (Exception ex) + { + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Template_System, $"Error saving changes to the template file: {ex.Message}"); + } } } } diff --git a/InvoicesManager.csproj b/InvoicesManager.csproj index 019cdf6..e4ece30 100644 --- a/InvoicesManager.csproj +++ b/InvoicesManager.csproj @@ -8,8 +8,8 @@ InvoicesManager.App true True - 1.4.3.0 - 1.4.3.0 + 1.4.4.0 + 1.4.4.0 GermanNightmare Schecher_1 Debug;Release diff --git a/README.md b/README.md index 4dbcf4a..bee2552 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ It's simple, there are enough ways to filter your documents. ## How to Download: Go to the "Releases" and download any version. (for security the latest one).
-Or [press here](https://github.com/Invoices-Manager/Invoices-Manager-Windows/releases/download/InvoicesManager-Vers-1.4.3.0/InvoicesManager_WindowsX86.zip) to download if you want the latest one (normal)
-Or [press here](https://github.com/Invoices-Manager/Invoices-Manager-Windows/releases/download/InvoicesManager-Vers-1.4.3.0/InvoicesManager_WindowsX86_Standalone.zip) to download if you want the latest one (standalone)
+Or [press here](https://github.com/Invoices-Manager/Invoices-Manager-Windows/releases/download/InvoicesManager-Vers-1.4.4.0/InvoicesManager_WindowsX86.zip) to download if you want the latest one (normal)
+Or [press here](https://github.com/Invoices-Manager/Invoices-Manager-Windows/releases/download/InvoicesManager-Vers-1.4.4.0/InvoicesManager_WindowsX86_Standalone.zip) to download if you want the latest one (standalone)
## Features: @@ -66,6 +66,9 @@ Or [press here](https://github.com/Invoices-Manager/Invoices-Manager-Windows/rel ### Z = Minor version (small updates) ### W = Revision version (bug fixes) +## v1.4.4.0 +- Logging has been improved. (more loggin, no worries will only be stored on your pc) + ## v1.4.3.0 - In the invoice view (add & edit) you can now search by template, document type & the organization (just type in the box) - The backup view has been improved (there is now a backup manager) diff --git a/Views/InvoiceMainView.xaml.cs b/Views/InvoiceMainView.xaml.cs index 85b4d6e..345da23 100644 --- a/Views/InvoiceMainView.xaml.cs +++ b/Views/InvoiceMainView.xaml.cs @@ -565,7 +565,7 @@ private void MenuItem_Click(object sender, RoutedEventArgs e) //save into the config file ConfigSystem _cs = new ConfigSystem(); - _cs.Save(); + _cs.SaveIntoJsonFile(); } private void SetColumnVisibility() diff --git a/Views/SettingView.xaml.cs b/Views/SettingView.xaml.cs index 5e61a43..01915e3 100644 --- a/Views/SettingView.xaml.cs +++ b/Views/SettingView.xaml.cs @@ -33,7 +33,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Setting_View, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Setting_View, "Error while loading settings, err: " + ex.Message); } } @@ -58,14 +58,14 @@ private void Bttn_SaveSettings_Click(object sender, RoutedEventArgs e) EnvironmentsVariable.InitWorkPath(); ConfigSystem cSys = new ConfigSystem(); - cSys.Save(); + cSys.SaveIntoJsonFile(); LanguageManager.Init(); NotebookSystem nSys = new NotebookSystem(); nSys.Init(); } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Setting_View, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Setting_View, "Error while saving settings, err: " + ex.Message); } } diff --git a/Windows/MainWindow.xaml.cs b/Windows/MainWindow.xaml.cs index df869e8..d6a0569 100644 --- a/Windows/MainWindow.xaml.cs +++ b/Windows/MainWindow.xaml.cs @@ -33,7 +33,7 @@ public MainWindow() } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.MainWindow_View, ex.Message); + LoggerSystem.Log(LogStateEnum.Fatal, LogPrefixEnum.MainWindow_View, "Error while initializing the main window, err: " + ex.Message); } } diff --git a/Windows/NotebookWindow.xaml.cs b/Windows/NotebookWindow.xaml.cs index ebaa311..b93dc2b 100644 --- a/Windows/NotebookWindow.xaml.cs +++ b/Windows/NotebookWindow.xaml.cs @@ -56,7 +56,7 @@ private void LoadNotebooks() } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, "Error while loading the notebooks, err: " + ex.Message); } } @@ -80,7 +80,7 @@ private void Bttn_LoadNote_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, "Error while loading the note, err: " + ex.Message); } } @@ -101,7 +101,7 @@ private void Bttn_DeleteNote_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, "Error while deleting the note, err: " + ex.Message); } } @@ -143,7 +143,7 @@ private void Bttn_SaveNote_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { - LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, ex.Message); + LoggerSystem.Log(LogStateEnum.Error, LogPrefixEnum.Notebook_View, "Error while saving the note, err: " + ex.Message); } }