diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-04-15 19:51:07 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-04-15 19:51:07 +0300 |
| commit | ca293b80c52a54c73251fbf3cd50741fb5653ae9 (patch) | |
| tree | f1168fa167a26bf8455e601291b8a19945a70187 /Software/Visual_Studio | |
| parent | 9ff8293b603f72c5faa8d238b3005524c31cc5a8 (diff) | |
| download | Tango-ca293b80c52a54c73251fbf3cd50741fb5653ae9.tar.gz Tango-ca293b80c52a54c73251fbf3cd50741fb5653ae9.zip | |
Lots Of Work !
Diffstat (limited to 'Software/Visual_Studio')
35 files changed, 1074 insertions, 235 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/application-logs.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/application-logs.png Binary files differnew file mode 100644 index 000000000..584379dc8 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/application-logs.png diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/embedded-logs.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/embedded-logs.png Binary files differnew file mode 100644 index 000000000..86cd56486 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/embedded-logs.png diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/events.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/events.png Binary files differnew file mode 100644 index 000000000..437679cd6 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/events.png diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs index 6f4fcbceb..e8a14cc3d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs @@ -8,7 +8,10 @@ namespace Tango.MachineStudio.Logging.Navigation { public enum LoggingNavigationView { + HomeView, EventsView, TimelineView, + ApplicationLogsView, + EmbeddedLogsView, } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ApplicationLogFileParser.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ApplicationLogFileParser.cs new file mode 100644 index 000000000..d082aeca6 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ApplicationLogFileParser.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Tango.Logging; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public class ApplicationLogFileParser : ILogFileParser<MessageLogItem> + { + public List<LogFile> GetLogFiles() + { + List<LogFile> logFiles = new List<LogFile>(); + + foreach (var file in Directory.GetFiles(FileLogger.DefaultLogsFolder, "*.log").Where(x => Path.GetFileName(x).StartsWith("Tango.MachineStudio.UI"))) + { + String dateString = Path.GetFileNameWithoutExtension(file).Replace("Tango.MachineStudio.UI-", ""); + DateTime date = DateTime.ParseExact(dateString, "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture); + logFiles.Add(new LogFile() { DateTime = date, File = file }); + } + + return logFiles; + } + + public List<MessageLogItem> Parse(LogFile logFile) + { + List<MessageLogItem> logItems = new List<MessageLogItem>(); + + String text = File.ReadAllText(logFile.File); + var logs = Regex.Split(text, @"(\[\d{2}:\d{2}:\d{2}.\d{2}\])"); + + for (int i = 1; i < logs.Length; i += 2) + { + try + { + DateTime date = DateTime.ParseExact(logs[i].Replace("[", "").Replace("]", ""), "HH:mm:ss.ff", CultureInfo.InvariantCulture); + String rest = logs[i + 1]; + + var entries = Regex.Split(rest, @"\[(.*?)\]"); + + MessageLogItem item = new MessageLogItem(); + item.TimeStamp = new DateTime(logFile.DateTime.Year, logFile.DateTime.Month, logFile.DateTime.Day, date.Hour, date.Minute, date.Second, date.Millisecond); + item.Category = (LogCategory)Enum.Parse(typeof(LogCategory), entries[1]); + item.CallerFile = entries[3]; + item.CallerMethodName = entries[5]; + item.CallerLineNumber = int.Parse(entries[7]); + item.Message = new String(entries[8].Skip(2).ToArray()); + + logItems.Add(item); + } + catch (Exception ex) + { + //TODO: What to do now ? + } + } + + return logItems; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/EmbeddedLogFileParser.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/EmbeddedLogFileParser.cs new file mode 100644 index 000000000..76ca0d162 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/EmbeddedLogFileParser.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Tango.Integration.Operation; +using Tango.Logging; +using Tango.Settings; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public class EmbeddedLogFileParser : ILogFileParser<EmbeddedLogItem> + { + public List<LogFile> GetLogFiles() + { + List<LogFile> logFiles = new List<LogFile>(); + + foreach (var file in Directory.GetFiles(SettingsManager.DefaultFolder + "\\embedded logs", "*.log").Where(x => Path.GetFileName(x).StartsWith("embedded"))) + { + String dateString = Path.GetFileNameWithoutExtension(file).Replace("embedded-", ""); + DateTime date = DateTime.ParseExact(dateString, "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture); + logFiles.Add(new LogFile() { DateTime = date, File = file }); + } + + return logFiles; + } + + public List<EmbeddedLogItem> Parse(LogFile logFile) + { + List<EmbeddedLogItem> logItems = new List<EmbeddedLogItem>(); + + String text = File.ReadAllText(logFile.File); + var logs = Regex.Split(text, @"(\[\d{2}:\d{2}:\d{2}.\d{2}\])"); + + for (int i = 1; i < logs.Length; i += 2) + { + try + { + DateTime date = DateTime.ParseExact(logs[i].Replace("[", "").Replace("]", ""), "HH:mm:ss.ff", CultureInfo.InvariantCulture); + String rest = logs[i + 1]; + + var entries = Regex.Split(rest, @"\[(.*?)\]"); + + EmbeddedLogItem item = new EmbeddedLogItem(new PMR.Debugging.DebugLogResponse() + { + Category = (PMR.Debugging.DebugLogCategory)Enum.Parse(typeof(PMR.Debugging.DebugLogCategory), entries[1]), + FileName = entries[3], + LineNumber = uint.Parse(entries[5]), + ModuleId = uint.Parse(entries[7]), + Filter = uint.Parse(entries[9]), + Message = new String(entries[10].Skip(2).ToArray()) + }); + + item.TimeStamp = new DateTime(logFile.DateTime.Year, logFile.DateTime.Month, logFile.DateTime.Day, date.Hour, date.Minute, date.Second, date.Millisecond); + + logItems.Add(item); + } + catch (Exception ex) + { + //TODO: What to do now ? + } + } + + return logItems; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ILogFileParser.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ILogFileParser.cs new file mode 100644 index 000000000..05003c1a2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ILogFileParser.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public interface ILogFileParser<T> + { + List<T> Parse(LogFile logFile); + + List<LogFile> GetLogFiles(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/LogFile.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/LogFile.cs new file mode 100644 index 000000000..4248bdbdc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/LogFile.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public class LogFile + { + public DateTime DateTime { get; set; } + + public String File { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj index b893dcb53..42229544a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj @@ -93,17 +93,29 @@ <Compile Include="LoggingModule.cs" /> <Compile Include="Navigation\LoggingNavigationManager.cs" /> <Compile Include="Navigation\LoggingNavigationView.cs" /> + <Compile Include="Parsing\ApplicationLogFileParser.cs" /> + <Compile Include="Parsing\EmbeddedLogFileParser.cs" /> + <Compile Include="Parsing\ILogFileParser.cs" /> + <Compile Include="Parsing\LogFile.cs" /> <Compile Include="ViewModelLocator.cs" /> + <Compile Include="ViewModels\ApplicationLogsViewVM.cs" /> <Compile Include="ViewModels\EventDetailsViewVM.cs" /> - <Compile Include="ViewModels\MainViewVM.cs" /> + <Compile Include="ViewModels\HomeViewVM.cs" /> + <Compile Include="ViewModels\EventsViewVM.cs" /> <Compile Include="ViewModels\TimelineEventGroup.cs" /> <Compile Include="ViewModels\TimelineViewVM.cs" /> <Compile Include="Views\EventDetailsView.xaml.cs"> <DependentUpon>EventDetailsView.xaml</DependentUpon> </Compile> + <Compile Include="Views\ApplicationLogsView.xaml.cs"> + <DependentUpon>ApplicationLogsView.xaml</DependentUpon> + </Compile> <Compile Include="Views\EventsView.xaml.cs"> <DependentUpon>EventsView.xaml</DependentUpon> </Compile> + <Compile Include="Views\HomeView.xaml.cs"> + <DependentUpon>HomeView.xaml</DependentUpon> + </Compile> <Compile Include="Views\MainView.xaml.cs"> <DependentUpon>MainView.xaml</DependentUpon> </Compile> @@ -189,10 +201,18 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\ApplicationLogsView.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Views\EventsView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\HomeView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\MainView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -209,5 +229,14 @@ <ItemGroup> <Resource Include="Images\machine-trans.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\application-logs.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\embedded-logs.png" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\events.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs index ef6923e27..0b1af937f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs @@ -18,17 +18,35 @@ namespace Tango.MachineStudio.Logging static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); - SimpleIoc.Default.Register<MainViewVM>(); + SimpleIoc.Default.Register<EventsViewVM>(); + SimpleIoc.Default.Register<ApplicationLogsViewVM>(); + SimpleIoc.Default.Register<HomeViewVM>(); SimpleIoc.Default.Unregister<LoggingNavigationManager>(); SimpleIoc.Default.Register<LoggingNavigationManager>(() => new LoggingNavigationManager()); } - public static MainViewVM MainViewVM + public static EventsViewVM EventsViewVM { get { - return ServiceLocator.Current.GetInstance<MainViewVM>(); + return ServiceLocator.Current.GetInstance<EventsViewVM>(); + } + } + + public static ApplicationLogsViewVM ApplicationLogsViewVM + { + get + { + return ServiceLocator.Current.GetInstance<ApplicationLogsViewVM>(); + } + } + + public static HomeViewVM HomeViewVM + { + get + { + return ServiceLocator.Current.GetInstance<HomeViewVM>(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs new file mode 100644 index 000000000..8ddc544c0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Logging; +using Tango.MachineStudio.Logging.Navigation; +using Tango.MachineStudio.Logging.Parsing; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Logging.ViewModels +{ + public class ApplicationLogsViewVM : ViewModel + { + private ApplicationLogFileParser _parser; + private List<LogFile> _logFiles; + + private ObservableCollection<MessageLogItem> _logs; + public ObservableCollection<MessageLogItem> Logs + { + get { return _logs; } + set { _logs = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection<DateTime> _dates; + public ObservableCollection<DateTime> Dates + { + get { return _dates; } + set { _dates = value; RaisePropertyChangedAuto(); } + } + + private DateTime _selectedDate; + public DateTime SelectedDate + { + get { return _selectedDate; } + set { _selectedDate = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } + } + + private DateTime _minDate; + public DateTime MinDate + { + get { return _minDate; } + set { _minDate = value; RaisePropertyChangedAuto(); } + } + + private DateTime _maxDate; + public DateTime MaxDate + { + get { return _maxDate; } + set { _maxDate = value; RaisePropertyChangedAuto(); } + } + + + private bool _isRealTime; + public bool IsRealTime + { + get { return _isRealTime; } + set { _isRealTime = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } + } + + public RelayCommand NavigateToHomeCommand { get; set; } + + public ApplicationLogsViewVM(LoggingNavigationManager navigation) + { + NavigateToHomeCommand = new RelayCommand(() => navigation.NavigateTo(LoggingNavigationView.HomeView)); + + _parser = new ApplicationLogFileParser(); + + _logFiles = _parser.GetLogFiles(); + Dates = new ObservableCollection<DateTime>(_logFiles.Select(x => x.DateTime).OrderBy(x => x)); + + SelectedDate = Dates.Last(); + + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + } + + private void OnSelectedDateChanged() + { + if (IsRealTime) + { + //Events = _realTimeEvents; + } + else + { + List<MessageLogItem> logs = new List<MessageLogItem>(); + + foreach (var logFile in _logFiles.Where(x => x.DateTime.Date == SelectedDate.Date)) + { + logs.AddRange(_parser.Parse(logFile)); + } + + Logs = logs.ToObservableCollection(); + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs index e5121e709..361adef01 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -18,7 +18,7 @@ using Tango.SharedUI; namespace Tango.MachineStudio.Logging.ViewModels { - public class MainViewVM : ViewModel + public class EventsViewVM : ViewModel { private INotificationProvider _notification; private IStudioApplicationManager _application; @@ -96,7 +96,9 @@ namespace Tango.MachineStudio.Logging.ViewModels public RelayCommand NavigateToEventsCommand { get; set; } - public MainViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application, LoggingNavigationManager navigation) + public RelayCommand NavigateToHomeCommand { get; set; } + + public EventsViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application, LoggingNavigationManager navigation) { TimelineViewVM = new TimelineViewVM(notification); @@ -110,6 +112,7 @@ namespace Tango.MachineStudio.Logging.ViewModels RegisterMessage<MachineConnectionChangedMessage>(OnMachineConnectionChanged); DisplayTimelineCommand = new RelayCommand<MachinesEvent>(DisplayTimeline); NavigateToEventsCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.EventsView)); + NavigateToHomeCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.HomeView)); } private void OnMachineConnectionChanged(MachineConnectionChangedMessage msg) diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/HomeViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/HomeViewVM.cs new file mode 100644 index 000000000..b87323491 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/HomeViewVM.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.MachineStudio.Logging.Navigation; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Logging.ViewModels +{ + public class HomeViewVM : ViewModel + { + private LoggingNavigationManager _navigation; + + public RelayCommand<String> NavigateToCommand { get; set; } + + public HomeViewVM(LoggingNavigationManager navigation) + { + _navigation = navigation; + + NavigateToCommand = new RelayCommand<string>((view) => + { + navigation.NavigateTo((LoggingNavigationView)Enum.Parse(typeof(LoggingNavigationView), view)); + }); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml new file mode 100644 index 000000000..1274f6523 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml @@ -0,0 +1,196 @@ +<UserControl x:Class="Tango.MachineStudio.Logging.Views.ApplicationLogsView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" + xmlns:autoCompleteMachine="clr-namespace:Tango.MachineStudio.Common.AutoComplete;assembly=Tango.MachineStudio.Common" + xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:global="clr-namespace:Tango.MachineStudio.Logging" + xmlns:localConverters="clr-namespace:Tango.MachineStudio.Logging.Converters" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:vm="clr-namespace:Tango.MachineStudio.Logging.ViewModels" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:Tango.MachineStudio.Logging.Views" + mc:Ignorable="d" + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:ApplicationLogsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.ApplicationLogsViewVM}"> + <UserControl.Resources> + <autoCompleteMachine:MachinesProvider x:Key="MachinesProvider" /> + <converters:DateTimeUTCToShortDateTimeConverter x:Key="DateTimeUTCToShortDateTimeConverter" /> + <converters:DateTimeUTCToStringConverter x:Key="DateTimeUTCToStringConverter" /> + <localConverters:DateIsInListToBooleanConverter x:Key="DateIsInListToBooleanConverter" /> + + <Style x:Key="CustomCalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}" BasedOn="{StaticResource MaterialDesignCalendarDayButton}"> + <Style.Triggers> + <DataTrigger Value="True"> + <DataTrigger.Binding> + <MultiBinding Converter="{StaticResource DateIsInListToBooleanConverter}"> + <Binding /> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.Dates" /> + <Binding RelativeSource="{RelativeSource AncestorType=DatePicker}" Path="IsDropDownOpen" ></Binding> + </MultiBinding> + </DataTrigger.Binding> + <Setter Property="Foreground" Value="{StaticResource AccentColorBrush}" /> + </DataTrigger> + </Style.Triggers> + </Style> + + <Style x:Key="HighlightDatePickerStyle" TargetType="{x:Type Calendar}" BasedOn="{StaticResource {x:Type Calendar}}"> + <Setter Property="CalendarDayButtonStyle" Value="{StaticResource CustomCalendarDayButtonStyle}" /> + </Style> + + <Style TargetType="DatePickerTextBox" BasedOn="{StaticResource {x:Type DatePickerTextBox}}"> + <Setter Property="IsReadOnly" Value="True"/> + </Style> + </UserControl.Resources> + + <Grid> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="79"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + + <Border Background="#F1F1F1"> + <Border.Effect> + <DropShadowEffect /> + </Border.Effect> + <Grid> + <StackPanel Orientation="Horizontal"> + <Button Margin="10 0 0 0" Height="50" Style="{StaticResource MaterialDesignFlatButton}" Command="{Binding NavigateToHomeCommand}" HorizontalContentAlignment="Left"> + <StackPanel Orientation="Horizontal" > + <materialDesign:PackIcon Kind="KeyboardBackspace" Width="20" Height="20" /> + <TextBlock Margin="5 0 0 0" FontSize="16">BACK</TextBlock> + </StackPanel> + </Button> + <Border Margin="10" Padding="5" BorderBrush="DimGray" BorderThickness="1"> + <Border.Background> + <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> + <GradientStop Color="White"/> + <GradientStop Color="#FFEAEAEA" Offset="1"/> + </LinearGradientBrush> + </Border.Background> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="Calendar" Width="24" Height="24" VerticalAlignment="Bottom" Margin="0 0 0 5" /> + <DatePicker x:Name="datePicker" DisplayDateStart="{Binding MinDate}" DisplayDateEnd="{Binding MaxDate}" CalendarStyle="{StaticResource HighlightDatePickerStyle}" SelectedDate="{Binding SelectedDate}" materialDesign:HintAssist.Hint="Pick Date" Margin="10 0 0 5" Width="200" VerticalAlignment="Bottom" FontSize="16"> + </DatePicker> + <ToggleButton VerticalAlignment="Bottom" Margin="20 0 0 5" IsChecked="{Binding IsRealTime}"></ToggleButton> + <TextBlock VerticalAlignment="Center" Margin="10 17 0 0">Real-Time</TextBlock> + </StackPanel> + </Border> + </StackPanel> + </Grid> + </Border> + + <Grid Grid.Row="1" Background="#B3FFFFFF"> + <Grid Margin="10"> + <Grid.ColumnDefinitions> + + <ColumnDefinition Width="1*"/> + </Grid.ColumnDefinitions> + + <Grid> + <Grid> + <Grid> + <DataGrid Background="Transparent" AutoGenerateColumns="False" SelectionMode="Single" ItemsSource="{Binding Logs}" SelectedItem="{Binding SelectedEvent}" RowHeight="40" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="True" IsReadOnly="True"> + <DataGrid.RowStyle> + <Style TargetType="DataGridRow" BasedOn="{StaticResource {x:Type DataGridRow}}"> + <Style.Triggers> + <Trigger Property="IsMouseOver" Value="True"> + <Setter Property="Background" Value="Transparent"></Setter> + <Setter Property="Foreground" Value="{StaticResource AccentColorBrush}" /> + <Setter Property="Cursor" Value="Hand"></Setter> + </Trigger> + <Trigger Property="IsSelected" Value="True"> + <Setter Property="Background" Value="Transparent"></Setter> + </Trigger> + <Trigger Property="IsFocused" Value="True"> + <Setter Property="Background" Value="Transparent"></Setter> + </Trigger> + <DataTrigger Binding="{Binding CallerMethodName}" Value="OnStartup"> + <Setter Property="Background" Value="{StaticResource AccentColorBrush}"></Setter> + <Setter Property="Foreground" Value="White" /> + <Setter Property="FontWeight" Value="SemiBold"></Setter> + <Setter Property="Cursor" Value="Arrow"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </DataGrid.RowStyle> + <DataGrid.CellStyle> + <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}"> + <Setter Property="BorderThickness" Value="0"/> + <Setter Property="FocusVisualStyle" Value="{x:Null}"/> + <Setter Property="VerticalContentAlignment" Value="Center"></Setter> + <Style.Triggers> + <Trigger Property="IsSelected" Value="True"> + <Setter Property="Background" Value="Transparent"></Setter> + </Trigger> + <DataTrigger Binding="{Binding CallerMethodName}" Value="OnStartup"> + <Setter Property="Background" Value="{StaticResource AccentColorBrush}"></Setter> + <Setter Property="Foreground" Value="White" /> + <Setter Property="FontWeight" Value="SemiBold"></Setter> + <Setter Property="Cursor" Value="Arrow"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </DataGrid.CellStyle> + <DataGrid.Columns> + <DataGridTemplateColumn Header="#"> + <DataGridTemplateColumn.CellTemplate> + <DataTemplate> + <materialDesign:PackIcon Width="16" Height="16"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Kind" Value="Alert"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding Category}" Value="Info"> + <Setter Property="Kind" Value="Information"></Setter> + <Setter Property="Foreground" Value="DimGray"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Category}" Value="Warning"> + <Setter Property="Kind" Value="Alert"></Setter> + <Setter Property="Foreground" Value="#FFA300"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Category}" Value="Error"> + <Setter Property="Kind" Value="AlertOctagon"></Setter> + <Setter Property="Foreground" Value="#FF5C5C"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Category}" Value="Critical"> + <Setter Property="Kind" Value="BellPlus"></Setter> + <Setter Property="Foreground" Value="Red"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Category}" Value="Debug"> + <Setter Property="Kind" Value="Bug"></Setter> + <Setter Property="Foreground" Value="#303030"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding CallerMethodName}" Value="OnStartup"> + <Setter Property="Kind" Value="ClockFast"></Setter> + <Setter Property="Foreground" Value="White"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </materialDesign:PackIcon.Style> + </materialDesign:PackIcon> + </DataTemplate> + </DataGridTemplateColumn.CellTemplate> + </DataGridTemplateColumn> + <DataGridTextColumn Header="DATE TIME" Binding="{Binding TimeStamp,Converter={StaticResource DateTimeUTCToStringConverter},ConverterParameter='MM/dd/yyyy HH:mm:ss.ff'}" /> + <DataGridTextColumn Header="FILE" Binding="{Binding CallerFile}" /> + <DataGridTextColumn Header="METHOD" Binding="{Binding CallerMethodName}" /> + <DataGridTextColumn Header="LINE" Binding="{Binding CallerLineNumber}" /> + <DataGridTemplateColumn Header="MESSAGE" Width="1*"> + <DataGridTemplateColumn.CellTemplate> + <DataTemplate> + <TextBlock Text="{Binding Message}" TextTrimming="CharacterEllipsis"></TextBlock> + </DataTemplate> + </DataGridTemplateColumn.CellTemplate> + </DataGridTemplateColumn> + </DataGrid.Columns> + </DataGrid> + </Grid> + </Grid> + </Grid> + </Grid> + </Grid> + </Grid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml.cs new file mode 100644 index 000000000..6cdf6ea53 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Logging.Views +{ + /// <summary> + /// Interaction logic for EventsView.xaml + /// </summary> + public partial class ApplicationLogsView : UserControl + { + public ApplicationLogsView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml index d92e56ddc..3089ad610 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml @@ -12,7 +12,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tango.MachineStudio.Logging.Views" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:EventsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.EventsViewVM}"> <UserControl.Resources> <autoCompleteMachine:MachinesProvider x:Key="MachinesProvider" /> <converters:DateTimeUTCToShortDateTimeConverter x:Key="DateTimeUTCToShortDateTimeConverter" /> @@ -56,6 +56,13 @@ </Border.Effect> <Grid> <StackPanel Orientation="Horizontal"> + <Button Margin="10 0 0 0" Height="50" Style="{StaticResource MaterialDesignFlatButton}" Command="{Binding NavigateToHomeCommand}" HorizontalContentAlignment="Left"> + <StackPanel Orientation="Horizontal" > + <materialDesign:PackIcon Kind="KeyboardBackspace" Width="20" Height="20" /> + <TextBlock Margin="5 0 0 0" FontSize="16">BACK</TextBlock> + </StackPanel> + </Button> + <Border Margin="10" Padding="5" BorderBrush="DimGray" BorderThickness="1"> <Border.Background> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml new file mode 100644 index 000000000..b41351064 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml @@ -0,0 +1,87 @@ +<UserControl x:Class="Tango.MachineStudio.Logging.Views.HomeView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:global="clr-namespace:Tango.MachineStudio.Logging" + xmlns:vm="clr-namespace:Tango.MachineStudio.Logging.ViewModels" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:local="clr-namespace:Tango.MachineStudio.Logging.Views" + mc:Ignorable="d" + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:HomeViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.HomeViewVM}"> + + <UserControl.Resources> + <Style TargetType="Border" x:Key="LogBorder"> + <Setter Property="Padding" Value="50"></Setter> + <Setter Property="Background"> + <Setter.Value> + <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> + <GradientStop Color="#35FFFFFF"/> + <GradientStop Color="White" Offset="1"/> + + </LinearGradientBrush> + </Setter.Value> + </Setter> + <Setter Property="CornerRadius" Value="20"></Setter> + <Setter Property="Width" Value="450"></Setter> + <Setter Property="Height" Value="400"></Setter> + <Setter Property="TextElement.Foreground" Value="#202020"></Setter> + <Setter Property="TextElement.FontSize" Value="25"></Setter> + <Setter Property="BorderThickness" Value="1"></Setter> + <Setter Property="BorderBrush" Value="#D6D6D6"></Setter> + <Setter Property="Cursor" Value="Hand"></Setter> + <Style.Triggers> + <Trigger Property="IsMouseOver" Value="True"> + <Setter Property="TextElement.Foreground" Value="DodgerBlue"></Setter> + <Setter Property="BorderBrush" Value="DodgerBlue"></Setter> + </Trigger> + </Style.Triggers> + </Style> + </UserControl.Resources> + + <Grid> + + <TextBlock Margin="80 50" FontSize="16"> + <Run FontSize="20">Machine Studio logs information from multiple source.</Run> + <LineBreak/> + <LineBreak/> + <LineBreak/> + <Run FontWeight="SemiBold">• Machine Events</Run> <Run>are predefined events that occurs only when a set of predefined actions have occurred (e.g 'Job executed', 'Thread Break').</Run> + <LineBreak/> + <LineBreak/> + <Run FontWeight="SemiBold">• Application Logs</Run> <Run>are the standard machine studio logs which can be used to trace issues in code.</Run> + <LineBreak/> + <LineBreak/> + <Run FontWeight="SemiBold">• Embedded Logs</Run> <Run>are logs transmitted from the machine's embedded device software.</Run> + </TextBlock> + + <UniformGrid Columns="3" Rows="1" VerticalAlignment="Center" Margin="50 150 50 0"> + <Button Style="{StaticResource emptyButton}" Margin="70" Padding="0" Height="Auto" Command="{Binding NavigateToCommand}" CommandParameter="EventsView"> + <Border Style="{StaticResource LogBorder}"> + <DockPanel> + <TextBlock HorizontalAlignment="Center" Margin="0 20 0 0" DockPanel.Dock="Bottom">MACHINE EVENTS</TextBlock> + <Image Source="../Images/events.png"></Image> + </DockPanel> + </Border> + </Button> + + <Button Style="{StaticResource emptyButton}" Margin="70" Padding="0" Height="Auto" Command="{Binding NavigateToCommand}" CommandParameter="ApplicationLogsView"> + <Border Style="{StaticResource LogBorder}"> + <DockPanel> + <TextBlock HorizontalAlignment="Center" Margin="0 20 0 0" DockPanel.Dock="Bottom">APPLICATION LOGS</TextBlock> + <Image Source="../Images/application-logs.png"></Image> + </DockPanel> + </Border> + </Button> + + <Button Style="{StaticResource emptyButton}" Margin="70" Padding="0" Height="Auto" Command="{Binding NavigateToCommand}" CommandParameter="EmbeddedLogsView"> + <Border Style="{StaticResource LogBorder}"> + <DockPanel> + <TextBlock HorizontalAlignment="Center" Margin="0 20 0 0" DockPanel.Dock="Bottom">EMBEDDED LOGS</TextBlock> + <Image Source="../Images/embedded-logs.png"></Image> + </DockPanel> + </Border> + </Button> + </UniformGrid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml.cs new file mode 100644 index 000000000..36d261a2f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Logging.Views +{ + /// <summary> + /// Interaction logic for HomeView.xaml + /// </summary> + public partial class HomeView : UserControl + { + public HomeView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml index 6d5f98b51..b6ac29893 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml @@ -13,11 +13,17 @@ xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:vm="clr-namespace:Tango.MachineStudio.Logging.ViewModels" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:EventsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.EventsViewVM}"> <Grid> <controls:MultiTransitionControl x:Name="TransitionControl" x:FieldModifier="internal" TransitionType="Slide"> <controls:MultiTransitionControl.Controls> + <ContentControl Tag="HomeView"> + <local:HomeView/> + </ContentControl> + <ContentControl Tag="ApplicationLogsView"> + <local:ApplicationLogsView/> + </ContentControl> <ContentControl Tag="EventsView"> <local:EventsView/> </ContentControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml index abab55264..b436c55f5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml @@ -8,7 +8,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:Tango.MachineStudio.Logging.Views" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:EventsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.EventsViewVM}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="70"/> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 63aca3e70..88c50b549 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -29,6 +29,7 @@ using Tango.SharedUI; using Tango.Integration.Services; using Tango.BL.Enumerations; using Tango.BL; +using Tango.MachineStudio.Common.EventLogging; namespace Tango.MachineStudio.Technician.ViewModels { @@ -45,6 +46,7 @@ namespace Tango.MachineStudio.Technician.ViewModels private static object _elementsLock = new object(); private String _lastTechProjectFile; private INotificationProvider _notification; + private IEventLogger _eventLogger; private DateTime _lastDiagnosticsResponseUpdate; private const int MIN_DIAGNOSTICS_UPDATE_MILI = 500; @@ -171,9 +173,10 @@ namespace Tango.MachineStudio.Technician.ViewModels /// </summary> /// <param name="applicationManager">The application manager.</param> /// <param name="notificationProvider">The notification provider.</param> - public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider _diagnosticsFrameProvider) + public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider _diagnosticsFrameProvider, IEventLogger eventLogger) { _notification = notificationProvider; + _eventLogger = eventLogger; _singleControllers = new Dictionary<SingleGraphItem, GraphController>(); _multiControllers = new Dictionary<MultiGraphItem, GraphMultiController>(); AvailableTechItems = TechItem.GetAvailableTechItems().ToObservableCollection(); @@ -581,7 +584,8 @@ namespace Tango.MachineStudio.Technician.ViewModels else if (item is ControllerItem) { (item as ControllerItem).TechController = Adapter.TechControllers.FirstOrDefault(x => x.Guid == item.ItemGuid); - CreateElement<ControllerElementEditor>(item); + var editor = CreateElement<ControllerElementEditor>(item); + InitControllerItem(editor.ControllerItem); } } @@ -695,68 +699,78 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) - { - await MachineOperator.StartMotorJogging(new MotorJoggingRequest() - { - Code = item.TechMotor.Code, - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.ForwardReleased) + try { - await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = item.TechMotor.Code, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.ForwardReleased) { - Code = item.TechMotor.Code, - Direction = MotorDirection.Backward, - }); - } - else if (action == MotorActionType.BackwardReleased) - { - await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Code = item.TechMotor.Code, - }); - } - else if (action == MotorActionType.HomingStarted) - { - item.HomingProgress = 0; - item.IsHoming = true; - item.IsHomingCompleted = false; - - MachineOperator.StartMotorHoming(new MotorHomingRequest() + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.BackwardReleased) { - Code = item.TechMotor.Code - }) - .Subscribe((response) => + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + else if (action == MotorActionType.HomingStarted) { + item.HomingProgress = 0; + item.IsHoming = true; + item.IsHomingCompleted = false; + + MachineOperator.StartMotorHoming(new MotorHomingRequest() + { + Code = item.TechMotor.Code + }) + .Subscribe((response) => + { - item.HomingMaximumProgress = response.MaxProgress; - item.HomingProgress = response.Progress; + item.HomingMaximumProgress = response.MaxProgress; + item.HomingProgress = response.Progress; + + }, () => + { - }, () => + item.IsHoming = false; + item.IsHomingCompleted = true; + + }); + } + else if (action == MotorActionType.HomingStopped) { + await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + { + Code = item.TechMotor.Code, + }); item.IsHoming = false; - item.IsHomingCompleted = true; - - }); + } } - else if (action == MotorActionType.HomingStopped) + catch (Exception ex) { - await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() - { - Code = item.TechMotor.Code, - }); - - item.IsHoming = false; + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action,item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -769,68 +783,78 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) - { - await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() - { - Code = item.TechDispenser.Code, - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.ForwardReleased) + try { - await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = item.TechDispenser.Code, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + { + Code = item.TechDispenser.Code, + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.ForwardReleased) { - Code = item.TechDispenser.Code, - Direction = MotorDirection.Backward, - }); - } - else if (action == MotorActionType.BackwardReleased) - { - await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + { + Code = item.TechDispenser.Code, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Code = item.TechDispenser.Code, - }); - } - else if (action == MotorActionType.HomingStarted) - { - item.HomingProgress = 0; - item.IsHoming = true; - item.IsHomingCompleted = false; - - MachineOperator.StartDispenserHoming(new DispenserHomingRequest() + await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + { + Code = item.TechDispenser.Code, + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.BackwardReleased) { - Code = item.TechDispenser.Code - }) - .Subscribe((response) => + await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + { + Code = item.TechDispenser.Code, + }); + } + else if (action == MotorActionType.HomingStarted) { + item.HomingProgress = 0; + item.IsHoming = true; + item.IsHomingCompleted = false; - item.HomingMaximumProgress = response.MaxProgress; - item.HomingProgress = response.Progress; + MachineOperator.StartDispenserHoming(new DispenserHomingRequest() + { + Code = item.TechDispenser.Code + }) + .Subscribe((response) => + { - }, () => + item.HomingMaximumProgress = response.MaxProgress; + item.HomingProgress = response.Progress; + + }, () => + { + + item.IsHoming = false; + item.IsHomingCompleted = true; + + }); + } + else if (action == MotorActionType.HomingStopped) { + await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest() + { + Code = item.TechDispenser.Code, + }); item.IsHoming = false; - item.IsHomingCompleted = true; - - }); + } } - else if (action == MotorActionType.HomingStopped) + catch (Exception ex) { - await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest() - { - Code = item.TechDispenser.Code, - }); - - item.IsHoming = false; + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -886,23 +910,33 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) + try { - await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + { + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Direction = MotorDirection.Backward, - }); + await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + { + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.ForwardReleased || action == MotorActionType.BackwardReleased) + { + await MachineOperator.StopThreadJogging(new ThreadAbortJoggingRequest()); + } } - else if (action == MotorActionType.ForwardReleased || action == MotorActionType.BackwardReleased) + catch (Exception ex) { - await MachineOperator.StopThreadJogging(new ThreadAbortJoggingRequest()); + LogManager.Log(ex, String.Format(String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName))); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -915,69 +949,79 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) + try { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = motor.Code, - Direction = MotorDirection.Forward, - }))); - } - else if (action == MotorActionType.ForwardReleased) - { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Forward, + }))); + } + else if (action == MotorActionType.ForwardReleased) { - Code = motor.Code, - }))); - } - else if (action == MotorActionType.BackwardPressed) - { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + else if (action == MotorActionType.BackwardPressed) { - Code = motor.Code, - Direction = MotorDirection.Backward, - }))); - } - else if (action == MotorActionType.BackwardReleased) - { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Backward, + }))); + } + else if (action == MotorActionType.BackwardReleased) { - Code = motor.Code, - }))); - } - //else if (action == MotorActionType.HomingStarted) - //{ - // item.HomingProgress = 0; - // item.IsHoming = true; - // item.IsHomingCompleted = false; + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + //else if (action == MotorActionType.HomingStarted) + //{ + // item.HomingProgress = 0; + // item.IsHoming = true; + // item.IsHomingCompleted = false; - // MachineOperator.StartMotorHoming(new MotorHomingRequest() - // { - // Code = item.TechMotor.Code - // }) - // .Subscribe((response) => - // { + // MachineOperator.StartMotorHoming(new MotorHomingRequest() + // { + // Code = item.TechMotor.Code + // }) + // .Subscribe((response) => + // { - // item.HomingMaximumProgress = response.Message.MaxProgress; - // item.HomingProgress = response.Message.Progress; + // item.HomingMaximumProgress = response.Message.MaxProgress; + // item.HomingProgress = response.Message.Progress; - // }, () => - // { + // }, () => + // { - // item.IsHoming = false; - // item.IsHomingCompleted = true; + // item.IsHoming = false; + // item.IsHomingCompleted = true; - // }); - //} - //else if (action == MotorActionType.HomingStopped) - //{ - // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() - // { - // Code = item.TechMotor.Code, - // }); + // }); + //} + //else if (action == MotorActionType.HomingStopped) + //{ + // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + // { + // Code = item.TechMotor.Code, + // }); - // item.IsHoming = false; - //} + // item.IsHoming = false; + //} + } + catch (Exception ex) + { + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); + } }; } @@ -991,11 +1035,13 @@ namespace Tango.MachineStudio.Technician.ViewModels { try { + CheckMachineOperator(); await MachineOperator.SetDigitalOut(new SetDigitalOutRequest() { Port = item.TechIo.Port, Value = value }); } catch (Exception ex) { - //TODO: Show Exception. + LogManager.Log(ex, String.Format("Error executing technician set digital out command on '{0}'.", item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician set digital out command on '{0}'.", item.TechName)); } }; } @@ -1010,6 +1056,7 @@ namespace Tango.MachineStudio.Technician.ViewModels { try { + CheckMachineOperator(); await MachineOperator.SetComponentValue(new SetComponentValueRequest() { Component = (ValueComponent)item.TechController.Code, @@ -1018,11 +1065,24 @@ namespace Tango.MachineStudio.Technician.ViewModels } catch (Exception ex) { - //TODO: Show Exception. + LogManager.Log(ex, String.Format("Error executing technician set value component command on '{0}'.", item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician set value component command on '{0}'.", item.TechName)); } }; } + /// <summary> + /// Checks the machine operator. + /// </summary> + /// <exception cref="InvalidOperationException">No machine connected.</exception> + private void CheckMachineOperator() + { + if (MachineOperator == null || MachineOperator.State != Transport.TransportComponentState.Connected) + { + throw new InvalidOperationException("No machine connected."); + } + } + #endregion #region Public Methods diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs index 76c7b3e58..1334a349d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs @@ -28,6 +28,9 @@ namespace Tango.MachineStudio.UI protected override void OnStartup(StartupEventArgs e) { + LogManager.RegisterLogger(new VSOutputLogger()); + LogManager.RegisterLogger(new FileLogger()); + LogManager.Log("Application Started..."); base.OnStartup(e); @@ -44,9 +47,6 @@ namespace Tango.MachineStudio.UI LogManager.Categories.AddRange(SettingsManager.Default.MachineStudio.LoggingCategories); - LogManager.RegisterLogger(new VSOutputLogger()); - LogManager.RegisterLogger(new FileLogger()); - exceptionTrapper = new WpfGlobalExceptionTrapper(); exceptionTrapper.Initialize(this); exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs index 121d429ec..07834393b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs @@ -80,8 +80,12 @@ namespace Tango.MachineStudio.UI.Modules if (!_loaded) { //Preloaded + + LogManager.Log(String.Format("Loading module '{0}'...", nameof(StubsModule))); AllModules.Add(new StubsModule()); + LogManager.Log(String.Format("Loading module '{0}'...", nameof(DBModule))); AllModules.Add(new DBModule()); + LogManager.Log(String.Format("Loading module '{0}'...", nameof(MachineDesignerModule))); AllModules.Add(new MachineDesignerModule()); //Preloaded @@ -103,6 +107,7 @@ namespace Tango.MachineStudio.UI.Modules { try { + LogManager.Log(String.Format("Loading module '{0}'...", moduleType.Name)); var module = Activator.CreateInstance(moduleType) as IStudioModule; AllModules.Add(module); } @@ -117,7 +122,7 @@ namespace Tango.MachineStudio.UI.Modules catch { } } - _loaded = true; + _loaded = true; } UserModules.Clear(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index f78cc15be..8e451cdce 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -425,7 +425,7 @@ namespace Tango.MachineStudio.UI.ViewModels { LogManager.Log(ex); _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError(ex.Message); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); } InvalidateRelayCommands(); @@ -455,7 +455,7 @@ namespace Tango.MachineStudio.UI.ViewModels { LogManager.Log(ex); _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError(ex.Message); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); } InvalidateRelayCommands(); @@ -472,7 +472,7 @@ namespace Tango.MachineStudio.UI.ViewModels } else { - _notificationProvider.ShowModalDialog<ConnectedMachineViewVM>((x) => + _notificationProvider.ShowModalDialog<ConnectedMachineViewVM>((x) => { DisconnectFromMachine(); }); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs index e0ae60b87..442d11cdd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs @@ -25,6 +25,7 @@ using Tango.MachineStudio.Common; using System.Threading; using Tango.Core.Helpers; using Tango.SharedUI.Helpers; +using Tango.Logging; namespace Tango.MachineStudio.UI.Views { @@ -54,6 +55,8 @@ namespace Tango.MachineStudio.UI.Views Task.Factory.StartNew(() => { + LogManager.Default.Log("Loading modules views..."); + var item = ServiceLocator.Current.GetInstance<INotificationProvider>().PushTaskItem("Loading Modules..."); var modules = _loader.UserModules.ToList(); @@ -67,6 +70,8 @@ namespace Tango.MachineStudio.UI.Views foreach (var module in modules) { + LogManager.Default.Log("Loading module view '" + module.Name + "'..."); + ThreadsHelper.InvokeUI(() => { Grid grid = new Grid(); diff --git a/Software/Visual_Studio/Tango.Integration/Operation/EmbeddedLogItem.cs b/Software/Visual_Studio/Tango.Integration/Operation/EmbeddedLogItem.cs index 192cb576f..1e29858ea 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/EmbeddedLogItem.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/EmbeddedLogItem.cs @@ -24,7 +24,7 @@ namespace Tango.Integration.Operation public override string ToString() { - return String.Format("[{0}] [{1}] [{2}] [Line {3}] [ModuleId {4}] [Filter {5}]: {6}", TimeStamp.ToString("HH:mm:ss.ff"), DebugLogResponse.Category, Path.GetFileName(DebugLogResponse.FileName), DebugLogResponse.LineNumber, DebugLogResponse.ModuleId, DebugLogResponse.Filter, DebugLogResponse.Message); + return String.Format("[{0}] [{1}] [{2}] [{3}] [{4}] [{5}]: {6}", TimeStamp.ToString("HH:mm:ss.ff"), DebugLogResponse.Category, Path.GetFileName(DebugLogResponse.FileName), DebugLogResponse.LineNumber, DebugLogResponse.ModuleId, DebugLogResponse.Filter, DebugLogResponse.Message); } } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 88fc04090..9af0d9f49 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -136,7 +136,7 @@ namespace Tango.Integration.Operation String folder = SettingsManager.DefaultFolder + "\\embedded logs"; Directory.CreateDirectory(folder); - FileLogger fileLogger = new FileLogger(Path.Combine(folder, String.Format("{1}-{0:yyyy-MM-dd_hh-mm-ss}.log", DateTime.Now, "embedded"))) { Enabled = true }; + FileLogger fileLogger = new FileLogger(Path.Combine(folder, String.Format("{1}-{0:dd-MM-yyyy_HH-mm-ss}.log", DateTime.Now, "embedded"))) { Enabled = true }; _embeddedLogger.RegisterLogger(fileLogger); } } diff --git a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs index cc8980cdc..de8485249 100644 --- a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs +++ b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs @@ -25,10 +25,13 @@ namespace Tango.Logging /// <summary> /// Gets the log message. /// </summary> - /// <returns></returns> - public override string GetMessage() + public override string Message { - return Exception.Message; + get + { + return Exception.Message; + } + set { } } /// <summary> @@ -36,7 +39,7 @@ namespace Tango.Logging /// </summary> public override string ToString() { - return String.Format("[{0}] [{6}] [{1}] [{2}] [Line {3}]: {4}{5}", TimeStamp.ToString("HH:mm:ss.ff"), Path.GetFileNameWithoutExtension(CallerFile), CallerMethodName, CallerLineNumber, Description, Environment.NewLine + Exception.FlattenException(), Category); + return String.Format("[{0}] [{6}] [{1}] [{2}] [{3}]: {4}{5}", TimeStamp.ToString("HH:mm:ss.ff"), GetRelativeCallerFilePath(), CallerMethodName, CallerLineNumber, Description, Environment.NewLine + Exception.FlattenException(), Category); } } diff --git a/Software/Visual_Studio/Tango.Logging/FileLogger.cs b/Software/Visual_Studio/Tango.Logging/FileLogger.cs index e104b59b9..215b1d9ac 100644 --- a/Software/Visual_Studio/Tango.Logging/FileLogger.cs +++ b/Software/Visual_Studio/Tango.Logging/FileLogger.cs @@ -13,6 +13,10 @@ namespace Tango.Logging /// <seealso cref="Tango.Logging.ILogger" /> public class FileLogger : ILogger { + /// <summary> + /// Gets the logs folder. + /// </summary> + public static String DefaultLogsFolder { get; private set; } /// <summary> /// Gets or sets the log file. @@ -20,14 +24,21 @@ namespace Tango.Logging public String LogFile { get; private set; } /// <summary> + /// Initializes the <see cref="FileLogger"/> class. + /// </summary> + static FileLogger() + { + DefaultLogsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "logs"); + } + + /// <summary> /// Initializes a new instance of the <see cref="FileLogger"/> class. /// </summary> public FileLogger() { _isEnabled = true; - String logsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "logs"); - Directory.CreateDirectory(logsFolder); - LogFile = Path.Combine(logsFolder, string.Format("{1}-{0:dd-MM-yyyy_hh-mm-ss}.log", DateTime.Now, Path.GetFileNameWithoutExtension(System.AppDomain.CurrentDomain.FriendlyName))); + Directory.CreateDirectory(DefaultLogsFolder); + LogFile = Path.Combine(DefaultLogsFolder, string.Format("{1}-{0:dd-MM-yyyy_HH-mm-ss}.log", DateTime.Now, Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName))); } /// <summary> diff --git a/Software/Visual_Studio/Tango.Logging/LogItemBase.cs b/Software/Visual_Studio/Tango.Logging/LogItemBase.cs index 85451488a..6b282b6ab 100644 --- a/Software/Visual_Studio/Tango.Logging/LogItemBase.cs +++ b/Software/Visual_Studio/Tango.Logging/LogItemBase.cs @@ -11,6 +11,13 @@ namespace Tango.Logging /// </summary> public abstract class LogItemBase { + private static String base_path; + + /// <summary> + /// Gets or sets the assembly. + /// </summary> + public String CallerAssembly { get; set; } + /// <summary> /// Gets or sets the caller method adding the exception. /// </summary> @@ -39,12 +46,23 @@ namespace Tango.Logging /// <summary> /// Gets the log message. /// </summary> - /// <returns></returns> - public abstract String GetMessage(); + public abstract String Message { get; set; } /// <summary> /// Returns a formatted string of the log item. /// </summary> public abstract override String ToString(); + + protected String GetRelativeCallerFilePath() + { + if (base_path == null) + { + int index = CallerFile.IndexOf("Visual_Studio") + "Visual_Studio".Length + 1; + String relative = CallerFile.Substring(index, CallerFile.Length - index); + base_path = CallerFile.Replace(relative, ""); + } + + return CallerFile.Replace(base_path, ""); + } } } diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs index c654b646f..804fc14c5 100644 --- a/Software/Visual_Studio/Tango.Logging/LogManager.cs +++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using System.Threading; @@ -107,6 +108,7 @@ namespace Tango.Logging if (!Categories.Contains(category)) return e; ExceptionLogItem log = new ExceptionLogItem(); + log.CallerAssembly = Assembly.GetCallingAssembly().FullName; log.CallerMethodName = caller; log.CallerFile = file; log.CallerLineNumber = lineNumber; @@ -164,6 +166,7 @@ namespace Tango.Logging if (!Categories.Contains(category)) return message; MessageLogItem log = new MessageLogItem(); + log.CallerAssembly = Assembly.GetCallingAssembly().FullName; log.CallerMethodName = caller; log.CallerFile = file; log.CallerLineNumber = lineNumber; diff --git a/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs b/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs index f7d7e004c..f45aa8cea 100644 --- a/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs +++ b/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs @@ -12,18 +12,20 @@ namespace Tango.Logging /// </summary> public class MessageLogItem : LogItemBase { + private String _message; /// <summary> /// Gets or sets the log message. /// </summary> - public String Message { get; set; } - - /// <summary> - /// Gets the log message. - /// </summary> - /// <returns></returns> - public override string GetMessage() + public override string Message { - return Message; + get + { + return _message; + } + set + { + _message = value; + } } /// <summary> @@ -31,7 +33,7 @@ namespace Tango.Logging /// </summary> public override string ToString() { - return String.Format("[{0}] [{5}] [{1}] [{2}] [Line {3}]: {4}", TimeStamp.ToString("HH:mm:ss.ff"), Path.GetFileNameWithoutExtension(CallerFile), CallerMethodName, CallerLineNumber, Message, Category); + return String.Format("[{0}] [{5}] [{1}] [{2}] [{3}]: {4}", TimeStamp.ToString("HH:mm:ss.ff"), GetRelativeCallerFilePath(), CallerMethodName, CallerLineNumber, Message, Category); } } } diff --git a/Software/Visual_Studio/Tango.UnitTesting/Logging_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Logging_TST.cs new file mode 100644 index 000000000..6d95674ff --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Logging_TST.cs @@ -0,0 +1,33 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.MachineStudio.Logging.Parsing; + +namespace Tango.UnitTesting +{ + [TestClass] + [TestCategory("Logging")] + public class Logging_TST + { + [TestMethod] + public void Parse_Application_Logs() + { + ApplicationLogFileParser parser = new ApplicationLogFileParser(); + var logFiles = parser.GetLogFiles(); + var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); + var logs = parser.Parse(logFile); + } + + [TestMethod] + public void Parse_Embedded_Logs() + { + EmbeddedLogFileParser parser = new EmbeddedLogFileParser(); + var logFiles = parser.GetLogFiles(); + var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); + var logs = parser.Parse(logFile); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 045e09360..6d4fb984d 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -79,6 +79,7 @@ <Compile Include="..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="Logging_TST.cs" /> <Compile Include="Scripting_TST.cs" /> <Compile Include="Embroidery_TST.cs" /> <Compile Include="Helper.cs" /> @@ -94,6 +95,10 @@ <None Include="packages.config" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\MachineStudio\Modules\Tango.MachineStudio.Logging\Tango.MachineStudio.Logging.csproj"> + <Project>{1674f726-0e66-414f-b9fd-c6f20d7f07c7}</Project> + <Name>Tango.MachineStudio.Logging</Name> + </ProjectReference> <ProjectReference Include="..\Tango.BL\Tango.BL.csproj"> <Project>{f441feee-322a-4943-b566-110e12fd3b72}</Project> <Name>Tango.BL</Name> diff --git a/Software/Visual_Studio/Tango.Visuals/Fader/Fader.xaml b/Software/Visual_Studio/Tango.Visuals/Fader/Fader.xaml index e3313ef43..c7aac0872 100644 --- a/Software/Visual_Studio/Tango.Visuals/Fader/Fader.xaml +++ b/Software/Visual_Studio/Tango.Visuals/Fader/Fader.xaml @@ -13,7 +13,7 @@ <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></converters:BooleanToVisibilityConverter> <converters:DoubleTunerConverter x:Key="DoubleTunerConverter"></converters:DoubleTunerConverter> - + <LinearGradientBrush x:Key="TrackBrush" StartPoint="0,0.5" EndPoint="1,0.5"> <GradientStop Color="#101010" Offset="1"/> <GradientStop Color="#FF252525" Offset="0.5"/> @@ -28,11 +28,27 @@ <SolidColorBrush x:Key="TicksBrush" Color="DimGray"></SolidColorBrush> <SolidColorBrush x:Key="BigTicksBrush" Color="Gray"></SolidColorBrush> + + <DataTemplate x:Key="leftTickTemplate"> + <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=TicksWidth,FallbackValue=8}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=TicksBrush,FallbackValue={StaticResource TicksBrush},TargetNullValue={StaticResource TicksBrush}}" HorizontalAlignment="Left"></Rectangle> + </DataTemplate> + + <DataTemplate x:Key="leftBigTickTemplate"> + <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=BigTicksWidth,FallbackValue=20}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=BigTicksBrush,FallbackValue={StaticResource BigTicksBrush},TargetNullValue={StaticResource BigTicksBrush}}" HorizontalAlignment="Left"></Rectangle> + </DataTemplate> + + <DataTemplate x:Key="rightTickTemplate"> + <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=TicksWidth,FallbackValue=8}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=TicksBrush,FallbackValue={StaticResource TicksBrush},TargetNullValue={StaticResource TicksBrush}}" HorizontalAlignment="Right"></Rectangle> + </DataTemplate> + + <DataTemplate x:Key="rightBigTickTemplate"> + <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=BigTicksWidth,FallbackValue=20}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=BigTicksBrush,FallbackValue={StaticResource BigTicksBrush},TargetNullValue={StaticResource BigTicksBrush}}" HorizontalAlignment="Left"></Rectangle> + </DataTemplate> </UserControl.Resources> <Grid> - <Border x:Name="border" Width="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=TrackWidth,FallbackValue=10}" Margin="0 35 0 35" CornerRadius="10" Background="{Binding ElementName=fader,Path=TrackBrush,FallbackValue={StaticResource TrackBrush},TargetNullValue={StaticResource TrackBrush}}"></Border> - <Border x:Name="borderHighLight" Visibility="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=HighlightTrack,Converter={StaticResource BooleanToVisibilityConverter}}" Width="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=TrackWidth,FallbackValue=8,Converter={StaticResource DoubleTunerConverter},ConverterParameter=-2}" Margin="0 38 0 38" VerticalAlignment="Bottom" CornerRadius="10" Background="{Binding ElementName=fader,Path=TrackHighlighBrush,FallbackValue={StaticResource TrackHighlighBrush},TargetNullValue={StaticResource TrackHighlighBrush}}"></Border> + <Border x:Name="border" Width="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=TrackWidth,FallbackValue=10}" Margin="0 35 0 35" CornerRadius="10" Background="{Binding ElementName=fader,Path=TrackBrush,FallbackValue={StaticResource TrackBrush},TargetNullValue={StaticResource TrackBrush}}"></Border> + <Border x:Name="borderHighLight" Visibility="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=HighlightTrack,Converter={StaticResource BooleanToVisibilityConverter}}" Width="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=TrackWidth,FallbackValue=8,Converter={StaticResource DoubleTunerConverter},ConverterParameter=-2}" Margin="0 38 0 38" VerticalAlignment="Bottom" CornerRadius="10" Background="{Binding ElementName=fader,Path=TrackHighlighBrush,FallbackValue={StaticResource TrackHighlighBrush},TargetNullValue={StaticResource TrackHighlighBrush}}"></Border> <Grid Margin="0 10 0 10"> <Grid.ColumnDefinitions> @@ -41,45 +57,27 @@ <ColumnDefinition Width="28*"/> </Grid.ColumnDefinitions> - <Grid Visibility="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=ShowTicks,Converter={StaticResource BooleanToVisibilityConverter}}"> - <local:YAxisTicks DataContext="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=.}" Ticks="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=Ticks}" BigTickInterval="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=BigTicksInterval}" IsHitTestVisible="False"> - <local:YAxisTicks.TickTemplate> - <DataTemplate> - <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TicksWidth,FallbackValue=8}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TicksBrush,FallbackValue={StaticResource TicksBrush},TargetNullValue={StaticResource TicksBrush}}" HorizontalAlignment="Left"></Rectangle> - </DataTemplate> - </local:YAxisTicks.TickTemplate> - <local:YAxisTicks.BigTickTemplate> - <DataTemplate> - <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.BigTicksWidth,FallbackValue=20}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.BigTicksBrush,FallbackValue={StaticResource BigTicksBrush},TargetNullValue={StaticResource BigTicksBrush}}" HorizontalAlignment="Left"></Rectangle> - </DataTemplate> - </local:YAxisTicks.BigTickTemplate> + <Grid Visibility="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=ShowTicks,Converter={StaticResource BooleanToVisibilityConverter}}"> + <local:YAxisTicks TickTemplate="{StaticResource leftTickTemplate}" BigTickTemplate="{StaticResource leftBigTickTemplate}" Ticks="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=Ticks}" BigTickInterval="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=BigTicksInterval}" IsHitTestVisible="False"> + </local:YAxisTicks> </Grid> - <Grid Grid.Column="2" Visibility="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=ShowTicks,Converter={StaticResource BooleanToVisibilityConverter}}"> - <local:YAxisTicks DataContext="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=.}" Ticks="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=Ticks}" BigTickInterval="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=BigTicksInterval}" IsHitTestVisible="False"> - <local:YAxisTicks.TickTemplate> - <DataTemplate> - <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TicksWidth,FallbackValue=8}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.TicksBrush,FallbackValue={StaticResource TicksBrush},TargetNullValue={StaticResource TicksBrush}}" HorizontalAlignment="Right"></Rectangle> - </DataTemplate> - </local:YAxisTicks.TickTemplate> - <local:YAxisTicks.BigTickTemplate> - <DataTemplate> - <Rectangle Width="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.BigTicksWidth,FallbackValue=20}" Height="1" Fill="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.BigTicksBrush,FallbackValue={StaticResource BigTicksBrush},TargetNullValue={StaticResource BigTicksBrush}}" HorizontalAlignment="Right"></Rectangle> - </DataTemplate> - </local:YAxisTicks.BigTickTemplate> + <Grid Grid.Column="2" Visibility="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=ShowTicks,Converter={StaticResource BooleanToVisibilityConverter}}"> + <local:YAxisTicks TickTemplate="{StaticResource rightTickTemplate}" BigTickTemplate="{StaticResource rightBigTickTemplate}" Ticks="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=Ticks}" BigTickInterval="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=BigTicksInterval}" IsHitTestVisible="False"> + </local:YAxisTicks> </Grid> </Grid> - <Grid Width="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=FaderWidth,FallbackValue=40}" VerticalAlignment="Bottom" x:Name="gridThumb"> + <Grid Width="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=FaderWidth,FallbackValue=40}" VerticalAlignment="Bottom" x:Name="gridThumb"> <Grid.RenderTransform> <TranslateTransform x:Name="faderTranslate" Y="0"></TranslateTransform> </Grid.RenderTransform> <Image RenderOptions.BitmapScalingMode="Fant" Source="pack://application:,,,/Tango.Visuals;component/Fader/fader-dark.png"></Image> <Grid> <Grid.Background> - <SolidColorBrush Color="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=FaderColor,TargetNullValue=Transparent}" Opacity="0.3"></SolidColorBrush> + <SolidColorBrush Color="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=FaderColor,TargetNullValue=Transparent}" Opacity="0.3"></SolidColorBrush> </Grid.Background> <Grid.RowDefinitions> <RowDefinition Height="35*"/> @@ -92,10 +90,10 @@ <Setter Property="Fill" Value="Transparent"></Setter> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=thumbMove,Path=IsMouseOver}" Value="True"> - <Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=FaderLightBrush,FallbackValue=#FF3100,TargetNullValue=#FF3100}"></Setter> + <Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=FaderLightBrush,FallbackValue=#FF3100,TargetNullValue=#FF3100}"></Setter> </DataTrigger> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=IsKeyDown}" Value="True"> - <Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=FaderLightBrush,FallbackValue=#FF3100,TargetNullValue=#FF3100}"></Setter> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=IsKeyDown}" Value="True"> + <Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=FaderLightBrush,FallbackValue=#FF3100,TargetNullValue=#FF3100}"></Setter> </DataTrigger> </Style.Triggers> </Style> @@ -120,7 +118,7 @@ </Setter.Value> </Setter> <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=IsFocused}" Value="True"> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:Fader},Path=IsFocused}" Value="True"> <Setter Property="Opacity" Value="0.2"></Setter> </DataTrigger> </Style.Triggers> |
