/*************************************************************************** Copyright (c) Microsoft Corporation 2011. This code is licensed using the Microsoft Public License (Ms-PL). The text of the license can be found here: http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx ***************************************************************************/ using System; using System.Management.Automation; namespace OpenXmlPowerTools.Commands { /// /// Set-OpenXmlWatermark cmdlet /// [Cmdlet(VerbsCommon.Set, "OpenXmlWatermark", SupportsShouldProcess = true)] [OutputType("OpenXmlPowerToolsDocument")] public class SetOpenXmlWatermarkCmdlet : PowerToolsModifierCmdlet { #region Parameters private bool diagonalOrientation; private string watermarkText; /// /// WatermarkText parameter /// [Parameter(Position = 2, Mandatory = true, ValueFromPipeline = true, HelpMessage = "Text to show in the watermark")] [ValidateNotNullOrEmpty] public string WatermarkText { get { return watermarkText; } set { watermarkText = value; } } /// /// DiagonalOrientation parameter /// [Parameter( Mandatory = false, HelpMessage = "Specifies diagonal orientation for watermark")] [ValidateNotNullOrEmpty] public SwitchParameter DiagonalOrientation { get { return diagonalOrientation; } set { diagonalOrientation = value; } } #endregion #region Cmdlet Overrides 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)); } } } #endregion } }