2020-03-24 19:08:37 +01:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
2018-02-13 18:23:53 +01:00
|
|
|
// Licensed under the MIT License.
|
2016-07-29 22:02:49 +02:00
|
|
|
|
2016-03-30 23:20:52 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Management.Automation;
|
|
|
|
using System.Management.Automation.Internal;
|
2019-04-30 07:25:11 +02:00
|
|
|
|
2016-03-30 23:20:52 +02:00
|
|
|
namespace Microsoft.PowerShell.Commands
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A command that appends the specified content to the item at the specified path.
|
|
|
|
/// </summary>
|
2016-07-29 22:02:49 +02:00
|
|
|
[Cmdlet(VerbsCommon.Add, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
2019-12-02 19:25:56 +01:00
|
|
|
HelpUri = "https://go.microsoft.com/fwlink/?linkid=2096489")]
|
2016-03-30 23:20:52 +02:00
|
|
|
public class AddContentCommand : WriteContentCommandBase
|
|
|
|
{
|
|
|
|
#region protected members
|
|
|
|
|
|
|
|
/// <summary>
|
2017-01-16 22:31:14 +01:00
|
|
|
/// Seeks to the end of the writer stream in each of the writers in the
|
2016-03-30 23:20:52 +02:00
|
|
|
/// content holders.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contentHolders">
|
|
|
|
/// The content holders that contain the writers to be moved.
|
|
|
|
/// </param>
|
|
|
|
/// <exception cref="ProviderInvocationException">
|
|
|
|
/// If calling Seek on the content writer throws an exception.
|
|
|
|
/// </exception>
|
|
|
|
internal override void SeekContentPosition(List<ContentHolder> contentHolders)
|
|
|
|
{
|
|
|
|
foreach (ContentHolder holder in contentHolders)
|
|
|
|
{
|
|
|
|
if (holder.Writer != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
holder.Writer.Seek(0, System.IO.SeekOrigin.End);
|
|
|
|
}
|
|
|
|
catch (Exception e) // Catch-all OK, 3rd party callout
|
|
|
|
{
|
|
|
|
ProviderInvocationException providerException =
|
|
|
|
new ProviderInvocationException(
|
|
|
|
"ProviderSeekError",
|
|
|
|
SessionStateStrings.ProviderSeekError,
|
|
|
|
holder.PathInfo.Provider,
|
|
|
|
holder.PathInfo.Path,
|
|
|
|
e);
|
|
|
|
|
|
|
|
// Log a provider health event
|
|
|
|
|
|
|
|
MshLog.LogProviderHealthEvent(
|
|
|
|
this.Context,
|
|
|
|
holder.PathInfo.Provider.Name,
|
|
|
|
providerException,
|
|
|
|
Severity.Warning);
|
|
|
|
|
|
|
|
throw providerException;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 17:53:30 +01:00
|
|
|
}
|
2016-03-30 23:20:52 +02:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Makes the call to ShouldProcess with appropriate action and target strings.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">
|
|
|
|
/// The path to the item on which the content will be added.
|
|
|
|
/// </param>
|
|
|
|
/// <returns>
|
|
|
|
/// True if the action should continue or false otherwise.
|
|
|
|
/// </returns>
|
|
|
|
internal override bool CallShouldProcess(string path)
|
|
|
|
{
|
|
|
|
string action = NavigationResources.AddContentAction;
|
|
|
|
|
2016-07-29 22:02:49 +02:00
|
|
|
string target = StringUtil.Format(NavigationResources.AddContentTarget, path);
|
2016-03-30 23:20:52 +02:00
|
|
|
|
|
|
|
return ShouldProcess(target, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion protected members
|
2018-12-08 17:53:30 +01:00
|
|
|
}
|
|
|
|
}
|