Skip to content

Commit ed53f92

Browse files
committed
Naming changes, some refactoring
In preparation for placing this module into a new public repository, I've made the following changes to module and command names: Renamed module from PSLogging to PowerShellLogging , to avoid the PS prefix per Microsoft's recent posts. Renamed Add-LogFile and Add-OutputSubscriber cmdlets to Enable-LogFile and Enable-OutputSubscriber instead, so they match up better with the Disable-* cmdlets. Some minor code changes (removed unnecessary "this" references, etc.)
1 parent 4e4f7eb commit ed53f92

14 files changed

+215
-216
lines changed

Commands/DisableLogFileCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DisableLogFileCommand : PSCmdlet
1616

1717
protected override void EndProcessing()
1818
{
19-
HostIOInterceptor.Instance.RemoveSubscriber(this.InputObject);
19+
HostIOInterceptor.Instance.RemoveSubscriber(InputObject);
2020
}
2121
} // End DisableLogFileCommand class
2222
}

Commands/DisableOutputSubscriberCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DisableOutputSubscriberCommand : PSCmdlet
1616

1717
protected override void EndProcessing()
1818
{
19-
HostIOInterceptor.Instance.RemoveSubscriber(this.InputObject);
19+
HostIOInterceptor.Instance.RemoveSubscriber(InputObject);
2020
}
2121
} // End DisableOutputSubscriberCommand class
2222
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace PSLogging.Commands
77
{
88
using System.Management.Automation;
99

10-
[Cmdlet(VerbsCommon.Add, "LogFile")]
11-
public class AddLogFileCommand : PSCmdlet
10+
[Cmdlet(VerbsLifecycle.Enable, "LogFile")]
11+
public class EnableLogFileCommand : PSCmdlet
1212
{
1313
private ScriptBlock errorCallback;
1414
private LogFile inputObject;
@@ -23,34 +23,34 @@ public class AddLogFileCommand : PSCmdlet
2323
ValueFromPipeline = true)]
2424
public LogFile InputObject
2525
{
26-
get { return this.inputObject; }
27-
set { this.inputObject = value; }
26+
get { return inputObject; }
27+
set { inputObject = value; }
2828
}
2929

3030
[Parameter(ParameterSetName = "New")]
3131
public ScriptBlock OnError
3232
{
33-
get { return this.errorCallback; }
34-
set { this.errorCallback = value; }
33+
get { return errorCallback; }
34+
set { errorCallback = value; }
3535
}
3636

3737
[Parameter(Mandatory = true,
3838
Position = 0,
3939
ParameterSetName = "New")]
4040
public string Path
4141
{
42-
get { return this.path; }
42+
get { return path; }
4343
set
4444
{
45-
this.path = this.GetUnresolvedProviderPathFromPSPath(value);
45+
path = GetUnresolvedProviderPathFromPSPath(value);
4646
}
4747
}
4848

4949
[Parameter(ParameterSetName = "New")]
5050
public StreamType StreamType
5151
{
52-
get { return this.streams; }
53-
set { this.streams = value; }
52+
get { return streams; }
53+
set { streams = value; }
5454
}
5555

5656
#endregion
@@ -59,17 +59,17 @@ protected override void EndProcessing()
5959
{
6060
LogFile logFile;
6161

62-
if (this.ParameterSetName == "New")
62+
if (ParameterSetName == "New")
6363
{
64-
logFile = new LogFile(this.path, this.streams, this.errorCallback);
65-
this.WriteObject(logFile);
64+
logFile = new LogFile(path, streams, errorCallback);
65+
WriteObject(logFile);
6666
}
6767
else
6868
{
69-
logFile = this.inputObject;
69+
logFile = inputObject;
7070
}
7171

72-
HostIOInterceptor.Instance.AttachToHost(this.Host);
72+
HostIOInterceptor.Instance.AttachToHost(Host);
7373
HostIOInterceptor.Instance.AddSubscriber(logFile);
7474
}
7575
} // End AddLogFileCommand class
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace PSLogging.Commands
66
{
77
using System.Management.Automation;
88

9-
[Cmdlet(VerbsCommon.Add, "OutputSubscriber")]
10-
public class AddOutputSubscriberCommand : PSCmdlet
9+
[Cmdlet(VerbsLifecycle.Enable, "OutputSubscriber")]
10+
public class EnableOutputSubscriberCommand : PSCmdlet
1111
{
1212
private ScriptBlockOutputSubscriber inputObject;
1313
private ScriptBlock onWriteDebug;
@@ -24,43 +24,43 @@ public class AddOutputSubscriberCommand : PSCmdlet
2424
Position = 0)]
2525
public ScriptBlockOutputSubscriber InputObject
2626
{
27-
get { return this.inputObject; }
28-
set { this.inputObject = value; }
27+
get { return inputObject; }
28+
set { inputObject = value; }
2929
}
3030

3131
[Parameter(ParameterSetName = "New")]
3232
public ScriptBlock OnWriteDebug
3333
{
34-
get { return this.onWriteDebug; }
35-
set { this.onWriteDebug = value; }
34+
get { return onWriteDebug; }
35+
set { onWriteDebug = value; }
3636
}
3737

3838
[Parameter(ParameterSetName = "New")]
3939
public ScriptBlock OnWriteError
4040
{
41-
get { return this.onWriteError; }
42-
set { this.onWriteError = value; }
41+
get { return onWriteError; }
42+
set { onWriteError = value; }
4343
}
4444

4545
[Parameter(ParameterSetName = "New")]
4646
public ScriptBlock OnWriteOutput
4747
{
48-
get { return this.onWriteOutput; }
49-
set { this.onWriteOutput = value; }
48+
get { return onWriteOutput; }
49+
set { onWriteOutput = value; }
5050
}
5151

5252
[Parameter(ParameterSetName = "New")]
5353
public ScriptBlock OnWriteVerbose
5454
{
55-
get { return this.onWriteVerbose; }
56-
set { this.onWriteVerbose = value; }
55+
get { return onWriteVerbose; }
56+
set { onWriteVerbose = value; }
5757
}
5858

5959
[Parameter(ParameterSetName = "New")]
6060
public ScriptBlock OnWriteWarning
6161
{
62-
get { return this.onWriteWarning; }
63-
set { this.onWriteWarning = value; }
62+
get { return onWriteWarning; }
63+
set { onWriteWarning = value; }
6464
}
6565

6666
#endregion
@@ -69,21 +69,21 @@ protected override void EndProcessing()
6969
{
7070
ScriptBlockOutputSubscriber subscriber;
7171

72-
if (this.ParameterSetName == "New")
72+
if (ParameterSetName == "New")
7373
{
74-
subscriber = new ScriptBlockOutputSubscriber(this.onWriteOutput,
75-
this.onWriteDebug,
76-
this.onWriteVerbose,
77-
this.onWriteError,
78-
this.onWriteWarning);
79-
this.WriteObject(subscriber);
74+
subscriber = new ScriptBlockOutputSubscriber(onWriteOutput,
75+
onWriteDebug,
76+
onWriteVerbose,
77+
onWriteError,
78+
onWriteWarning);
79+
WriteObject(subscriber);
8080
}
8181
else
8282
{
83-
subscriber = this.inputObject;
83+
subscriber = inputObject;
8484
}
8585

86-
HostIOInterceptor.Instance.AttachToHost(this.Host);
86+
HostIOInterceptor.Instance.AttachToHost(Host);
8787
HostIOInterceptor.Instance.AddSubscriber(subscriber);
8888
}
8989
} // End AddOutputSubscriberCommand class

Commands/GetLogFileCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public class GetLogFileCommand : PSCmdlet
1818
[ValidateNotNullOrEmpty]
1919
public string Path
2020
{
21-
get { return this.path; }
21+
get { return path; }
2222
set
2323
{
24-
this.path = this.GetUnresolvedProviderPathFromPSPath(value);
24+
path = GetUnresolvedProviderPathFromPSPath(value);
2525
}
2626
}
2727

@@ -32,9 +32,9 @@ protected override void EndProcessing()
3232
var logFile = subscriber as LogFile;
3333

3434
if (logFile != null &&
35-
(this.path == null || System.IO.Path.GetFullPath(logFile.Path) == System.IO.Path.GetFullPath(this.path)))
35+
(path == null || System.IO.Path.GetFullPath(logFile.Path) == System.IO.Path.GetFullPath(path)))
3636
{
37-
this.WriteObject(logFile);
37+
WriteObject(logFile);
3838
}
3939
}
4040
}

Commands/GetOutputSubscriberCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected override void EndProcessing()
1717
var scriptBlockSubscriber = subscriber as ScriptBlockOutputSubscriber;
1818
if (scriptBlockSubscriber != null)
1919
{
20-
this.WriteObject(scriptBlockSubscriber);
20+
WriteObject(scriptBlockSubscriber);
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)