summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Views/ConnectionRetryView.cs
blob: 94d0947c55e8ea2949242b46ea5ad87699d2c143 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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);
			}
		}
	}
}