Exemplo n.º 1
0
        public static string GenerateHtml(InstanceAnomalyReportDto report)
        {
            var html =
                "<!DOCTYPE html><html xmlns = 'http://www.w3.org/1999/xhtml'><head><meta charset = 'utf-8'/><title>Analyze </title></head><body>"
                + "<table width = '100%' style='margin: 20px auto'><tr><td width = '100%' align = 'center' valign = 'middle'><span style = 'font-family: Arial; font-size: 14pt'>Analyze by date - "
                + report.Date +
                "<br/><span><br/></span><div style = 'border-top: 3px solid #22BCE5'></div></span></td></tr> <tr><td><br/><span style='font-family: Arial; font-size: 14pt'>";

            html = html + GenerateTable(report.AnomalyGroups[0], "CPU") +
                   GenerateTable(report.AnomalyGroups[0], "RAM") + GenerateTable(report.AnomalyGroups[0], "DISC");

            html = html + "</span></td></tr></table></body></html>";

            return(html);
        }
 public static string GetHtml(InstanceAnomalyReportDto report) => GenerateWholeHtml.GenerateHtml(report);
Exemplo n.º 3
0
        public async Task <string> CreateAnomalyReportNotificationAsync(NotificationRequest notificationRequest, InstanceAnomalyReportDto report)
        {
            var receivers     = new List <User>();
            var notifications = new List <NotificationDto>();

            if (notificationRequest.InstanceId == null)
            {
                return(string.Empty);
            }

            var instance = await _uow.InstanceRepository.GetFirstOrDefaultAsync(i => i.GuidId == notificationRequest.InstanceId,
                                                                                include : instances => instances.Include(o => o.Organization)
                                                                                .ThenInclude(uo => uo.UserOrganizations)
                                                                                .ThenInclude(uo => uo.User));

            if (instance == null)
            {
                return(string.Empty);
            }

            var htmlTable  = InstanceAnomalyReportsService.GetHtml(report);
            var htmlDocUrl = await _fileStorageProvider.UploadHtmlFileAsync(htmlTable, report.Id);

            notificationRequest.Text           = $"Anomaly Report was created for instance: {instance.Title} (id: {instance.Id}). Download it <a href=\"{htmlDocUrl}\">here</a>";
            notificationRequest.OrganizationId = instance.OrganizationId;
            receivers.AddRange(instance.Organization.UserOrganizations.Select(userOrganization => userOrganization.User));

            foreach (var receiver in receivers)
            {
                var entity = _mapper.Map <NotificationRequest, Notification>(notificationRequest);
                entity.UserId     = receiver.Id;
                entity.InstanceId = instance.Id;
                var notificationSetting = await _uow.NotificationSettingsRepository.GetFirstOrDefaultAsync(
                    ns => ns.Type == notificationRequest.Type && ns.UserId == entity.UserId);

                if (notificationSetting == null || notificationSetting.IsDisable)
                {
                    continue;
                }

                entity.NotificationSettingId = notificationSetting.Id;

                var created = await _uow.NotificationsRepository.CreateAsync(entity);

                var result = await _uow.SaveAsync();

                if (!result)
                {
                    return(null);
                }

                var dto = _mapper.Map <Notification, NotificationDto>(created);
                dto.NotificationSetting = _mapper.Map <NotificationSetting, NotificationSettingDto>(notificationSetting);


                if (notificationSetting.IsEmailable)
                {
                    var htmlLetter = InstanceAnomalyReportsService.GetHtmlForLetter(receiver.DisplayName, instance.Title, htmlDocUrl);
                    await _emailProvider.SendMessageOneToOne(
                        "*****@*****.**",
                        $"{notificationSetting.Type} Notification",
                        receiver.EmailForNotifications,
                        dto.Text, htmlLetter);
                }

                notifications.Add(dto);

                if (!NotificationsHub.UsersConnections.ContainsKey(dto.UserId))
                {
                    continue;
                }

                foreach (string connectionId in NotificationsHub.UsersConnections[dto.UserId])
                {
                    await _notificationsHub.Clients.Client(connectionId).SendAsync("AddNotification", dto);
                }
            }

            return(htmlDocUrl);
        }