public void PlayLed()
        {
            var seconds = 10;

            ISirenOfShameDevice sos = new SirenOfShameDevice();
            sos.TryConnect();
            var ledPattern = new LedPattern();
            ledPattern.Id = 12;

            var duration = new TimeSpan(0, 0, 0, seconds);
            sos.PlayLightPattern(ledPattern, duration);
        }
        public void FailedBuild()
        {
            var seconds = 30;
            var ledPattern = new LedPattern();
            ledPattern.Id = 56;

            var duration = new TimeSpan(0, 0, 0, seconds);
            if (_device.TryConnect())
            {
                _device.PlayLightPattern(ledPattern, duration);
            }
        }
Example #3
0
 public bool Equals(LedPattern other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.Id == Id && Equals(other.Name, Name));
 }
 public void PlayLightPattern(LedPattern lightPattern, TimeSpan?durationTimeSpan)
 {
     EnsureConnected();
     if (lightPattern == null)
     {
         SendControlPacket(ledMode: 0, ledDuration: 0);
     }
     else
     {
         UInt16 duration = CalculateDurationFromTimeSpan(durationTimeSpan);
         SendControlPacket(ledMode: (byte)lightPattern.Id, ledDuration: duration);
     }
 }
        public void PlayLightPattern(LedPattern lightPattern, TimeSpan?durationTimeSpan)
        {
            EnsureConnected();
            var timespanIsZero = (durationTimeSpan.HasValue && durationTimeSpan.Value.Ticks == 0);

            if (lightPattern == null || timespanIsZero)
            {
                SendControlPacket(ledMode: 0, ledDuration: 0);
            }
            else
            {
                UInt16 duration = CalculateDurationFromTimeSpan(durationTimeSpan);
                SendControlPacket(ledMode: (byte)lightPattern.Id, ledDuration: duration);
            }
        }
Example #6
0
 private void _timer_Tick(object sender, EventArgs e)
 {
     if (CurrentAudioDuration != null)
     {
         _currentAudioDuration = CurrentAudioDuration.Value.Add(new TimeSpan(0, 0, 0, 0, -_timer.Interval));
         if (CurrentAudioDuration.Value.TotalMilliseconds < 0)
         {
             _currentAudioPattern  = null;
             _currentAudioDuration = null;
         }
     }
     if (CurrentLightDuration != null)
     {
         _currentLightDuration = CurrentLightDuration.Value.Add(new TimeSpan(0, 0, 0, 0, -_timer.Interval));
         if (CurrentLightDuration.Value.TotalMilliseconds < 0)
         {
             _currentLightPattern  = null;
             _currentLightDuration = null;
         }
     }
     _audioPattern.Text = CurrentAudioPattern == null ? "None" : CurrentAudioPattern.Name + "(" + CurrentAudioDuration + ")";
     _ledPattern.Text   = CurrentLightPattern == null ? "None" : CurrentLightPattern.Name + "(" + CurrentLightDuration + ")";
 }
Example #7
0
 public void InvokeSetLights(LedPattern ledPattern, int? duration)
 {
     var stopSiren = SetLights;
     if (stopSiren == null) return;
     stopSiren(this, new SetLightsEventArgs { LedPattern = ledPattern, Duration = duration });
 }
Example #8
0
        private IEnumerable<ToolStripMenuItem> GetDurations(Rule rule, LedPattern ledPattern, AudioPattern audioPattern, bool patternIsMatch, string buildDefinitionId, TriggerType triggerType, string person)
        {
            int? duration = null;
            if (rule != null)
                duration = ledPattern == null ? rule.AudioDuration : rule.LightsDuration;

            var durations = _durations.Select(d => new ToolStripMenuItem(d.Value)
            {
                Checked = patternIsMatch && duration == d.Key,
                Tag = new RuleDropDownItemTag
                {
                    AlertType = null,
                    BuildDefinitionId = buildDefinitionId,
                    TriggerPerson = person,
                    TriggerType = triggerType,
                    LedPattern = ledPattern,
                    AudioPattern = audioPattern,
                    Duration = d.Key
                }
            }).ToArray();
            foreach (var toolStripMenuItem in durations)
            {
                toolStripMenuItem.Click += RuleDropDownItemClick;
            }
            return durations;
        }
Example #9
0
 private ToolStripMenuItem LedPatternMenu(LedPattern lp, Rule rule, string buildDefinitionId, TriggerType triggerType, string person)
 {
     bool patternIsMatch = false;
     if (rule != null && !rule.InheritLedSettings && rule.LedPattern != null)
         patternIsMatch = rule.LedPattern.Equals(lp);
     var menu = new ToolStripMenuItem(lp.Name)
     {
         Checked = patternIsMatch
     };
     AddToolStripItems(menu.DropDownItems, GetDurations(rule, lp, null, patternIsMatch, buildDefinitionId, triggerType, person));
     return menu;
 }
Example #10
0
 public bool Equals(LedPattern other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Id == Id && Equals(other.Name, Name);
 }
 public void PlayLightPattern(LedPattern pattern, TimeSpan? duration)
 {
     _dlg.SetLight(pattern, duration);
 }
        public void BuildInitiallyFailsWithGlobalPlayLightsAlert_SetLights()
        {
            var rulesEngine = new RulesEngineWrapper();

            var ledPattern = new LedPattern { Id = 2, Name = "Sally" };
            rulesEngine.Rules.Add(new Rule
            {
                TriggerType = TriggerType.InitialFailedBuild,
                LedPattern = ledPattern,
                LightsDuration = 60,
            });

            rulesEngine.InvokeStatusChecked(BuildStatusEnum.Broken);
            Assert.AreEqual(0, rulesEngine.SetAudioEvents.Count);
            Assert.AreEqual(1, rulesEngine.SetLightsEvents.Count);
            Assert.AreEqual(new TimeSpan(0, 0, 0, 60), rulesEngine.SetLightsEvents[0].TimeSpan);
            Assert.AreEqual(ledPattern, rulesEngine.SetLightsEvents[0].LedPattern);
        }
        public void IsBuildingWithBuildTriggeredRuleToStopOnSuccess_BuildSucceeds_LedsStop()
        {
            var rulesEngine = new RulesEngineWrapper();

            var ledPattern = new LedPattern { Id = 2, Name = "Sally" };
            rulesEngine.Rules.Add(new Rule
            {
                TriggerType = TriggerType.BuildTriggered,
                LedPattern = ledPattern,
                LightsDuration = null,
            });

            Assert.AreEqual(0, rulesEngine.SetLightsEvents.Count);
            rulesEngine.InvokeStatusChecked(BuildStatusEnum.Working);
            Assert.AreEqual(0, rulesEngine.SetLightsEvents.Count);
            rulesEngine.InvokeStatusChecked(BuildStatusEnum.InProgress);
            Assert.AreEqual(1, rulesEngine.SetLightsEvents.Count);
            Assert.AreEqual("Sally", rulesEngine.SetLightsEvents[0].LedPattern.Name);
            rulesEngine.InvokeStatusChecked(BuildStatusEnum.Working);
            Assert.AreEqual(2, rulesEngine.SetLightsEvents.Count);
            Assert.AreEqual(null, rulesEngine.SetLightsEvents[1].LedPattern);
        }
Example #14
0
 public void SetLight(LedPattern pattern, TimeSpan?duration)
 {
     _currentLightPattern  = pattern;
     _currentLightDuration = duration;
 }
        public void BuildInitiallyFailsThenPassesWithGlobalPlayLightsUntilBuildFixedAlert_SetLightsOnThenOff()
        {
            var rulesEngine = new RulesEngineWrapper();

            var ledPattern = new LedPattern { Id = 2, Name = "Real Fast" };
            rulesEngine.Rules.Add(new Rule
            {
                TriggerType = TriggerType.InitialFailedBuild,
                LedPattern = ledPattern,
                LightsDuration = null,
                // until the build passes
            });

            rulesEngine.InvokeStatusChecked(BuildStatusEnum.Broken);

            Assert.AreEqual(1, rulesEngine.SetLightsEvents.Count);
            Assert.AreEqual(null, rulesEngine.SetLightsEvents[0].TimeSpan);
            Assert.AreEqual(ledPattern, rulesEngine.SetLightsEvents[0].LedPattern);

            rulesEngine.InvokeStatusChecked(BuildStatusEnum.Working);
            Assert.AreEqual(2, rulesEngine.SetLightsEvents.Count);
            Assert.AreEqual(null, rulesEngine.SetLightsEvents[1].LedPattern);
        }
 public void PlayLightPattern(LedPattern lightPattern, TimeSpan? durationTimeSpan)
 {
     EnsureConnected();
     if (lightPattern == null)
     {
         SendControlPacket(ledMode: 0, ledDuration: 0);
     }
     else
     {
         UInt16 duration = CalculateDurationFromTimeSpan(durationTimeSpan);
         SendControlPacket(ledMode: (byte)lightPattern.Id, ledDuration: duration);
     }
 }
 public void SetLight(LedPattern pattern, TimeSpan? duration)
 {
     _currentLightPattern = pattern;
     _currentLightDuration = duration;
 }
 private void _timer_Tick(object sender, EventArgs e)
 {
     if (CurrentAudioDuration != null)
     {
         _currentAudioDuration = CurrentAudioDuration.Value.Add(new TimeSpan(0, 0, 0, 0, -_timer.Interval));
         if (CurrentAudioDuration.Value.TotalMilliseconds < 0)
         {
             _currentAudioPattern = null;
             _currentAudioDuration = null;
         }
     }
     if (CurrentLightDuration != null)
     {
         _currentLightDuration = CurrentLightDuration.Value.Add(new TimeSpan(0, 0, 0, 0, -_timer.Interval));
         if (CurrentLightDuration.Value.TotalMilliseconds < 0)
         {
             _currentLightPattern = null;
             _currentLightDuration = null;
         }
     }
     _audioPattern.Text = CurrentAudioPattern == null ? "None" : CurrentAudioPattern.Name + "(" + CurrentAudioDuration + ")";
     _ledPattern.Text = CurrentLightPattern == null ? "None" : CurrentLightPattern.Name + "(" + CurrentLightDuration + ")";
 }
 public void PlayLightPattern(LedPattern lightPattern, TimeSpan? durationTimeSpan)
 {
     EnsureConnected();
     var timespanIsZero = (durationTimeSpan.HasValue && durationTimeSpan.Value.Ticks == 0);
     if (lightPattern == null || timespanIsZero)
     {
         SendControlPacket(ledMode: 0, ledDuration: 0);
     }
     else
     {
         UInt16 duration = CalculateDurationFromTimeSpan(durationTimeSpan);
         SendControlPacket(ledMode: (byte)lightPattern.Id, ledDuration: duration);
     }
 }
 public void PlayLightPattern(LedPattern pattern, TimeSpan?duration)
 {
     _dlg.SetLight(pattern, duration);
 }