diff options
Diffstat (limited to 'Codemerx/Gestor.Application/Views/ConnectionRetryView.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/Views/ConnectionRetryView.cs | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Views/ConnectionRetryView.cs b/Codemerx/Gestor.Application/Views/ConnectionRetryView.cs new file mode 100644 index 0000000..94d0947 --- /dev/null +++ b/Codemerx/Gestor.Application/Views/ConnectionRetryView.cs @@ -0,0 +1,218 @@ +using Gestor.Application;
+using Gestor.Application.Helpers;
+using Gestor.Infrastructure.UnitOfWork.Generic;
+using Gestor.Infrastructure.UnitOfWork.Logic;
+using System;
+using System.CodeDom.Compiler;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Input;
+using System.Windows.Markup;
+using System.Windows.Media;
+using System.Windows.Shapes;
+using System.Windows.Shell;
+
+namespace Gestor.Application.Views
+{
+ public class ConnectionRetryView : Window, IComponentConnector
+ {
+ public TaskCompletionSource<object> CloseTask = new TaskCompletionSource<object>();
+
+ private bool _buttonClickable;
+
+ internal System.Windows.Shell.WindowChrome WindowChrome;
+
+ internal Grid MinimizeButton;
+
+ internal Grid CloseButton;
+
+ internal ProgressBar ProgressRing;
+
+ internal ItemsControl Controls;
+
+ private bool _contentLoaded;
+
+ public UnitOfWork UnitOfWOrk
+ {
+ get;
+ set;
+ }
+
+ public ConnectionRetryView()
+ {
+ this.InitializeComponent();
+ this.MinimizeButton.MouseEnter += new MouseEventHandler(ConnectionRetryView.TopControls_OnMouseEnter);
+ this.MinimizeButton.MouseLeave += new MouseEventHandler(this.TopControls_OnMouseLeave);
+ this.CloseButton.MouseEnter += new MouseEventHandler(ConnectionRetryView.TopControls_OnMouseEnter);
+ this.CloseButton.MouseLeave += new MouseEventHandler(this.TopControls_OnMouseLeave);
+ base.Closed += new EventHandler((object s, EventArgs a) => this.CloseTask.SetResult(null));
+ }
+
+ private void btnRestart_OnClick(object sender, RoutedEventArgs e)
+ {
+ Instancia.App.Restart();
+ }
+
+ private async void btnRetry_Click(object sender, RoutedEventArgs e)
+ {
+ this.Loading(true);
+ UnitOfWork unitOfWork1 = await Task.Run<UnitOfWork>(() => {
+ UnitOfWork unitOfWork;
+ try
+ {
+ Instancia.Conexao = Instancia.Conexao ?? Connection.GetConnection(true);
+ unitOfWork = new UnitOfWork(Instancia.Conexao, true);
+ }
+ catch (Exception exception)
+ {
+ unitOfWork = null;
+ }
+ return unitOfWork;
+ });
+ this.Loading(false);
+ if (unitOfWork1 != null && unitOfWork1.get_HasSession())
+ {
+ this.UnitOfWOrk = unitOfWork1;
+ base.Close();
+ }
+ }
+
+ public void CloseButton_Click()
+ {
+ base.Close();
+ }
+
+ [DebuggerNonUserCode]
+ [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
+ public void InitializeComponent()
+ {
+ if (this._contentLoaded)
+ {
+ return;
+ }
+ this._contentLoaded = true;
+ System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/views/connectionretryview.xaml", UriKind.Relative));
+ }
+
+ private void Loading(bool isLoading)
+ {
+ this.Controls.Visibility = (!isLoading ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed);
+ this.ProgressRing.Visibility = (isLoading ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed);
+ base.IsEnabled = !isLoading;
+ }
+
+ public void MinimizeButton_Click()
+ {
+ base.WindowState = System.Windows.WindowState.Minimized;
+ }
+
+ [DebuggerNonUserCode]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
+ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
+ {
+ switch (connectionId)
+ {
+ case 1:
+ {
+ this.WindowChrome = (System.Windows.Shell.WindowChrome)target;
+ return;
+ }
+ case 2:
+ {
+ this.MinimizeButton = (Grid)target;
+ this.MinimizeButton.MouseLeftButtonDown += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonDown);
+ this.MinimizeButton.MouseLeftButtonUp += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonUp);
+ return;
+ }
+ case 3:
+ {
+ this.CloseButton = (Grid)target;
+ this.CloseButton.MouseLeftButtonDown += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonDown);
+ this.CloseButton.MouseLeftButtonUp += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonUp);
+ return;
+ }
+ case 4:
+ {
+ this.ProgressRing = (ProgressBar)target;
+ return;
+ }
+ case 5:
+ {
+ this.Controls = (ItemsControl)target;
+ return;
+ }
+ case 6:
+ {
+ ((RepeatButton)target).Click += new RoutedEventHandler(this.btnRetry_Click);
+ return;
+ }
+ case 7:
+ {
+ ((RepeatButton)target).Click += new RoutedEventHandler(this.btnRestart_OnClick);
+ return;
+ }
+ }
+ this._contentLoaded = true;
+ }
+
+ private static void TopControls_OnMouseEnter(object sender, MouseEventArgs e)
+ {
+ ((Grid)sender).Background = (((Grid)sender).Name == "CloseButton" ? new SolidColorBrush(Color.FromRgb(232, 17, 35)) : new SolidColorBrush(Colors.Blue));
+ Path child = VisualTreeHelper.GetChild((Grid)sender, 0) as Path;
+ if (child != null)
+ {
+ child.Stroke = new SolidColorBrush(Colors.White);
+ }
+ }
+
+ private void TopControls_OnMouseLeave(object sender, MouseEventArgs e)
+ {
+ this._buttonClickable = false;
+ ((Grid)sender).Background = new SolidColorBrush(Colors.Transparent);
+ Path child = VisualTreeHelper.GetChild((Grid)sender, 0) as Path;
+ if (child != null)
+ {
+ child.Stroke = new SolidColorBrush(Colors.White);
+ }
+ }
+
+ private void TopControls_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ this._buttonClickable = true;
+ if (((Grid)sender).Name != "CloseButton")
+ {
+ ((Grid)sender).Background = new SolidColorBrush(Colors.Blue);
+ }
+ else
+ {
+ ((Grid)sender).Background = new SolidColorBrush(Color.FromRgb(241, 112, 123));
+ Path child = VisualTreeHelper.GetChild((Grid)sender, 0) as Path;
+ if (child != null)
+ {
+ child.Stroke = new SolidColorBrush(Colors.Black);
+ return;
+ }
+ }
+ }
+
+ private void TopControls_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+ {
+ if (this._buttonClickable)
+ {
+ MethodInfo method = base.GetType().GetMethod(string.Concat(((Grid)sender).Name, "_Click"));
+ if (method == null)
+ {
+ return;
+ }
+ method.Invoke(this, null);
+ }
+ }
+ }
+}
\ No newline at end of file |