Beispiel #1
0
        public async Task SendMail(ThresholdInfo eventMessage, string templateName = "")
        {
            var messageTemplate = (await _dbTargetRepository.GetTemplate()).Where(x => x.TemplateName == templateName).ToList().FirstOrDefault();

            if (messageTemplate == null)
            {
                return;
            }
            var emailAccount = _mailConfig.Value.EmailAccount;
            var contacts     = await GetContactListByServerId(eventMessage.Id);

            var dto = new ThresholdInfoDto {
                ThresholdInfo = eventMessage, MonitorLog = null
            };
            var message = GetTemplateWithTkn(messageTemplate, dto);

            foreach (var contact in contacts)
            {
                if (!string.IsNullOrEmpty(contact.Email))
                {
                    _emailSender.SendEmail(emailAccount,
                                           message.Subject,
                                           message.Content,
                                           emailAccount.Email, emailAccount.DisplayName,
                                           contact.Email,
                                           contact.Name);
                }
            }
        }
Beispiel #2
0
        private void HandleSpecialBrokenCounter()
        {
            int           healthRatio = (int)((context.Owner.Health / context.Owner.MaxHealth) * 100);
            ThresholdInfo threshold   = context.BreakThresholds.First();

            if (healthRatio < threshold.MinHealth && context.BrokenCounter >= threshold.MinFlinch)
            {
                specialThreshold  = Math.Min(context.BrokenCounter + 1, specialThreshold);
                PartBrokenCounter = $"{context.BrokenCounter}/{specialThreshold}";
            }
            else
            {
                PartBrokenCounter = $"{context.BrokenCounter}";
            }
        }
Beispiel #3
0
        private static ThresholdInfo[] ConvertToThresholdArray(XmlNodeList dataList)
        {
            if (dataList == null)
            {
                return(Array.Empty <ThresholdInfo>());
            }

            List <ThresholdInfo> info = new List <ThresholdInfo>(dataList.Count);

            foreach (XmlNode node in dataList)
            {
                bool          hasConditions = bool.Parse(node.Attributes["HasConditions"]?.Value ?? "False");
                ThresholdInfo dummy         = new ThresholdInfo
                {
                    Threshold     = int.Parse(node.Attributes["Threshold"].Value),
                    HasConditions = hasConditions,
                    MinFlinch     = hasConditions ? int.Parse(node.Attributes["MinFlinch"]?.Value ?? "0") : 0,
                    MinHealth     = hasConditions ? int.Parse(node.Attributes["MinHealth"]?.Value ?? "100") : 100
                };
                info.Add(dummy);
            }
            return(info.ToArray());
        }
Beispiel #4
0
        public void NotifyOnTemperatureChange_ShouldNotNotify(double triggerReading, double threshold, double sensitivityVariance, TemperatureChangeType changeType, ThresholdInfo result)
        {
            // Arrange
            // Set the reading before we request a notfication so it's not the first time
            _thermometer.SetReading(triggerReading);

            // Act
            var actualReading = default(ThresholdInfo);

            _thermometer.NotifyOnTemperatureChange(changeType, "Boiling", threshold, sensitivityVariance, (t) => { actualReading = t; });
            _thermometer.SetReading(triggerReading);

            // Assert
            // Should be null and should not have been called
            Assert.AreEqual(result, actualReading);
        }