Ejemplo n.º 1
0
        /// <summary>
        /// Entry point for PowerShell commandlets
        /// </summary>
        protected override void ProcessRecord()
        {
            List <MatchInfo> results = new List <MatchInfo>();

            foreach (var document in AllDocuments("Select-OpenXmlString"))
            {
                try
                {
                    if (!(document is WmlDocument))
                    {
                        throw new PowerToolsDocumentException("Not a wordprocessing document.");
                    }
                    MatchInfo[] result = PowerToolsExtensions.SearchInDocument((WmlDocument)document, m_StyleSearch, m_TextSearch, !m_SimpleMatch, !m_CaseSensitive);
                    if (!m_List)
                    {
                        foreach (MatchInfo item in result)
                        {
                            item.Path = document.FileName;
                            results.Add(item);
                        }
                    }
                    else if (result.GetUpperBound(0) >= 0)
                    {
                        result[0].Path = document.FileName;
                        results.Add(result[0]);
                    }
                }
                catch (Exception e)
                {
                    WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
                }
                WriteObject(results, true);
            }
        }
Ejemplo n.º 2
0
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Add-OpenXmlContent"))
     {
         try
         {
             OutputDocument(PowerToolsExtensions.InsertXml(document, xmlPartPaths, xpathInsertionPoint, xmlContent));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Confirm-OpenXmlValid"))
     {
         try
         {
             foreach (ValidationErrorInfo item in PowerToolsExtensions.ValidateXml(document))
             {
                 WriteObject(new ValidationInfo(document, item), true);
             }
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 /// <summary>
 /// Entry point for PowerShell cmdlets
 /// </summary>
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Remove-OpenXmlPersonalInformationCmdlet"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(PowerToolsExtensions.RemovePersonalInformation((WmlDocument)document));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void EndProcessing()
 {
     if (PassThru || !File.Exists(outputPath) || ShouldProcess(outputPath, "Export-OpenXmlWordprocessing"))
     {
         using (OpenXmlMemoryStreamDocument streamDoc = OpenXmlMemoryStreamDocument.CreateWordprocessingDocument())
         {
             using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
             {
                 if (processedObjects.Count > 0)
                 {
                     PowerToolsExtensions.SetContent(document, processedObjects.Select(e => new XElement(W.p, new XElement(W.r, new XElement(W.t, new XAttribute(XNamespace.Xml + "space", "preserve"), e)))));
                 }
             }
             OpenXmlPowerToolsDocument output = streamDoc.GetModifiedDocument();
             output.FileName = outputPath;
             OutputDocument(output);
         }
     }
 }