コード例 #1
0
        private async void Watcher()
        {
            while (!disposedValue)
            {
                // Can we talk to the server?
                serverIsOnline = ServerPinging();

                // Is the DB Cache available?
                cacheIsAvailable = DBCacheFunctions.CacheUpToDate(serverIsOnline);

                // Get status based on values of server online and cache mode.
                var status = GetWatchdogStatus();
                if (status != currentWatchdogStatus)
                {
                    currentWatchdogStatus = status;
                    OnStatusChanged(new WatchdogStatusEventArgs(currentWatchdogStatus));
                }

                if (serverIsOnline)
                {
                    //Fire tick event to update server datatime.
                    OnWatcherTick(new WatchdogTickEventArgs(GetServerTime()));
                }

                CheckForCacheRebuild();

                await Task.Delay(watcherInterval);
            }
        }
コード例 #2
0
        private async void WatchdogRebuildCache(object sender, EventArgs e)
        {
            if (GlobalSwitches.BuildingCache)
            {
                return;
            }

            GlobalSwitches.BuildingCache = true;
            try
            {
                SetStatusBar("Rebuilding DB Cache...");
                await Task.Run(() =>
                {
                    DBCacheFunctions.RefreshLocalDBCache();
                });
            }
            catch (Exception ex)
            {
                ErrorHandling.ErrHandle(ex, System.Reflection.MethodBase.GetCurrentMethod());
            }
            finally
            {
                GlobalSwitches.BuildingCache = false;
                DoneWaiting();
            }
        }
コード例 #3
0
 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;
     }
 }
コード例 #4
0
        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();
            }
        }