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); }
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)); }
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); }
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); }