コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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|&nbsp;)([^<])", "$1 $3");      // todo: разобраться, нужно ли это сейчас
            }

            if (xml != null)
            {
                return(XDocument.Parse(xml));
            }

            throw new NotSupportedException(documentId.GetType().Name);
        }
コード例 #4
0
        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);
        }