8000 Remove '-ComputerName' from 'Get/Set/Remove-Service' by daxian-dbw · Pull Request #5094 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@daxian-dbw
Copy link
Member

Fix #5090
Remove '-ComputerName' from 'Get/Set/Remove-Service'

@daxian-dbw
Copy link
Member Author

It's easier to review the changes after ignoring whitespaces: https://github.com/PowerShell/PowerShell/pull/5094/files?w=1

Copy link
@anmenaga anmenaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

NativeMethods.SERVICE_CONFIG_DESCRIPTION,
buffer);
// If '-Status' parameter is specified, do the necessary action to bring about the desired result

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like this comment. It says if -Status, do something to get what you want. Can we be more specific or remove this comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will change it to // Handle '-Status' parameter.

//stop service,give the force parameter always true as we have already checked for the dependent services
//Specify NoWait parameter as always false since we are not adding this switch to this cmdlet
DoStopService(service, true, true);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are touching the code here, can we use named parameters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

WriteObject(displayservice);
if (!service.Status.Equals(ServiceControllerStatus.Paused))
//pause service
DoPauseService(service);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change this one. I will remove it.

bool objServiceShouldBeDisposed = false;
try
if (InputObject != null)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks very similar to line 1485. Can we refactor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are from two different cmdlets: Set-Service (line 1485) and Remove-Service (2083)

@daxian-dbw
10BC0 Copy link
Member Author

@adityapatwardhan Your comments are addressed. Can you please take another look?

ServiceCommandException exception =
new ServiceCommandException(message, innerException);
exception.ServiceName = serviceName;
(null == innerException) ? "" : innerException.Message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use String.Empty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clarify for me: I found many "*" strings in cs files - should we create a constant for it?

foreach (ServiceController service in OneService(pattern))
ServiceController service = GetOneService(pattern);
if (service != null)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems GetOneService() never return null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the service doesn't exist, accessing sc.Status; will throw InvalidOperationException. In that case the method will catch the exception and return null.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Closed.

@iSazonov iSazonov added Breaking-Change breaking change that may affect users Documentation Needed in this repo Documentation is needed in this repo labels Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0