Esempio n. 1
0
        /// <summary>
        /// Prepares the header.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <param name="report">The report.</param>
        protected void PrepareHeader(IReportBodyDetails details, HtmlDocument report)
        {
            string headerTypeText = string.Empty;

            if (details.IsChannel)
            {
                headerTypeText = $"History bot backup from {details.TeamName}, {details.ChannelName} Channel";
            }

            if (details.IsConversation)
            {
                headerTypeText = $"History bot backup of conversation(thread) from {details.TeamName}, {details.ChannelName} Channel";
            }

            if (details.IsGroupChat)
            {
                headerTypeText = $"History bot backup from group chat";
            }

            report.GetElementbyId("report-type").AppendChild(HtmlNode.CreateNode(headerTypeText));

            var headerRange = string.Empty;

            if (details.Since.HasValue)
            {
                headerRange = $"Showing all messages posted between {details.Since.ToInternational()} and {details.Till.ToInternational()}";
            }
            else
            {
                headerRange = $"Showing all messages posted till {details.Till.ToInternational()}";
            }

            report.GetElementbyId("report-time-range").AppendChild(HtmlNode.CreateNode(headerRange));
            report.GetElementbyId("report-generation-details").AppendChild(HtmlNode.CreateNode($"Generated at {DateTimeOffset.Now.ToInternational()} by {details.Author}"));
        }
Esempio n. 2
0
        /// <summary>
        /// Prepares the header part.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <returns></returns>
        private string PrepareHeaderPart(IReportBodyDetails details)
        {
            var header = new StringBuilder();

            if (details.IsChannel)
            {
                header.AppendLine($"History bot backup from '{details.TeamName}' team, '{details.ChannelName}' channel");
            }

            if (details.IsConversation)
            {
                header.AppendLine($"History bot backup of conversation(thread) from '{details.TeamName}' team, '{details.ChannelName}' channel");
            }

            if (details.IsGroupChat)
            {
                header.AppendLine($"History bot backup from group chat");
            }

            if (details.Since.HasValue)
            {
                header.AppendLine($"Showing all messages posted between {details.Since.ToInternational()} and {details.Till.ToInternational()}");
            }
            else
            {
                header.AppendLine($"Showing all messages posted till {details.Till.ToInternational()}");
            }

            header.AppendLine($"Generated at {DateTimeOffset.Now.ToInternational()} by {details.Author}");

            return(header.ToString());
        }
Esempio n. 3
0
        protected string PrepareHtml(IReportBodyDetails details)
        {
            var          template        = File.ReadAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Templates\ReportTemplateMain.html");
            var          messageTemplate = File.ReadAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Templates\ReportTemplateMessage.html");
            HtmlDocument report          = new HtmlDocument();

            report.LoadHtml(template);
            PrepareHeader(details, report);
            PrepareBody(details, report, messageTemplate);
            return(report.DocumentNode.OuterHtml);
        }
Esempio n. 4
0
        /// <summary>
        /// Prepares the report body as byte array by report body details.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <returns></returns>
        public byte[] PrepareDocument(IReportBodyDetails details)
        {
            var threads = MessageSorter.ProcessMessages(details.Messages);
            var report  = new StringBuilder();

            var header = PrepareHeaderPart(details);

            report.AppendLine(header).AppendLine(string.Empty);

            threads.ForEach(c => report.AppendLine(PrepareContentPart(c, details.Since, details.IsChannel)));
            return(Encoding.UTF8.GetBytes(report.ToString()));
        }
Esempio n. 5
0
        private async Task <IDriveItem> UploadFile(byte[] byteArray, IReportBodyDetails reportDetails, string fileName, ITurnContext context, CancellationToken cancellationToken)
        {
            using (var stream = new MemoryStream(byteArray))
            {
                stream.Position = 0;
                stream.Flush();
                IDriveItem file =
                    await graphClient.UploadFileInPersonalOneDrive(() => context.GetUserTokenAsync(this.connectionName, cancellationToken), stream, fileName);

                return(file);
            }
        }
Esempio n. 6
0
        private async Task <byte[]> GenerateReportByteArray(ITurnContext context, IReportBodyDetails reportBodyDetails, ReportFormatType format, CancellationToken cancellationToken)
        {
            switch (format)
            {
            case ReportFormatType.HTML:
            case ReportFormatType.PDF:
            {
                await graphClient.DownloadImages(() => context.GetUserTokenAsync(this.connectionName, cancellationToken), reportBodyDetails.Messages);

                break;
            }
            }

            return(reportGenerator.PrepareDocument(reportBodyDetails, format));
        }
Esempio n. 7
0
        private async Task <IDriveItem> UploadReportAsync(ITurnContext context, IReportBodyDetails reportDetails, byte[] reportBytes, ReportFormatType format, CancellationToken cancellationToken)
        {
            IDriveItem file       = null;
            var        folderName = string.IsNullOrEmpty(reportsFolderName) ? string.Empty : (reportsFolderName + "/");
            var        fileName   = $"{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}_history_report";

            var reportBytesToUpload = reportBytes;

            switch (format)
            {
            case ReportFormatType.TXT:
            {
                fileName = $"{fileName}_.txt";
                break;
            }

            case ReportFormatType.JSON:
            {
                fileName = $"{fileName}_.json";
                break;
            }

            case ReportFormatType.HTML:
            {
                fileName = $"{fileName}_.html";
                break;
            }

            case ReportFormatType.PDF:
            {
                fileName = $"{fileName}_.pdf";
                break;
            }
            }

            file = await UploadFile(reportBytesToUpload, reportDetails, $"{folderName}{fileName}", context, cancellationToken);

            file.FileName = fileName;
            return(file);
        }
Esempio n. 8
0
        /// <summary>
        /// Prepares the body.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <param name="doc">The document.</param>
        /// <param name="messageTemplate">The message template.</param>
        protected void PrepareBody(IReportBodyDetails details, HtmlDocument doc, string messageTemplate)
        {
            var threadsNode = doc.GetElementbyId("history");

            var threads = MessageSorter.ProcessMessages(details.Messages);

            foreach (var thread in threads)
            {
                threadsNode.SetAttributeValue("class", "threads-container");

                if (details.IsChannel)
                {
                    if (thread.IsFull)
                    {
                        threadsNode.AppendChild(PrepareMessageDetails(thread.Messages.First(), true, messageTemplate, details.IsChannel));
                    }
                    else
                    {
                        if (details.Since.HasValue)
                        {
                            threadsNode.AppendChild(CreateConversationWarning(details.Since.Value));
                        }

                        threadsNode.AppendChild(PrepareMessageDetails(thread.Messages.First(), false, messageTemplate, details.IsChannel));
                    }

                    thread.Messages.Skip(1).ToList().ForEach(c => threadsNode.AppendChild(PrepareMessageDetails(c, false, messageTemplate, details.IsChannel)));
                }
                else
                {
                    if (!thread.IsFull && details.Since.HasValue)
                    {
                        threadsNode.AppendChild(CreateConversationWarning(details.Since.Value));
                    }

                    thread.Messages.ForEach(c => threadsNode.AppendChild(PrepareMessageDetails(c, false, messageTemplate, details.IsChannel)));
                }
            }
        }
        /// <summary>
        /// Prepares the report body as byte array by report body details.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <returns></returns>
        public byte[] PrepareDocument(IReportBodyDetails details)
        {
            var jsonStr = JsonConvert.SerializeObject(details.Messages);

            return(Encoding.UTF8.GetBytes(jsonStr.ToString()));
        }
 /// <inheritdoc/>
 public byte[] PrepareDocument(IReportBodyDetails details, ReportFormatType format)
 {
     return(GetGenerator(format).PrepareDocument(details));
 }
Esempio n. 11
0
        /// <summary>
        /// Prepares the report body as byte array by report body details.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <returns></returns>
        public byte[] PrepareDocument(IReportBodyDetails details)
        {
            var html = PrepareHtml(details);

            return(Encoding.UTF8.GetBytes(html));
        }
        /// <inheritdoc/>
        public new byte[] PrepareDocument(IReportBodyDetails details)
        {
            var html = PrepareHtml(details);

            return(generatePdf.GetPDF(html));
        }