"Fossies" - the Fresh Open Source Software Archive

Member "PowerShell-7.2.6/src/Microsoft.PowerShell.Commands.Management/commands/management/AddContentCommand.cs" (11 Aug 2022, 3094 Bytes) of package /linux/misc/PowerShell-7.2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AddContentCommand.cs" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) Microsoft Corporation.
    2 // Licensed under the MIT License.
    3 
    4 using System;
    5 using System.Collections.Generic;
    6 using System.Management.Automation;
    7 using System.Management.Automation.Internal;
    8 
    9 namespace Microsoft.PowerShell.Commands
   10 {
   11     /// <summary>
   12     /// A command that appends the specified content to the item at the specified path.
   13     /// </summary>
   14     [Cmdlet(VerbsCommon.Add, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
   15         HelpUri = "https://go.microsoft.com/fwlink/?linkid=2096489")]
   16     public class AddContentCommand : WriteContentCommandBase
   17     {
   18         #region protected members
   19 
   20         /// <summary>
   21         /// Seeks to the end of the writer stream in each of the writers in the
   22         /// content holders.
   23         /// </summary>
   24         /// <param name="contentHolders">
   25         /// The content holders that contain the writers to be moved.
   26         /// </param>
   27         /// <exception cref="ProviderInvocationException">
   28         /// If calling Seek on the content writer throws an exception.
   29         /// </exception>
   30         internal override void SeekContentPosition(List<ContentHolder> contentHolders)
   31         {
   32             foreach (ContentHolder holder in contentHolders)
   33             {
   34                 if (holder.Writer != null)
   35                 {
   36                     try
   37                     {
   38                         holder.Writer.Seek(0, System.IO.SeekOrigin.End);
   39                     }
   40                     catch (Exception e) // Catch-all OK, 3rd party callout
   41                     {
   42                         ProviderInvocationException providerException =
   43                             new(
   44                                 "ProviderSeekError",
   45                                 SessionStateStrings.ProviderSeekError,
   46                                 holder.PathInfo.Provider,
   47                                 holder.PathInfo.Path,
   48                                 e);
   49 
   50                         // Log a provider health event
   51 
   52                         MshLog.LogProviderHealthEvent(
   53                             this.Context,
   54                             holder.PathInfo.Provider.Name,
   55                             providerException,
   56                             Severity.Warning);
   57 
   58                         throw providerException;
   59                     }
   60                 }
   61             }
   62         }
   63 
   64         /// <summary>
   65         /// Makes the call to ShouldProcess with appropriate action and target strings.
   66         /// </summary>
   67         /// <param name="path">
   68         /// The path to the item on which the content will be added.
   69         /// </param>
   70         /// <returns>
   71         /// True if the action should continue or false otherwise.
   72         /// </returns>
   73         internal override bool CallShouldProcess(string path)
   74         {
   75             string action = NavigationResources.AddContentAction;
   76 
   77             string target = StringUtil.Format(NavigationResources.AddContentTarget, path);
   78 
   79             return ShouldProcess(target, action);
   80         }
   81 
   82         #endregion protected members
   83     }
   84 }