Exemple #1
0
        private ForeignEnumValue GetEnumDataFromSelectedValue(EnumTranslation translation, TriggerPropertyEntry entry, NotificationTriggerDataTrigger raw, string typedValue)
        {
            //Maybe the typed value has a different value to its raw counterpart. e.g. in German,
            //the typed value might be "Min." while the german value is "Minute"

            ForeignEnumValue enumData = null;

            var rawValue = (string)entry.RawProperty.GetValue(raw);

            if (typedValue != rawValue)
            {
                var rawInput = (string)entry.RawInput.GetValue(raw);

                //e.g. condition "change" on change triggers (which thankfully is always in English) doesn't have rawInput
                if (rawInput != null)
                {
                    var selected = HtmlParser.Default.GetDropDownList(rawInput)
                                   .SelectMany(d => d.Options.Where(o => o.Selected)).First();

                    enumData = translation.Translations.Single(t => t.Value == selected.Value);
                    enumData.ForeignName.Add(typedValue);
                }
            }

            return(enumData);
        }
Exemple #2
0
 private void SetTriggerValue(NotificationTrigger trigger, ForeignEnumValue enumData, TriggerPropertyEntry entry, string typedValue)
 {
     if (enumData != null && enumData.EnglishValue != null && typedValue != enumData.EnglishValue)
     {
         //Channels only really refer to StandardTriggerChannel values applied to non-sensor objects. A Disk IO sensor could
         //have a channel with ID 0 which refers to "Avg Bytes Per Read". As such, instead of updating the value right now,
         //we'll defer to trigger.SetEnumChannel(). SetEnumChannel() won't even be called if the channel name refers to a real
         //channel, so if SetEnumChannel() is called we can safely assume we'll need to use our translated value as our enum value
         if (entry.TypedProperty.Type == typeof(TriggerChannel))
         {
             trigger.translatedChannelName = enumData.EnglishValue;
         }
         else
         {
             entry.TypedRawField.SetValue(trigger, enumData.EnglishValue);
         }
     }
 }