Add ConvertTo-Clixml and ConvertFrom-Clixml cmdlet - #12845
Add ConvertTo-Clixml and ConvertFrom-Clixml cmdlet#12845Shri Ram K S (Shriram0908) wants to merge 7 commits into
Conversation
|
Hi Ilya (@iSazonov), Could you review the PR and provide your feedback. |
There was a problem hiding this comment.
Ilya (@iSazonov) , I tired to use the same function but I was not sure how to do it so I have created a overloaded the method. This is to make sure that Import-Clixml and ConvertFrom-Clixml use the same helper function.
There was a problem hiding this comment.
It is static. So it could be moved to a temp class or a base class.
There was a problem hiding this comment.
class ImportXmlHelper does't not derive from any other class.
I tried to convert sting into memory stream so that we dont need this function itself. Let me know if we can implementation this
internal ImportXmlHelper(PSCmdlet cmdlet, string cliObject)
{
_cmdlet = cmdlet;
_memoryStream = new MemoryStream();
StreamWriter memeoryWriter = new StreamWriter(_memoryStream);
memeoryWriter.Write(cliObject);
memeoryWriter.Flush();
_memoryStream.Position = 0;
CreateStream();
}
There was a problem hiding this comment.
It depends on whether we want to process "#< CLIXML".
|
Ilya (@iSazonov) I have made the requested changes. Please review and provide your feedback. |
|
I have one main question regarding the code here (there are minor things, but I think the main thing should be addressed first) -- if I'm not mistaken, a fair amount of parameters and the serialization methods are pretty similar to the existing Export/Import-Csv cmdlets. Have we looked at whether some of the existing code (and/or the new code) can be moved into a base class that both cmdlets can implement to reduce code duplication here? Or are we expecting to do that after this PR? |
|
Rain Sallow (/u/ta11ow) (@vexx32), I tried not make too many changes to existing code. I made modifications only to I am following this approach to reduce the PR size. we can have two separate PR or one single PR. I am okay with it either way. |
Rain Sallow (/u/ta11ow) (vexx32)
left a comment
There was a problem hiding this comment.
Looks good to me, apart from a couple smaller comments. 🙂
There was a problem hiding this comment.
It's unusual for a Dispose() method to throw, but iirc it can happen; I'd prefer to see this with a try/finally so that _disposed is always set correctly.
There was a problem hiding this comment.
It seems _importXmlHelper.Dispose() can not throw.
There was a problem hiding this comment.
Dongbo Wang (@daxian-dbw) seeing PSObject[] as a parameter type reminds of the weird issue we had with Write-Output where it was enumerating input arrays and wrapping every single item in PSObject during parameter binding. Is that desired here, or should we go with PSObject to avoid it like I think we did with Write-Output?
There was a problem hiding this comment.
We use the same pattern in ConvertFrom-Csv.
There was a problem hiding this comment.
Rain Sallow (/u/ta11ow) (@vexx32) I changed to PSObject and tried it code execution seems to follow the same path. No difference either way. Maybe using PSObject can improve readability.
I used PSObject[] seeing ConvertFrom-Csv.
There was a problem hiding this comment.
Yeah Ilya (@iSazonov) I'm sure a lot of commands still do. I'm not sure if it's the right way to go though.
Shri Ram K S (@Shriram0908) if it works both ways... it's probably fine to leave as is. I would prefer to have someone on the PS team weigh in first though.
There was a problem hiding this comment.
Rain Sallow (/u/ta11ow) (@vexx32) Sure okay. let me know anything else needs to be done.
There was a problem hiding this comment.
| _stringBuilder.AppendLine( InputObject[0].ToString() ); | |
| _stringBuilder.AppendLine(InputObject[0].ToString()); |
There was a problem hiding this comment.
| $content = Get-Command export* -Type Cmdlet | Select-Object -First 3 | ConvertTo-Clixml | |
| $results = ConvertFrom-CliXml $content | |
| $results.Count | Should -Be 3 | |
| $results[0].PSTypeNames[0] | Should -BeExactly "Deserialized.System.Management.Automation.CmdletInfo" | |
| $content = Get-Command export* -Type Cmdlet | Select-Object -First 3 | ConvertTo-Clixml | |
| $results = ConvertFrom-CliXml $content | |
| $results.Count | Should -Be 3 | |
| $results[0].PSTypeNames[0] | Should -BeExactly "Deserialized.System.Management.Automation.CmdletInfo" |
There was a problem hiding this comment.
| It "ConvertFrom-CliXml with Rehydration should work" { | |
| $property1 = 256 | |
| $property2 = "abcdef" | |
| $isHiddenTestType = [IsHiddenTestType]::New($property1,$property2) | |
| $content = $isHiddenTestType | ConvertTo-Clixml | |
| $results = ConvertFrom-CliXml $content | |
| $results.Property1 | Should -Be $property1 | |
| $results.Property2 | Should -BeExactly $property2 | |
| It "ConvertFrom-CliXml with Rehydration should work" { | |
| $property1 = 256 | |
| $property2 = "abcdef" | |
| $isHiddenTestType = [IsHiddenTestType]::New($property1,$property2) | |
| $content = $isHiddenTestType | ConvertTo-Clixml | |
| $results = ConvertFrom-CliXml $content | |
| $results.Property1 | Should -Be $property1 | |
| $results.Property2 | Should -BeExactly $property2 |
There was a problem hiding this comment.
| It "ConvertFrom-CliXml StopProcessing should succeed" { | |
| $content = 1,2,3 | ConvertTo-Clixml | |
| $ps = [PowerShell]::Create() | |
| $ps.AddCommand("Get-Process") | |
| $ps.AddCommand("ConvertFrom-CliXml") | |
| $ps.AddParameter("InputObject", $content) | |
| $ps.BeginInvoke() | |
| $ps.Stop() | |
| $ps.InvocationStateInfo.State | Should -BeExactly "Stopped" | |
| It "ConvertFrom-CliXml StopProcessing should succeed" { | |
| $content = 1,2,3 | ConvertTo-Clixml | |
| $ps = [PowerShell]::Create() | |
| $ps.AddCommand("Get-Process") | |
| $ps.AddCommand("ConvertFrom-CliXml") | |
| $ps.AddParameter("InputObject", $content) | |
| $ps.BeginInvoke() | |
| $ps.Stop() | |
| $ps.InvocationStateInfo.State | Should -BeExactly "Stopped" |
There was a problem hiding this comment.
| It "ConvertFrom-CliXml -First and -Skip work together for collections" { | |
| $content = @{ a = 1; b = 2; c = 3; d = 4 } | ConvertTo-Clixml | |
| # order not guaranteed, even with [ordered] so we have to be smart here and compare against the full result | |
| $out1 = ConvertFrom-CliXml -InputObject $content # this results in a hashtable | |
| $out2 = ConvertFrom-CliXml -InputObject $content -First 2 -Skip 1 # this results in a dictionary entry | |
| $out2.Count | Should -Be 2 | |
| It "ConvertFrom-CliXml -First and -Skip work together for collections" { | |
| $content = @{ a = 1; b = 2; c = 3; d = 4 } | ConvertTo-Clixml | |
| # order not guaranteed, even with [ordered] so we have to be smart here and compare against the full result | |
| $out1 = ConvertFrom-CliXml -InputObject $content # this results in a hashtable | |
| $out2 = ConvertFrom-CliXml -InputObject $content -First 2 -Skip 1 # this results in a dictionary entry | |
| $out2.Count | Should -Be 2 |
There was a problem hiding this comment.
Ilya (@iSazonov) I just realized that the indentation issues is due to mix of tab and space. Which one should I use space or tab or is it fine as long as I use it consistently ?
There was a problem hiding this comment.
Spaces is generally the norm in the repo. The only exceptions I usually see are really old files.
|
Ilya (@iSazonov) Rain Sallow (/u/ta11ow) (@vexx32) |
|
Yeah, please file a documentation issue in the docs repo and put the link in the PR description. 😊 |
|
Ilya (@iSazonov) Rain Sallow (/u/ta11ow) (@vexx32) , Please let me know what to do next. |
|
Waiting MSFT team approve. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Shri Ram K S (@Shriram0908) thank you for this one, hope it gets merged ❤️ |
|
Ilya (@iSazonov) Rain Sallow (/u/ta11ow) (@vexx32) Travis Plunk (@TravisEz13) Steve Lee (@SteveL-MSFT) Its been quite some time. Please let me know if I could help. |
|
I can not merge without additional reviews. |
|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |
|
How to re-open this PR ? |
|
Ilya (@iSazonov) Thank you for opening the PR. Seems like Link in internals.md and ADOPTERS.md are failing. Let me know if there is something that I can do. |
|
Shri Ram K S (@Shriram0908) I think you need to rebase. |
|
Ilya (@iSazonov) Once I rebased the pushed to repo, It worked. Thanks. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
Test for ConvertTo-Clixml and ConvertFrom-CliXml
use memory stream instead of string builder code cleanup
convert tab to space
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
It appears that Travis Plunk (@TravisEz13)'s feedback hasn't been addressed yet |
Travis Plunk (TravisEz13)
left a comment
There was a problem hiding this comment.
Please address the comments from #12845 (comment).
|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |

PR Summary
ConvertTo-ClixmlandConvertFrom-CliXmlto work with clixml objects. Fixes #3898PR Context
The new cmdlet can be used to work with clixml without needed to save it file.
The cmdlets behave similar to
ConvertTo-CsvandConvertFrom-CsvPR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.