diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-15 20:04:52 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-15 20:04:52 +0200 |
| commit | 2836f1031bf9c1414a80620e040c1414a45c1648 (patch) | |
| tree | 5b615d1da2023aaab6aa914cabfcbe0f4e897df8 | |
| parent | 74438bb2f5d3ad782dec27a8f00838175ae67f8c (diff) | |
| download | Tango-2836f1031bf9c1414a80620e040c1414a45c1648.tar.gz Tango-2836f1031bf9c1414a80620e040c1414a45c1648.zip | |
Working on machine events !
14 files changed, 268 insertions, 34 deletions
diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf Binary files differindex 40dc38df3..f3bd407f1 100644 --- a/Software/DB/Tango.mdf +++ b/Software/DB/Tango.mdf diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf Binary files differindex 98a0a5ed0..833108156 100644 --- a/Software/DB/Tango_log.ldf +++ b/Software/DB/Tango_log.ldf diff --git a/Software/Graphics/error-message.png b/Software/Graphics/error-message.png Binary files differnew file mode 100644 index 000000000..c7c719b8a --- /dev/null +++ b/Software/Graphics/error-message.png diff --git a/Software/Graphics/exception.png b/Software/Graphics/exception.png Binary files differindex 9a4abb703..7b941818c 100644 --- a/Software/Graphics/exception.png +++ b/Software/Graphics/exception.png 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 ff4badffe..3763a06b4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -33,6 +33,7 @@ namespace Tango.MachineStudio.Common.EventLogging private IAuthenticationProvider _authentication; private Dictionary<EventTypes, BL.Entities.EventType> _eventTypesGuids; private String _hostName; + private bool _isInitialized; #region Constructors @@ -47,21 +48,8 @@ namespace Tango.MachineStudio.Common.EventLogging _events = new ConcurrentQueue<MachinesEvent>(); - _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; - _eventTypesGuids = new Dictionary<EventTypes, BL.Entities.EventType>(); - _db.ActionTypes.ToList(); - _db.EventTypesCategories.ToList(); - _db.EventTypesGroups.ToList(); - _db.EventTypes.ToList(); - - foreach (var type in _db.EventTypes) - { - _eventTypesGuids.Add((EventTypes)type.Code, type); - } - _application = applicationManager; _authentication = authenticationProvider; _logThread = new Thread(LogThreadMethod); @@ -73,6 +61,31 @@ namespace Tango.MachineStudio.Common.EventLogging #endregion + #region Private Methods + + private void Init() + { + if (!_isInitialized) + { + _db = ObservablesContext.CreateDefault(); + _db.Configuration.LazyLoadingEnabled = false; + + _db.ActionTypes.ToList(); + _db.EventTypesCategories.ToList(); + _db.EventTypesGroups.ToList(); + _db.EventTypes.ToList(); + + foreach (var type in _db.EventTypes) + { + _eventTypesGuids.Add((EventTypes)type.Code, type); + } + + _isInitialized = true; + } + } + + #endregion + #region Event Handlers /// <summary> @@ -135,7 +148,7 @@ namespace Tango.MachineStudio.Common.EventLogging /// </summary> /// <param name="sender">The sender.</param> /// <param name="events">The events.</param> - private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable<Event> events) + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable<MachinesEvent> events) { foreach (var ev in events) { @@ -153,6 +166,11 @@ 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); } @@ -164,13 +182,12 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="message">The message.</param> public void Log(EventTypes eventType, string message) { + Init(); + MachinesEvent machineEvent = new MachinesEvent(); - machineEvent.MachineGuid = _application.ConnectedMachine != null ? _application.ConnectedMachine.Guid : null; machineEvent.DateTime = DateTime.UtcNow; machineEvent.Description = message; machineEvent.EventType = _eventTypesGuids[eventType]; - machineEvent.UserGuid = _authentication.CurrentUser != null ? _authentication.CurrentUser.Guid : null; - machineEvent.HostName = _hostName; Log(machineEvent); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/error-message.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/error-message.png Binary files differnew file mode 100644 index 000000000..c7c719b8a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/error-message.png diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png Binary files differindex 9a4abb703..7b941818c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 6a879e965..95c2a9925 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -421,6 +421,9 @@ <ItemGroup> <Resource Include="Images\new-version.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\error-message.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <PropertyGroup> <PostBuildEvent>if $(ConfigurationName) == Debug $(TargetDir)linkgen.exe -s "$(TargetPath)" -d "$(TargetDir)Utilities\Machine Studio.lnk" 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 ba94cd860..b3c6236f8 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Integration.Services; using Tango.Logging; @@ -75,6 +76,16 @@ namespace Tango.MachineStudio.UI.ViewModels set { _isMenuOpened = value; RaisePropertyChangedAuto(); } } + private bool _isMachineErrorsOpened; + /// <summary> + /// Gets or sets a value indicating whether to display the machine errors. + /// </summary> + public bool IsMachineErrorsOpened + { + get { return _isMachineErrorsOpened; } + set { _isMachineErrorsOpened = value; RaisePropertyChangedAuto(); } + } + /// <summary> /// Gets or sets the start module command. /// </summary> @@ -225,6 +236,31 @@ namespace Tango.MachineStudio.UI.ViewModels _updateCheckThread = new Thread(UpdateCheckThreadMethod); _updateCheckThread.IsBackground = true; _updateCheckThread.Start(); + + ApplicationManager.ConnectedMachineChanged += (sender, machine) => + { + if (machine != null) + { + machine.MachineEventsStateProvider.NewEvents -= MachineEventsStateProvider_NewEvents; + machine.MachineEventsStateProvider.NewEvents += MachineEventsStateProvider_NewEvents; + + machine.MachineEventsStateProvider.EventsResolved -= MachineEventsStateProvider_EventsResolved; + machine.MachineEventsStateProvider.EventsResolved += MachineEventsStateProvider_EventsResolved; + } + }; + } + + private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable<MachinesEvent> e) + { + if (ApplicationManager.ConnectedMachine.MachineEventsStateProvider.Events.Count == 0) + { + IsMachineErrorsOpened = false; + } + } + + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable<MachinesEvent> e) + { + IsMachineErrorsOpened = true; } private void UpdateCheckThreadMethod() @@ -323,7 +359,7 @@ namespace Tango.MachineStudio.UI.ViewModels else { ApplicationManager.ConnectedMachine = x.SelectedMachine; - _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP",x.SelectedMachine.SerialNumber)); + _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber)); } } catch (Exception ex) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index 8e6fa36f5..beade3d88 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -9,6 +9,7 @@ xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:db="clr-namespace:Tango.MachineStudio.DB.Views;assembly=Tango.MachineStudio.DB" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" @@ -225,6 +226,17 @@ </StackPanel> </Button> + <ToggleButton Visibility="{Binding ApplicationManager.ConnectedMachine.MachineEventsStateProvider.HasEvents,Converter={StaticResource BooleanToVisibilityConverter},FallbackValue=Collapsed,TargetNullValue=Collapsed,Mode=OneWay}" IsChecked="{Binding IsMachineErrorsOpened}" Style="{StaticResource emptyToggleButton}" Margin="0 0 10 0" Cursor="Hand"> + <ToggleButton.ToolTip> + <TextBlock> + <Run>Press to view</Run> + <Run Text="{Binding ApplicationManager.ConnectedMachine.MachineEventsStateProvider.Events.Count,Mode=OneWay}"></Run> + <Run>hardware messages</Run> + </TextBlock> + </ToggleButton.ToolTip> + <Image Source="/Images/error-message.png" Width="32" /> + </ToggleButton> + <Button Style="{StaticResource emptyButton}" Cursor="Hand" Command="{Binding UpdateCenterCommand}" Visibility="{Binding IsUpdateAvailable,Converter={StaticResource BooleanToVisibilityConverter}}"> <Button.ToolTip> <TextBlock> @@ -383,6 +395,55 @@ <TextBlock Text="{Binding NotificationProvider.CurrentTaskItem.Message,Converter={StaticResource StringEllipsisConverter},ConverterParameter=35}" Foreground="White" VerticalAlignment="Center" Margin="10 0 0 0" TextWrapping="Wrap"></TextBlock> </StackPanel> </Border> + + <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" Visibility="{Binding IsMachineErrorsOpened,Converter={StaticResource BooleanToVisibilityConverter}}"> + <Border Width="350" Background="#ECFFFFFF" BorderBrush="White" CornerRadius="5" Padding="5"> + <Border.Effect> + <DropShadowEffect ShadowDepth="0" BlurRadius="10" /> + </Border.Effect> + + <ItemsControl ItemsSource="{Binding ApplicationManager.ConnectedMachine.MachineEventsStateProvider.Events}"> + <ItemsControl.ItemTemplate> + <DataTemplate DataType="{x:Type entities:MachinesEvent}"> + <Border BorderThickness="0 0 0 1" BorderBrush="#E1E1E1" Padding="5"> + <StackPanel> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Width="24" Height="24"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Kind" Value="AlertCircle"></Setter> + <Setter Property="Foreground" Value="#464646"></Setter> + <Style.Triggers> + <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> + + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding EventType.Name}"></TextBlock> + </StackPanel> + </StackPanel> + </Border> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </Border> + + <Canvas HorizontalAlignment="Center"> + <Polygon Points="12,0 0,35 24,35" Fill="#86FFFFFF" Canvas.Top="-35" Canvas.Left="95"></Polygon> + </Canvas> + </Grid> </Grid> </DockPanel> </materialDesign:DrawerHost> diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/MachineEvent.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/MachineEvent.cs new file mode 100644 index 000000000..19a6989ce --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/MachineEvent.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Enumerations; +using Tango.PMR.Diagnostics; + +namespace Tango.BL.Entities +{ + public partial class MachinesEvent + { + private static Dictionary<EventTypes, EventType> _eventTypesGuids; + private static bool _eventFactoryInitialized; + + private void InitializeEventFactory() + { + if (!_eventFactoryInitialized) + { + _eventFactoryInitialized = true; + + _eventTypesGuids = new Dictionary<EventTypes, EventType>(); + + foreach (var type in ObservablesEntitiesAdapter.Instance.EventTypes) + { + _eventTypesGuids.Add((EventTypes)type.Code, type); + } + } + } + + public MachinesEvent(Event pmrEvent) : this() + { + InitializeEventFactory(); + + DateTime = DateTime.UtcNow; + Description = pmrEvent.Message; + EventType = _eventTypesGuids[(EventTypes)pmrEvent.Type]; + } + + [NotMapped] + public EventTypesCategories Category + { + get { return (EventTypesCategories)EventType.EventTypesCategory.Code; } + } + + [NotMapped] + public EventTypesGroups Group + { + get { return (EventTypesGroups)EventType.EventTypesGroup.Code; } + } + + [NotMapped] + public EventTypes Type + { + get { return (EventTypes)EventType.Code; } + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index ae00498af..d56324d8f 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -89,6 +89,7 @@ <Compile Include="Dispensing\StandardColorDispensingCalc.cs" /> <Compile Include="Dispensing\TransparentLiquidDispensingCalc.cs" /> <Compile Include="EntitiesExtensions\Contact.cs" /> + <Compile Include="EntitiesExtensions\MachineEvent.cs" /> <Compile Include="Entities\EventTypesCategory.cs" /> <Compile Include="Entities\EventTypesGroup.cs" /> <Compile Include="Entities\TechController.cs" /> diff --git a/Software/Visual_Studio/Tango.Integration/Operation/DefaultMachineEventsStateProvider.cs b/Software/Visual_Studio/Tango.Integration/Operation/DefaultMachineEventsStateProvider.cs index d8ac112df..9a5119330 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/DefaultMachineEventsStateProvider.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/DefaultMachineEventsStateProvider.cs @@ -4,6 +4,8 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core; using Tango.PMR.Diagnostics; namespace Tango.Integration.Operation @@ -12,13 +14,13 @@ namespace Tango.Integration.Operation /// Represents the default machine events state provider. /// </summary> /// <seealso cref="Tango.Integration.Operation.IMachineEventsStateProvider" /> - public class DefaultMachineEventsStateProvider : IMachineEventsStateProvider + public class DefaultMachineEventsStateProvider : ExtendedObject, IMachineEventsStateProvider { - private ReadOnlyCollection<Event> _events; + private ReadOnlyCollection<MachinesEvent> _events; /// <summary> /// Gets the current machine events. /// </summary> - public ReadOnlyCollection<Event> Events + public ReadOnlyCollection<MachinesEvent> Events { get { @@ -27,21 +29,37 @@ namespace Tango.Integration.Operation } /// <summary> + /// Gets or sets a value indicating whether this instance has events. + /// </summary> + public bool HasEvents + { + get + { + return Events.Count > 0; + } + } + + /// <summary> /// Occurs when new events are available. /// </summary> - public event EventHandler<IEnumerable<Event>> NewEvents; + public event EventHandler<IEnumerable<MachinesEvent>> NewEvents; /// <summary> /// Occurs when a new events states has been received. /// </summary> - public event EventHandler<IEnumerable<Event>> EventsReceived; + public event EventHandler<IEnumerable<MachinesEvent>> EventsReceived; + + /// <summary> + /// Occurs when old events has been resolved. + /// </summary> + public event EventHandler<IEnumerable<MachinesEvent>> EventsResolved; /// <summary> /// Initializes a new instance of the <see cref="DefaultMachineEventsStateProvider"/> class. /// </summary> public DefaultMachineEventsStateProvider() { - _events = new ReadOnlyCollection<Event>(new Collection<Event>()); + _events = new ReadOnlyCollection<MachinesEvent>(new Collection<MachinesEvent>()); } /// <summary> @@ -50,19 +68,38 @@ namespace Tango.Integration.Operation /// <param name="events">The events.</param> public void ApplyEvents(IEnumerable<Event> events) { - List<Event> currentEvents = Events.ToList(); - List<Event> newEvents = events.Where(x => !currentEvents.Exists(y => y.Type == x.Type)).ToList(); - _events = new ReadOnlyCollection<Event>(new Collection<Event>(events.ToList())); - OnNewEvents(newEvents); - OnEventsReceived(events); + List<MachinesEvent> receivedEvents = events.Select(x => new MachinesEvent(x)).ToList(); + + List<MachinesEvent> newEvents = receivedEvents.Where(x => !_events.ToList().Exists(y => y.Type == x.Type)).ToList(); + List<MachinesEvent> oldEvents = _events.Where(x => !receivedEvents.Exists(y => y.Type == x.Type)).ToList(); + + _events = new ReadOnlyCollection<MachinesEvent>(receivedEvents); + + if (newEvents.Count > 0) + { + OnNewEvents(newEvents); + } + if (oldEvents.Count > 0) + { + OnEventsResolved(oldEvents); + } + + OnEventsReceived(_events); + + RaisePropertyChanged(nameof(HasEvents)); + + if (newEvents.Count > 0 || oldEvents.Count > 0) + { + RaisePropertyChanged(nameof(Events)); + } } /// <summary> /// Called when the new has been events /// </summary> /// <param name="events">The events.</param> - protected virtual void OnNewEvents(IEnumerable<Event> events) + protected virtual void OnNewEvents(IEnumerable<MachinesEvent> events) { NewEvents?.Invoke(this, events); } @@ -71,9 +108,18 @@ namespace Tango.Integration.Operation /// Called when the events has been received /// </summary> /// <param name="events">The events.</param> - protected virtual void OnEventsReceived(IEnumerable<Event> events) + protected virtual void OnEventsReceived(IEnumerable<MachinesEvent> events) { EventsReceived?.Invoke(this, events); } + + /// <summary> + /// Called when the events has been resolved + /// </summary> + /// <param name="events">The events.</param> + protected virtual void OnEventsResolved(IEnumerable<MachinesEvent> events) + { + EventsResolved?.Invoke(this, events); + } } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs index bb7215254..6b3fc2e2c 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; using Tango.PMR.Diagnostics; namespace Tango.Integration.Operation @@ -16,17 +17,27 @@ namespace Tango.Integration.Operation /// <summary> /// Gets the current machine events. /// </summary> - ReadOnlyCollection<Event> Events { get; } + ReadOnlyCollection<MachinesEvent> Events { get; } + + /// <summary> + /// Gets or sets a value indicating whether this instance has events. + /// </summary> + bool HasEvents { get; } /// <summary> /// Occurs when new events are available. /// </summary> - event EventHandler<IEnumerable<Event>> NewEvents; + event EventHandler<IEnumerable<MachinesEvent>> NewEvents; + + /// <summary> + /// Occurs when old events has been resolved. + /// </summary> + event EventHandler<IEnumerable<MachinesEvent>> EventsResolved; /// <summary> /// Occurs when a new events states has been received. /// </summary> - event EventHandler<IEnumerable<Event>> EventsReceived; + event EventHandler<IEnumerable<MachinesEvent>> EventsReceived; /// <summary> /// Applies the collection of events received from the machine operator. |
