Commits

Aaron Jensen committed 9e469ba

Set-DotNetAppSetting and Set-DotNetConnectionString can now make changes to .NET 2 configuration when running under PowerShell 3.

  • Participants
  • Parent commits 0086bc6

Comments (0)

Files changed (8)

File Carbon/Carbon.psm1

 $supportNotFoundErrorMessage = 'Unable to find support for managing Windows features.  Couldn''t find servermanagercmd.exe, ocsetup.exe, or WMI support.'
 
 Get-Item (Join-Path $PSScriptRoot *\*.ps1) | 
+    Where-Object { $_.Directory.Name -ne 'bin' } |
     ForEach-Object {
         Write-Debug ("Importing sub-module {0}." -f $_.FullName)
         . $_.FullName

File Carbon/DotNet/Set-DotNetAppSetting.ps1

         return
     }
     
-    $command = {
-        param(
-            $Name,
-            $Value
-        )
-        
-        Add-Type -AssemblyName System.Configuration
-
-        $config = [Configuration.ConfigurationManager]::OpenMachineConfiguration()
-        $appSettings = $config.AppSettings.Settings
-        if( $appSettings[$Name] )
-        {
-            $appSettings[$Name].Value = $Value
-        }
-        else
-        {
-            $appSettings.Add( $Name, $Value )
-        }
-        $config.Save()
-    }
-    
     $runtimes = @()
     if( $Clr2 )
     {
 
     $runtimes | ForEach-Object {
         $params = @{
-            Command = $command;
-            Args = $Name,$Value;
+            FilePath = (Join-Path $CarbonBinDir 'Set-DotNetAppSetting.ps1' -Resolve);
+            ArgumentList = @( 
+                                (ConvertTo-Base64 -Value $Name),
+                                (ConvertTo-Base64 -Value $Value)
+                            );
             Runtime = $_
         }
         

File Carbon/DotNet/Set-DotNetConnectionString.ps1

         return
     }
     
-    $command = {
-        param(
-            $Name,
-            $Value,
-            $ProviderName
-        )
-        
-        Add-Type -AssemblyName System.Configuration
-
-        $config = [Configuration.ConfigurationManager]::OpenMachineConfiguration()
-        $connectionStrings = $config.ConnectionStrings.ConnectionStrings
-        if( $connectionStrings[$Name] )
-        {
-            $connectionStrings.Remove( $Name )
-        }
-
-        $args = @( $Name, $Value )
-        if( $ProviderName )
-        {
-            $args += $ProviderName
-        }
-        $connectionString = New-Object Configuration.ConnectionStringSettings $args
-        $connectionStrings.Add( $connectionString )
-
-        $config.Save()
-    }
-
     $runtimes = @()
     if( $Clr2 )
     {
 
     $runtimes | ForEach-Object {
         $params = @{
-            Command = $command;
-            Args = $Name,$Value,$ProviderName;
+            FilePath = (Join-Path $CarbonBinDir 'Set-DotNetConnectionString.ps1' -Resolve);
+            ArgumentList = @(
+                                (ConvertTo-Base64 -Value $Name),
+                                (ConvertTo-Base64 -Value $Value),
+                                (ConvertTo-Base64 -Value $ProviderName) 
+                            );
             Runtime = $_;
         }
 

File Carbon/bin/Set-DotNetAppSetting.ps1

+<#
+.SYNOPSIS
+*Internal*.  Use `Set-DotNetAppSetting` function instead.
+.LINK
+Set-DotNetAppSetting
+#>
+
+# Copyright 2012 Aaron Jensen
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+[CmdletBinding()]
+param(
+    [Parameter(Mandatory=$true,Position=0)]
+    [string]
+    $Name,
+
+    [Parameter(Mandatory=$true,Position=1)]
+    [string]
+    $Value
+)
+
+Set-StrictMode -Version Latest
+$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
+. (Join-Path $PSScriptRoot ..\PowerShell\ConvertFrom-Base64.ps1 -Resolve)
+
+$Name = $Name | ConvertFrom-Base64
+$Value = $Value | ConvertFrom-Base64
+
+Add-Type -AssemblyName System.Configuration
+
+$config = [Configuration.ConfigurationManager]::OpenMachineConfiguration()
+$appSettings = $config.AppSettings.Settings
+if( $appSettings[$Name] )
+{
+    $appSettings[$Name].Value = $Value
+}
+else
+{
+    $appSettings.Add( $Name, $Value )
+}
+$config.Save()

File Carbon/bin/Set-DotNetConnectionString.ps1

+<#
+.SYNOPSIS
+Internal.  Use `Set-DotNetConnectionString` function instead.
+#>
+
+# Copyright 2012 Aaron Jensen
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+[CmdletBinding()]
+param(
+    [Parameter(Mandatory=$true,Position=0)]
+    [string]
+    $Name,
+
+    [Parameter(Mandatory=$true,Position=1)]
+    [string]
+    $Value,
+
+    [Parameter(Position=2)]
+    [string]
+    $ProviderName
+)
+
+Set-StrictMode -Version Latest
+$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
+. (Join-Path $PSScriptRoot ..\PowerShell\ConvertFrom-Base64.ps1 -Resolve)
+
+$Name = $Name | ConvertFrom-Base64
+$Value = $Value | ConvertFrom-Base64
+$ProviderName = $ProviderName | ConvertFrom-Base64
+
+Add-Type -AssemblyName System.Configuration
+
+$config = [Configuration.ConfigurationManager]::OpenMachineConfiguration()
+$connectionStrings = $config.ConnectionStrings.ConnectionStrings
+if( $connectionStrings[$Name] )
+{
+    $connectionStrings.Remove( $Name )
+}
+
+$args = @( $Name, $Value )
+if( $ProviderName )
+{
+    $args += $ProviderName
+}
+$connectionString = New-Object Configuration.ConnectionStringSettings $args
+$connectionStrings.Add( $connectionString )
+
+$config.Save()

File RELEASE NOTES.txt

  * Renamed [Invoke-PowerShell](http://get-carbon.org/help/Invoke-PowerShell.html)'s `Args` parameter to `ArgumentList` (with backwards compatibile `Args` alias).
  * Renamed [Invoke-PowerShell](http://get-carbon.org/help/Invoke-PowerShell.html)'s `Command` parameter to `ScriptBlock` (with backwards-compatible `Command` alias).
  
+ ## Bug Fixes
+ 
+ ### .NET
+
+ * [Set-DotNetAppSetting](http://get-carbon.org/help/Set-DotNetAppSetting.html) and [Set-DotNetConnectionString](http://get-carbon.org/help/Set-DotNetConnectionString.html) weren't able to set .NET 2.0 app settings and connections string when running under PowerShell 3.
+ 
+ 
 # 1.2.0 (25 June 2013)
 
 ## Enhancements

File Test/DotNet/Test-SetDotNetAppSetting.ps1

     Assert-Like $error[0].Exception 'You must supply either or both of the Clr2 and Clr4 switches.'
 }
 
+function Test-ShouldAddAppSettingWithSensitiveCharacters
+{
+    $name = $value = '`1234567890-=qwertyuiop[]\a sdfghjkl;''zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?'
+    Set-DotNetAppSetting -Name $name -Value $value -Framework64 -Clr4
+    Assert-AppSetting -Name $name -Value $value -Framework64 -Clr4
+}
+
 function Assert-AppSetting($Name, $value, [Switch]$Framework, [Switch]$Framework64, [Switch]$Clr2, [Switch]$Clr4)
 {
     $command = {

File Test/DotNet/Test-SetDotNetConnectionString.ps1

     Assert-Like $error[0].Exception 'You must supply either or both of the Clr2 and Clr4 switches.'    
 }
 
+function Test-ShouldAddConnectionStringWithSensitiveCharacters
+{
+    $name = $value = $providerName = '`1234567890-=qwertyuiop[]\a sdfghjkl;''zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?'
+    Set-DotNetConnectionString -Name $name -Value $value -ProviderName $providerName -Framework64 -Clr4
+    Assert-ConnectionString -Name $name -Value $value -ProviderName $providerName -Framework64 -Clr4
+}
+
 function Assert-ConnectionString
 {
     param(