forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartTransactionCommand.cs
More file actions
105 lines (96 loc) · 3.51 KB
/
Copy pathStartTransactionCommand.cs
File metadata and controls
105 lines (96 loc) · 3.51 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
95
96
97
98
99
100
101
102
103
104
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Management.Automation;
using Dbg = System.Management.Automation;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// A command that begins a transaction.
/// </summary>
[Cmdlet(VerbsLifecycle.Start, "Transaction", SupportsShouldProcess = true, HelpUri = "http://go.microsoft.com/fwlink/?LinkID=135262")]
public class StartTransactionCommand : PSCmdlet
{
/// <summary>
/// The time, in minutes, before this transaction is rolled back
/// automatically.
/// </summary>
[Parameter()]
[Alias("TimeoutMins")]
public int Timeout
{
get
{
return (int) timeout.TotalMinutes;
}
set
{
// The transactions constructor treats a timeout of
// zero as infinite. So we fudge it to be a bit longer.
if(value == 0)
timeout = TimeSpan.FromTicks(1);
else
timeout = TimeSpan.FromMinutes(value);
timeoutSpecified = true;
}
}
bool timeoutSpecified = false;
private TimeSpan timeout = TimeSpan.MinValue;
/// <summary>
/// Gets or sets the flag to determine if this transaction can
/// be committed or rolled back independently of other transactions.
/// </summary>
[Parameter()]
public SwitchParameter Independent
{
get { return independent; }
set { independent = value; }
}
private SwitchParameter independent;
/// <summary>
/// Gets or sets the rollback preference for this transaction.
/// </summary>
[Parameter()]
public RollbackSeverity RollbackPreference
{
get { return rollbackPreference; }
set { rollbackPreference = value; }
}
private RollbackSeverity rollbackPreference = RollbackSeverity.Error;
/// <summary>
/// Creates a new transaction.
/// </summary>
protected override void EndProcessing ()
{
if(ShouldProcess(
NavigationResources.TransactionResource,
NavigationResources.CreateAction))
{
// Set the default timeout
if(! timeoutSpecified)
{
// See if we're being invoked directly at the
// command line. In that case, set the timeout to infinite.
if(MyInvocation.CommandOrigin == CommandOrigin.Runspace)
{
timeout = TimeSpan.MaxValue;
}
else
{
timeout = TimeSpan.FromMinutes(30);
}
}
// Create the new transaction
if(independent)
{
this.Context.TransactionManager.CreateNew(rollbackPreference, timeout);
}
else
{
this.Context.TransactionManager.CreateOrJoin(rollbackPreference, timeout);
}
}
}
} // StartTransactionCommand
} // namespace Microsoft.PowerShell.Commands