public static string ToHtml(this DocumentPart part)
        {
            var visitor = new ToHtmlVisitor();

            part.Accept(visitor);
            return(visitor.HtmlText);
        }
Пример #2
0
 public override void SetDocumentPart(DocumentPart documentPart)
 {
     DeleteTempFile();
     if (documentPart is InternalDocumentPart)
     {
         _tempFilename = Path.Combine(Path.GetTempPath(), Path.GetFileName(documentPart.Uri));
         using (Stream stream = ((InternalDocumentPart)documentPart).GetStream())
         {
             using (FileStream fileStream = new FileStream(_tempFilename, FileMode.Create, FileAccess.Write))
             {
                 byte[] buffer    = new byte[1024];
                 int    bytesRead = stream.Read(buffer, 0, 1024);
                 while (bytesRead > 0)
                 {
                     fileStream.Write(buffer, 0, bytesRead);
                     bytesRead = stream.Read(buffer, 0, 1024);
                 }
             }
             _browser.Navigate(_tempFilename);
         }
     }
     else if (documentPart is ExternalDocumentPart)
     {
         _browser.Navigate(documentPart.Uri);
     }
 }
        public static string ToPlainText(this DocumentPart part)
        {
            var visitor = new ToPlainTextVisitor();

            part.Accept(visitor);
            return(visitor.PlainTextString);
        }
        public static string ToLaTeX(this DocumentPart part)
        {
            var visitor = new ToLaTeXVisitor();

            part.Accept(visitor);
            return(visitor.LaTeX);
        }
Пример #5
0
        private string GetTextToIndex(DocumentPart part)
        {
            var mediaPart   = ((ContentItem)part.ContentItem).As <MediaPart>();
            var textToIndex = String.Empty;

            if (mediaPart != null)
            {
                var extension = Path.GetExtension(mediaPart.FileName);

                if (AllowedExtension(extension))
                {
                    var document = _storageProvider.GetFile(Path.Combine(mediaPart.FolderPath, mediaPart.FileName));

                    var documentStream = document.OpenRead();
                    if (documentStream == null)
                    {
                        return(textToIndex);
                    }
                    byte[] data = StreamHelper.ReadToEnd(documentStream);
                    if (data == null)
                    {
                        return(textToIndex);
                    }

                    // Text Extraction
                    var extractor     = new TextExtractor();
                    var contentResult = extractor.Extract(data);
                    textToIndex = contentResult.Text;
                }
            }
            return(textToIndex);
        }
Пример #6
0
 public void CloseDocumentPart(DocumentPart documentPart)
 {
     if (_tabPages.ContainsKey(documentPart))
     {
         TabPages.Remove(_tabPages[documentPart]);
         _tabPages.Remove(documentPart);
     }
 }
Пример #7
0
 /// <summary>
 /// Removes all parts and sets given part the only part.
 /// </summary>
 /// <param name="part">the document part</param>
 public void setPart(DocumentPart part)
 {
     if (this.documentParts.ContainsKey(part.PartName))
     {
         this.documentParts[part.PartName].Clear();
     }
     addPart(part.PartName, part.PartValue);
 }
Пример #8
0
        /// <summary>
        /// Add a part to the list of parts
        /// </summary>
        /// <param name="part">the document part</param>
        public void addPart(DocumentPart part)
        {
            if (!this.documentParts.ContainsKey(part.PartName))
            {
                this.documentParts[part.PartName] = new List <DocumentPart>();
            }

            this.documentParts[part.PartName].Add(part);
        }
Пример #9
0
        internal PackagePart CreateDefaultNumberingPart()
        {
            var packagePartUri = new Uri("/word/numbering.xml", UriKind.Relative);
            var part           = package.CreatePart(packagePartUri, ContentTypes.Numbering, CompressionOption.Normal);

            DocumentPart.CreateRelationship(packagePartUri, TargetMode.Internal, RelationshipTypes.Numbering);
            var content = XmlResourceHelper.GetXmlResource("Wordroller.Packages.Defaults.numbering.xml");

            PackagePartHelper.SavePackagePart(part, content);
            return(part);
        }
Пример #10
0
        public override string Convert(DocumentPart elem)
        {
            IDocumentPartConverter converter;

            if (Converters.TryGetValue(elem.GetType(), out converter))
            {
                return(converter.Convert(elem));
            }

            throw new InvalidOperationException($"can't find a converter for the {nameof(elem)}");
        }
Пример #11
0
        private void addStringToDocument(DocumentPart part)
        {
            FormFields fields = this.document.FormFields;

            foreach (FormField field in fields)
            {
                if (field.Name == part.PartName)
                {
                    field.Range.Text += "\n" + part.PartValue;
                }
            }
        }
Пример #12
0
        public (PackagePart, PackageRelationship) AddFooterPart()
        {
            var safePartIndex = package.GetParts().Count() + 1;
            var partUri       = new Uri($"/word/footer{safePartIndex}.xml", UriKind.Relative);
            var part          = package.CreatePart(partUri, ContentTypes.Footer, CompressionOption.Normal);
            var content       = XmlResourceHelper.GetXmlResource("Wordroller.Packages.Defaults.footer.xml");

            PackagePartHelper.SavePackagePart(part, content);
            var relationship = DocumentPart.CreateRelationship(part.Uri, TargetMode.Internal, RelationshipTypes.Footer);

            return(part, relationship);
        }
Пример #13
0
        protected override void OnBeforeExpand(TreeViewCancelEventArgs e)
        {
            foreach (TreeNode node in e.Node.Nodes)
            {
                DocumentPart part = (DocumentPart)node.Tag;

                foreach (DocumentPart childPart in part.DocumentParts)
                {
                    node.Nodes.Add(CreatePartNode(childPart));
                }
            }
            base.OnBeforeExpand(e);
        }
Пример #14
0
        public override void SetDocumentPart(DocumentPart documentPart)
        {
            InternalDocumentPart internalPart = documentPart as InternalDocumentPart;

            if (internalPart != null)
            {
                Image image = null;
                using (Stream stream = CreateImageStream(internalPart))
                {
                    image = Image.FromStream(stream);
                }
                _picture.Image = image;
            }
        }
Пример #15
0
        private void addPictureToDocument(DocumentPart part)
        {
            FormFields fields = this.document.FormFields;

            foreach (FormField field in fields)
            {
                if (field.Name == part.PartName)
                {
                    object msoTrue = Microsoft.Office.Core.MsoTriState.msoTrue;
                    object missing = Missing.Value;
                    field.Range.InlineShapes.AddPicture(part.PartValue, ref msoTrue, ref msoTrue, ref missing);
                    field.Range.InsertAfter("\n");
                }
            }
        }
Пример #16
0
        void UpdateNodeText(TreeNode node)
        {
            DocumentPart part = (DocumentPart)node.Tag;

            if (_displayRelations)
            {
                node.Text = String.Format("{0} - {1}", part.RelationshipID, part.Name);
            }
            else
            {
                node.Text = part.Name;
            }
            foreach (TreeNode childNode in node.Nodes)
            {
                UpdateNodeText(childNode);
            }
        }
Пример #17
0
        /// <summary>
        /// Covert document part.
        /// </summary>
        /// <param name="documentPart">document part</param>
        public string Convert(DocumentPart documentPart)
        {
            if (documentPart.GetType() == typeof(Hyperlink))
            {
                return($"{ConvertHyperlink((Hyperlink) documentPart)}\n");
            }
            if (documentPart.GetType() == typeof(PlainText))
            {
                return($"{ConvertPlainText((PlainText) documentPart)}\n");
            }

            if (documentPart.GetType() == typeof(BoldText))
            {
                return($"{ConvertBoldText((BoldText) documentPart)}\n");
            }

            return("");
        }
Пример #18
0
        public string Get(DocumentPart part)
        {
            if (part is BoldText)
            {
                return(Get(part as BoldText));
            }

            if (part is PlainText)
            {
                return(Get(part as PlainText));
            }

            if (part is Hyperlink)
            {
                return(Get(part as Hyperlink));
            }

            return(string.Empty);
        }
Пример #19
0
        TreeNode CreatePartNode(DocumentPart part)
        {
            TreeNode node = new TreeNode();

            node.Name = part.Uri;
            Debug.WriteLine(part.Uri);
            node.Tag = part;
            if (part is PackageDocumentPart)
            {
                node.ImageIndex         = 0;
                node.SelectedImageIndex = 0;
            }
            else
            {
                node.ImageIndex         = 1;
                node.SelectedImageIndex = 1;
            }
            UpdateNodeText(node);
            return(node);
        }
Пример #20
0
        public void OpenDocumentPart(DocumentPart documentPart)
        {
            TabPage page = null;

            if (_tabPages.ContainsKey(documentPart))
            {
                page = _tabPages[documentPart];
            }
            else
            {
                page     = new TabPage(documentPart.Name);
                page.Tag = documentPart;
                DocumentPartViewer viewControl = CreateViewControl(documentPart);
                viewControl.SetDocumentPart(documentPart);
                viewControl.Dock = DockStyle.Fill;
                page.Controls.Add((Control)viewControl);
                TabPages.Add(page);
                _tabPages.Add(documentPart, page);
            }
            SelectedTab = page;
        }
Пример #21
0
        DocumentPartViewer CreateViewControl(DocumentPart part)
        {
            PackageExplorerSection config   = (PackageExplorerSection)ConfigurationManager.GetSection("packageExplorer");
            PartViewerSettings     settings = null;

            foreach (PartViewerSettings partViewer in config.PartViewers)
            {
                foreach (string contentType in partViewer.ContentTypes.Split('|'))
                {
                    if (String.Equals(part.ContentType, contentType, StringComparison.InvariantCultureIgnoreCase))
                    {
                        settings = partViewer;
                    }
                }
            }
            if (settings == null)
            {
                settings = config.PartViewers[config.DefaultViewer];
            }
            return((DocumentPartViewer)Activator.CreateInstance(Type.GetType(settings.Type)));
        }
Пример #22
0
        /// <summary>
        /// Removes all parts with a certain value
        /// </summary>
        /// <param name="part">the document part</param>
        public void removePart(DocumentPart part)
        {
            if (!this.documentParts.ContainsKey(part.PartName))
            {
                return;
            }

            DocumentPart target = new DocumentPart(part.PartName, part.PartValue);

            List <DocumentPart> parts = this.documentParts[part.PartName].FindAll(target.Equals);

            foreach (DocumentPart partToRemove in parts)
            {
                this.documentParts[part.PartName].Remove(partToRemove);
            }

            if (this.documentParts[part.PartName].Count == 0)
            {
                this.documentParts.Remove(part.PartName);
            }
        }
 public int ContentCount(DocumentPart documentPart)
 {
     return ContentCount(documentPart, VersionOptions.Published);
 }
 public int ContentCount(DocumentPart documentPart, VersionOptions versionOptions)
 {
     return GetDocumentQuery(documentPart, versionOptions).Count();
 }
Пример #25
0
 public static string DocumentForAdmin(this UrlHelper urlHelper, DocumentPart documentPart)
 {
     return urlHelper.Action("Item", "DocumentAdmin", new { documentId = documentPart.Id, area = "Infusion.Documents" });
 }
Пример #26
0
 public static string DocumentContentCreate(this UrlHelper urlHelper, DocumentPart documentPart)
 {
     return urlHelper.Action("Create", "DocumentContentAdmin", new { documentId = documentPart.Id, area = "Infusion.Documents" });
 }
Пример #27
0
 //public void addSnapshot(string snap)
 //{
 //  myMinutes.snapshots = myMinutes.snapshots + ";" + snap;
 //}
 //public void addParticipant(string part)
 //{
 //  myMinutes.participants = myMinutes.participants + "\n" + part;
 //}
 private void addPartsToDocument(DocumentPart[] parts)
 {
     foreach (DocumentPart part in parts)
     {
         switch (part.PartType)
         {
             case DocumentPartType.String:
                 addStringToDocument(part);
                 break;
             case DocumentPartType.Picture:
                 addPictureToDocument(part);
                 break;
         }
     }
 }
Пример #28
0
 public static string ToPlainText(this DocumentPart documentPart)
 => ToPlainText((dynamic)documentPart);
 public void DynamicVisit(DocumentPart part) => Visit((dynamic)part);
Пример #30
0
 public static string ToHtml(this DocumentPart documentPart)
 => ToHtml((dynamic)documentPart);
 public DocumentPartModifiedEventArgs(DocumentPart affectedDocumentPart, string propertyName, DocumentPartModificationType modificationType)
 {
     this.propertyName = propertyName;
     this.affectedDocumentPart = affectedDocumentPart;
     this.modificationType = modificationType;
 }
Пример #32
0
 private void addStringToDocument(DocumentPart part)
 {
     FormFields fields = this.document.FormFields;
     foreach (FormField field in fields)
     {
         if (field.Name == part.PartName)
         {
             field.Range.Text += "\n" + part.PartValue;
         }
     }
 }
Пример #33
0
 private void addPictureToDocument(DocumentPart part)
 {
     FormFields fields = this.document.FormFields;
     foreach (FormField field in fields)
     {
         if (field.Name == part.PartName)
         {
             object msoTrue = Microsoft.Office.Core.MsoTriState.msoTrue;
             object missing = Missing.Value;
             field.Range.InlineShapes.AddPicture(part.PartValue, ref msoTrue, ref msoTrue, ref missing);
             field.Range.InsertAfter("\n");
         }
     }
 }
        public string Convert(DocumentPart elem)
        {
            BoldText target = (BoldText)elem;

            return("<b>" + target.Text + "</b>");;
        }
Пример #35
0
 public static string ToLaTeX(this DocumentPart documentPart)
 => ToLaTeX((dynamic)documentPart);
Пример #36
0
 public string Visit(DocumentPart documentPart) => Visit((dynamic)documentPart);
 public void SetDocumentPart(DocumentPart documentPart)
 {
     _contentTypeField.Text      = documentPart.ContentType;
     _relationshipTypeField.Text = documentPart.RelationshipType;
     _documentPartNameField.Text = documentPart.Name;
 }
Пример #38
0
        /// <summary>
        /// Removes all parts with a certain value
        /// </summary>
        /// <param name="part">the document part</param>
        public void removePart(DocumentPart part)
        {
            if (!this.documentParts.ContainsKey(part.PartName)) return;

            DocumentPart target = new DocumentPart(part.PartName, part.PartValue);

            List<DocumentPart> parts = this.documentParts[part.PartName].FindAll(target.Equals);

            foreach (DocumentPart partToRemove in parts)
                this.documentParts[part.PartName].Remove(partToRemove);

            if (this.documentParts[part.PartName].Count == 0)
                this.documentParts.Remove(part.PartName);
        }
Пример #39
0
        /// <summary>
        /// Add a part to the list of parts
        /// </summary>
        /// <param name="part">the document part</param>
        public void addPart(DocumentPart part)
        {
            if (!this.documentParts.ContainsKey(part.PartName))
            {
                this.documentParts[part.PartName] = new List<DocumentPart>();
            }

            this.documentParts[part.PartName].Add(part);
        }
Пример #40
0
 public override string Accept(DocumentPart visitor)
 {
     return(visitor.ToHtml());
 }
Пример #41
0
 /// <summary>
 /// Removes all parts and sets given part the only part.
 /// </summary>
 /// <param name="part">the document part</param>
 public void setPart(DocumentPart part)
 {
     if (this.documentParts.ContainsKey(part.PartName))
         this.documentParts[part.PartName].Clear();
     addPart(part.PartName, part.PartValue);
 }