static void Main() { Logging.Logger("Starting application..."); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += Application_ThreadException; try { // GlobalSwitches.ServerOnline = CanReachServer(); Logging.Logger("Loading attributes..."); AttributeFunctions.PopulateAttributeIndexes(); //Logging.Logger("Caching tables..."); // if (GlobalSwitches.ServerOnline) CacheFunctions.CacheTables(); Logging.Logger("Init Scanning UI..."); var scanUI = new ScanningUI(); Logging.Logger("Init Scanning Controller..."); var scanController = new ScanningController(scanUI); Logging.Logger("Launch UI..."); Application.Run(scanUI); } catch (Exception ex) { Logging.Logger("ERROR: " + ex.ToString()); Console.WriteLine(ex.ToString()); if (ex.InnerException != null) { if (ex.InnerException.Message.Contains("connect")) { OtherFunctions.Message("Cannot connect to server.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "No Connection"); Application.Exit(); } } else { OtherFunctions.Message(ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Stop, "Error"); } } }
private void ChangeDatabase(DatabaseName database) { try { if (currentTransaction == null) { if (!GlobalSwitches.CachedMode & ServerInfo.ServerPinging) { if (database != ServerInfo.CurrentDataBase) { var blah = OtherFunctions.Message("Are you sure? This will close all open forms.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, "Change Database", this); if (blah == DialogResult.Yes) { if (this.OkToCloseChildren()) { this.CloseChildren(); ServerInfo.CurrentDataBase = database; AttributeFunctions.PopulateAttributeIndexes(); RefreshCombos(); SecurityTools.PopulateUserAccess(); InitDBControls(); GlobalSwitches.BuildingCache = true; Task.Run(() => DBCacheFunctions.RefreshLocalDBCache()); ShowTestDBWarning(); SetDatabaseTitleText(); ShowAll(); } } } } else { OtherFunctions.Message("Cannot switch database while Offline or in Cached Mode.", MessageBoxButtons.OK, MessageBoxIcon.Information, "Unavailable", this); } } else { OtherFunctions.Message("There is currently an active transaction. Please commit or rollback before switching databases.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Stop"); } } finally { DatabaseToolCombo.SelectedIndex = (int)ServerInfo.CurrentDataBase; } }
public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += MyApplication_UnhandledException; bool connectionSuccessful = false; bool cacheAvailable = false; try { NetworkInfo.LocalDomainUser = Environment.UserName; ChildFormControl.SplashScreenInstance().Show(); ProcessCommandArgs(); Logging.Logger("Starting AssetManager..."); Status("Checking Server Connection..."); connectionSuccessful = CheckConnection(); ServerInfo.ServerPinging = connectionSuccessful; Status("Checking Cache State..."); cacheAvailable = DBCacheFunctions.CacheUpToDate(connectionSuccessful); // If connected to DB and cache is out-of-date, rebuild it. if (connectionSuccessful && !cacheAvailable) { Status("Building Cache DB..."); Task.Run(() => { DBCacheFunctions.RefreshLocalDBCache(); }).Wait(); } // No DB connection and cache not ready. Don't run. if (!connectionSuccessful & !cacheAvailable) { OtherFunctions.Message("Could not connect to server and the local DB cache is unavailable. The application will now close.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "No Connection"); Application.Exit(); return; } // No DB connection but cache is ready. Prompt and run. else if (!connectionSuccessful & cacheAvailable) { GlobalSwitches.CachedMode = true; OtherFunctions.Message("Could not connect to server. Running from local DB cache.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Cached Mode"); } // Try to populate access groups and user from DB. Status("Checking Access Level..."); SecurityTools.PopulateAccessGroups(); SecurityTools.PopulateUserAccess(); // Make sure the current user is allowed to run the software. if (!SecurityTools.CanAccess(SecurityGroups.CanRun)) { OtherFunctions.Message("You do not have permission to run this software.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Access Denied"); Application.Exit(); return; } Status("Caching Attributes..."); AttributeFunctions.PopulateAttributeIndexes(); Status("Collecting Field Info..."); DBControlExtensions.GetFieldLengths(); Status("Ready!"); Application.Run(new UserInterface.Forms.AssetManagement.MainForm()); } catch (Exception ex) { ErrorHandling.ErrHandle(ex, System.Reflection.MethodBase.GetCurrentMethod()); Application.Exit(); } }