diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-28 14:34:58 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-28 14:34:58 +0300 |
| commit | 08bd4400dfd45245ae301b5cb28103322ddf865a (patch) | |
| tree | 6cc7caf742e00e5746fe20401857fdc569b922a7 /Software/Visual_Studio/MachineStudio | |
| parent | bfbdac5a071e7aea068e6f4acd796e83e73cf970 (diff) | |
| parent | 953fc4deb9d94a63afe07d66ccf78ff42f54c3bb (diff) | |
| download | Tango-08bd4400dfd45245ae301b5cb28103322ddf865a.tar.gz Tango-08bd4400dfd45245ae301b5cb28103322ddf865a.zip | |
SystemReset request
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
28 files changed, 1277 insertions, 205 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Controls/TimeRuler.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Controls/TimeRuler.cs new file mode 100644 index 000000000..552f8f416 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Controls/TimeRuler.cs @@ -0,0 +1,227 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace Tango.MachineStudio.Logging.Controls +{ + public class TimeRuler : Control + { + private double _smallStep; + private double _bigStep; + + #region Private Methods + + private static T FindVisualParent<T>(DependencyObject child) where T : DependencyObject + { + // get parent item + DependencyObject parentObject = VisualTreeHelper.GetParent(child); + + // we’ve reached the end of the tree + if (parentObject == null) return null; + + // check if the parent matches the type we’re looking for + T parent = parentObject as T; + if (parent != null) + { + return parent; + } + else + { + // use recursion to proceed with next level + return FindVisualParent<T>(parentObject); + } + } + + #endregion + + #region Properties + + public double RenderWidth + { + get { return (double)GetValue(RenderWidthProperty); } + set { SetValue(RenderWidthProperty, value); } + } + public static readonly DependencyProperty RenderWidthProperty = + DependencyProperty.Register("RenderWidth", typeof(double), typeof(TimeRuler), new FrameworkPropertyMetadata(400.0, FrameworkPropertyMetadataOptions.AffectsRender)); + + public double HorizontalOffset + { + get { return (double)GetValue(HorizontalOffsetProperty); } + set { SetValue(HorizontalOffsetProperty, value); } + } + public static readonly DependencyProperty HorizontalOffsetProperty = + DependencyProperty.Register("HorizontalOffset", typeof(double), typeof(TimeRuler), new PropertyMetadata(0.0, HorizontalOffsetChanged)); + + private static void HorizontalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var control = d as TimeRuler; + control.Margin = new Thickness(-control.HorizontalOffset, 0, 0, 0); + control.InvalidateVisual(); + } + + + + #region Zoom + /// <summary> + /// Gets or sets the zoom factor for the ruler. The default value is 1.0. + /// </summary> + public double Zoom + { + get + { + return (double)GetValue(ZoomProperty); + } + set + { + SetValue(ZoomProperty, value); + this.InvalidateVisual(); + } + } + + private void SetSteps(double value) + { + if (value >= 50) + { + _smallStep = 0.25; + _bigStep = 1; + } + else if (value >= 40) + { + _smallStep = 0.25; + _bigStep = 2; + } + else if (value >= 30) + { + _smallStep = 0.5; + _bigStep = 2; + } + else if (value >= 20) + { + _smallStep = 1; + _bigStep = 5; + } + else if (value >= 10) + { + _smallStep = 1; + _bigStep = 10; + } + else if (value >= 5) + { + _smallStep = 2; + _bigStep = 20; + } + else if (value >= 3) + { + _smallStep = 5; + _bigStep = 30; + } + else if (value >= 1) + { + _smallStep = 30; + _bigStep = 300; + } + else if (value >= 0.5) + { + _smallStep = 60; + _bigStep = 600; + } + } + + /// <summary> + /// Identifies the Zoom dependency property. + /// </summary> + public static readonly DependencyProperty ZoomProperty = + DependencyProperty.Register("Zoom", typeof(double), typeof(TimeRuler), new FrameworkPropertyMetadata((double)1.0, FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(ZoomChanged))); + + private static void ZoomChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as TimeRuler).SetSteps((double)e.NewValue); + } + + + #endregion + + #endregion + + #region Constructor + + public TimeRuler() + { + _smallStep = 1; + _bigStep = 10; + FontSize = 10; + this.Loaded += TimeRuler_Loaded; + } + + private void TimeRuler_Loaded(object sender, RoutedEventArgs e) + { + this.InvalidateVisual(); + } + + #endregion + + #region Methods + + /// <summary> + /// Participates in rendering operations. + /// </summary> + /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param> + protected override void OnRender(DrawingContext drawingContext) + { + base.OnRender(drawingContext); + + double xDest = RenderWidth; + int start = (int)(HorizontalOffset / Zoom); + + drawingContext.DrawRectangle(Background, new Pen(BorderBrush, 0), new Rect(new Point(start * Zoom, 0.0), new Point(xDest + (start * Zoom) + 100, Height))); + drawingContext.DrawLine(new Pen(BorderBrush, 1), new Point(start * Zoom, Height - 1), new Point(xDest + (start * Zoom) + 100, Height)); + + + double l = (start % _smallStep); + while (l != 0) //I don't know why, but this is needed in order to prevent ruler from flickering on some lower scale factors :/ + { + start += 1; + l = (start % _smallStep); + } + + for (double dUnit = start; dUnit < (RenderWidth / Zoom) + (start) + 10; dUnit += _smallStep) + { + double d = dUnit * (this.Zoom); + + double startHeight; + double endHeight; + + startHeight = Height; + endHeight = ((dUnit % _bigStep == 0) ? (this.ActualHeight / 5) * 1.5 : this.ActualHeight / 5); + + drawingContext.DrawLine(new Pen(Foreground, 1), new Point(d, startHeight), new Point(d, (startHeight - endHeight))); + + double uu = (dUnit % _bigStep); + + if ((dUnit != 0.0) && (uu == 0) && (dUnit < (RenderWidth / Zoom) + start + 10)) + { + double u = dUnit; + TimeSpan t = TimeSpan.FromSeconds((u)); + + FormattedText ft = new FormattedText(t.ToString("g"), + CultureInfo.CurrentCulture, + FlowDirection.LeftToRight, + new Typeface(FontFamily.ToString()), + FontSize, + Foreground); + ft.SetFontWeight(FontWeight); + ft.TextAlignment = TextAlignment.Center; + drawingContext.DrawText(ft, new Point(d, (Height / 2) - (ft.Height / 2) - 2)); + } + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/DateIsInListToBooleanConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/DateIsInListToBooleanConverter.cs new file mode 100644 index 000000000..cd4f60d4c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/DateIsInListToBooleanConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.MachineStudio.Logging.ViewModels; + +namespace Tango.MachineStudio.Logging.Converters +{ + public class DateIsInListToBooleanConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length < 2 || !(values[0] is DateTime) || !(values[1] is IEnumerable<DateTime>)) + return false; + + var date = (DateTime)values[0]; + var dateList = (IEnumerable<DateTime>)values[1]; + + return dateList.ToList().Exists(x => x.ToLocalTime().ToShortDateString() == date.ToLocalTime().ToShortDateString()); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/EventsToTimeRulerTicksConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/EventsToTimeRulerTicksConverter.cs new file mode 100644 index 000000000..35df1723b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/EventsToTimeRulerTicksConverter.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.MachineStudio.Logging.ViewModels; + +namespace Tango.MachineStudio.Logging.Converters +{ + public class EventsToTimeRulerTicksConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + ObservableCollection<TimelineEventGroup> groups = value as ObservableCollection<TimelineEventGroup>; + + DateTime maxTime = groups.SelectMany(x => x.Events).Max(x => x.DateTime); + DateTime minTime = groups.SelectMany(x => x.Events).Min(x => x.DateTime); + + List<DateTime> dates = new List<DateTime>(); + + for (DateTime time = minTime; time < maxTime; time = time.AddSeconds(1)) + { + dates.Add(time); + } + + return dates; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/MachineEventToXConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/MachineEventToXConverter.cs new file mode 100644 index 000000000..193a63ffc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/MachineEventToXConverter.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.BL.Entities; +using Tango.MachineStudio.Logging.Helpers; +using Tango.MachineStudio.Logging.ViewModels; + +namespace Tango.MachineStudio.Logging.Converters +{ + public class MachineEventToXConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 3) + { + MachinesEvent ev = values[0] as MachinesEvent; + + if (ev != null) + { + ObservableCollection<TimelineEventGroup> groups = values[1] as ObservableCollection<TimelineEventGroup>; + + if (groups.Count > 0) + { + double scale = (double)values[2]; + + DateTime maxTime = groups.SelectMany(x => x.Events).Max(x => x.DateTime); + DateTime minTime = groups.SelectMany(x => x.Events).Min(x => x.DateTime); + + TimeSpan range = maxTime - minTime; + TimeSpan time = maxTime - ev.DateTime; + + time = range - time; + + return TimelineHelper.ConvertTimeToPixels(time, scale); + } + } + } + + return 0.0; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/SecondsToWidthConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/SecondsToWidthConverter.cs new file mode 100644 index 000000000..66e888cc0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/SecondsToWidthConverter.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.MachineStudio.Logging.Helpers; + +namespace Tango.MachineStudio.Logging.Converters +{ + public class SecondsToWidthConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + double scale = (double)value; + double seconds = System.Convert.ToDouble(parameter.ToString()); + + return TimelineHelper.ConvertTimeToPixels(TimeSpan.FromSeconds(seconds), scale); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/TimeSpanToXConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/TimeSpanToXConverter.cs new file mode 100644 index 000000000..4c9f5b569 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/TimeSpanToXConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.MachineStudio.Logging.Helpers; + +namespace Tango.MachineStudio.Logging.Converters +{ + public class TimeSpanToXConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 2) + { + TimeSpan time = (TimeSpan)values[0]; + double scale = (double)values[1]; + + return TimelineHelper.ConvertTimeToPixels(time, scale) + 300; + } + + return null; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Helpers/TimelineHelper.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Helpers/TimelineHelper.cs new file mode 100644 index 000000000..6cfe51ba4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Helpers/TimelineHelper.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Logging.Helpers +{ + public static class TimelineHelper + { + public static double ConvertTimeToPixels(TimeSpan time, double scaleFactor) + { + return ((double)(0.05f * ((double)(time.TotalSeconds) * 20))) * scaleFactor; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationManager.cs new file mode 100644 index 000000000..b86df7b0f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationManager.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Logging; +using Tango.MachineStudio.Common.Navigation; +using Tango.MachineStudio.Logging.Views; + +namespace Tango.MachineStudio.Logging.Navigation +{ + public class LoggingNavigationManager + { + private LogManager LogManager = LogManager.Default; + + public void NavigateTo(LoggingNavigationView view) + { + LogManager.Log(String.Format("Navigating to view {0}...", view.ToString())); + MainView.Instance.TransitionControl.AutoNavigate(view.ToString()); + } + } +} 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 new file mode 100644 index 000000000..6f4fcbceb --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Logging.Navigation +{ + public enum LoggingNavigationView + { + EventsView, + TimelineView, + } +} 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 d62246cf2..8bcdbe016 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 @@ -81,13 +81,28 @@ <Compile Include="..\..\..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="Controls\TimeRuler.cs" /> + <Compile Include="Converters\DateIsInListToBooleanConverter.cs" /> + <Compile Include="Converters\EventsToTimeRulerTicksConverter.cs" /> + <Compile Include="Converters\MachineEventToXConverter.cs" /> + <Compile Include="Converters\SecondsToWidthConverter.cs" /> + <Compile Include="Converters\TimeSpanToXConverter.cs" /> + <Compile Include="Helpers\TimelineHelper.cs" /> <Compile Include="LoggingModule.cs" /> + <Compile Include="Navigation\LoggingNavigationManager.cs" /> + <Compile Include="Navigation\LoggingNavigationView.cs" /> <Compile Include="ViewModelLocator.cs" /> - <Compile Include="ViewModels\DateVM.cs" /> <Compile Include="ViewModels\MainViewVM.cs" /> + <Compile Include="ViewModels\TimelineEventGroup.cs" /> + <Compile Include="Views\EventsView.xaml.cs"> + <DependentUpon>EventsView.xaml</DependentUpon> + </Compile> <Compile Include="Views\MainView.xaml.cs"> <DependentUpon>MainView.xaml</DependentUpon> </Compile> + <Compile Include="Views\TimelineView.xaml.cs"> + <DependentUpon>TimelineView.xaml</DependentUpon> + </Compile> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs"> @@ -150,16 +165,28 @@ <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> <Name>Tango.SharedUI</Name> </ProjectReference> + <ProjectReference Include="..\..\..\Tango.Transport\Tango.Transport.csproj"> + <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project> + <Name>Tango.Transport</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.MachineStudio.Common\Tango.MachineStudio.Common.csproj"> <Project>{cb0b0aa2-bb24-4bca-a720-45e397684e12}</Project> <Name>Tango.MachineStudio.Common</Name> </ProjectReference> </ItemGroup> <ItemGroup> + <Page Include="Views\EventsView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\MainView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\TimelineView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> </ItemGroup> <ItemGroup> <Resource Include="Images\machine-trans.png" /> 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 76c89000d..ef6923e27 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs @@ -1,6 +1,7 @@ using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Ioc; using Microsoft.Practices.ServiceLocation; +using Tango.MachineStudio.Logging.Navigation; using Tango.MachineStudio.Logging.ViewModels; namespace Tango.MachineStudio.Logging @@ -18,6 +19,9 @@ namespace Tango.MachineStudio.Logging { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); SimpleIoc.Default.Register<MainViewVM>(); + + SimpleIoc.Default.Unregister<LoggingNavigationManager>(); + SimpleIoc.Default.Register<LoggingNavigationManager>(() => new LoggingNavigationManager()); } public static MainViewVM MainViewVM diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/DateVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/DateVM.cs deleted file mode 100644 index fd03d6328..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/DateVM.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core; - -namespace Tango.MachineStudio.Logging.ViewModels -{ - public class DateVM : ExtendedObject - { - public DateTime Date { get; set; } - - public String Description { get; set; } - - public DateVM(DateTime date) - { - Date = date; - Description = date.ToLocalTime().ToShortDateString(); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs index 94765ccdb..81b0a587c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs @@ -1,12 +1,18 @@ -using System; +using GalaSoft.MvvmLight.Messaging; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; using Tango.BL.Entities; +using Tango.Core.Commands; using Tango.MachineStudio.Common.EventLogging; +using Tango.MachineStudio.Common.Messages; using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.MachineStudio.Logging.Navigation; using Tango.SharedUI; namespace Tango.MachineStudio.Logging.ViewModels @@ -14,9 +20,11 @@ namespace Tango.MachineStudio.Logging.ViewModels public class MainViewVM : ViewModel { private INotificationProvider _notification; + private IStudioApplicationManager _application; private IEventLogger _eventLogger; - private DateVM _realTimeDate; private ObservableCollection<MachinesEvent> _realTimeEvents; + private Machine _connectedMachine; + private LoggingNavigationManager _navigation; private Machine _selectedMachine; public Machine SelectedMachine @@ -39,55 +47,139 @@ namespace Tango.MachineStudio.Logging.ViewModels set { _selectedEvent = value; RaisePropertyChangedAuto(); OnSelectedEventChanged(); } } - private ObservableCollection<DateVM> _dates; - public ObservableCollection<DateVM> Dates + private ObservableCollection<DateTime> _dates; + public ObservableCollection<DateTime> Dates { get { return _dates; } set { _dates = value; RaisePropertyChangedAuto(); } } - private DateVM _selectedDate; - public DateVM SelectedDate + private DateTime _selectedDate; + public DateTime SelectedDate { get { return _selectedDate; } set { _selectedDate = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } } - public MainViewVM(INotificationProvider notification, IEventLogger eventLogger) + 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(); } + } + + private ObservableCollection<TimelineEventGroup> _timelineEventGroups; + public ObservableCollection<TimelineEventGroup> TimelineEventGroups + { + get { return _timelineEventGroups; } + set { _timelineEventGroups = value; RaisePropertyChangedAuto(); } + } + + private TimeSpan _timelineMaxTime; + public TimeSpan TimelineMaxTime + { + get { return _timelineMaxTime; } + set { _timelineMaxTime = value; RaisePropertyChangedAuto(); } + } + + private double _timelineScaleFactor; + public double TimelineScaleFactor + { + get { return _timelineScaleFactor; } + set + { + + if (value < 0.1) value = 0.1; + + _timelineScaleFactor = value; + RaisePropertyChangedAuto(); + } + } + + public RelayCommand<MachinesEvent> DisplayTimelineCommand { get; set; } + + public RelayCommand NavigateToEventsCommand { get; set; } + + public MainViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application, LoggingNavigationManager navigation) + { + _navigation = navigation; + _application = application; _notification = notification; _eventLogger = eventLogger; - _realTimeDate = new DateVM(DateTime.Now) { Description = "Real Time" }; _realTimeEvents = new ObservableCollection<MachinesEvent>(); _eventLogger.NewLog += _eventLogger_NewLog; + + TimelineScaleFactor = 10; + + RegisterMessage<MachineConnectionChangedMessage>(OnMachineConnectionChanged); + DisplayTimelineCommand = new RelayCommand<MachinesEvent>(DisplayTimeline); + NavigateToEventsCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.EventsView)); + } + + private void OnMachineConnectionChanged(MachineConnectionChangedMessage msg) + { + if (msg.Machine != null) + { + _connectedMachine = ObservablesEntitiesAdapter.Instance.Machines.SingleOrDefault(x => x.SerialNumber == msg.Machine.SerialNumber); + SelectedMachine = _connectedMachine; + } + else + { + _connectedMachine = null; + } } private void _eventLogger_NewLog(object sender, MachinesEvent machineEvent) { - _realTimeEvents.Add(machineEvent); + InvokeUI(() => + { + _realTimeEvents.Insert(0, machineEvent); + }); } private void OnSelectedMachineChanged() { if (SelectedMachine != null) { - Dates = new ObservableCollection<DateVM>(); - Dates.Add(_realTimeDate); + Dates = new ObservableCollection<DateTime>(); + + if (SelectedMachine == _connectedMachine) + { + IsRealTime = true; + } foreach (var day in SelectedMachine.MachinesEvents.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) { - Dates.Add(new DateVM(day)); + Dates.Add(day); } - SelectedDate = Dates.First(); + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + + SelectedDate = Dates.FirstOrDefault(); } } private void OnSelectedDateChanged() { - if (SelectedDate != null) + if (SelectedDate != null && SelectedMachine != null) { - if (SelectedDate == _realTimeDate) + if (IsRealTime) { Events = _realTimeEvents; } @@ -100,10 +192,34 @@ namespace Tango.MachineStudio.Logging.ViewModels private void OnSelectedEventChanged() { - if (SelectedEvent != null) + if (SelectedEvent != null && SelectedEvent.Type != BL.Enumerations.EventTypes.ApplicationStarted) { _notification.ShowInfo(SelectedEvent.Description); } } + + private void DisplayTimeline(MachinesEvent ev) + { + var events = Events.OrderBy(x => x.DateTime).SkipWhile(x => x != ev).Skip(1).TakeWhile(x => x.DateTime > ev.DateTime && x.Type != BL.Enumerations.EventTypes.ApplicationStarted).ToObservableCollection(); + events.Insert(0, ev); + + TimelineEventGroups = new ObservableCollection<TimelineEventGroup>(); + + foreach (var group in events.GroupBy(x => x.Group)) + { + TimelineEventGroup evGroup = new TimelineEventGroup(group.Key.ToString().ToWords()); + + foreach (var e in group) + { + evGroup.Events.Add(e); + } + + TimelineEventGroups.Add(evGroup); + } + + TimelineMaxTime = events.Max(x => x.DateTime) - events.Min(x => x.DateTime); + + _navigation.NavigateTo(LoggingNavigationView.TimelineView); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/TimelineEventGroup.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/TimelineEventGroup.cs new file mode 100644 index 000000000..978348fd2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/TimelineEventGroup.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core; + +namespace Tango.MachineStudio.Logging.ViewModels +{ + public class TimelineEventGroup : ExtendedObject + { + public String Name { get; set; } + + public ObservableCollection<MachinesEvent> Events { get; set; } + + public TimelineEventGroup() + { + Events = new ObservableCollection<MachinesEvent>(); + } + + public TimelineEventGroup(String name) : this() + { + Name = name; + } + } +} 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 new file mode 100644 index 000000000..a3b4ae6bf --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml @@ -0,0 +1,244 @@ +<UserControl x:Class="Tango.MachineStudio.Logging.Views.EventsView" + 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:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + <UserControl.Resources> + <autoCompleteMachine:MachinesProvider x:Key="MachinesProvider" /> + <converters:DateTimeUTCToShortDateTimeConverter x:Key="DateTimeUTCToShortDateTimeConverter" /> + <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"> + <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"> + <Image Source="../Images/machine-trans.png" RenderOptions.BitmapScalingMode="Fant"></Image> + <StackPanel Orientation="Horizontal" Width="300" Margin="20 0 0 5" VerticalAlignment="Bottom"> + <materialDesign:PackIcon Kind="BarcodeScan" VerticalAlignment="Center" Width="24" Height="24" /> + <autoComplete:AutoCompleteTextBox HorizontalContentAlignment="Stretch" Width="300" Margin="10 0 0 0" FontSize="16" Provider="{StaticResource MachinesProvider}" SelectedItem="{Binding SelectedMachine,Mode=TwoWay}" materialDesign:HintAssist.Hint="Serial Number / Name" DisplayMember="SerialNumber"> + <autoComplete:AutoCompleteTextBox.ItemTemplate> + <DataTemplate> + <Border Padding="5"> + <DockPanel LastChildFill="False" Width="250"> + <StackPanel Orientation="Horizontal" DockPanel.Dock="Left"> + <Image Source="/Images/machine-trans.png" Width="24" RenderOptions.BitmapScalingMode="Fant" /> + <TextBlock Margin="10 0 0 0" FontWeight="SemiBold" Text="{Binding SerialNumber}" VerticalAlignment="Center"></TextBlock> + </StackPanel> + <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right" Text="{Binding Name}" Foreground="Gray" VerticalAlignment="Center"></TextBlock> + </DockPanel> + </Border> + </DataTemplate> + </autoComplete:AutoCompleteTextBox.ItemTemplate> + </autoComplete:AutoCompleteTextBox> + </StackPanel> + </StackPanel> + </Border> + <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 Events}" 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 Type}" Value="ApplicationStarted"> + <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 Type}" Value="ApplicationStarted"> + <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 Type}" Value="ApplicationStarted"> + <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 DateTime,Converter={StaticResource DateTimeUTCToShortDateTimeConverter}}" /> + <DataGridTextColumn Header="HOST" Binding="{Binding HostName}" /> + <DataGridTextColumn Header="USER" Binding="{Binding User.Contact.FullName,Mode=OneTime}" /> + <DataGridTextColumn Header="GROUP" Binding="{Binding EventType.EventTypesGroup.Name}" /> + <DataGridTextColumn Header="EVENT" Binding="{Binding EventType.Name}" /> + <DataGridTemplateColumn Header="MESSAGE" Width="1*"> + <DataGridTemplateColumn.CellTemplate> + <DataTemplate> + <TextBlock Text="{Binding Description}" TextTrimming="CharacterEllipsis"></TextBlock> + </DataTemplate> + </DataGridTemplateColumn.CellTemplate> + </DataGridTemplateColumn> + <DataGridTemplateColumn Header="" Width="150"> + <DataGridTemplateColumn.CellTemplate> + <DataTemplate> + <ContentControl> + <ContentControl.Style> + <Style TargetType="ContentControl"> + <Setter Property="ContentTemplate" Value="{x:Null}"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding Type}" Value="ApplicationStarted"> + <Setter Property="ContentTemplate"> + <Setter.Value> + <DataTemplate> + <Button Style="{StaticResource emptyButton}" Cursor="Hand" Foreground="White" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.DisplayTimelineCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContentControl},Path=DataContext}"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="Display Timeline" VerticalAlignment="Center"></TextBlock> + <materialDesign:PackIcon VerticalAlignment="Center" Margin="5 0 0 0" Kind="ArrowRight" Width="16" Height="16" /> + </StackPanel> + </Button> + </DataTemplate> + </Setter.Value> + </Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </ContentControl.Style> + </ContentControl> + </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/EventsView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml.cs new file mode 100644 index 000000000..b17eea54c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.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 EventsView : UserControl + { + public EventsView() + { + 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 d4567d90f..6d841149e 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 @@ -8,142 +8,23 @@ 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: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}"> - <UserControl.Resources> - <autoCompleteMachine:MachinesProvider x:Key="MachinesProvider" /> - <converters:DateTimeUTCToShortDateTimeConverter x:Key="DateTimeUTCToShortDateTimeConverter" /> - </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" Margin="10"> - <Image Source="../Images/machine-trans.png" RenderOptions.BitmapScalingMode="Fant"></Image> - <StackPanel Orientation="Horizontal" Width="300" Margin="20 0 0 5" VerticalAlignment="Bottom"> - <materialDesign:PackIcon Kind="BarcodeScan" VerticalAlignment="Center" Width="24" Height="24" /> - <autoComplete:AutoCompleteTextBox HorizontalContentAlignment="Stretch" Width="300" Margin="10 0 0 0" FontSize="16" Provider="{StaticResource MachinesProvider}" SelectedItem="{Binding SelectedMachine,Mode=TwoWay}" materialDesign:HintAssist.Hint="Serial Number / Name" DisplayMember="SerialNumber"> - <autoComplete:AutoCompleteTextBox.ItemTemplate> - <DataTemplate> - <Border Padding="5"> - <DockPanel LastChildFill="False" Width="250"> - <StackPanel Orientation="Horizontal" DockPanel.Dock="Left"> - <Image Source="/Images/machine-trans.png" Width="24" RenderOptions.BitmapScalingMode="Fant" /> - <TextBlock Margin="10 0 0 0" FontWeight="SemiBold" Text="{Binding SerialNumber}" VerticalAlignment="Center"></TextBlock> - </StackPanel> - <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right" Text="{Binding Name}" Foreground="Gray" VerticalAlignment="Center"></TextBlock> - </DockPanel> - </Border> - </DataTemplate> - </autoComplete:AutoCompleteTextBox.ItemTemplate> - </autoComplete:AutoCompleteTextBox> - </StackPanel> - - <materialDesign:PackIcon Kind="Calendar" Width="24" Height="24" VerticalAlignment="Bottom" Margin="20 0 0 5" /> - <ComboBox Margin="10 0 0 5" Width="200" VerticalAlignment="Bottom" FontSize="16" ItemsSource="{Binding Dates}" SelectedItem="{Binding SelectedDate}" DisplayMemberPath="Description"></ComboBox> - </StackPanel> - </Grid> - </Border> - - <Grid Grid.Row="1" Background="#B3FFFFFF"> - <Grid Margin="10"> - <Grid.ColumnDefinitions> - - <ColumnDefinition Width="1*"/> - </Grid.ColumnDefinitions> - - <Grid> - <DockPanel> - <Grid DockPanel.Dock="Top"> - <StackPanel Orientation="Horizontal"> - <materialDesign:PackIcon Kind="NoteText" Width="32" Height="32" /> - <TextBlock VerticalAlignment="Center" Margin="10 0 0 0" FontSize="16" FontWeight="SemiBold" FontStyle="Italic">MACHINE EVENTS</TextBlock> - </StackPanel> - </Grid> - - <Grid> - <DataGrid Background="Transparent" AlternatingRowBackground="#ECECEC" AutoGenerateColumns="False" SelectionMode="Single" ItemsSource="{Binding Events}" 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> - </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> - </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> - </Style.Triggers> - </Style> - </materialDesign:PackIcon.Style> - </materialDesign:PackIcon> - </DataTemplate> - </DataGridTemplateColumn.CellTemplate> - </DataGridTemplateColumn> - <DataGridTextColumn Header="DATE TIME" Binding="{Binding DateTime,Converter={StaticResource DateTimeUTCToShortDateTimeConverter}}" /> - <DataGridTextColumn Header="HOST" Binding="{Binding HostName}" /> - <DataGridTextColumn Header="USER" Binding="{Binding User.Contact.FullName}" /> - <DataGridTextColumn Header="GROUP" Binding="{Binding EventType.EventTypesGroup.Name}" /> - <DataGridTextColumn Header="EVENT" Binding="{Binding EventType.Name}" /> - <DataGridTemplateColumn Header="MESSAGE" Width="1*"> - <DataGridTemplateColumn.CellTemplate> - <DataTemplate> - <TextBlock Text="{Binding Description}" TextTrimming="CharacterEllipsis"></TextBlock> - </DataTemplate> - </DataGridTemplateColumn.CellTemplate> - </DataGridTemplateColumn> - </DataGrid.Columns> - </DataGrid> - </Grid> - </DockPanel> - </Grid> - </Grid> - </Grid> - </Grid> + <controls:MultiTransitionControl x:Name="TransitionControl" x:FieldModifier="internal" TransitionType="Slide"> + <controls:MultiTransitionControl.Controls> + <ContentControl Tag="EventsView"> + <local:EventsView/> + </ContentControl> + <ContentControl Tag="TimelineView"> + <local:TimelineView/> + </ContentControl> + </controls:MultiTransitionControl.Controls> + </controls:MultiTransitionControl> </Grid> </UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml.cs index 160767603..c8d232e86 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml.cs @@ -20,9 +20,12 @@ namespace Tango.MachineStudio.Logging.Views /// </summary> public partial class MainView : UserControl { + public static MainView Instance { get; private set; } + public MainView() { InitializeComponent(); + Instance = this; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineView.xaml new file mode 100644 index 000000000..e746f67b3 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineView.xaml @@ -0,0 +1,161 @@ +<UserControl x:Class="Tango.MachineStudio.Logging.Views.TimelineView" + 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: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:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:vm="clr-namespace:Tango.MachineStudio.Logging.ViewModels" + xmlns:localControls="clr-namespace:Tango.MachineStudio.Logging.Controls" + xmlns:local="clr-namespace:Tango.MachineStudio.Logging.Views" + mc:Ignorable="d" + d:DesignHeight="1080" d:DesignWidth="1920" Background="White" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}" MouseWheel="UserControl_MouseWheel"> + + <UserControl.Resources> + <localConverters:TimeSpanToXConverter x:Key="TimeSpanToXConverter" /> + <localConverters:MachineEventToXConverter x:Key="MachineEventToXConverter" /> + <localConverters:SecondsToWidthConverter x:Key="SecondsToWidthConverter" /> + + <LinearGradientBrush x:Key="infoBrush" StartPoint="0.5,0" EndPoint="0.5,1"> + <GradientStop Color="White"/> + <GradientStop Color="#FFBFBFBF" Offset="1"/> + </LinearGradientBrush> + + <LinearGradientBrush x:Key="warningBrush" StartPoint="0.5,0" EndPoint="0.5,1"> + <GradientStop Color="#FFFF8C57"/> + <GradientStop Color="White" Offset="1"/> + </LinearGradientBrush> + + <LinearGradientBrush x:Key="errorBrush" StartPoint="0.5,0" EndPoint="0.5,1"> + <GradientStop Color="#FFFF6A6A"/> + <GradientStop Color="#FFD9D9" Offset="1"/> + </LinearGradientBrush> + + <LinearGradientBrush x:Key="criticalBrush" StartPoint="0.5,0" EndPoint="0.5,1"> + <GradientStop Color="Red"/> + <GradientStop Color="White" Offset="1"/> + </LinearGradientBrush> + + </UserControl.Resources> + + <Grid> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="70"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + + <Grid> + <StackPanel Orientation="Horizontal" Margin="10"> + <Button MinWidth="160" Height="50" Style="{StaticResource MaterialDesignFlatButton}" Command="{Binding NavigateToEventsCommand}" 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> + </StackPanel> + </Grid> + + <Grid Grid.Row="1"> + <Grid.RowDefinitions> + <RowDefinition Height="30"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="300"/> + <ColumnDefinition Width="1*"/> + </Grid.ColumnDefinitions> + + <Grid Grid.Column="1" ClipToBounds="True"> + <localControls:TimeRuler HorizontalAlignment="Left" FontSize="14" HorizontalOffset="{Binding ElementName=scrollViewer,Path=HorizontalOffset}" Background="White" BorderBrush="{StaticResource AccentColorBrush}" BorderThickness="1" Foreground="{StaticResource AccentColorBrush}" Height="30" x:Name="ruler" Width="{Binding RelativeSource={RelativeSource AncestorType=Grid},Path=ActualWidth}" RenderWidth="{Binding RelativeSource={RelativeSource AncestorType=Grid},Path=ActualWidth}" Zoom="{Binding TimelineScaleFactor}"></localControls:TimeRuler> + </Grid> + + <Grid Background="White"> + + </Grid> + + <ItemsControl ItemsSource="{Binding TimelineEventGroups}" Grid.Column="0" Grid.Row="1" Margin="0 -3 0 0"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <UniformGrid Columns="1" /> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate DataType="{x:Type vm:TimelineEventGroup}"> + <Border BorderThickness="1 1 1 1" BorderBrush="{StaticResource AccentColorBrush}" Margin="2 2 0 2"> + + <TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="28" FontWeight="SemiBold" Foreground="{StaticResource AccentColorBrush}"></TextBlock> + </Border> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + + <ScrollViewer x:Name="scrollViewer" Grid.Column="1" Grid.Row="1" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto"> + <ItemsControl ItemsSource="{Binding TimelineEventGroups}" HorizontalAlignment="Left"> + <ItemsControl.Width> + <MultiBinding Converter="{StaticResource TimeSpanToXConverter}"> + <Binding Path="TimelineMaxTime" /> + <Binding Path="TimelineScaleFactor" /> + </MultiBinding> + </ItemsControl.Width> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <UniformGrid Columns="1" /> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate DataType="{x:Type vm:TimelineEventGroup}"> + <ItemsControl ItemsSource="{Binding Events}"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <UniformGrid IsItemsHost="True" Columns="1"></UniformGrid> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate DataType="{x:Type entities:MachinesEvent}"> + <Canvas Margin="10"> + <Grid Height="{Binding RelativeSource={RelativeSource AncestorType=Canvas},Path=ActualHeight}"> + <Canvas.Left> + <MultiBinding Converter="{StaticResource MachineEventToXConverter}"> + <Binding Path="." /> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.TimelineEventGroups" /> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.TimelineScaleFactor" /> + </MultiBinding> + </Canvas.Left> + <Border BorderBrush="#4E4E4E" BorderThickness="1" Padding="10" MinHeight="20" MinWidth="50"> + <Border.Style> + <Style TargetType="Border"> + <Style.Triggers> + <DataTrigger Binding="{Binding Category}" Value="Info"> + <Setter Property="Background" Value="{StaticResource infoBrush}"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Category}" Value="Warning"> + <Setter Property="Background" Value="{StaticResource warningBrush}"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Category}" Value="Error"> + <Setter Property="Background" Value="{StaticResource errorBrush}"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Category}" Value="Crtitical"> + <Setter Property="Background" Value="{StaticResource criticalBrush}"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </Border.Style> + <TextBlock Text="{Binding Description}" Height="17"></TextBlock> + </Border> + </Grid> + </Canvas> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </ScrollViewer> + </Grid> + </Grid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineView.xaml.cs new file mode 100644 index 000000000..53e2362dc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineView.xaml.cs @@ -0,0 +1,44 @@ +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; +using Tango.MachineStudio.Logging.ViewModels; + +namespace Tango.MachineStudio.Logging.Views +{ + /// <summary> + /// Interaction logic for TimelineView.xaml + /// </summary> + public partial class TimelineView : UserControl + { + private MainViewVM _vm; + + public TimelineView() + { + InitializeComponent(); + this.Loaded += (_, __) => _vm = DataContext as MainViewVM; + } + + private void UserControl_MouseWheel(object sender, MouseWheelEventArgs e) + { + if (e.Delta > 0) + { + _vm.TimelineScaleFactor += 0.5; + } + else + { + _vm.TimelineScaleFactor -= 0.5; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index 0f19d3b6d..d3fb0897f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -34,13 +34,14 @@ namespace Tango.MachineStudio.Common.EventLogging private Dictionary<EventTypes, BL.Entities.EventType> _eventTypesGuids; private String _hostName; private bool _isInitialized; + private List<MachinesEvent> _pendingEvents; #region Events /// <summary> /// Occurs when a new machine event has been logged. /// </summary> - public event EventHandler<MachinesEvent> NewLog; + public event EventHandler<MachinesEvent> NewLog; #endregion @@ -56,6 +57,7 @@ namespace Tango.MachineStudio.Common.EventLogging _hostName = Environment.MachineName; _events = new ConcurrentQueue<MachinesEvent>(); + _pendingEvents = new List<MachinesEvent>(); _eventTypesGuids = new Dictionary<EventTypes, BL.Entities.EventType>(); @@ -90,7 +92,7 @@ namespace Tango.MachineStudio.Common.EventLogging _eventTypesGuids.Add((EventTypes)type.Code, type); } - _isInitialized = true; + _isInitialized = true; } } @@ -176,15 +178,33 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="machineEvent">The machine event.</param> public void Log(MachinesEvent machineEvent) { - machineEvent.MachineGuid = _application.ConnectedMachine != null ? _application.ConnectedMachine.Guid : null; - machineEvent.UserGuid = _authentication.CurrentUser != null ? _authentication.CurrentUser.Guid : null; machineEvent.HostName = _hostName; machineEvent.EventType = _eventTypesGuids[machineEvent.Type]; - LogManager.Log("Logging event " + machineEvent.EventType.Name + " - " + machineEvent.Description); - _events.Enqueue(machineEvent); + if (_application.ConnectedMachine == null || _authentication.CurrentUser == null) + { + _pendingEvents.Add(machineEvent); + } + else + { + if (_pendingEvents.Count > 0) + { + var pending = _pendingEvents.ToList(); + _pendingEvents.Clear(); + + foreach (var ev in pending) + { + Log(ev); + } + } - NewLog?.Invoke(this, machineEvent); + LogManager.Log("Logging event " + machineEvent.EventType.Name + " - " + machineEvent.Description); + machineEvent.MachineGuid = _application.ConnectedMachine.Guid; + machineEvent.UserGuid = _authentication.CurrentUser.Guid; + machineEvent.User = _authentication.CurrentUser; + _events.Enqueue(machineEvent); + NewLog?.Invoke(this, machineEvent); + } } /// <summary> @@ -223,6 +243,16 @@ namespace Tango.MachineStudio.Common.EventLogging } /// <summary> + /// Logs the specified exception using the <see cref="EventTypes.ApplicationException" />. + /// </summary> + /// <param name="exception">The exception.</param> + /// <param name="description"></param> + public void Log(Exception exception, string description) + { + Log(EventTypes.ApplicationException, description + Environment.NewLine + exception.ToString()); + } + + /// <summary> /// Logs the specified message using the <see cref="EventTypes.ApplicationInformation"/>. /// </summary> /// <param name="message">The message.</param> @@ -238,32 +268,40 @@ namespace Tango.MachineStudio.Common.EventLogging { while (true) { - bool _saveChanges = false; + FlushAll(); + Thread.Sleep(5000); + } + } - while (_events.Count > 0) - { - MachinesEvent ev = null; + /// <summary> + /// Immediately saves all pending events to database. + /// </summary> + public void FlushAll() + { + bool _saveChanges = false; - if (_events.TryDequeue(out ev)) - { - _db.MachinesEvents.Add(ev); - _saveChanges = true; - } - } + while (_events.Count > 0) + { + MachinesEvent ev = null; - if (_saveChanges) + if (_events.TryDequeue(out ev)) { - try - { - _db.SaveChanges(); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error saving machine event to database."); - } + ev.User = null; + _db.MachinesEvents.Add(ev); + _saveChanges = true; } + } - Thread.Sleep(5000); + if (_saveChanges) + { + try + { + _db.SaveChanges(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error saving machine event to database."); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs index aeecb4ae6..ce599a398 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs @@ -45,9 +45,20 @@ namespace Tango.MachineStudio.Common.EventLogging void Log(Exception exception); /// <summary> + /// Logs the specified exception using the <see cref="EventTypes.ApplicationException"/>. + /// </summary> + /// <param name="exception">The exception.</param> + void Log(Exception exception, String description); + + /// <summary> /// Logs the specified message using the <see cref="EventTypes.ApplicationInformation"/>. /// </summary> /// <param name="message">The message.</param> void Log(String message); + + /// <summary> + /// Immediately saves all pending events to database. + /// </summary> + void FlushAll(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Messages/MachineConnectionChangedMessage.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Messages/MachineConnectionChangedMessage.cs new file mode 100644 index 000000000..90820ed47 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Messages/MachineConnectionChangedMessage.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Services; + +namespace Tango.MachineStudio.Common.Messages +{ + public class MachineConnectionChangedMessage : IStudioMessage + { + public IExternalBridgeClient Machine { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 15ab97a27..df553f502 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -105,6 +105,7 @@ <Compile Include="EventLogging\IEventLogger.cs" /> <Compile Include="ExtensionMethods\CommonDialogExtensions.cs" /> <Compile Include="Helpers\GraphsHelper.cs" /> + <Compile Include="Messages\MachineConnectionChangedMessage.cs" /> <Compile Include="Notifications\BarItem.cs" /> <Compile Include="Notifications\DialogViewVM.cs" /> <Compile Include="StudioApplication\IModuleRequestListener.cs" /> 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 f94a6c9d9..8b3233ab1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs @@ -14,6 +14,7 @@ using Tango.MachineStudio.UI.Windows; using Tango.Settings; using Microsoft.Practices.ServiceLocation; using Tango.MachineStudio.Common.EventLogging; +using Tango.BL.Enumerations; namespace Tango.MachineStudio.UI { @@ -49,6 +50,12 @@ namespace Tango.MachineStudio.UI exceptionTrapper = new WpfGlobalExceptionTrapper(); exceptionTrapper.Initialize(this); exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; + + var eventLogger = ServiceLocator.Current.GetInstance<IEventLogger>(); + if (eventLogger != null) + { + eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); + } } #region Global Exception Trapping @@ -74,7 +81,7 @@ namespace Tango.MachineStudio.UI var eventLogger = ServiceLocator.Current.GetInstance<IEventLogger>(); if (eventLogger != null) { - eventLogger.Log(e.Exception); + eventLogger.Log(e.Exception, "Application Crashed!"); } } catch { } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index b4b1c5153..52602e6de 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -18,6 +18,8 @@ using Tango.MachineStudio.Common; using Tango.Settings; using System.Windows; using Tango.Integration.Services; +using Tango.MachineStudio.Common.EventLogging; +using Tango.BL.Enumerations; namespace Tango.MachineStudio.UI.StudioApplication { @@ -189,6 +191,13 @@ namespace Tango.MachineStudio.UI.StudioApplication LogManager.Log(ex, "Error disconnecting from machine."); } + var eventLogger = ServiceLocator.Current.GetInstance<IEventLogger>(); + if (eventLogger != null) + { + eventLogger.Log(EventTypes.ApplicationTerminated, "Application Terminated!"); + eventLogger.FlushAll(); + } + Thread.Sleep(1500); Environment.Exit(0); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 54b83a5cc..5776cadc2 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -70,7 +70,6 @@ namespace Tango.MachineStudio.UI.ViewModels { _studioModuleLoader.LoadModules(); _navigationManager.NavigateTo(NavigationView.LoginView); - _eventLogger.Log("Application started successfully"); IsLoading = false; }); } 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 f54a9dae1..81719287b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -1,4 +1,5 @@ using GalaSoft.MvvmLight.Ioc; +using GalaSoft.MvvmLight.Messaging; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -19,6 +20,7 @@ using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.EventLogging; +using Tango.MachineStudio.Common.Messages; using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; @@ -321,12 +323,27 @@ namespace Tango.MachineStudio.UI.ViewModels { using (_notificationProvider.PushTaskItem("Disconnecting from machine...")) { - _isDisconnecting = true; - InvalidateRelayCommands(); - await ApplicationManager.ConnectedMachine.Disconnect(); - ApplicationManager.ConnectedMachine = null; - _isDisconnecting = false; - InvalidateRelayCommands(); + try + { + _isDisconnecting = true; + InvalidateRelayCommands(); + String serial = ApplicationManager.ConnectedMachine.SerialNumber; + await ApplicationManager.ConnectedMachine.Disconnect(); + ApplicationManager.ConnectedMachine = null; + _eventLogger.Log("Disconnected from machine " + serial); + + PostMessage(new MachineConnectionChangedMessage() { Machine = null }); + } + catch (Exception ex) + { + _eventLogger.Log(ex, "Error disconnecting from machine."); + LogManager.Log(ex, "Could not disconnect from machine."); + } + finally + { + _isDisconnecting = false; + InvalidateRelayCommands(); + } } } @@ -377,12 +394,14 @@ namespace Tango.MachineStudio.UI.ViewModels else { ApplicationManager.ConnectedMachine = x.SelectedMachine; + PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber)); } } catch (Exception ex) { LogManager.Log(ex); + _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); _notificationProvider.ShowError(ex.Message); } @@ -403,6 +422,8 @@ namespace Tango.MachineStudio.UI.ViewModels await x.SelectedMachine.Connect(); x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; ApplicationManager.ConnectedMachine = x.SelectedMachine; + + PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); _eventLogger.Log(String.Format("Successfully connected to machine {0} via USB", x.SelectedMachine.SerialNumber)); SettingsManager.Default.MachineStudio.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; SettingsManager.SaveDefaultSettings(); @@ -410,6 +431,7 @@ namespace Tango.MachineStudio.UI.ViewModels catch (Exception ex) { LogManager.Log(ex); + _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); _notificationProvider.ShowError(ex.Message); } |
