コード例 #1
0
        private async Task LoadHostedContent(ChatMessage message)
        {
            var jsonFile = MgTeamChannelMessage.GetBackupMessageHostedContentFile(_Options.SourcePath, _TeamId, _ChannelId, message);

            _Logger.LogTrace($"File: {jsonFile}");

            if (System.IO.File.Exists(jsonFile))
            {
                using System.IO.FileStream fs = System.IO.File.OpenRead(jsonFile);
                message.HostedContents        = await JsonSerializer.DeserializeAsync <ChatMessageHostedContentsCollectionPage>(fs);
            }
        }
コード例 #2
0
        public async Task LoadReplies()
        {
            _Replies = new List <ChatMessage>();

            var jsonDirectory = MgTeamChannelMessage.GetBackupPath(_Options.SourcePath, _TeamId, _ChannelId, _MessageId);

            _Logger.LogTrace($"File: {jsonDirectory}");

            foreach (var jsonFile in System.IO.Directory.GetFiles(jsonDirectory, MgTeamChannelMessage.MessageReplyFilePattern))
            {
                _Replies.Add(await LoadMessageFile(jsonFile));
            }
        }
コード例 #3
0
        public async Task LoadMessage()
        {
            var jsonFile = MgTeamChannelMessage.GetBackupMessageFile(_Options.SourcePath, _TeamId, _ChannelId, _MessageId);

            _Message = await LoadMessageFile(jsonFile);
        }
コード例 #4
0
        private void GetHtmlForPost(HtmlNode threadNode, ChatMessage message)
        {
            var htmlDocument = threadNode.OwnerDocument;
            var messagetNode = message.ReplyToId == null?htmlDocument.CreateElement("post") : htmlDocument.CreateElement("reply");

            threadNode.AppendChild(messagetNode);

            if (!string.IsNullOrEmpty(message.Subject))
            {
                var messageSubjectNode = htmlDocument.CreateElement("h2");
                messagetNode.AppendChild(messageSubjectNode);
                messageSubjectNode.InnerHtml = message.Subject;
            }

            var messageInfoNode = htmlDocument.CreateElement("chatmeta");

            messagetNode.AppendChild(messageInfoNode);
            messageInfoNode.InnerHtml = "Created: " + message.CreatedDateTime.Value.ToString(_Options.DateTimeFormat);
            if (message.LastEditedDateTime != null)
            {
                messageInfoNode.InnerHtml += " | Edited: " + message.LastEditedDateTime.Value.ToString(_Options.DateTimeFormat);
            }
            if (message.From?.User != null)
            {
                messageInfoNode.InnerHtml += " | Author: " + message.From.User.DisplayName;
            }
            if (message.From?.Application != null)
            {
                messageInfoNode.InnerHtml += " | Application: " + message.From.Application.DisplayName;
            }
            if (message.DeletedDateTime != null)
            {
                var messageBodyNode = htmlDocument.CreateElement("p");
                messagetNode.AppendChild(messageBodyNode);
                messageBodyNode.InnerHtml = "DELETED CONTENT";
            }
            else
            {
                var messageBodyNode = htmlDocument.CreateElement("p");
                messagetNode.AppendChild(messageBodyNode);

                messageBodyNode.InnerHtml = message.Body.Content;

                var imageNodes = messageBodyNode.SelectNodes(".//img");
                if (imageNodes != null)
                {
                    foreach (var imgNode in imageNodes)
                    {
                        if (imgNode.Attributes["src"].Value.EndsWith("$value"))
                        {
                            var chunks          = imgNode.Attributes["src"].Value.Split('/');
                            var hostedContentid = chunks[chunks.Length - 2];

                            var blobFileName = MgTeamChannelMessage.GetBackupMessageHostedContentBlob(_Options.SourcePath, _TeamId, _ChannelId, message, hostedContentid);

                            if (_Options.UseInlineImages)
                            {
                                var blobFileb64 = System.Convert.ToBase64String(System.IO.File.ReadAllBytes(blobFileName));
                                imgNode.SetAttributeValue("src", $"data:image/png;base64,{blobFileb64}");
                            }
                            else
                            {
                                string outFilename = null;
                                if (message.ReplyToId == null)
                                {
                                    outFilename = GetOutputMessageImgFile(_Options.TargetPath, _TeamId, _ChannelId, message.Id, null, System.IO.Path.GetFileName(blobFileName));
                                }
                                else
                                {
                                    outFilename = GetOutputMessageImgFile(_Options.TargetPath, _TeamId, _ChannelId, message.ReplyToId, message.Id, System.IO.Path.GetFileName(blobFileName));
                                }
                                System.IO.File.Copy(blobFileName, outFilename, true);
                                System.IO.File.SetCreationTime(outFilename, message.CreatedDateTime.Value.DateTime);
                                System.IO.File.SetLastWriteTime(outFilename, message.CreatedDateTime.Value.DateTime);

                                imgNode.SetAttributeValue("src", $"./img/{System.IO.Path.GetFileName(outFilename)}");
                            }

                            imgNode.SetAttributeValue("class", "hc");
                        }

                        imgNode.SetAttributeValue("style", "");
                    }
                }
            }
        }