From 6c57a826a4287b1ca3ea418fcc2aed50ed129bdc Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 24 Nov 2019 16:39:46 +0200 Subject: Implemented AutoLogRemoval & MaxFileSizeLimit to FileLogger, LogFileParser and TFS bug reporting!!! --- .../Tango.UnitTesting/Logging/Parsing_TST.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Software/Visual_Studio/Tango.UnitTesting/Logging') diff --git a/Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs index 57856f9cb..8cc87e700 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.Integration.Logging; using Tango.Logging; @@ -30,5 +31,26 @@ namespace Tango.UnitTesting.Logging var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); var logs = parser.Parse(logFile); } + + [TestMethod] + public void Parse_Multi_Part_Log_Files() + { + var manager = LogManager.Default; + var fileLogger = new FileLogger(); + var folder = FileLogger.DefaultLogsFolder; + fileLogger.EnableMaxFileSizeLimit = true; + fileLogger.MaxFileSizeLimit = 10000; + LogManager.Default.RegisterLogger(fileLogger); + for (int i = 0; i < 100; i++) + { + manager.Log($"This is a test {i}"); + Thread.Sleep(100); + } + Thread.Sleep(1000); + ApplicationLogFileParser parser = new ApplicationLogFileParser(); + var logFiles = parser.GetLogFiles(); + var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); + var logs = parser.Parse(logFile); + } } } -- cgit v1.3.1 From 5a06b997b7ef29c566bad2bc65f927e9443c3888 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 8 Jan 2020 13:53:48 +0200 Subject: Implemented maintenance mid-tank graphics. Implemented session file logger. --- .../Converters/LiquidTypeToBrushConverter.cs | 52 ++++++++++ .../MidTankLevelToElementHeightConverter.cs | 6 +- .../Tango.PPC.Maintenance/Images/cl-full.png | Bin 0 -> 3454 bytes .../Tango.PPC.Maintenance/Images/cone-empty.png | Bin 0 -> 2174 bytes .../Tango.PPC.Maintenance/Images/cone-full.png | Bin 0 -> 1752 bytes .../Tango.PPC.Maintenance/Images/l-full.png | Bin 0 -> 19717 bytes .../Tango.PPC.Maintenance/Images/lubricant2.png | Bin 0 -> 194234 bytes .../Tango.PPC.Maintenance.csproj | 12 ++- .../Views/MaintenanceView.xaml | 113 +++++++++++---------- .../Visual_Studio/Tango.BL/Entities/LiquidType.cs | 8 ++ .../Tango.Logging/SessionFileLogger.cs | 103 +++++++++++++++++++ .../Tango.Logging/Tango.Logging.csproj | 1 + .../Tango.UnitTesting/Logging/SessionLoging_TST.cs | 38 +++++++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 3 +- 14 files changed, 277 insertions(+), 59 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/LiquidTypeToBrushConverter.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cl-full.png create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-empty.png create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-full.png create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/l-full.png create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/lubricant2.png create mode 100644 Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Logging/SessionLoging_TST.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting/Logging') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/LiquidTypeToBrushConverter.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/LiquidTypeToBrushConverter.cs new file mode 100644 index 000000000..c7e828148 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/LiquidTypeToBrushConverter.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using Tango.BL.Entities; +using Tango.SharedUI.Helpers; + +namespace Tango.PPC.Maintenance.Converters +{ + public class LiquidTypeToBrushConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is LiquidType) + { + LiquidType type = value as LiquidType; + if (type.Type == BL.Enumerations.LiquidTypes.Lubricant) + { + ImageBrush lubricantBrush = new ImageBrush() { Stretch = Stretch.None, TileMode = TileMode.Tile, ViewportUnits = BrushMappingMode.Absolute }; + lubricantBrush.ImageSource = ResourceHelper.GetImageFromResources(@"Images/lubricant2.png"); + lubricantBrush.Viewport = new System.Windows.Rect(lubricantBrush.ImageSource.Width/3, lubricantBrush.ImageSource.Height/3, lubricantBrush.ImageSource.Width, lubricantBrush.ImageSource.Height); + return lubricantBrush; + } + if (type.Type == BL.Enumerations.LiquidTypes.Cleaner) + { + ImageBrush cleanerBrush = new ImageBrush(){ Stretch = Stretch.None, TileMode = TileMode.Tile, ViewportUnits = BrushMappingMode.Absolute }; + cleanerBrush.ImageSource = ResourceHelper.GetImageFromResources(@"Images/cl-full.png"); + cleanerBrush.Viewport = new System.Windows.Rect(5, 5, cleanerBrush.ImageSource.Width, cleanerBrush.ImageSource.Height); + return cleanerBrush; + } + else + { + return new SolidColorBrush(type.LiquidTypeColor); ; + } + } + return null; + + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + + } +} + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/MidTankLevelToElementHeightConverter.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/MidTankLevelToElementHeightConverter.cs index 5cf3f535c..94d1ed8b8 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/MidTankLevelToElementHeightConverter.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Converters/MidTankLevelToElementHeightConverter.cs @@ -16,9 +16,9 @@ namespace Tango.PPC.Maintenance.Converters try { double parentActualHeight = (double)values[0]; - double midTankLevel = (double)values[1]; - - return (midTankLevel / MachineOperator.MAX_MIDTANK_LITERS) * parentActualHeight; + double midTankLevel = Math.Min((double)values[1], MachineOperator.MAX_MIDTANK_LITERS); + //var test = (parentActualHeight - (midTankLevel / MachineOperator.MAX_MIDTANK_LITERS) * parentActualHeight); + return (parentActualHeight - (midTankLevel / MachineOperator.MAX_MIDTANK_LITERS) * parentActualHeight); } catch { diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cl-full.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cl-full.png new file mode 100644 index 000000000..5aaea8e6c Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cl-full.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-empty.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-empty.png new file mode 100644 index 000000000..d65b8f793 Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-empty.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-full.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-full.png new file mode 100644 index 000000000..c42abf56e Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/cone-full.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/l-full.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/l-full.png new file mode 100644 index 000000000..2607f4a26 Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/l-full.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/lubricant2.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/lubricant2.png new file mode 100644 index 000000000..554c16305 Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Images/lubricant2.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj index a43fc2dc3..3f9f7c7b9 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj @@ -102,6 +102,7 @@ GlobalVersionInfo.cs + @@ -255,10 +256,19 @@ + + + + + + + + + - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml index c843daffc..e71a1827e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml @@ -15,6 +15,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -88,67 +144,16 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Temperature Inks diff --git a/Software/Visual_Studio/Tango.BL/Entities/LiquidType.cs b/Software/Visual_Studio/Tango.BL/Entities/LiquidType.cs index 60fdc6707..ce09d72ac 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/LiquidType.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/LiquidType.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; +using Tango.BL.Enumerations; namespace Tango.BL.Entities { @@ -24,6 +25,13 @@ namespace Tango.BL.Entities get { return Core.Helpers.ColorHelper.IntegerToColor(Color); } } + [NotMapped] + [JsonIgnore] + public LiquidTypes Type + { + get { return (LiquidTypes)Code; } + } + /// /// Initializes a new instance of the class. /// diff --git a/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs new file mode 100644 index 000000000..f3c23ca25 --- /dev/null +++ b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Logging +{ + public class SessionFileLogger : ILogger + { + private bool _inInSession; + + public const string FILE_SESSION_EXTENSION = "_session"; + + public static String DefaultLogsFolder { get; private set; } + + public bool Enabled { get; set; } + + public String Folder { get; private set; } + + public String LogFile { get; private set; } + + public String Tag { get; private set; } + + static SessionFileLogger() + { + DefaultLogsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Logs", Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName), "session"); + } + + public SessionFileLogger(String folder, String tag) + { + Folder = folder; + Tag = tag; + Directory.CreateDirectory(Folder); + Enabled = true; + } + + public SessionFileLogger() : this(DefaultLogsFolder, Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName)) + { + + } + + public void CreateSession() + { + RemoveOldLogFile(); + LogFile = CreateLogFileName(); + _inInSession = true; + } + + public void EndSession() + { + _inInSession = false; + } + + private String CreateLogFileName() + { + return Path.Combine(Folder, string.Format("{1}-{0:dd-MM-yyyy_HH-mm-ss}{2}.log", DateTime.Now, Tag, FILE_SESSION_EXTENSION)); + } + + private void RemoveOldLogFile() + { + try + { + if (Directory.Exists(Folder)) + { + string[] fileEntries = Directory.GetFiles(Folder, "*.log"); + foreach (string fileName in fileEntries) + { + try + { + File.Delete(fileName); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + } + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + + public void OnLog(LogItemBase output) + { + if (_inInSession) + { + try + { + File.AppendAllText(LogFile, output.ToString() + Environment.NewLine); + } + catch + { + Debug.WriteLine("Error Writing To Session Log File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + } + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj index 311579625..e2e2b1edd 100644 --- a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj +++ b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj @@ -69,6 +69,7 @@ + diff --git a/Software/Visual_Studio/Tango.UnitTesting/Logging/SessionLoging_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Logging/SessionLoging_TST.cs new file mode 100644 index 000000000..873fcca57 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Logging/SessionLoging_TST.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.Logging; + +namespace Tango.UnitTesting.Logging +{ + [TestClass] + [TestCategory("Logging")] + public class SessionLoging_TST + { + [TestMethod] + public void Create_Session_File_Logger() + { + SessionFileLogger sessionlogger = new SessionFileLogger(); + LogManager.Default.RegisterLogger(sessionlogger); + sessionlogger.CreateSession(); + var manager = LogManager.Default; + + manager.Log($"This is a test 1"); + Thread.Sleep(300); + SessionFileLogger slogger = LogManager.Default.RegisteredLoggers.FirstOrDefault(x => x.GetType() == typeof(SessionFileLogger)) as SessionFileLogger; + string[] fileEntries = Directory.GetFiles(slogger.Folder, "*.log"); + Assert.AreEqual(1, fileEntries.Count()); + + sessionlogger.CreateSession(); + manager.Log($"This is a test 2"); + Thread.Sleep(300); + fileEntries = Directory.GetFiles(slogger.Folder, "*.log"); + Assert.AreEqual(1, fileEntries.Count()); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 05daac6c7..01e639a75 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -140,6 +140,7 @@ + @@ -309,7 +310,7 @@ - + \ No newline at end of file -- cgit v1.3.1