From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- Codemerx/Gestor.Application/App.cs | 276 +++++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 Codemerx/Gestor.Application/App.cs (limited to 'Codemerx/Gestor.Application/App.cs') diff --git a/Codemerx/Gestor.Application/App.cs b/Codemerx/Gestor.Application/App.cs new file mode 100644 index 0000000..d996857 --- /dev/null +++ b/Codemerx/Gestor.Application/App.cs @@ -0,0 +1,276 @@ +using Agger.Registro; +using Gestor.Application.Helpers; +using Gestor.Application.Views; +using Gestor.Common.Validation; +using Gestor.Infrastructure.UnitOfWork.Logic; +using Gestor.Model.API; +using Gestor.Model.Domain.Common; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; +using MaterialDesignThemes.Wpf; +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Forms; +using System.Windows.Markup; +using System.Windows.Threading; +using Xceed.Wpf.AvalonDock.Controls; + +namespace Gestor.Application +{ + [Serializable] + public class App : System.Windows.Application, IStyleConnector + { + private bool _contentLoaded; + + public static Grid ProgressRing + { + get; + set; + } + + public static Snackbar SnackBar + { + get; + set; + } + + public App() + { + } + + public void Close() + { + System.Windows.Application.Current.Shutdown(); + } + + public void CloseToolTip_Click(object sender, RoutedEventArgs e) + { + System.Windows.Controls.ToolTip toolTip = Extentions.FindVisualAncestor((System.Windows.Controls.Button)sender); + if (toolTip != null) + { + toolTip.IsOpen = false; + } + } + + public Task ConnectionRetry() + { + return base.Dispatcher.Invoke>(async () => { + UnitOfWork unitOfWOrk; + ConnectionRetryView connectionRetryView = ViewHelper.Window(); + if (connectionRetryView == null) + { + ConnectionRetryView connectionRetryView1 = new ConnectionRetryView(); + connectionRetryView1.ShowDialog(); + unitOfWOrk = connectionRetryView1.UnitOfWOrk; + } + else + { + await connectionRetryView.CloseTask.Task; + unitOfWOrk = Instancia.Commited; + } + return unitOfWOrk; + }); + } + + private void DispatcherUnhandled(DispatcherUnhandledExceptionEventArgs exception) + { + this.Registrar(exception.Exception, 1000); + COMException cOMException = exception.Exception as COMException; + if (cOMException != null && cOMException.ErrorCode == -2147221040) + { + exception.Handled = true; + } + Instancia.ExcluirCfg(); + } + + [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/app.xaml", UriKind.Relative)); + } + + [DebuggerNonUserCode] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + [STAThread] + public static void Main() + { + App app = new App(); + app.InitializeComponent(); + app.Run(); + } + + protected override void OnStartup(StartupEventArgs e) + { + string str; + App.SetLanguage(); + this.RegisterLogException(); + Instancia.App = this; + Recursos.Parametros = e.Args.ToList(); + string str1 = Recursos.Parametros.Find((string x) => x.Contains("REGISTRAR_")); + if (str1 != null) + { + str = str1.Replace("REGISTRAR_", ""); + } + else + { + str = null; + } + Recursos.Registrar = str; + if (!string.IsNullOrWhiteSpace(Recursos.Registrar)) + { + Recursos.Parametros.Remove(Recursos.Parametros.Find((string x) => x.Contains("REGISTRAR_"))); + } + if (Recursos.Parametros.Count > 2) + { + ApplicationHelper.Subkey = ((new RegistryHelper(Recursos.Parametros[2])).get_Registrado() ? Recursos.Parametros[2] : string.Empty); + } + Recursos.Host = Dns.GetHostEntry(Dns.GetHostName()); + ApplicationHelper.Conectado = Recursos.Parametros.Contains("CONECTADO"); + if (!Recursos.Parametros.Contains("INICIAR")) + { + return; + } + base.StartupUri = new Uri("pack://application:,,,/Views/LoginWindow.xaml"); + base.OnStartup(e); + } + + private void RegisterLogException() + { + AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((object s, UnhandledExceptionEventArgs exception) => this.Registrar((Exception)exception.ExceptionObject, 1000)); + base.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler((object s, DispatcherUnhandledExceptionEventArgs exception) => this.DispatcherUnhandled(exception)); + TaskScheduler.UnobservedTaskException += new EventHandler((object s, UnobservedTaskExceptionEventArgs exception) => this.Registrar(exception.Exception, 1000)); + } + + private void Registrar(Exception e, TipoErro erro) + { + string nome; + string str; + long id; + string str1; + LogError logError = new LogError(); + logError.set_IdFornecedor(ApplicationHelper.IdFornecedor); + Empresa empresa = Recursos.Empresa; + if (empresa != null) + { + nome = empresa.get_Nome(); + } + else + { + nome = null; + } + logError.set_Fornecedor(nome); + Usuario usuario = Recursos.Usuario; + if (usuario != null) + { + str = usuario.get_Nome(); + } + else + { + str = null; + } + logError.set_UsuarioLogado(str); + Usuario usuario1 = Recursos.Usuario; + if (usuario1 != null) + { + id = usuario1.get_Id(); + } + else + { + id = (long)0; + } + logError.set_IdUsuarioLogado(id); + logError.set_Versao(ApplicationHelper.Versao.ToString()); + logError.set_Data(Funcoes.GetNetworkTime()); + logError.set_IdErro(erro); + logError.set_Erro(Gestor.Common.Validation.ValidationHelper.GetDescription(erro)); + logError.set_HResult(e.HResult); + if (e != null) + { + Exception innerException = e.InnerException; + if (innerException != null) + { + str1 = innerException.ToString(); + } + else + { + str1 = null; + } + } + else + { + str1 = null; + } + logError.set_InnerException(str1); + logError.set_HelpLink(e.HelpLink); + logError.set_Message(e.Message); + logError.set_Source(e.Source); + logError.set_StackTrace(e.StackTrace); + logError.set_Maquina(Environment.MachineName); + logError.set_UsuarioMaquina(Environment.UserName); + Erro.RegistrarErro(logError, true); + } + + public void Restart() + { + System.Windows.Forms.Application.Restart(); + System.Windows.Application.Current.Shutdown(); + } + + private static void SetLanguage() + { + XmlLanguage language = XmlLanguage.GetLanguage(CultureInfo.GetCultureInfo("pt-BR").IetfLanguageTag); + FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(language)); + } + + [DebuggerNonUserCode] + [EditorBrowsable(EditorBrowsableState.Never)] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target) + { + switch (connectionId) + { + case 1: + { + ((System.Windows.Controls.Button)target).Click += new RoutedEventHandler(this.CloseToolTip_Click); + return; + } + case 2: + { + ((System.Windows.Controls.Button)target).Click += new RoutedEventHandler(this.CloseToolTip_Click); + return; + } + case 3: + { + ((System.Windows.Controls.Button)target).Click += new RoutedEventHandler(this.CloseToolTip_Click); + return; + } + case 4: + { + ((System.Windows.Controls.Button)target).Click += new RoutedEventHandler(this.CloseToolTip_Click); + return; + } + default: + { + return; + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3