示例#1
0
        public void UpdatedValueShouldBeUsedOverEvaluator()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();

            int evaluatorCalled = 0;

            double Evaluator() => ++ evaluatorCalled;

            var c = new Gauge(transport.Object, telemetry.Object, timer, MetricName, Evaluator, Tags);

            c.Update(5.0);

            timer.TriggerElapsed();
            Assert.AreEqual(0, evaluatorCalled);
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(1));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(1));

            c.Update(6.0);

            timer.TriggerElapsed();
            Assert.AreEqual(0, evaluatorCalled);
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(2));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(2));
        }
        public BossSummonerAiBehaviour(CharacterInstance character)
        {
            base.Character            = character;
            this.m_parameters         = ParseParameters(character.Character.BossAiParameters);
            this.m_skillData          = ConfigSkills.BOSS_SUMMONER_SKILLS[this.m_parameters.SkillType];
            this.m_targetingBehaviour = new MonsterTargetingAiBehaviour(character);
            switch (character.Character.CoreAiBehaviour)
            {
            case AiBehaviourType.MonsterRanged:
                this.m_attackBehaviour = new PursuitAndRangedAttackAiBehaviour(character);
                break;

            case AiBehaviourType.MonsterRangedToMelee:
                this.m_attackBehaviour = new PursuitAndRangedMeleeAttackAiBehaviour(character);
                break;

            case AiBehaviourType.MonsterPuffer:
                this.m_attackBehaviour = new StationarySkillUseAiBehaviour(character, SkillType.PoisonPuff);
                break;

            default:
                this.m_attackBehaviour = new PursuitAndMeleeAttackAiBehaviour(character);
                break;
            }
            if (this.m_skillData.AiTriggerType == TriggerType.TimeInterval)
            {
                this.m_timer = new ManualTimer(this.m_skillData.AiTriggerModifier);
            }
        }
示例#3
0
        public static MPProtectedChannel GetChannel(string channelName, int waitTime)
        {
            if (MPChannelSettings.Find(channelName) == null)
            {
                return(null);
            }

            if (waitTime <= 0)
            {
                waitTime = 20 * 1000;
            }
            ManualTimer        timer = new ManualTimer(waitTime);
            MPProtectedChannel pc    = GetChannel(channelName, true);

            while (!timer.Timeout)
            {
                if (pc != null)
                {
                    return(pc);
                }
                pc = GetChannel(channelName, false);
                System.Threading.Thread.Sleep(200);
            }
            MPChannels.Log(string.Format("Cannot open channel to {0}", channelName));
            return(null);
        }
示例#4
0
        public void SetShouldSendOneMetricByUniqueValue()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();
            var s         = new Set(transport.Object, telemetry.Object, timer, MetricName, null);

            s.Add(5);
            s.Add(6);
            s.Add(7);
            s.Add(5);
            s.Add(7);
            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(3));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(3));

            s.Add(5);
            s.Add(6);
            s.Add(7);
            s.Add(8);
            s.Add(5);
            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(7));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(7));
        }
示例#5
0
        void _setup()
        {
            client = new TcpClient(GetHostName(settings.Address), GetPort(settings.Address));

            MPChannels.Log(string.Format("*** Channel {0} connected {1}->{2}",
                                         Id, client.Client.LocalEndPoint, client.Client.RemoteEndPoint));

            client.SendTimeout    = SendByteTimeout;
            client.ReceiveTimeout = ReceiveByteTimeout;

            channelStreamReader = new BinaryReader(client.GetStream());
            channelStreamWriter = new BinaryWriter(client.GetStream());
            alg     = TripleDES.Create();
            alg.Key = Encoding.ASCII.GetBytes(settings.KeyForSend);

            packetBodyStreamReader = new BinaryReader(packetBodyStream);
            packetBodyStreamWriter = new BinaryWriter(packetBodyStream);

            channelStreamWriter.Write("PCh"); // Just HeaderId
            channelStreamWriter.Write("");    // Settings
            channelStreamWriter.Write(settings.NameForConnect);
            channelStreamReader.ReadString(); // OK

            stopTimer     = new ManualTimer(NotUsedTimeout);
            idleSendTimer = new ManualTimer(SendIdleTimeout);

            state = State.Connected;
        }
示例#6
0
 public static void StopAllTimers()
 {
     if (ACHTimer != null)
     {
         ACHTimer.Stop();
     }
     if (AutoCloseSelectorTimer != null)
     {
         AutoCloseSelectorTimer.Stop();
     }
     if (ManualTimer != null)
     {
         ManualTimer.Stop();
     }
     if (MSRTimer != null)
     {
         MSRTimer.Stop();
     }
     if (ServiceCallerTimer != null)
     {
         ServiceCallerTimer.Stop();
     }
     if (SignatureTimer != null)
     {
         SignatureTimer.Stop();
     }
     if (TransactionTimer != null)
     {
         TransactionTimer.Stop();
     }
 }
示例#7
0
 public void Constructor_Test()
 {
     IXamarinWrapper xamarinWrapper = new XamarinWrapperStub();
     IFileHelper     fileHelper     = new FileHelperStub();
     ManualTimer     manualTimer    = new ManualTimer();
     ResultsService  resultsService = new ResultsService(xamarinWrapper, fileHelper);
     GameService     gameService    = new GameService(xamarinWrapper, fileHelper, manualTimer, resultsService);
 }
示例#8
0
        public void UpdateShouldThrowIfValueIsNaN()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();

            var c = new Gauge(transport.Object, telemetry.Object, timer, MetricName, null, Tags);

            Assert.Throws <ArgumentException>(() => c.Update(double.NaN));
        }
示例#9
0
        public void EvaluatorShouldBeCalledOnDispose()
        {
            var transport       = new Mock <ITransport>();
            var telemetry       = new Mock <ITelemetry>();
            var timer           = new ManualTimer();
            int evaluatorCalled = 0;
            var c = new Gauge(transport.Object, telemetry.Object, timer, MetricName, () => evaluatorCalled++, Tags);

            c.Dispose();
            Assert.AreEqual(1, evaluatorCalled);
        }
示例#10
0
        public void SetShouldFlushOnDispose()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();
            var s         = new Set(transport.Object, telemetry.Object, timer, MetricName, null);

            s.Add(0);
            s.Dispose();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(1));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(1));
        }
示例#11
0
        public void CountShouldFlushOnDispose()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();
            var c         = new Count(transport.Object, telemetry.Object, timer, MetricName, Tags);

            c.Increment();
            c.Dispose();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(1));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(1));
        }
示例#12
0
        private static GameViewModel CreateGameViewModel(ManualTimer manualTimer = null)
        {
            IXamarinWrapper xamarinWrapper = new XamarinWrapperStub();
            IFileHelper     fileHelper     = new FileHelperStub(0);

            manualTimer = manualTimer ?? new ManualTimer();
            ResultsService resultsService = new ResultsService(xamarinWrapper, fileHelper);
            GameService    gameService    = new GameService(xamarinWrapper, fileHelper, manualTimer, resultsService);

            GameViewModel gameViewModel = new GameViewModel(xamarinWrapper, gameService);

            return(gameViewModel);
        }
示例#13
0
        public void NothingShouldBeSentIfEvaluatorThrowsAndNoValueWasUpdated()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();

            double Evaluator() => throw new Exception();

            var c = new Gauge(transport.Object, telemetry.Object, timer, MetricName, Evaluator, Tags);

            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(0));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(0));
        }
示例#14
0
        public void CountShouldntBeFlushedIfDecrementsPlusIncrementsEqualZero()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();
            var c         = new Count(transport.Object, telemetry.Object, timer, MetricName, Tags);

            c.Increment();
            c.Increment(4);
            c.Decrement(5);
            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(0));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(0));
        }
示例#15
0
        public void SetShouldntBeFlushedIfDidntChange()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();
            var s         = new Set(transport.Object, telemetry.Object, timer, MetricName, null);

            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(0));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(0));

            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(0));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(0));
        }
示例#16
0
        public void NothingShouldBeSentIfNoEvaluatorAndNoUpdatedValue()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();

            var c = new Gauge(transport.Object, telemetry.Object, timer, MetricName, null, Tags);

            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(0));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(0));

            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(0));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(0));
        }
示例#17
0
        public void EvaluatorShouldBeCalledForEachTick()
        {
            var transport       = new Mock <ITransport>();
            var telemetry       = new Mock <ITelemetry>();
            var timer           = new ManualTimer();
            int evaluatorCalled = 0;
            var c = new Gauge(transport.Object, telemetry.Object, timer, MetricName, () => evaluatorCalled++, Tags);

            timer.TriggerElapsed();
            Assert.AreEqual(1, evaluatorCalled);
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(1));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(1));

            timer.TriggerElapsed();
            Assert.AreEqual(2, evaluatorCalled);
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(2));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(2));
        }
示例#18
0
        public void UpdatedValueShouldBeUsedWhenNoEvaluator()
        {
            var transport = new Mock <ITransport>();
            var telemetry = new Mock <ITelemetry>();
            var timer     = new ManualTimer();

            var c = new Gauge(transport.Object, telemetry.Object, timer, MetricName, null, Tags);

            c.Update(5.0);

            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(1));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(1));

            c.Update(6.0);

            timer.TriggerElapsed();
            transport.Verify(t => t.Send(It.IsAny <ArraySegment <byte> >()), Times.Exactly(2));
            telemetry.Verify(t => t.MetricSent(), Times.Exactly(2));
        }
示例#19
0
        // external, for separate thread
        // no exception
        public bool SendAndWaitAnswer(string destId, object packet, int timeout)
        {
            if (timeout <= 0)
            {
                timeout = 20 * 1000;
            }
            ManualTimer timer = new ManualTimer(timeout);

            workAnswer  = null;
            workDestId  = destId;
            workRequest = packet;
            while (workAnswer == null && this.IsValid && !timer.Timeout)
            {
                System.Threading.Thread.Sleep(200);
            }
            if (workAnswer != null)
            {
                return(true);
            }
            Close();
            return(false);
        }
示例#20
0
        public void Tests()
        {
            ManualTimer manualTimer = new ManualTimer();

            int fireCount = 0;

            // Can't start without an action.
            Assert.Throws <InvalidOperationException>(() => manualTimer.Start());

            // Can't fire without an action.
            Assert.Throws <InvalidOperationException>(() => manualTimer.Fire());

            // Can't set an empty action.
            Assert.Throws <ArgumentNullException>(() => manualTimer.SetAction(null));

            manualTimer.SetAction(() => fireCount++);

            // Can't set action twice.
            Assert.Throws <InvalidOperationException>(() => manualTimer.SetAction(() => fireCount++));

            // Can't fire before starting.
            Assert.Throws <InvalidOperationException>(() => manualTimer.Fire());

            manualTimer.Start();

            Assert.AreEqual(0, fireCount);
            manualTimer.Fire();
            Assert.AreEqual(1, fireCount);

            // Can't fire again before re-starting.
            Assert.Throws <InvalidOperationException>(() => manualTimer.Fire());

            manualTimer.Start();

            Assert.AreEqual(1, fireCount);
            manualTimer.Fire();
            Assert.AreEqual(2, fireCount);
        }
 public StationarySkillUseAiBehaviour(CharacterInstance character, GameLogic.SkillType skillType)
 {
     base.Character    = character;
     this.SkillType    = skillType;
     this.m_skillTimer = new ManualTimer(1f / base.Character.AttacksPerSecond(false));
 }
示例#22
0
        public void PlayTest()
        {
            ManualTimer manualTimer = new ManualTimer();

            using (GameViewModel gameViewModel = CreateGameViewModel(manualTimer))
            {
                Assert.IsTrue(gameViewModel.StartCommand.CanExecute(null));
                Assert.IsFalse(gameViewModel.HitCommand.CanExecute(null));
                Assert.IsTrue(gameViewModel.OverlayIsVisible);

                // Should not be able to Hit if a game is not in progress.
                Assert.Throws <InvalidOperationException>(() => gameViewModel.HitCommand.Execute(0));

                // Start a game.
                gameViewModel.StartCommand.Execute(null);

                // Can't start or hit during countdown.
                Assert.IsFalse(gameViewModel.StartCommand.CanExecute(null));
                Assert.IsFalse(gameViewModel.HitCommand.CanExecute(null));
                Assert.IsTrue(gameViewModel.OverlayIsVisible);

                // Should not be able to Start if a game is already in progress.
                Assert.Throws <InvalidOperationException>(() => gameViewModel.StartCommand.Execute(null));

                // Do countdown.
                for (int i = 0; i < Constants.CountdownSteps - 1; i++)
                {
                    manualTimer.Fire();
                    Assert.IsFalse(gameViewModel.HitCommand.CanExecute(null));
                }

                manualTimer.Fire();
                Assert.IsTrue(gameViewModel.HitCommand.CanExecute(0));
                Assert.IsFalse(gameViewModel.OverlayIsVisible);

                int score = 0;

                for (int i = 0; i < Constants.TargetCount; i++)
                {
                    gameViewModel.HitCommand.Execute(i);
                    Assert.AreNotEqual(score, gameViewModel.Score);
                    score = gameViewModel.Score;
                }

                Assert.Throws <ArgumentOutOfRangeException>(() => gameViewModel.HitCommand.Execute(Constants.TargetCount));

                double timeLeft = gameViewModel.TimeLeft;

                for (int i = 0; i < Constants.PlaySeconds; i++)
                {
                    Thread.Sleep(1000);
                    manualTimer.Fire();
                    Assert.AreNotEqual(timeLeft, gameViewModel.TimeLeft);
                    timeLeft = gameViewModel.TimeLeft;
                }

                Assert.AreEqual(0, timeLeft);

                Assert.IsTrue(gameViewModel.StartCommand.CanExecute(null));
                Assert.IsFalse(gameViewModel.HitCommand.CanExecute(null));
                Assert.IsTrue(gameViewModel.OverlayIsVisible);
            }
        }
示例#23
0
 public static void StartManualTimer()
 {
     ManualTimer.Start();
 }
示例#24
0
 public static void StopManualTimer()
 {
     ManualTimer?.Stop();
 }