Ejemplo n.º 1
0
    public RegularTimer(TimerManager manager, float start, float end, RunTimer TimerDelegate)
    {
        //
        started = false;

        //
        startTime        = start;
        endTime          = end;
        initialStartTime = start;

        //
        TimerCount = TimerDelegate;

        // Ensure manager exists!
        if (manager == null)
        {
            if (managerReference == null)
            {
                GameObject timerManager = GameObject.Instantiate(new GameObject());
                timerManager.name = "TimerManager";
                timerManager.AddComponent <TimerManager>();
                managerReference = timerManager.GetComponent <TimerManager>();
            }
        }
        else
        {
            managerReference = manager;
        }


        //
        AddTimer();
    }
Ejemplo n.º 2
0
        public void CheckIfThereIsTimeLeft()
        {
            RunTimer RunWithTimer = new RunTimer(0);

            Thread.Sleep(1);
            Assert.AreEqual(RunWithTimer.IsTimeLeft, false);
        }
Ejemplo n.º 3
0
 private void RunTimer_Tick(object sender, EventArgs e)
 {
     RunTimer.Stop();
     loaded++;
     UpdateStats();
     LoadFile(FileToolStripStatusLabel.Text);
 }
Ejemplo n.º 4
0
 public void OnCompleted()
 {
     this.Invoke(new Action(() =>
     {
         RunTimer.Stop();
         MessageBox.Show($"Task completed in {Math.Round(TestSec / 60d, 2)}", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
         btn_Upload.Enabled        = true;
         toolStripStatusLabel.Text = "Done";
     }));
 }
Ejemplo n.º 5
0
 private void Awake()
 {
     if (Instance)
     {
         DestroyImmediate(gameObject);
     }
     else
     {
         Instance = this;
     }
 }
Ejemplo n.º 6
0
 private void CodeFileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
 {
     changed++;
     UpdateStats();
     if (e.ChangeType == WatcherChangeTypes.Changed)
     {
         // Stop current timer.
         RunTimer.Stop();
         // Restart it again.
         RunTimer.Start();
     }
 }
Ejemplo n.º 7
0
 private void btnAutoRun_Click(object sender, EventArgs e)
 {
     if (RunTimer.Enabled)
     {
         RunTimer.Stop();
         btnAutoRun.Text = "Run Auto";
     }
     else
     {
         RunTimer.Start();
         btnAutoRun.Text = "Stop Auto";
     }
 }
Ejemplo n.º 8
0
        public virtual void Update()
        {
            ManageMovement();

            if (IsAffectedByGravityPush)
            {
                float multiplier = 1;
                if (GravityPushPushDurationTimer != null)
                {
                    multiplier = GravityPushPushDurationTimer.Progress;
                    GravityPushPushDurationTimer.Update();
                }

                // Horizontal
                Rectangle futurePositionX = new Rectangle(CollisionBox.X + VelocityX * multiplier, CollisionBox.Y, CollisionBox.Width, CollisionBox.Height);
                ManageHorizontalMovement(futurePositionX);

                // Vertical
                Rectangle futurePositionY = new Rectangle(CollisionBox.X, CollisionBox.Y + VelocityY, CollisionBox.Width, CollisionBox.Height);
                SetCollisionBoxY(futurePositionY.Y);

                // Rotate clockwise in the air
                // Make one full rotation for the duration of the timer
                InclineAngle = 2 * (float)Math.PI * multiplier;

                // Return the state of the unit back to normal after the push is over
                if (GravityPushPushDurationTimer != null && GravityPushPushDurationTimer.Progress == 0)
                {
                    ResetVelocities();
                    IsUnableToMove          = false;
                    IsAffectedByGravityPush = false;
                    IsIdle = true;
                    GravityPushPushDurationTimer = null;
                    InclineAngle = 0;
                }
            }

            // Update timers
            RunTimer.Update();
            JumpTimer.Update();

            LastState = new Midori(this);
        }
Ejemplo n.º 9
0
 private void RunTimer_Tick(object sender, EventArgs e)
 {
     // this timer keeps the mount in position while it is waiting for the satellite to pass
     if (nextAos < DateTime.Now.Add(new TimeSpan(offsetHours, offsetMins, 1)) && nextAos > DateTime.Now.Add(new TimeSpan(offsetHours, offsetMins, -1))) // need to include a tolerence
     {
         sdx = 0;
         ImageTimer.Start();
         RunTimer.Stop();
     }
     else if (nextAos < DateTime.Now.Add(new TimeSpan(offsetHours, offsetMins, 0)))
     {
         RunTimer.Stop();
         lbTargetLocked.Text = "Missed image";
         trackSatellites();
     }
     else
     {
         lbTargetLocked.Text = "Awaiting frame";
         lbTime.Text         = DateTime.Now.Add(new TimeSpan(offsetHours, offsetMins, 0)).ToString();
     }
 }
Ejemplo n.º 10
0
        protected void ManageInput()
        {
            if (!IsUnableToMove)
            {
                IsIdle = true;
            }

            // Interaction
            if (Engine.InputManager.IsKeyDown(Key.F) && !IsUnableToMove)
            {
                if (!IsInteracting)
                {
                    IsMovingLeft  = false;
                    IsMovingRight = false;
                    IsIdle        = true;
                    IsInteracting = true;
                    Interact();
                    return;
                }
                else if (GameContext.Scene.CurrentInteration.Finished)
                {
                    IsInteracting  = false;
                    InteractTarget = null;
                    return;
                }
            }

            if (IsInteracting)
            {
                return;
            }

            // Movement
            if (Engine.InputManager.IsKeyHeld(Key.A) && !IsUnableToMove)
            {
                if (RunTimer.Progress == 0 && !IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoNormal();
                    Sprite.Reset();
                }
                IsMovingLeft  = true;
                IsMovingRight = false;
                IsIdle        = false;
                IsFacingRight = false;
            }
            else
            {
                IsMovingLeft = false;
                if (!IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoInReverse();
                    RunTimer.End();
                }
            }

            if (Engine.InputManager.IsKeyHeld(Key.D) && !IsUnableToMove)
            {
                if (RunTimer.Progress == 0 && !IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoNormal();
                    Sprite.Reset();
                }
                IsMovingRight = true;
                IsMovingLeft  = false;
                IsIdle        = false;
                IsFacingRight = true;
            }
            else
            {
                IsMovingRight = false;
                if (!IsMovingLeft && !IsMovingRight)
                {
                    RunTimer.GoInReverse();
                    RunTimer.End();
                }
            }

            // Jumping
            if (Engine.InputManager.IsKeyHeld(Key.Space) && IsGrounded && !IsUnableToMove)
            {
                IsGrounded = false;
                IsJumping  = true;
                JumpTimer.GoInReverse();
                VelocityY = _jumpVelocity;
            }

            // Gravity Push
            if (Engine.InputManager.IsKeyHeld(Key.G) && IsGrounded && !IsUnableToMove)
            {
                IsIdle              = false;
                IsMovingLeft        = false;
                IsMovingRight       = false;
                IsUnableToMove      = true;
                IsGravityPushActive = true;

                Sprite.Reset();
            }

            // Magic Flow
            if (Engine.InputManager.IsKeyHeld(Key.H) && !IsUnableToMove && !IsMagicFlowActive)
            {
                // Set CurrentMagicFlow
                CurrentMagicFlow = CollisionUtils.RectangleIntesectsWithMagicFlow(CollisionBox.ToRectangle());
                if (CurrentMagicFlow == null)
                {
                    return;
                }

                if (CurrentMagicFlow.TraverseFirstToLast)
                {
                    // If traversing from first to last => start from Point A of the first segment
                    CurrentMagicFlowSegmentIndex = 0;
                    SetCollisionBoxX(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointA.X - (CollisionBox.Width / 2));
                    SetCollisionBoxY(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointA.Y - (CollisionBox.Height / 2));
                }
                else
                {
                    // If traversing from last to first => start from Point B of the last segment
                    CurrentMagicFlowSegmentIndex = CurrentMagicFlow.Segments.Count - 1;
                    SetCollisionBoxX(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointB.X - (CollisionBox.Width / 2));
                    SetCollisionBoxY(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointB.Y - (CollisionBox.Height / 2));
                }

                // TODO: Reset timers
                IsIdle            = false;
                IsMovingLeft      = false;
                IsMovingRight     = false;
                IsJumping         = false; // Reset jump timer
                IsFalling         = false;
                IsUnableToMove    = true;  // ?
                IsMagicFlowActive = true;

                Sprite.Reset();
            }

            // Debug
            // Teleport to X
            if (Engine.InputManager.IsKeyHeld(Key.LeftControl))
            {
                IsGrounded = true;
                IsFalling  = false;
                IsJumping  = false;
                JumpTimer.End();
                SetCollisionBoxY(500);
                SetCollisionBoxX(700);
            }
            else if (Engine.InputManager.IsKeyHeld(Key.RightControl))
            {
                IsGrounded = true;
                IsFalling  = false;
                IsJumping  = false;
                JumpTimer.End();
                SetCollisionBoxY(5100);
                SetCollisionBoxX(550);
            }

            if (Engine.InputManager.IsKeyDown(Key.Q))
            {
                CodeSwitch = !CodeSwitch;
                Console.WriteLine(CodeSwitch);
            }
        }
Ejemplo n.º 11
0
        public ValidationResponse Validate(Connection testConnection, Test test)
        {
            if (test == null)
            {
                return(null);
            }
            _scriptResolver = new ScriptResolverFactory(test).GetScriptResolver();
            if (_scriptResolver == null)
            {
                return(null);
            }
            var scriptValue   = _scriptResolver.GetSqlScript();
            var runLog        = new StringBuilder();
            var resultMessage = new StringBuilder();
            var valResponse   = new ValidationResponse
            {
                RunDateTime = DateTime.Now,
                TestId      = test.Id,
                TestName    = test.Name,
                TestValue   = test.TestValue
            };

            RunTimer.Reset();
            RunTimer.Start();

            try
            {
                using (var dbConnection = (DbConnection)DbConnectionFactory.GetConnection(testConnection))
                {
                    using (
                        var reader = _sqlScriptRunner.RunScript(dbConnection,
                                                                scriptValue))
                    {
                        while (reader.Read())
                        {
                            foreach (var expResult in test.ExpectedResults.Clone())
                            {
                                if (reader[expResult.ResultIndex].IsNullOrDbNull())
                                {
                                    continue;
                                }
                                var actual = reader[expResult.ResultIndex].ToString();
                                runLog.AppendFormat("Comparing results: Expected = {0} \n Response = {1} \n",
                                                    expResult.ExpectedValue, actual);

                                var comparerFactory = new ComparerFactory();
                                var comparer        = comparerFactory.GetComparer(expResult.AssertType.Name);
                                valResponse.IsValid = comparer.Compare(expResult.ExpectedValue, actual);

                                if (valResponse.IsValid)
                                {
                                    resultMessage.Append("Is Valid!");
                                    continue;
                                }
                                resultMessage.AppendFormat("expected: {0} \n but was: {1}",
                                                           expResult.ExpectedValue, actual);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                runLog.AppendFormat("Exception caught: {0}", exception.Message);
                valResponse.IsValid = false;
                resultMessage.AppendFormat("Error occurred while trying to run validation {0}. \n \n {1} : {2}",
                                           scriptValue,
                                           exception.Message,
                                           exception.StackTrace);
            }
            finally
            {
                RunTimer.Stop();
                valResponse.Duration      = (decimal)RunTimer.Elapsed.TotalMilliseconds;
                valResponse.RunLog        = runLog.ToString();
                valResponse.ResultMessage = resultMessage.ToString();
            }
            return(valResponse);
        }
Ejemplo n.º 12
0
        private void trackSatellites()
        {
            // main function
            // does not loop, is run each time a satellite is tracked, or the second photograph is taken
            // this is to allow the timers to run, as well as to easily allow missed passes

            lbTime.Text           = DateTime.Now.Add(new TimeSpan(offsetHours, offsetMins, 0)).ToString();
            objTelescope.Tracking = true;

            if (idx < nTargets)
            {
                if (imagesCaptured == 0)
                {
                    try
                    {
                        findNextTarget();
                        lbTargetLocked.Text = "Slewing";
                        double offsetRa;
                        // this if statement accounts for the overflow of offsetting RA, which cycles through 0 to 24 to 0
                        if (nextRa > offsetHours + 1.0 / 60.0 * offsetMins)
                        {
                            // RA is offset in the opposite direction to time, as we simulate seeing events occuring later, but want to ensure
                            // that they are above the horizon
                            offsetRa = nextRa - offsetHours - 1.0 / 60.0 * offsetMins;
                        }
                        else
                        {
                            offsetRa = 24 - (offsetHours + 1.0 / 60.0 * offsetMins - nextRa);
                        }
                        try
                        {
                            objTelescope.SlewToCoordinates(offsetRa, nextDec);
                            RunTimer.Start();
                            imagesCaptured = 1;
                        }
                        catch
                        {
                        }
                    }
                    catch
                    {
                        lbWarningText.Text = "All satellite passes have finished";
                    }
                }
                else if (imagesCaptured == 1)
                {
                    goToNextImage();
                    lbTargetLocked.Text = "Slewing";
                    double offsetRa;
                    if (nextRa > offsetHours + 1.0 / 60.0 * offsetMins)
                    {
                        offsetRa = nextRa - offsetHours - 1.0 / 60.0 * offsetMins;
                    }
                    else
                    {
                        offsetRa = 24 - (offsetHours + 1.0 / 60.0 * offsetMins - nextRa);
                    }
                    try
                    {
                        objTelescope.SlewToCoordinates(offsetRa, nextDec);
                        RunTimer.Start();
                        imagesCaptured = 0;
                    }
                    catch
                    {
                    }
                }
            }
        }
 public DynamicTimer(TimerManager manager, float start, float end, RunTimer TimerDelegate, GameObject gameObject) : base(manager, start, end, TimerDelegate, gameObject)
 {
 }
 public DynamicTimer(TimerManager manager, float start, float end, RunTimer TimerDelegate) : base(manager, start, end, TimerDelegate)
 {
 }
Ejemplo n.º 15
0
 private void btn_Start_Click(object sender, EventArgs e)
 {
     Start();
     RunTimer.Start();
 }