Example #1
0
        public void CallSequentialAsyncTest()
        {
            bool?t1Called = false; int d1 = 1000;
            bool?t2Called = false; int d2 = 2000;
            bool?t3Called = false; int d3 = 1000;

            Stopwatch sw     = Stopwatch.StartNew();
            var       result = ActionTools.CallSequentialAsync(
                () => { Task.Delay(d1).Wait(); t1Called = true; },
                () => { Task.Delay(d2).Wait(); t2Called = true; },
                () => { Task.Delay(d3).Wait(); t3Called = true; }
                );

            Assert.IsTrue(sw.ElapsedMilliseconds < TestTimingTolerance);
            Thread.Sleep(d1 + d2 + d3 + TestTimingTolerance);

            Assert.IsTrue(result.IsCompleted);
            Assert.IsTrue(t1Called.Value);
            Assert.IsTrue(t2Called.Value);
            Assert.IsTrue(t3Called.Value);

            var elapsed = sw.ElapsedMilliseconds;

            Assert.IsTrue(Math.Abs(result.Result - elapsed) < 2 * TestTimingTolerance);
        }
Example #2
0
 void Start()
 {
     OpenPort();
     m_Command         = new SystemCommandOfSerialPort();
     dataReceiveThread = new Thread(new ThreadStart(DataReceiveFunction));
     dataReceiveThread.Start();
     ActionTools.AddListener <object>(MyEventName.test1, WriteObj);
 }
 /// <summary>
 /// SQL Server takes awhile to recover to a usable state after restoring.  Wait until it is.
 /// </summary>
 public static void WaitForDatabaseRecovery(Database database)
 {
     if (database is NoDatabase)
     {
         return;
     }
     StatusStatics.SetStatus("Waiting for database to be ready...");
     ActionTools.Retry(() => database.GetLineMarker(), "Database failed to be ready.");
     StatusStatics.SetStatus("Database is ready.");
 }
Example #4
0
        public void CallParallelThreadSafeTest()
        {
            int?      sum      = 0;
            Stopwatch sw       = Stopwatch.StartNew();
            long      duration = ActionTools.CallParallelThreadSafe(100,
                                                                    () => { sum += 2; Task.Delay(10).Wait(); },
                                                                    () => { sum -= 1; Task.Delay(10).Wait(); }
                                                                    );

            var elapsed = sw.ElapsedMilliseconds;

            Assert.AreEqual(100, sum);
            Assert.IsTrue(Math.Abs(duration - elapsed) < TestTimingTolerance);
        }
        public void CallParallelThreadSafeAsyncTest()
        {
            Assert.Inconclusive();
            int?      sum    = 0;
            Stopwatch sw     = Stopwatch.StartNew();
            var       result = ActionTools.CallParallelThreadSafeAsync(100,
                                                                       () => { sum += 2; Task.Delay(10).Wait(); },
                                                                       () => { sum -= 1; Task.Delay(10).Wait(); }
                                                                       );

            Assert.IsTrue(sw.ElapsedMilliseconds < TestTimingTolerance);

            result.Wait();
            var elapsed = sw.ElapsedMilliseconds;

            Assert.IsTrue(Math.Abs(result.Result - elapsed) < TestTimingTolerance);
            Assert.AreEqual(100, sum);
        }
Example #6
0
        public void CallParallelTest()
        {
            bool?t1Called = false; int d1 = 1000;
            bool?t2Called = false; int d2 = 2000;
            bool?t3Called = false; int d3 = 1000;

            Stopwatch sw       = Stopwatch.StartNew();
            long      duration = ActionTools.CallParallel(
                () => { Task.Delay(d1).Wait(); t1Called = true; },
                () => { Task.Delay(d2).Wait(); t2Called = true; },
                () => { Task.Delay(d3).Wait(); t3Called = true; }
                );

            var elapsed = sw.ElapsedMilliseconds;

            Assert.IsTrue(t1Called.Value);
            Assert.IsTrue(t2Called.Value);
            Assert.IsTrue(t3Called.Value);

            Assert.IsTrue(elapsed - Math.Max(d3, Math.Max(d1, d2)) < TestTimingTolerance);
            Assert.IsTrue(Math.Abs(duration - elapsed) < TestTimingTolerance);
        }
Example #7
0
        void Database.ShrinkAfterPostUpdateDataCommands()
        {
            // Give SQL Server a chance to clean up ghost records that may have been generated by post update data commands.
            // To determine how long this takes for a specified database, repeatedly refresh the Disk Usage by Table report while the ISU is running and watch the
            // Data(KB) column values drop for your LOB tables after the post update data commands have executed.
            StatusStatics.SetStatus("Waiting for ghost record cleanup.");
            Thread.Sleep(TimeSpan.FromMinutes(5));

            ExecuteDbMethod(
                cn => {
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET AUTO_UPDATE_STATISTICS_ASYNC OFF".FormatWith(info.Database));
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE".FormatWith(info.Database));
                ActionTools.Retry(
                    () => {
                    // This sometimes fails with "A severe error occurred on the current command."
                    executeLongRunningCommand(cn, "DBCC SHRINKDATABASE( {0}, 10 )".FormatWith(info.Database));
                },
                    "Failed to shrink database.",
                    maxAttempts: 10,
                    retryIntervalMs: 30000);
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET MULTI_USER".FormatWith(info.Database));
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET AUTO_UPDATE_STATISTICS_ASYNC ON".FormatWith(info.Database));
            });
        }
        public void CallParallelAsyncTest()
        {
            Assert.Inconclusive();
            bool?t1Called = false; int d1 = 1000;
            bool?t2Called = false; int d2 = 2000;
            bool?t3Called = false; int d3 = 1000;

            Stopwatch sw     = Stopwatch.StartNew();
            var       result = ActionTools.CallParallelAsync(
                () => { Task.Delay(d1).Wait(); t1Called = true; },
                () => { Task.Delay(d2).Wait(); t2Called = true; },
                () => { Task.Delay(d3).Wait(); t3Called = true; }
                );

            Assert.IsTrue(sw.ElapsedMilliseconds < TestTimingTolerance);

            Thread.Sleep(Math.Max(d3, Math.Max(d1, d2)) + TestTimingTolerance);

            Assert.IsTrue(result.IsCompleted);
            Assert.IsTrue(t1Called.Value);
            Assert.IsTrue(t2Called.Value);
            Assert.IsTrue(t3Called.Value);
            Assert.IsTrue(Math.Abs(result.Result - sw.ElapsedMilliseconds) < 2 * TestTimingTolerance);
        }
Example #9
0
    /// <summary>
    /// Processes the command key.
    /// </summary>
    /// <seealso cref="M:System.Windows.Forms.Form.ProcessCmdKey(Message@,Keys)"/>
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (Globals.IsReady)
        {
            switch (keyData)
            {
            // Top menu system
            case Keys.Alt | Keys.S:
                ActionSettings.ShowDropDown();
                return(true);

            case Keys.Alt | Keys.I:
                ActionInformation.ShowDropDown();
                return(true);

            case Keys.F9:
                ActionPreferences.PerformClick();
                return(true);

            case Keys.Alt | Keys.Control | Keys.F4:
                ActionExit.PerformClick();
                return(true);

            case Keys.Escape:
                if (!EditESCtoExit.Checked || EditMeanings.IsCurrentCellInEditMode)
                {
                    break;
                }
                ActionExit.PerformClick();
                return(true);

            // Rotate view
            case Keys.Control | Keys.Shift | Keys.Tab:
                if (Globals.AllowClose)
                {
                    SetView(Settings.CurrentView.Previous(ViewMode.Notebook));// TODO notebook remove when ready
                }
                return(true);

            case Keys.Control | Keys.Tab:
                if (Globals.AllowClose)
                {
                    SetView(Settings.CurrentView.Next(ViewMode.Notebook));// TODO notebook remove when ready
                }
                return(true);

            // Change view
            case Keys.F1:
                ActionViewAnalysis.PerformClick();
                return(true);

            case Keys.F2:
                ActionViewLetters.PerformClick();
                return(true);

            case Keys.F3:
                if (!Globals.IsDebugExecutable)
                {
                    break;                         // TODO remove when ready
                }
                ActionViewNotebook.PerformClick();
                return(true);

            // Application functions
            case Keys.F5:
            case Keys.Control | Keys.F:
                ActionSearchTerm.PerformClick();
                return(true);

            case Keys.Control | Keys.N:
                ActionNewInstance.PerformClick();
                return(true);

            // Top menu system
            case Keys.Alt | Keys.T:
                ActionTools.ShowDropDown();
                return(true);

            case Keys.Alt | Keys.L:
                if (ActionWebLinks.Enabled)
                {
                    ActionWebLinks.ShowDropDown();
                }
                return(true);

            // Data edition
            case Keys.Control | Keys.S:
                ActionSave.PerformClick();
                return(true);

            case Keys.Control | Keys.Back:
                ActionUndo.Focus();
                ActionUndo.PerformClick();
                return(true);
            }
        }
        // Letters navigation
        if (Globals.AllowClose && Settings.CurrentView == ViewMode.Letters)
        {
            switch (keyData)
            {
            case Keys.Control | Keys.Home:
                LettersNavigator.ActionFirst.PerformClick();
                return(true);

            case Keys.Control | Keys.End:
                LettersNavigator.ActionLast.PerformClick();
                return(true);

            case Keys.Control | Keys.PageUp:
                LettersNavigator.ActionPrevious.PerformClick();
                return(true);

            case Keys.Control | Keys.PageDown:
                LettersNavigator.ActionNext.PerformClick();
                return(true);
            }
        }
        return(base.ProcessCmdKey(ref msg, keyData));
    }