예제 #1
0
 public Notifications(AlertSettingsDto settings)
 {
     Address = settings.Address;
     Alert = settings.Alert;
     Host = settings.EmailHost;
     Password = settings.Password;
     Port = settings.Port;
     Username = settings.Username;
 }
예제 #2
0
 public AlertIntervals(AlertSettingsDto service, AlertTypeDto alertType)
 {
     var item = service.AlertRules.FirstOrDefault(x => x.AlertType == alertType);
     if (item != null)
     {
         var notificationTime = item.ThresholdTime;
         CriticalNotification = TimeSpan.FromSeconds(notificationTime);
     }
 }
예제 #3
0
 public AlertThreshold(AlertSettingsDto service, AlertTypeDto alertType)
 {
     var item = service.AlertRules.FirstOrDefault(x => x.AlertType == alertType);
     if (item != null)
     {
         var critical = item.Percentage;
         CriticalLoad = critical;
     }
 }
예제 #4
0
        static AlertMapperInitialise()
        {
            // View to DTO
            Mapper.AddMap<AlertSettingsViewModel, AlertSettingsDto>(x =>
            {
                //var settings = new AlertSettingsDto
                //{
                //    AlertRules = x.AlertRules
                //        .Select(c => new AlertRulesDto().InjectFrom(c)).Cast<AlertRulesDto>()
                //        .ToList()
                //};

                var settings = new AlertSettingsDto();
                settings.InjectFrom(x);
                foreach (var a in x.AlertRules)
                {
                    var newA = new AlertRulesDto();
                    newA.InjectFrom(a);
                    newA.AlertType = (AlertTypeDto)(int)a.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // DTO to Entity
            Mapper.AddMap<AlertSettingsDto, AlertSettings>(x =>
            {
                //var settings = new AlertSettings
                //{
                //    AlertRules = x.AlertRules
                //        .Select(c => new DataAccessLayer.Models.Settings.AlertRules().InjectFrom(c)).Cast<DataAccessLayer.Models.Settings.AlertRules> ()
                //        .ToList()
                //};

                var settings = new AlertSettings { AlertRules = new List<DataAccessLayer.Models.Settings.AlertRules>()};
                settings.InjectFrom(x);
                foreach (var a in x.AlertRules)
                {
                    var newA = new DataAccessLayer.Models.Settings.AlertRules();
                    newA.InjectFrom(a);
                    newA.AlertType = (DataAccessLayer.Models.Settings.AlertType)(int)a.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // Entity to DTO
            Mapper.AddMap<AlertSettings, AlertSettingsDto>(x =>
            {
                var settings = new AlertSettingsDto { AlertRules = new List<AlertRulesDto>() };
                settings.InjectFrom(x);
                //foreach (var entityAr in x.AlertRules)
                //{
                //    settings.AlertRules.Add((AlertRulesDto)new AlertRulesDto().InjectFrom(entityAr));
                //}
                foreach (var entityAr in x.AlertRules)
                {
                    var newA = new AlertRulesDto();
                    newA.InjectFrom(entityAr);
                    newA.AlertType = (AlertTypeDto)(int)entityAr.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // DTO to View
            Mapper.AddMap<AlertSettingsDto, AlertSettingsViewModel>(x =>
            {
                //var settings = new AlertSettingsViewModel
                //{
                //    AlertRules = x.AlertRules
                //        .Select(c => new AlertRules().InjectFrom(c)).Cast<AlertRules>()
                //        .ToList()
                //};

                var settings = new AlertSettingsViewModel();
                settings.InjectFrom(x);
                foreach (var entityAr in x.AlertRules)
                {
                    var newA = new AlertRules();
                    newA.InjectFrom(entityAr);
                    newA.AlertType = (AlertType)(int)entityAr.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // View to DTO
            Mapper.AddMap<AlertRules, AlertRulesDto>(x =>
            {
                var dto = new AlertRulesDto();
                dto.InjectFrom(x);
                dto.AlertType = (AlertTypeDto)(int)x.AlertType;
                return dto;
            });

            // DTO to Entity
            Mapper.AddMap<AlertRulesDto, DataAccessLayer.Models.Settings.AlertRules>(x =>
            {
                var dto = new DataAccessLayer.Models.Settings.AlertRules();
                dto.InjectFrom(x);
                dto.AlertType = (DataAccessLayer.Models.Settings.AlertType)(int)x.AlertType;
                return dto;
            });

            // Entity to DTO
            Mapper.AddMap<DataAccessLayer.Models.Settings.AlertRules, AlertRulesDto>(x =>
            {
                var dto = new AlertRulesDto();
                dto.InjectFrom(x);
                dto.AlertType = (AlertTypeDto)(int)x.AlertType;
                return dto;
            });

            // DTO to View
            Mapper.AddMap<AlertRulesDto, AlertRules>(x =>
            {
                var dto = new AlertRules();
                dto.InjectFrom(x);
                dto.AlertType = (AlertType)(int)x.AlertType;
                return dto;
            });
        }