Skip to content

Commit ce55e87

Browse files
author
Dave Wyatt
committed
More code style changes
Revisions based on some of the guidelines listed in http://blogs.msdn.com/b/brada/archive/2005/01/26/361363.aspx and http://msdn.microsoft.com/en-us/library/ms229043.aspx (possibly more to come along these lines). No functionality changes, just renaming private members / parameters / local variables, and rearranging code.
1 parent dbdfc5b commit ce55e87

16 files changed

Lines changed: 547 additions & 528 deletions

Commands/AddLogFileCommand.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+

2+
// ReSharper disable MemberCanBePrivate.Global
3+
// ReSharper disable UnusedAutoPropertyAccessor.Global
4+
// ReSharper disable UnusedMember.Global
5+
6+
namespace PSLogging.Commands
7+
{
8+
using System.Management.Automation;
9+
10+
[Cmdlet(VerbsCommon.Add, "LogFile")]
11+
public class AddLogFileCommand : PSCmdlet
12+
{
13+
private ScriptBlock errorCallback;
14+
private LogFile inputObject;
15+
private string path;
16+
private StreamType streams = StreamType.All;
17+
18+
#region Parameters
19+
20+
[Parameter(ParameterSetName = "AttachExisting",
21+
Mandatory = true,
22+
Position = 0,
23+
ValueFromPipeline = true)]
24+
public LogFile InputObject
25+
{
26+
get { return this.inputObject; }
27+
set { this.inputObject = value; }
28+
}
29+
30+
[Parameter(ParameterSetName = "New")]
31+
public ScriptBlock OnError
32+
{
33+
get { return this.errorCallback; }
34+
set { this.errorCallback = value; }
35+
}
36+
37+
[Parameter(Mandatory = true,
38+
Position = 0,
39+
ParameterSetName = "New")]
40+
public string Path
41+
{
42+
get { return this.path; }
43+
set
44+
{
45+
this.path = System.IO.Path.IsPathRooted(value)
46+
? value
47+
: System.IO.Path.Combine(this.SessionState.Path.CurrentLocation.Path, value);
48+
}
49+
}
50+
51+
[Parameter(ParameterSetName = "New")]
52+
public StreamType StreamType
53+
{
54+
get { return this.streams; }
55+
set { this.streams = value; }
56+
}
57+
58+
#endregion
59+
60+
protected override void EndProcessing()
61+
{
62+
LogFile logFile;
63+
64+
if (this.ParameterSetName == "New")
65+
{
66+
logFile = new LogFile(this.path, this.streams, this.errorCallback);
67+
this.WriteObject(logFile);
68+
}
69+
else
70+
{
71+
logFile = this.inputObject;
72+
}
73+
74+
HostIoInterceptor.GetInterceptor().AddSubscriber(logFile);
75+
}
76+
} // End AddLogFileCommand class
77+
}
78+
79+
// ReSharper restore MemberCanBePrivate.Global
80+
// ReSharper restore UnusedAutoPropertyAccessor.Global
81+
// ReSharper restore UnusedMember.Global
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// ReSharper disable MemberCanBePrivate.Global
2+
// ReSharper disable UnusedAutoPropertyAccessor.Global
3+
// ReSharper disable UnusedMember.Global
4+
5+
namespace PSLogging.Commands
6+
{
7+
using System.Management.Automation;
8+
9+
[Cmdlet(VerbsCommon.Add, "OutputSubscriber")]
10+
public class AddOutputSubscriberCommand : PSCmdlet
11+
{
12+
private ScriptBlockOutputSubscriber inputObject;
13+
private ScriptBlock onWriteDebug;
14+
private ScriptBlock onWriteError;
15+
private ScriptBlock onWriteOutput;
16+
private ScriptBlock onWriteVerbose;
17+
private ScriptBlock onWriteWarning;
18+
19+
#region Parameters
20+
21+
[Parameter(ParameterSetName = "AttachExisting",
22+
Mandatory = true,
23+
ValueFromPipeline = true,
24+
Position = 0)]
25+
public ScriptBlockOutputSubscriber InputObject
26+
{
27+
get { return this.inputObject; }
28+
set { this.inputObject = value; }
29+
}
30+
31+
[Parameter(ParameterSetName = "New")]
32+
public ScriptBlock OnWriteDebug
33+
{
34+
get { return this.onWriteDebug; }
35+
set { this.onWriteDebug = value; }
36+
}
37+
38+
[Parameter(ParameterSetName = "New")]
39+
public ScriptBlock OnWriteError
40+
{
41+
get { return this.onWriteError; }
42+
set { this.onWriteError = value; }
43+
}
44+
45+
[Parameter(ParameterSetName = "New")]
46+
public ScriptBlock OnWriteOutput
47+
{
48+
get { return this.onWriteOutput; }
49+
set { this.onWriteOutput = value; }
50+
}
51+
52+
[Parameter(ParameterSetName = "New")]
53+
public ScriptBlock OnWriteVerbose
54+
{
55+
get { return this.onWriteVerbose; }
56+
set { this.onWriteVerbose = value; }
57+
}
58+
59+
[Parameter(ParameterSetName = "New")]
60+
public ScriptBlock OnWriteWarning
61+
{
62+
get { return this.onWriteWarning; }
63+
set { this.onWriteWarning = value; }
64+
}
65+
66+
#endregion
67+
68+
protected override void EndProcessing()
69+
{
70+
ScriptBlockOutputSubscriber subscriber;
71+
72+
if (this.ParameterSetName == "New")
73+
{
74+
subscriber = new ScriptBlockOutputSubscriber(this.onWriteOutput,
75+
this.onWriteDebug,
76+
this.onWriteVerbose,
77+
this.onWriteError,
78+
this.onWriteWarning);
79+
this.WriteObject(subscriber);
80+
}
81+
else
82+
{
83+
subscriber = this.inputObject;
84+
}
85+
86+
HostIoInterceptor.GetInterceptor().AddSubscriber(subscriber);
87+
}
88+
} // End AddOutputSubscriberCommand class
89+
}
90+
91+
// ReSharper restore MemberCanBePrivate.Global
92+
// ReSharper restore UnusedAutoPropertyAccessor.Global
93+
// ReSharper restore UnusedMember.Global

0 commit comments

Comments
 (0)