Skip to content

Commit

Permalink
Closes #116 Extend cmdlet Set-IshSetting and Get-IshSetting with -Val…
Browse files Browse the repository at this point in the history
…ueType parameter to allow element names
  • Loading branch information
ddemeyer committed Apr 8, 2021
1 parent 322421f commit ccaba28
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Source/ISHRemote/Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Minor>12</Minor>
<Build>$([MSBuild]::Add($([MSBuild]::Multiply(1200, $([MSBuild]::Subtract($([System.DateTime]::UtcNow.Year), 2015)))), $([MSBuild]::Add($([MSBuild]::Multiply(100, $([System.DateTime]::UtcNow.Month))),$([System.DateTime]::UtcNow.Day)))))</Build>
<!-- <AdvBuild>$([System.DateTime]::UtcNow.ToString("HHmmss"))</AdvBuild> -->
<Revision>8</Revision>
<Revision>9</Revision>
<ModuleVersion>$(Major).$(Minor).0.$(Revision)</ModuleVersion>
<ModuleBuildVersion>$(Major).$(Minor).$(Build).$(Revision)</ModuleBuildVersion>
<FullModuleBuildVersion>$(Major).$(Minor).$(Revision)</FullModuleBuildVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ Describe “Get-IshSetting" -Tags "Read" {
}

Context Get-IshSetting ParameterGroup returns string object" {
It "Parameter IshSession implicit" {
It "Parameter FieldName" {
$fieldValue = Get-IshSetting -IShSession $ishSession -FieldName "NAME"
$fieldValue.GetType().Name | Should BeExactly "String"
$fieldValue | Should Be "Configuration card"
}
It "Parameter ValueType" {
$fieldValue = Get-IshSetting -FieldName FISHSYSTEMRESOLUTION -ValueType Element
$fieldValue.StartsWith('VRES') | Should Be $true
}
}

Context Get-IshSetting ParameterGroup returns string FileInfo object" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public sealed class GetIshSetting : SettingsCmdlet
[ValidateNotNullOrEmpty]
public string FieldName { get; set; }

/// <summary>
/// <para type="description">The value type</para>
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
public Enumerations.ValueType ValueType
{
get { return _valueType; }
set { _valueType = value; }
}

/// <summary>
/// <para type="description">File on the Windows filesystem where to save the retrieved setting</para>
/// </summary>
Expand All @@ -112,6 +122,13 @@ public sealed class GetIshSetting : SettingsCmdlet
[ValidateNotNullOrEmpty]
public SwitchParameter Force { get; set; }

#region Private fields
/// <summary>
/// Private fields to store the parameters and provide a default for non-mandatory parameters
/// </summary>
private Enumerations.ValueType _valueType = Enumerations.ValueType.Value;
#endregion

protected override void BeginProcessing()
{
if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
Expand All @@ -135,7 +152,7 @@ protected override void ProcessRecord()
}
else if (FieldName != null)
{
requestedMetadata.AddField(new IshRequestedMetadataField(FieldName, Enumerations.Level.None, Enumerations.ValueType.Value));
requestedMetadata.AddField(new IshRequestedMetadataField(FieldName, Enumerations.Level.None, ValueType));
}

var metadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, requestedMetadata, Enumerations.ActionMode.Read);
Expand All @@ -155,7 +172,7 @@ protected override void ProcessRecord()
Directory.CreateDirectory(Path.GetDirectoryName(FilePath));
var fileMode = (Force.IsPresent) ? FileMode.Create : FileMode.CreateNew;

string value = ishFields.GetFieldValue(FieldName, Enumerations.Level.None, Enumerations.ValueType.Value);
string value = ishFields.GetFieldValue(FieldName, Enumerations.Level.None, ValueType);
if (!String.IsNullOrEmpty(value))
{
try
Expand Down Expand Up @@ -203,7 +220,7 @@ protected override void ProcessRecord()
else
{
WriteVerbose("returned object count[1]");
WriteObject(ishFields.GetFieldValue(FieldName, Enumerations.Level.None, Enumerations.ValueType.Value));
WriteObject(ishFields.GetFieldValue(FieldName, Enumerations.Level.None, ValueType));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,27 @@ namespace Trisoft.ISHRemote.Cmdlets.Settings
/// </example>
/// <example>
/// <code>
/// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential "username"
/// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
/// Set-IshSetting -FieldName FISHLCURI -Value https://something/deleteThis
/// </code>
/// <para>New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Update CTCONFIGURATION field with the presented value.</para>
/// </example>
/// <example>
/// <code>
/// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential "username"
/// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
/// Set-IshSetting -FieldName FISHLCURI
/// </code>
/// <para>New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Update CTCONFIGURATION field with the value empty string ("").</para>
/// </example>
/// <example>
/// <code>
/// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
/// $originalValue = Get-IshSetting -FieldName FISHENABLEOUTOFDATE -ValueType Element
/// Set-IshSetting -FieldName FISHENABLEOUTOFDATE -ValueType Element -Value $true
/// Set-IshSetting -FieldName FISHENABLEOUTOFDATE -ValueType Element -Value $originalValue
/// </code>
/// <para>New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Update CTCONFIGURATION field with the value empty string ("").</para>
/// </example>
[Cmdlet(VerbsCommon.Set, "IshSetting", SupportsShouldProcess = true)]
[OutputType(typeof(IshField))]
public sealed class SetIshSetting : SettingsCmdlet
Expand Down Expand Up @@ -120,6 +129,16 @@ public sealed class SetIshSetting : SettingsCmdlet
[ValidateNotNullOrEmpty]
public string Value { get; set; }

/// <summary>
/// <para type="description">The value type</para>
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ValueGroup")]
public Enumerations.ValueType ValueType
{
get { return _valueType; }
set { _valueType = value; }
}

/// <summary>
/// <para type="description">File on the Windows filesystem where to read the setting from</para>
/// </summary>
Expand All @@ -138,6 +157,13 @@ public sealed class SetIshSetting : SettingsCmdlet
[ValidateNotNullOrEmpty]
public IshField[] RequiredCurrentMetadata { get; set; }

#region Private fields
/// <summary>
/// Private fields to store the parameters and provide a default for non-mandatory parameters
/// </summary>
private Enumerations.ValueType _valueType = Enumerations.ValueType.Value;
#endregion

protected override void BeginProcessing()
{
if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
Expand Down Expand Up @@ -184,7 +210,7 @@ protected override void ProcessRecord()
else
{
Value = Value ?? ""; // if the value is not offered we presumse empty string ("")
metadata.AddField(new IshMetadataField(FieldName, Enumerations.Level.None, Enumerations.ValueType.Value, Value));
metadata.AddField(new IshMetadataField(FieldName, Enumerations.Level.None, ValueType, Value));
}

if (ShouldProcess("CTCONFIGURATION"))
Expand Down

0 comments on commit ccaba28

Please sign in to comment.