#region License // Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved. // This source code is made available under the terms of the GNU Lesser General Public License v3.0 // https://github.com/paulkohler/minisqlquery/blob/master/LICENSE #endregion using System; using System.Threading; using System.Windows.Forms; using MiniSqlQuery.Core; using MiniSqlQuery.Core.DbModel; using MiniSqlQuery.Core.Forms; using MiniSqlQuery.Core.Template; using MiniSqlQuery.PlugIns; using MiniSqlQuery.PlugIns.ConnectionStringsManager; using MiniSqlQuery.PlugIns.DatabaseInspector; using MiniSqlQuery.PlugIns.SearchTools; using MiniSqlQuery.PlugIns.TemplateViewer; using MiniSqlQuery.PlugIns.TextGenerator; using MiniSqlQuery.PlugIns.ViewTable; using MiniSqlQuery.Properties; namespace MiniSqlQuery { /// /// The application entry point. /// internal static class App { /// /// The configure container. /// /// The services. public static void ConfigureContainer(IApplicationServices services) { // singletons services.RegisterSingletonComponent("ApplicationSettings"); services.RegisterSingletonComponent("HostWindow"); services.RegisterSingletonComponent("FileEditorResolver"); // components services.RegisterComponent("AboutForm"); services.RegisterComponent("DefaultTextFindService"); services.RegisterComponent("QueryForm"); services.RegisterComponent("DefaultSqlWriter"); services.RegisterComponent("TextFormatter"); services.RegisterComponent("TemplateModel"); services.RegisterComponent("BatchQuerySelectForm"); } /// /// The application thread exception. /// /// The sender. /// The e. private static void ApplicationThreadException(object sender, ThreadExceptionEventArgs e) { if (!(e.Exception is ThreadAbortException)) { HandleException(e.Exception); } } /// /// The current domain unhandled exception. /// /// The sender. /// The e. private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { if (!(e.ExceptionObject is ThreadAbortException)) { HandleException((Exception)e.ExceptionObject); } } /// /// The handle exception. /// /// The e. private static void HandleException(Exception e) { ErrorForm errorForm = new ErrorForm(); errorForm.SetException(e); errorForm.ShowDialog(); errorForm.Dispose(); } /// /// The main entry point for the application. /// /// The args. [STAThread] private static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException; Application.ThreadException += ApplicationThreadException; #endif Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); IApplicationServices services = ApplicationServices.Instance; ConfigureContainer(services); services.LoadPlugIn(new CoreApplicationPlugIn()); services.LoadPlugIn(new ConnectionStringsManagerLoader()); services.LoadPlugIn(new DatabaseInspectorLoader()); services.LoadPlugIn(new ViewTableLoader()); services.LoadPlugIn(new TemplateViewerLoader()); services.LoadPlugIn(new SearchToolsLoader()); services.LoadPlugIn(new TextGeneratorLoader()); if (services.Settings.LoadExternalPlugins) { var plugins = PlugInUtility.GetInstances(Environment.CurrentDirectory, Settings.Default.PlugInFileFilter); Array.Sort(plugins, new PlugInComparer()); foreach (var plugin in plugins) { services.LoadPlugIn(plugin); } } services.HostWindow.SetArguments(args); Application.Run(services.HostWindow.Instance); } } }