aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/Views/LocalSynchronizationView.xaml
blob: e5a4aac5a04a9b227d6e5d5181477cc3721157db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<UserControl x:Class="Tango.MachineStudio.Synchronization.Views.LocalSynchronizationView"
             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:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:synchronization="clr-namespace:Tango.Synchronization;assembly=Tango.Synchronization"
             xmlns:global="clr-namespace:Tango.MachineStudio.Synchronization"
             xmlns:local="clr-namespace:Tango.MachineStudio.Synchronization.Views"
             xmlns:fa="http://schemas.fontawesome.io/icons/"
             mc:Ignorable="d" 
             d:DesignHeight="720" d:DesignWidth="1280"  DataContext="{x:Static global:ViewModelLocator.LocalSynchronizationViewVM}">

    <UserControl.Resources>
        <VisualBrush x:Key="badgeBackground">
            <VisualBrush.Visual>
                <Border>
                    <Path Stretch="Fill" RenderTransformOrigin="0.5,0.5">
                        <Path.RenderTransform>
                            <ScaleTransform ScaleX="-1"></ScaleTransform>
                        </Path.RenderTransform>
                        <Path.Fill>
                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                <GradientStop Color="#EEEEEE" Offset="0.4" />
                                <GradientStop Color="White" Offset="1"/>
                            </LinearGradientBrush>
                        </Path.Fill>
                        <Path.Data>
                            <PathGeometry Figures="M 53.868 43.913 H 19.511 c -0.444 0 -0.875 -0.151 -1.221 -0.428 L 0.734 29.439 c -0.978 -0.783 -0.978 -2.271 0 -3.053 L 18.29 12.341 c 0.347 -0.277 0.777 -0.428 1.221 -0.428 h 34.356 c 1.081 0 1.958 0.877 1.958 1.958 v 28.084 c 0 1.081 -0.876 1.958 -1.957 1.958 z" FillRule="NonZero"/>
                        </Path.Data>
                    </Path>
                </Border>
            </VisualBrush.Visual>
        </VisualBrush>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid>
            <StackPanel Orientation="Horizontal" Margin="20">
                <Button Style="{StaticResource MaterialDesignFlatButton}" Padding="0" Margin="0 5 0 0" VerticalAlignment="Center" Command="{Binding BackCommand}">
                    <materialDesign:PackIcon Kind="ArrowLeft" Foreground="#303030" ToolTip="Back" VerticalAlignment="Center" Width="40" Height="40"></materialDesign:PackIcon>
                </Button>
                <TextBlock VerticalAlignment="Center" Margin="10 0 0 0" FontSize="30">Local Database Synchronization</TextBlock>
            </StackPanel>
        </Grid>
        <Grid Grid.Row="1">
            <Grid Margin="20">
                <GroupBox Header="Compare &amp; Synchronize">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="57*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MaxWidth="250" />
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>

                            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Margin="20 0 0 0">
                                <Image Source="../Images/sqlite.png"  Width="100" Margin="10" Opacity="0.8" HorizontalAlignment="Left" RenderOptions.BitmapScalingMode="Fant"></Image>
                                <TextBlock Background="{StaticResource badgeBackground}" Padding="5" Width="200" FontSize="14" HorizontalAlignment="Left">Master Database</TextBlock>
                                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                                    <TextBox IsReadOnly="True" Width="130" BorderBrush="#4E4E4E" Text="{Binding MasterDBName}" ToolTip="{Binding MasterDBFile}"></TextBox>
                                    <Button Margin="5 0 0 0" Cursor="Hand" VerticalAlignment="Center" Style="{DynamicResource MetroCircleButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding BrowseMasterDBCommand}" ToolTip="Browse for master database file">
                                        <fa:ImageAwesome Icon="FolderOpen" Width="24" Foreground="Gray"></fa:ImageAwesome>
                                    </Button>
                                </StackPanel>
                            </StackPanel>

                            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="1" Margin="20 0 0 0">
                                <Image Source="../Images/sqlite.png"  Width="80" Margin="10" Opacity="0.8" HorizontalAlignment="Left" RenderOptions.BitmapScalingMode="Fant"></Image>
                                <TextBlock Background="{StaticResource badgeBackground}" Padding="5" Width="200" FontSize="14" HorizontalAlignment="Left">Slave Database</TextBlock>
                                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                                    <TextBox IsReadOnly="True" Width="130" BorderBrush="#4E4E4E" Text="{Binding SlaveDBName}" ToolTip="{Binding SlaveDBFile}"></TextBox>
                                    <Button Margin="5 0 0 0" Cursor="Hand" VerticalAlignment="Center" Style="{DynamicResource MetroCircleButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding BrowseSlaveDBCommand}" ToolTip="Browse for slave database file">
                                        <fa:ImageAwesome Icon="FolderOpen" Width="24" Foreground="Gray"></fa:ImageAwesome>
                                    </Button>
                                </StackPanel>
                            </StackPanel>
                        </Grid>

                        <Button Margin="20 10" Grid.Row="1" Width="160" Height="40" HorizontalAlignment="Left" Command="{Binding CompareCommand}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">COMPARE</TextBlock>
                                <fa:ImageAwesome Icon="LongArrowRight" VerticalAlignment="Center" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button},Path=Foreground}" Width="16"></fa:ImageAwesome>
                            </StackPanel>
                        </Button>

                        <Grid Grid.Column="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="671*"/>
                                <ColumnDefinition Width="301*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20"/>
                                <RowDefinition Height="205*"/>
                            </Grid.RowDefinitions>
                            <TextBlock Margin="10 5 0 0" FontSize="14">Differences</TextBlock>
                            <ListBox Margin="10" Background="#F1F1F1" Grid.Row="1" ItemsSource="{Binding Differences}" SelectedItem="{Binding SelectedDifference,Mode=TwoWay}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Border Padding="10">
                                            <StackPanel Orientation="Horizontal">
                                                <fa:ImageAwesome Icon="Cog" Width="20" Height="20" Foreground="Gray"></fa:ImageAwesome>
                                                <TextBlock VerticalAlignment="Center" Margin="10 0 0 0" Text="{Binding Description}">
                                                    <TextBlock.Style>
                                                        <Style TargetType="TextBlock">
                                                            <Setter Property="Foreground" Value="Red"></Setter>
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Action}" Value="ReplaceTableDataInSlave">
                                                                    <Setter Property="Foreground" Value="#404040"></Setter>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </TextBlock.Style>
                                                </TextBlock>
                                            </StackPanel>
                                        </Border>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>

                            <TextBlock Grid.Column="1" Margin="10 0 0 0" VerticalAlignment="Bottom">SQL Command</TextBlock>
                            <TextBox Grid.Column="1" Margin="10" Style="{x:Null}" BorderThickness="0" Foreground="Gray" FontSize="14" Text="{Binding SelectedDifference.Command,Mode=OneWay}" IsReadOnly="True" Background="#F1F1F1" Padding="5" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" AcceptsReturn="True" Grid.Row="1"></TextBox>
                        </Grid>

                        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Grid.Column="1">
                            <Button Margin="10 10" Width="160" Height="40" Background="#FF4F4F" BorderBrush="#FF4F4F" Command="{Binding CleanCommand}">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">CLEAN SLAVE</TextBlock>
                                    <fa:ImageAwesome Icon="TrashOutline" VerticalAlignment="Center" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button},Path=Foreground}" Width="16"></fa:ImageAwesome>
                                </StackPanel>
                            </Button>
                            <Button Margin="10 10" Grid.Row="1" Width="160" Height="40" HorizontalAlignment="Right" Command="{Binding CommitCommand}">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">COMMIT</TextBlock>
                                    <fa:ImageAwesome Icon="Bolt" VerticalAlignment="Center" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button},Path=Foreground}" Width="16"></fa:ImageAwesome>
                                </StackPanel>
                            </Button>
                            <Button Margin="10 10" Grid.Row="1" Width="160" Height="40" HorizontalAlignment="Right" Command="{Binding CommitAllCommand}">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">COMMIT ALL</TextBlock>
                                    <fa:ImageAwesome Icon="SortAmountAsc" VerticalAlignment="Center" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button},Path=Foreground}" Width="16"></fa:ImageAwesome>
                                </StackPanel>
                            </Button>
                        </StackPanel>

                    </Grid>
                </GroupBox>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
/// </summary> /// <param name="navigationManager">The navigation manager.</param> public DefaultStudioApplicationManager(INavigationManager navigationManager, IStudioModuleLoader moduleLoader, INotificationProvider notification) { _moduleLoader = moduleLoader; _navigationManager = navigationManager; _notification = notification; _openedWindows = new List<Window>(); _notified_view_models = new List<IStudioViewModel>(); Application.Current.MainWindow.ContentRendered += (_, __) => { TangoIOC.Default.GetAllInstancesByBase<IStudioViewModel>().ToList().ForEach(x => x.OnApplicationStarted()); }; } /// <summary> /// Gets a value indicating whether Machine Studio is shutting down. /// </summary> public bool IsShuttingDown { get; private set; } /// <summary> /// Occurs when the connected machine property has changed. /// </summary> public event EventHandler<IExternalBridgeClient> ConnectedMachineChanged; /// <summary> /// Gets or sets the machine. /// </summary> public Machine Machine { get; private set; } private IExternalBridgeClient _connectedMachine; /// <summary> /// Gets or sets the currently connected machine if any. /// </summary> public IExternalBridgeClient ConnectedMachine { get { return _connectedMachine; } private set { if (_connectedMachine != value) { _connectedMachine = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(IsMachineConnected)); RaisePropertyChanged(nameof(IsMachineConnectedViaTCP)); if (_connectedMachine != null) { _connectedMachine.StateChanged -= ConnectedMachine_StateChanged; _connectedMachine.StateChanged += ConnectedMachine_StateChanged; } ConnectedMachineChanged?.Invoke(this, _connectedMachine); } } } /// <summary> /// Gets a value indicating whether the <see cref="P:Tango.MachineStudio.Common.StudioApplication.IStudioApplicationManager.ConnectedMachine" /> is valid and connected through TCP/IP. /// </summary> public bool IsMachineConnectedViaTCP { get { return IsMachineConnected && ConnectedMachine is ExternalBridgeTcpClient; } } /// <summary> /// Handles the <see cref="ConnectedMachine"/> state changed event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void ConnectedMachine_StateChanged(object sender, Transport.TransportComponentState e) { if (e == Transport.TransportComponentState.Disconnected || e == Transport.TransportComponentState.Failed) { ConnectedMachine = null; if (e == Transport.TransportComponentState.Failed) { String failed_reason = (sender as IMachineOperator).FailedStateException.Message; if (!_isDialogShown) { _isDialogShown = true; ConnectionLostViewVM vm = new ConnectionLostViewVM() { Exception = failed_reason, AutoReconnect = true, }; InvokeUI(() => { _notification.ShowModalDialog<ConnectionLostViewVM, ConnectionLostView>(vm, (x) => { _isDialogShown = false; ReconnectionRequired?.Invoke(this, new EventArgs()); }, () => { _isDialogShown = false; }); }); } } } } /// <summary> /// Gets a value indicating whether the <see cref="P:Tango.MachineStudio.Common.StudioApplication.IStudioApplicationManager.ConnectedMachine" /> is valid. /// </summary> public bool IsMachineConnected { get { return ConnectedMachine != null; } } /// <summary> /// Gets the machine studio application version. /// </summary> public Version Version { get { return AssemblyHelper.GetCurrentAssemblyVersion(); } } /// <summary> /// Shutdown the application. /// </summary> public async void ShutDown() { if (IsShuttingDown) return; IsShuttingDown = true; try { Rect r = new Rect( MainWindow.Instance.Left, MainWindow.Instance.Top, MainWindow.Instance.Width, MainWindow.Instance.Height); await Task.Factory.StartNew(async () => { try { //Do Shutdown Procedures... foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<IStudioViewModel>()) { try { var result = await vm.OnShutdownRequest(); if (!result) { IsShuttingDown = false; return; } } catch (Exception ex) { LogManager.Log(ex, "Error on shutdown request with " + vm.GetType().Name); } } foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<IStudioViewModel>()) { vm.OnShuttingDown(); } var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>(); settings.LastBounds = r; settings.StudioModulesBounds.Clear(); foreach (var window in _openedWindows.OfType<Windows.ModuleWindow>()) { window.Invoke(() => { var context = window.ModuleContext; if (context != null) { settings.StudioModulesBounds.Add(new MachineStudioSettings.StudioModuleBounds() { Bounds = window.RestoreBounds, State = window.WindowState, Name = context.Module.Name, }); } }); } var mainViewVM = TangoIOC.Default.GetInstance<MainViewVM>(); settings.LastMainModuleName = mainViewVM.CurrentModule != null ? mainViewVM.CurrentModule.Name : null; try { SettingsManager.Default.Save(); } catch (Exception ex) { LogManager.Log(ex, "Error saving settings."); } await _navigationManager.NavigateTo(NavigationView.ShutdownView); Thread.Sleep(1500); foreach (var window in _openedWindows) { ThreadsHelper.InvokeUI(() => { window.Close(); }); } try { if (ConnectedMachine != null) { ConnectedMachine.Disconnect().Wait(); } } catch (Exception ex) { LogManager.Log(ex, "Error disconnecting from machine."); } var eventLogger = TangoIOC.Default.GetInstance<IEventLogger>(); if (eventLogger != null) { //eventLogger.Log(EventTypes.APPLICATION_TERMINATED, "Application Terminated!"); eventLogger.FlushAll(); } Thread.Sleep(1500); Environment.Exit(0); } catch { Environment.Exit(0); } }); } catch (Exception ex) { IsShuttingDown = false; LogManager.Log(ex, "An error occurred while shutting down machine studio."); } } /// <summary> /// Notify the application manager about an external opened window. /// When application exists. All registered windows will be closed. /// </summary> /// <param name="window">The window.</param> public void RegisterOpenedWindow(Window window) { _openedWindows.Add(window); window.Closed += (x, y) => { _openedWindows.Remove(window); }; } public bool IsModuleInNewWindow(IStudioModule module) { return _openedWindows.Exists(x => (x as ModuleWindow).ModuleContext.Module == module); } /// <summary> /// Gets the core libraries version. /// </summary> public Version CoreVersion { get { return typeof(ExtendedObject).Assembly.GetName().Version; } } /// <summary> /// Gets the build date. /// </summary> public string BuildDate { get { return AssemblyHelper.GetCurrentAssemblyBuildDate().ToShortDateString(); } } /// <summary> /// Gets the change log. /// </summary> public string ChangeLog { get { return EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.MachineStudio.UI.ChangeLog.txt"); } } /// <summary> /// Raises the application ready event. /// </summary> public void NotifyApplicationReady() { TangoIOC.Default.GetAllInstancesByBase<IStudioViewModel>().ToList().ForEach(x => { if (!_notified_view_models.Contains(x)) { x.OnApplicationReady(); _notified_view_models.Add(x); } }); ApplicationReady?.Invoke(this, new EventArgs()); } /// <summary> /// Sets the connected machine. /// </summary> /// <param name="connectedMachine">The connected machine.</param> public void SetConnectedMachine(IExternalBridgeClient connectedMachine) { if (connectedMachine != null) { Machine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == connectedMachine.SerialNumber); if (Machine == null) { throw new NullReferenceException($"The specified machine '{connectedMachine.SerialNumber}' could not be found on the database."); } //Adjust Dryer Buffer Length Mode ProcessParametersTable.DryerBufferMode = Machine.Type; connectedMachine.SetMachine(Machine); ConnectedMachine = connectedMachine; var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>(); ConnectedMachine.JobUploadStrategy = settings.JobUploadStrategy; settings.LastConnectedMachineType = Machine.MachineType; } else { Machine = null; ConnectedMachine = null; } } } }