forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddContentCommand.cs
More file actions
95 lines (83 loc) · 3.45 KB
/
Copy pathAddContentCommand.cs
File metadata and controls
95 lines (83 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Internal;
using Dbg = System.Management.Automation;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// A command that appends the specified content to the item at the specified path.
/// </summary>
[Cmdlet(VerbsCommon.Add, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113278")]
public class AddContentCommand : WriteContentCommandBase
{
#region protected members
/// <summary>
/// Seeks to the end of the writer stream in each of the writers in the
/// 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
{
CommandsCommon.CheckForSevereException(this, e);
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;
}
}
}
} // SeekContentPosition
/// <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;
string target = StringUtil.Format(NavigationResources.AddContentTarget, path);
return ShouldProcess(target, action);
}
#endregion protected members
} // AddContentCommand
} // namespace Microsoft.PowerShell.Commands