/// <summary>
        /// Entry point for PowerShell cmdlets
        /// </summary>
        protected override void ProcessRecord()
        {
            string picName = "PowerToolsPicture";

            if (image == null && picturePath != null)
            {
                image   = System.Drawing.Image.FromFile(picturePath, true);
                picName = picturePath.Substring(picturePath.LastIndexOf('\\') + 1);
            }
            foreach (var document in AllDocuments("Add-OpenXmlPicture"))
            {
                try
                {
                    if (!(document is WmlDocument))
                    {
                        throw new PowerToolsDocumentException("Not a wordprocessing document.");
                    }
                    OutputDocument(PictureAccessor.Insert((WmlDocument)document, xpathInsertionPoint, image, picName));
                }
                catch (Exception e)
                {
                    WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
                }
            }
        }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Merge-OpenXmlDocumentCommentCmdlet"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             if (current == null)
             {
                 current = (WmlDocument)document;
             }
             else
             {
                 current = CommentMerger.MergeComments(current, (WmlDocument)document);
             }
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 /// <summary>
 /// Entry point for PowerShell cmdlets
 /// </summary>
 protected override void ProcessRecord()
 {
     if (themePath != null)
     {
         themePackage = OpenXmlPowerToolsDocument.FromFileName(themePath);
     }
     if (themePackage == null)
     {
         WriteError(new ErrorRecord(new ArgumentException("No theme was specified."), "OpenXmlPowerTools", ErrorCategory.InvalidArgument, null));
     }
     else
     {
         foreach (var document in AllDocuments("Set-OpenXmlTheme"))
         {
             try
             {
                 if (!(document is WmlDocument))
                 {
                     throw new PowerToolsDocumentException("Not a wordprocessing document.");
                 }
                 OutputDocument(ThemeAccessor.SetTheme((WmlDocument)document, themePackage));
             }
             catch (Exception e)
             {
                 WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
             }
         }
     }
 }
 /// <summary>
 /// Entry point for PowerShell cmdlets
 /// </summary>
 protected override void ProcessRecord()
 {
     if (footerPath != null)
     {
         footer = XDocument.Load(footerPath);
     }
     if (footer == null)
     {
         WriteError(new ErrorRecord(new ArgumentException("No footer was specified."), "OpenXmlPowerTools", ErrorCategory.InvalidArgument, null));
         return;
     }
     foreach (var document in AllDocuments("Set-OpenXmlFooter"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(FooterAccessor.SetFooter((WmlDocument)document, footer, kind, Section - 1));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 /// <summary>
 /// Entry point for PowerShell cmdlets
 /// </summary>
 protected override void ProcessRecord()
 {
     if (stylesSourcePath != null)
     {
         stylesSource = XDocument.Load(stylesSourcePath);
     }
     if (stylesSource == null)
     {
         WriteError(new ErrorRecord(new Exception("No styles source was specified."), "BadParameters", ErrorCategory.InvalidArgument, null));
         return;
     }
     foreach (var document in AllDocuments("Set-OpenXmlContentStyle"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(StyleAccessor.Insert((WmlDocument)document, xpathInsertionPoint, styleName, stylesSource));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#6
0
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Merge-OpenXmlDocumentCmdlet"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             if (m_Count != -1)
             {
                 buildSources.Add(new Source((WmlDocument)document, m_Start - 1, m_Count, m_KeepSections));
             }
             else
             {
                 buildSources.Add(new Source((WmlDocument)document, m_Start - 1, m_KeepSections));
             }
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#7
0
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Get-OpenXmlTheme"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OpenXmlPowerToolsDocument theme = ThemeAccessor.GetTheme((WmlDocument)document);
             if (OutputPath != null)
             {
                 theme.SaveAs(System.IO.Path.Combine(SessionState.Path.CurrentLocation.Path, OutputPath));
             }
             if (PassThru || OutputPath == null)
             {
                 WriteObject(theme, true);
             }
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#8
0
 protected override void ProcessRecord()
 {
     if (xmlPath != null)
     {
         customData = XDocument.Load(xmlPath);
         if (partName == null)
         {
             partName = System.IO.Path.GetFileName(xmlPath);
         }
     }
     foreach (var document in AllDocuments("Set-OpenXmlCustomXmlData"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(CustomXmlAccessor.SetDocument((WmlDocument)document, customData, partName));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#9
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);
            }
        }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Set-OpenXmlString"))
     {
         try
         {
             if (!(document is WmlDocument) && !(document is PmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a supported document.");
             }
             if (document is WmlDocument)
             {
                 OutputDocument(TextReplacer.SearchAndReplace((WmlDocument)document, Pattern, Replace, CaseSensitive));
             }
             if (document is PmlDocument)
             {
                 OutputDocument(TextReplacer.SearchAndReplace((PmlDocument)document, Pattern, Replace, CaseSensitive));
             }
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#11
0
 protected override void EndProcessing()
 {
     try
     {
         if (m_Sources != null)
         {
             foreach (DocumentSource source in m_Sources)
             {
                 Collection <PathInfo> fileList = SessionState.Path.GetResolvedPSPathFromPSPath(source.SourceFile);
                 foreach (var file in fileList)
                 {
                     OpenXmlPowerToolsDocument document = OpenXmlPowerToolsDocument.FromFileName(file.Path);
                     try
                     {
                         if (!(document is WmlDocument))
                         {
                             throw new PowerToolsDocumentException("Not a wordprocessing document.");
                         }
                         if (source.Count != -1)
                         {
                             buildSources.Add(new Source((WmlDocument)document, source.Start - 1, source.Count, source.KeepSection));
                         }
                         else if (source.Start != -1)
                         {
                             buildSources.Add(new Source((WmlDocument)document, source.Start - 1, source.KeepSection));
                         }
                         else
                         {
                             buildSources.Add(new Source((WmlDocument)document, source.KeepSection));
                         }
                     }
                     catch (Exception e)
                     {
                         WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
                     }
                 }
             }
         }
         WmlDocument result = DocumentBuilder.BuildDocument(buildSources);
         if (m_OutputPath != null)
         {
             if (!File.Exists(m_OutputPath) || ShouldProcess(m_OutputPath, "Merge-OpenXmlDocumentCmdlet"))
             {
                 result.SaveAs(m_OutputPath);
             }
         }
         if (PassThru)
         {
             WriteObject(result, true);
         }
     }
     catch (Exception e)
     {
         WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, null));
     }
 }
示例#12
0
 protected override void ProcessRecord()
 {
     if (backgroundColor || backgroundImage)
     {
         foreach (var document in AllDocuments("Get-OpenXmlBackground"))
         {
             try
             {
                 if (!(document is WmlDocument))
                 {
                     throw new PowerToolsDocumentException("Not a wordprocessing document.");
                 }
                 string bgColor     = string.Empty;
                 string bgImagePath = string.Empty;
                 if (backgroundColor)
                 {
                     bgColor = BackgroundAccessor.GetBackgroundColor((WmlDocument)document);
                     if (bgColor != "")
                     {
                         WriteObject(System.Drawing.Color.FromArgb(Convert.ToInt32(bgColor, 16)), true);
                     }
                 }
                 else if (backgroundImage)
                 {
                     string filename = BackgroundAccessor.GetImageFileName((WmlDocument)document);
                     if (filename != "")
                     {
                         string target = filename;
                         if (OutputFolder != null)
                         {
                             FileInfo temp = new FileInfo(filename);
                             target = OutputFolder + "\\" + temp.Name;
                         }
                         if (!File.Exists(target) || ShouldProcess(target, "Get-OpenXmlBackground"))
                         {
                             BackgroundAccessor.SaveImageToFile((WmlDocument)document, target);
                             System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
                             WriteObject(fileInfo, true);
                         }
                     }
                 }
             }
             catch (Exception e)
             {
                 WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
             }
         }
     }
     else
     {
         WriteError(new ErrorRecord(new ArgumentException("Requires one of the two switches: Color or Image."), "OpenXmlPowerToolsError", ErrorCategory.InvalidArgument, null));
     }
 }
 /// <summary>
 /// Entry point for PowerShell cmdlets
 /// </summary>
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Remove-OpenXmlDigitalSignature"))
     {
         try
         {
             OutputDocument(DigitalSignatureAccessor.RemoveAll(document));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 /// <summary>
 /// Entry point for Power Shell Cmdlets
 /// </summary>
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Get-OpenXmlDigitalSignature"))
     {
         try
         {
             WriteObject(DigitalSignatureAccessor.GetList(document), true);
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Get-OpenXmlCustomXmlData"))
     {
         try
         {
             WriteObject(new OpenXmlPowerToolsDocument(document), true);
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#16
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));
         }
     }
 }
示例#17
0
 protected override void ProcessRecord()
 {
     try
     {
         if (styleFile != null)
         {
             stylesDocument = XDocument.Load(styleFile);
         }
         if (stylesDocument == null)
         {
             WriteError(new ErrorRecord(new ArgumentException("No styles document was specified."), "OpenXmlPowerTools", ErrorCategory.InvalidArgument, null));
         }
         else
         {
             foreach (var document in AllDocuments("Set-OpenXmlStyle"))
             {
                 try
                 {
                     if (!(document is WmlDocument))
                     {
                         throw new PowerToolsDocumentException("Not a wordprocessing document.");
                     }
                     OutputDocument(StyleAccessor.SetStylePart((WmlDocument)document, stylesDocument));
                 }
                 catch (Exception e)
                 {
                     WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
                 }
             }
         }
     }
     catch (ItemNotFoundException e)
     {
         WriteError(new ErrorRecord(e, "FileNotFound", ErrorCategory.OpenError, null));
     }
     catch (InvalidOperationException e)
     {
         WriteError(new ErrorRecord(e, "InvalidOperation", ErrorCategory.InvalidOperation, null));
     }
     catch (ArgumentException e)
     {
         WriteError(new ErrorRecord(e, "InvalidArgument", ErrorCategory.InvalidArgument, null));
     }
     catch (Exception e)
     {
         WriteError(new ErrorRecord(e, "General", ErrorCategory.NotSpecified, null));
     }
 }
        protected override void ProcessRecord()
        {
            IEnumerable <string> certList = SessionState.Path.GetResolvedPSPathFromPSPath(certificate).Select(e => e.Path);

            foreach (var document in AllDocuments("Add-OpenXmlDigitalSignature"))
            {
                try
                {
                    OutputDocument(DigitalSignatureAccessor.Insert(document, certList));
                }
                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));
         }
     }
 }
示例#20
0
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Remove-OpenXmlComment"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(CommentAccessor.RemoveAll((WmlDocument)document));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Get-OpenXmlCustomXmlData"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             WriteObject(CustomXmlAccessor.Find((WmlDocument)document, xmlPartName), true);
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Set-OpenXmlContentFormat"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(ContentFormatAccessor.Insert((WmlDocument)document, xpathInsertionPoint, xmlContent));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Get-OpenXmlStyle"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             WriteObject(StyleAccessor.GetStylesDocument((WmlDocument)document), true);
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#24
0
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Add-OpenXmlDocumentTOA"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(ReferenceAdder.AddToa((WmlDocument)document, InsertionPoint, Switches, null));
         }
         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 ProcessRecord()
 {
     foreach (var document in AllDocuments("Remove-OpenXmlMarkup"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(MarkupSimplifier.SimplifyMarkup((WmlDocument)document, settings));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Set-OpenXmlSpreadSheetCellValue"))
     {
         try
         {
             if (!(document is SmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a spreadsheet document.");
             }
             OutputDocument(WorksheetAccessor.SetCellValue((SmlDocument)document, worksheetName, fromRow, toRow, fromColumn, toColumn, _value));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#28
0
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Set-OpenXmlWatermark"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(WatermarkAccessor.InsertWatermark((WmlDocument)document, watermarkText, diagonalOrientation));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Add-OpenXmlSpreadSheetTable"))
     {
         try
         {
             if (!(document is SmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a spreadsheet document.");
             }
             OutputDocument(SpreadSheetTableAccessor.Add((SmlDocument)document, worksheetName, tableStyle, hasHeaders, fromColumn, toColumn, fromRow, toRow));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
示例#30
0
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Get-OpenXmlComment"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             object comments = CommentAccessor.GetAllComments((WmlDocument)document, CommentFormat.Xml);
             WriteObject(comments, true);
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }