Ejemplo n.º 1
0
        private XElement ProcessMessagesByChatIdentifier(IEnumerable <SmsMessage> items, string outputFolder)
        {
            var chatIdentifiers = items.Select(i => i.ChatIdentifier).Distinct().OrderBy(id => id);

            var container = new XElement("ul");
            var result    = new XElement("div", new XAttribute("id", "menu"), container);

            foreach (var chatIdentifier in chatIdentifiers)
            {
                var fileName = GetFileNameFromChatIdentifier(chatIdentifier);
                fileName = "chat-" + fileName + ".html";

                container.Add(ForEachChatIdentifier(chatIdentifier, fileName));

                var messages = from item in items
                               where item.ChatIdentifier.Equals(chatIdentifier)
                               orderby item.Date
                               select item;

                var generator = new HtmlGenerator(chatIdentifier, () =>
                {
                    return(ProcessMessages(messages));
                });

                generator.SaveAs(outputFolder, fileName);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private XElement ProcessAttachment(SmsAttachment item)
        {
            _logger.LogInformation("Processing attachment '{FileName}',MIME type='{MimeType}'", item.TransferName, item.MimeType);

            XElement result;

            if (item.MimeType.StartsWith("image/"))
            {
                result = HtmlGenerator.CreateImageElement(item.TransferName);
            }
            else if (item.MimeType.StartsWith("video/"))
            {
                result = HtmlGenerator.CreateVideoElement(item.TransferName, item.MimeType);
            }
            else if (item.MimeType.StartsWith("audio/"))
            {
                result = HtmlGenerator.CreateAudioElement(item.TransferName, item.MimeType);
            }
            else
            {
                result = HtmlGenerator.CreateAnchorElement(item.TransferName);
            }

            return(result);
        }
Ejemplo n.º 3
0
        private XElement ProcessMessagesByChatIdentifier(IEnumerable <SmsMessage> items, string outputFolder)
        {
            int i = 1;
            var chatIdentifiers = items.Select(i => i.ChatIdentifier).Distinct().OrderBy(id => id);

            var parent = new XElement("ul");

            foreach (var chatIdentifier in chatIdentifiers)
            {
                var fileName = "Conversation-" + i + ".html";

                parent.Add(ForEachChatIdentifier(chatIdentifier, fileName));

                var messages = from item in items
                               where item.ChatIdentifier.Equals(chatIdentifier)
                               orderby item.Date
                               select item;

                var generator = new HtmlGenerator(chatIdentifier, () =>
                {
                    return(ProcessMessagesForChatIdentifier(messages));
                });

                generator.SaveAs(outputFolder, fileName);

                ++i;
            }
            return(new XElement("div", new XAttribute("id", "menu"), parent));
        }
Ejemplo n.º 4
0
        public int Run(MessageOptions opts)
        {
            _logger.LogInformation("Starting {Command}", nameof(MessageCommand));

            var appContext = _appContext
                             .SetBackupMetadataInputPaths(opts.InputFolder)
                             .LoadBackupMetadata()
                             .SetVersionsFromMetadata();

            _backupFileProvider = new BackupFileProvider(opts.InputFolder, appContext.ManifestVersion.Major);

            var input = _backupFileProvider.GetPath(KnownDomains.HomeDomain, KnownFiles.Messages);

            _logger.LogInformation("Opening message database '{Source}'", input);
            using (var repository = new SmsRepository(SqliteRepository.GetConnectionString(input)))
            {
                var items = repository.GetAllItems().ToList();

                if (items.Any())
                {
                    HtmlGenerator.SaveCss(opts.OutputFolder, "bootstrap.min.css");
                    HtmlGenerator.SaveCss(opts.OutputFolder, "bootstrap-theme.min.css");
                    HtmlGenerator.SaveCss(opts.OutputFolder, "site.css");

                    foreach (var item in items)
                    {
                        if (item.CacheHasAttachments)
                        {
                            item.Attachments = repository.GetMessageAttachments(item.Id).ToArray();

                            SaveAttachments(item.Attachments, opts.OutputFolder);
                        }
                    }

                    var generator = new HtmlGenerator("Message Index", () =>
                    {
                        return(ProcessMessagesByChatIdentifier(items, opts.OutputFolder));
                    });

                    generator.SaveAs(opts.OutputFolder, "index.html");
                }
            }

            _logger.LogInformation("Completed {Command}", nameof(MessageCommand));
            return(0);
        }
Ejemplo n.º 5
0
        private void SaveAttachments(SmsAttachment[] items, string outputFolder)
        {
            foreach (var item in items)
            {
                if (string.IsNullOrEmpty(item.FileName) == false)
                {
                    _logger.LogInformation("Saving attachment '{InputFileName}','{TransferName}',MIME type='{MimeType}'", item.FileName, item.TransferName, item.MimeType);

                    var fileName  = item.FileName.RemovePrefix("~/");
                    var inputFile = _backupFileProvider.GetPath(KnownDomains.MediaDomain, fileName);

                    _logger.LogInformation("Saving attachment '{InputFile}' to folder '{OutputFolder}'", inputFile, outputFolder);
                    HtmlGenerator.SaveAttachmentAs(inputFile, outputFolder, item.TransferName);
                }
                else
                {
                    _logger.LogWarning("Missing file name for attachment with Id={Id}", item.Id);
                }
            }
        }
Ejemplo n.º 6
0
        public int Run(MessageOptions opts)
        {
            _logger.LogInformation("Starting {Command}", nameof(MessageCommand));

            var appContext = _appContext
                             .SetBackupMetadataInputPaths(opts.InputFolder)
                             .LoadBackupMetadata()
                             .SetVersionsFromMetadata()
                             .SetManifestEntriesFileInputPath(opts.InputFolder)
                             .AddManifestEntries();

            var backupFileProvider = new BackupFileProvider(opts.InputFolder, appContext.ManifestVersion.Major);

            var input = backupFileProvider.GetPath("3d0d7e5fb2ce288813306e4d4636395e047a3d28");

            _logger.LogInformation("Opening SMS database '{Source}'", input);
            using (var repository = new SmsRepository(SqliteRepository.GetConnectionString(input)))
            {
                var items = repository.GetAllItems().ToList();

                if (items.Any())
                {
                    HtmlGenerator.SaveCss(opts.OutputFolder, "bootstrap.min.css");
                    HtmlGenerator.SaveCss(opts.OutputFolder, "bootstrap-theme.min.css");
                    HtmlGenerator.SaveCss(opts.OutputFolder, "site.css");

                    foreach (var item in items)
                    {
                        if (item.CacheHasAttachments)
                        {
                            item.Attachments = repository.GetMessageAttachments(item.Id).ToArray();

                            foreach (var attachment in item.Attachments)
                            {
                                string fileName = attachment.FileName;

                                if (string.IsNullOrEmpty(fileName) == false && fileName.StartsWith("~/"))
                                {
                                    string toHash = KnownDomains.MediaDomain + KnownDomains.DomainSeparator + fileName.Remove(0, 2);

                                    var hash = CommonHelpers.Sha1HashAsHexString(toHash);

                                    var inputFile = backupFileProvider.GetPath(hash);

                                    HtmlGenerator.SaveAttachmentAs(inputFile, opts.OutputFolder, attachment.TransferName);
                                }
                            }
                        }
                    }

                    var generator = new HtmlGenerator("Message Index", () =>
                    {
                        return(ProcessMessagesByChatIdentifier(items, opts.OutputFolder));
                    });

                    generator.SaveAs(opts.OutputFolder, "index.html");
                }
            }

            _logger.LogInformation("Completed {Command}", nameof(MessageCommand));
            return(0);
        }