private static async Task <HtmlDocument> ReadDocumentAsync(IDocumentId documentId) { string fileContent = null; if (documentId is FileDocumentId fileDocumentId) { var filePath = fileDocumentId.FilePath; fileContent = File.ReadAllText(filePath); if (!StringUtils.ContainsHtml(fileContent)) { fileContent = string.Concat( fileContent.Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries) .Select(p => $"<p>{p}</p>")); documentId.SetReadonly(); } } else if (documentId is WebDocumentId webDocumentId) { throw new NotImplementedException(); // todo async? } else { throw new NotSupportedException(documentId.GetType().Name); } var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(fileContent); return(htmlDoc); }
private static WordprocessingDocument ReadDocument(IDocumentId documentId) { if (!(documentId is FileDocumentId fileDocumentId)) { throw new NotSupportedException(documentId.GetType().Name); } var filePath = fileDocumentId.FilePath; return(WordprocessingDocument.Open(filePath, !documentId.IsReadonly)); }
private async Task <XDocument> ReadDocumentAsync(IDocumentId documentId) { string xml = null; if (documentId is OneNoteDocumentId) { xml = await this.oneNoteApp.GetPageContentAsync(((OneNoteDocumentId)documentId).PageId); //html = Regex.Replace(html, "([^>])(\\n| )([^<])", "$1 $3"); // todo: разобраться, нужно ли это сейчас } if (xml != null) { return(XDocument.Parse(xml)); } throw new NotSupportedException(documentId.GetType().Name); }
private static XDocument ReadDocument(IDocumentId documentId) { string xml = null; if (documentId is FileDocumentId) { var filePath = ((FileDocumentId)documentId).FilePath; var ext = Path.GetExtension(filePath); xml = File.ReadAllText(filePath); } if (xml != null) { return(XDocument.Parse(xml)); } throw new NotSupportedException(documentId.GetType().Name); }