示例#1
0
        public AddRule(SirenOfShameSettings settings, Rule rule)
            : this(settings)
        {
            _rule = rule;

            _when.Text = Rule.TriggerTypes[rule.TriggerType];
            SetAlertType(rule.AlertType);
            _inheritAudio.Checked = rule.InheritAudioSettings;
            _turnOnAudio.Checked = !rule.InheritAudioSettings;
            _inheritLightSetting.Checked = rule.InheritLedSettings;
            _turnOnLights.Checked = !rule.InheritLedSettings;
            _lights.SelectedItem = rule.LedPattern;
            _windowsAudio.SelectedItem = _windowsAudio.Items.Cast<AudioFile>().FirstOrDefault(i => i.Location == rule.WindowsAudioLocation);
            _audio.SelectedItem = rule.AudioPattern;
            _lightsDurationTextBox.Text = rule.LightsDuration == null ? "" : rule.LightsDuration.ToString();
            _playLightsUntilBuildPasses.Checked = rule.LightsDuration == null;
            _customAudioDuration.Checked = rule.AudioDuration != null;
            _audioDurationTextBox.Text = rule.AudioDuration == null ? "" : rule.AudioDuration.ToString();
            _customLightsDuration.Checked = rule.LightsDuration != null;
            _playAudioUntilBuildPasses.Checked = rule.AudioDuration == null;
            _whoIsAnyone.Checked = rule.TriggerPerson == null;
            _whoIsCustom.Checked = rule.TriggerPerson != null;
            _who.Text = rule.TriggerPerson;
            if (rule.BuildDefinitionId == null)
            {
                _build.SelectedIndex = 0;
            }
            else
            {
                BuildDefinitionSetting buildDefinitionSetting = _settings.CiEntryPointSettings
                    .SelectMany(i => i.BuildDefinitionSettings)
                    .FirstOrDefault(bds => bds.Id == rule.BuildDefinitionId);
                _build.SelectedItem = buildDefinitionSetting;
            }

            _add.Text = "Update";
            Text = "Update Rule";
        }
示例#2
0
 private ToolStripMenuItem WindowsAudioPatternMenu(AudioFile af, Rule rule, string buildDefinitionId, TriggerType triggerType, string person)
 {
     bool patternIsMatch = false;
     if (rule != null && !string.IsNullOrEmpty(rule.WindowsAudioLocation))
         patternIsMatch = af.Location == rule.WindowsAudioLocation;
     var menu = new ToolStripMenuItem(af.DisplayName)
     {
         Checked = patternIsMatch,
         Tag = new RuleDropDownItemTag
         {
             AlertType = null,
             BuildDefinitionId = buildDefinitionId,
             TriggerPerson = person,
             TriggerType = triggerType,
             LedPattern = null,
             WindowsAudioLocation = af.Location,
             AudioPattern = null,
             Duration = null
         }
     };
     menu.Click += RuleDropDownItemClick;
     return menu;
 }
示例#3
0
        private void RuleDropDownItemClick(object sender, EventArgs e)
        {
            var toolStripSender = (ToolStripItem)sender;
            RuleDropDownItemTag tag = (RuleDropDownItemTag)toolStripSender.Tag;

            if (tag == null)
            {
                Log.Error("User clicked '" + toolStripSender.Text + "' but it had no tag");
                return;
            }

            var rule = Settings.Rules.FirstOrDefault(r =>
                r.TriggerType == tag.TriggerType &&
                r.BuildDefinitionId == tag.BuildDefinitionId &&
                r.TriggerPerson == tag.TriggerPerson
                );

            // find/add
            if (rule == null)
            {
                // base new rules on any generic high level rules
                var baseRule = Settings.Rules.FirstOrDefault(r =>
                                                          r.TriggerType == tag.TriggerType &&
                                                          r.BuildDefinitionId == null && r.TriggerPerson == null);

                rule = new Rule
                {
                    TriggerType = tag.TriggerType,
                    BuildDefinitionId = tag.BuildDefinitionId,
                    TriggerPerson = tag.TriggerPerson,
                };

                if (baseRule != null)
                {
                    rule.InheritAudioSettings = baseRule.InheritAudioSettings;
                    rule.InheritLedSettings = baseRule.InheritLedSettings;
                    rule.AlertType = baseRule.AlertType;
                    rule.LedPattern = baseRule.LedPattern;
                    rule.LightsDuration = baseRule.LightsDuration;
                    rule.WindowsAudioLocation = baseRule.WindowsAudioLocation;
                    rule.AudioPattern = baseRule.AudioPattern;
                    rule.AudioDuration = baseRule.AudioDuration;
                }

                Settings.Rules.Add(rule);
            }

            if (tag.AlertType != null)
            {
                bool uncheckedAlertType = rule.AlertType == tag.AlertType.Value;
                rule.AlertType = uncheckedAlertType ? AlertType.NoAlert : tag.AlertType.Value;
            }

            if (!string.IsNullOrEmpty(tag.WindowsAudioLocation))
            {
                bool uncheckWindowsAudio = tag.WindowsAudioLocation == rule.WindowsAudioLocation;
                rule.WindowsAudioLocation = uncheckWindowsAudio ? null : tag.WindowsAudioLocation;
            }

            if (tag.AudioPattern != null)
            {
                bool uncheckAudioPattern = tag.AudioPattern.Equals(rule.AudioPattern) && tag.Duration == rule.AudioDuration;
                rule.AudioPattern = uncheckAudioPattern ? null : tag.AudioPattern;
                rule.AudioDuration = tag.Duration;
                rule.InheritAudioSettings = rule.AudioPattern == null;
            }

            if (tag.LedPattern != null)
            {
                bool uncheckLedPattern = tag.LedPattern.Equals(rule.LedPattern) && tag.Duration == rule.LightsDuration;
                rule.LedPattern = uncheckLedPattern ? null : tag.LedPattern;
                rule.LightsDuration = tag.Duration;
                rule.InheritLedSettings = rule.LedPattern == null;
            }

            Settings.Save();
        }
示例#4
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;
 }
示例#5
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;
        }
 public void OnStartup_NeverShowWorkingTrayNotifications()
 {
     var rulesEngine = new RulesEngineWrapper();
     Rule rule = new Rule
     {
         TriggerType = TriggerType.SuccessfulBuild,
         AlertType = AlertType.TrayAlert
     };
     rulesEngine.Rules.Add(rule);
     rulesEngine.InvokeStatusChecked(BuildStatusEnum.Working);
     Assert.AreEqual(0, rulesEngine.TrayNotificationEvents.Count);
 }
 public void GlobalMuteOnBuildFailsWithWindowsAudioRule_NoAudio()
 {
     var rulesEngine = new RulesEngineWrapper();
     rulesEngine.Settings.Mute = true;
     Rule rule = new Rule
     {
         TriggerType = TriggerType.InitialFailedBuild,
         WindowsAudioLocation = "SirenOfShame.Resources.Sad-Trombone.wav"
     };
     rulesEngine.Rules.Add(rule);
     rulesEngine.InvokeStatusChecked(BuildStatusEnum.Working);
     rulesEngine.InvokeStatusChecked(BuildStatusEnum.Broken);
     Assert.AreEqual(0, rulesEngine.PlayWindowsAudioEvents.Count);
 }
 public void BuildInitiallyIsPassing_NoWindowsAudio()
 {
     var rulesEngine = new RulesEngineWrapper();
     Rule rule = new Rule
     {
         TriggerType = TriggerType.SuccessfulBuild,
         WindowsAudioLocation = "SirenOfShame.Resources.Sad-Trombone.wav"
     };
     rulesEngine.Rules.Add(rule);
     rulesEngine.InvokeStatusChecked(BuildStatusEnum.Working);
     Assert.AreEqual(0, rulesEngine.PlayWindowsAudioEvents.Count);
 }