Skip to content

Commit 194a041

Browse files
committed
Adds support for localization in Get-Resource, Search-Resources, Save-Resource and Import-RMConfig
1 parent d85958b commit 194a041

File tree

11 files changed

+316
-42
lines changed

11 files changed

+316
-42
lines changed

src/Lithnet.ResourceManagement.Automation.Installer/Product.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Product Id="*"
55
Name="Lithnet FIM/MIM Service PowerShell Module"
66
Language="1033"
7-
Version="1.0.6022"
7+
Version="1.0.6034"
88
Manufacturer="Lithnet"
99
UpgradeCode="CC6C89F6-8663-46ED-A792-15B1327D8AA8">
1010
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

src/Lithnet.ResourceManagement.Automation/GetResource.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.ResourceManagement.WebServices;
88
using System.Collections;
99
using Lithnet.ResourceManagement.Client;
10+
using System.Globalization;
1011

1112
namespace Lithnet.ResourceManagement.Automation
1213
{
@@ -47,15 +48,26 @@ public class GetResource : PSCmdlet //, IDynamicParameters
4748
[Parameter(ParameterSetName = "GetResource", Mandatory = false, Position = 2)]
4849
public string[] AttributesToGet { get; set; }
4950

51+
[Parameter(ParameterSetName = "GetResourceByKey", Mandatory = false, Position = 5)]
52+
[Parameter(ParameterSetName = "GetResourceByKeys", Mandatory = false, Position = 4)]
53+
[Parameter(ParameterSetName = "GetResource", Mandatory = false, Position = 3)]
54+
public string Locale { get; set; }
55+
5056
protected override void ProcessRecord()
5157
{
5258
ResourceObject resource;
59+
CultureInfo locale = null;
60+
61+
if (this.Locale != null)
62+
{
63+
locale = new CultureInfo(this.Locale);
64+
}
5365

5466
UniqueIdentifier uniqueID = this.ID as UniqueIdentifier;
5567

5668
if (uniqueID != null)
5769
{
58-
resource = RmcWrapper.Client.GetResource(uniqueID, this.AttributesToGet);
70+
resource = RmcWrapper.Client.GetResource(uniqueID, this.AttributesToGet, locale);
5971

6072
if (resource == null)
6173
{
@@ -70,7 +82,7 @@ protected override void ProcessRecord()
7082

7183
if (stringID != null)
7284
{
73-
resource = RmcWrapper.Client.GetResource(stringID, this.AttributesToGet);
85+
resource = RmcWrapper.Client.GetResource(stringID, this.AttributesToGet, locale);
7486

7587
if (resource == null)
7688
{
@@ -85,7 +97,7 @@ protected override void ProcessRecord()
8597

8698
if (guidID != null)
8799
{
88-
resource = RmcWrapper.Client.GetResource(guidID, this.AttributesToGet);
100+
resource = RmcWrapper.Client.GetResource(guidID, this.AttributesToGet, locale);
89101

90102
if (resource == null)
91103
{
@@ -98,7 +110,7 @@ protected override void ProcessRecord()
98110

99111
if (this.AttributeValuePairs != null)
100112
{
101-
resource = RmcWrapper.Client.GetResourceByKey(this.ObjectType, this.HashTableToDictionary(this.AttributeValuePairs), this.AttributesToGet);
113+
resource = RmcWrapper.Client.GetResourceByKey(this.ObjectType, this.HashTableToDictionary(this.AttributeValuePairs), this.AttributesToGet, locale);
102114

103115
if (resource == null)
104116
{
@@ -110,7 +122,7 @@ protected override void ProcessRecord()
110122
}
111123
else
112124
{
113-
resource = RmcWrapper.Client.GetResourceByKey(this.ObjectType, this.AttributeName, this.AttributeValue, this.AttributesToGet);
125+
resource = RmcWrapper.Client.GetResourceByKey(this.ObjectType, this.AttributeName, this.AttributeValue, this.AttributesToGet, locale);
114126

115127
if (resource == null)
116128
{

src/Lithnet.ResourceManagement.Automation/Lithnet.ResourceManagement.Automation.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
3434
<ItemGroup>
35-
<Reference Include="Lithnet.ResourceManagement.Client, Version=1.0.6003.14892, Culture=neutral, processorArchitecture=MSIL">
36-
<HintPath>..\packages\Lithnet.ResourceManagement.Client.1.0.6003.14892\lib\net40\Lithnet.ResourceManagement.Client.dll</HintPath>
35+
<Reference Include="Lithnet.ResourceManagement.Client, Version=1.0.6034.20090, Culture=neutral, processorArchitecture=MSIL">
36+
<HintPath>..\packages\Lithnet.ResourceManagement.Client.1.0.6034.20090\lib\net40\Lithnet.ResourceManagement.Client.dll</HintPath>
3737
<Private>True</Private>
3838
</Reference>
3939
<Reference Include="Microsoft.ResourceManagement">
@@ -110,7 +110,9 @@
110110
<None Include="Examples\Variables.xml">
111111
<SubType>Designer</SubType>
112112
</None>
113-
<None Include="LithnetRMA.Help.pshproj" />
113+
<None Include="LithnetRMA.Help.pshproj">
114+
<SubType>Designer</SubType>
115+
</None>
114116
<None Include="packages.config" />
115117
</ItemGroup>
116118
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

src/Lithnet.ResourceManagement.Automation/LithnetRMA.Help.pshproj

Lines changed: 225 additions & 21 deletions
Large diffs are not rendered by default.

src/Lithnet.ResourceManagement.Automation/LithnetRMA.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@{
1010

1111
# Version number of this module.
12-
ModuleVersion = '1.0.6022'
12+
ModuleVersion = '1.0.6034'
1313

1414
# ID used to uniquely identify this module
1515
GUID = 'd7c36446-aca6-418a-a2a3-cbfc32016a52'

src/Lithnet.ResourceManagement.Automation/SaveResource.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.ResourceManagement.WebServices;
88
using System.Collections;
99
using Lithnet.ResourceManagement.Client;
10+
using System.Globalization;
1011

1112
namespace Lithnet.ResourceManagement.Automation
1213
{
@@ -19,17 +20,27 @@ public class SaveResource : Cmdlet
1920
[Parameter(Mandatory = false)]
2021
public SwitchParameter Parallel { get; set; }
2122

23+
[Parameter(Mandatory = false)]
24+
public string Locale { get; set; }
25+
2226
protected override void ProcessRecord()
2327
{
2428
IEnumerable<RmaObject> creatingObjects = this.Resources.Where(t => t.InternalObject.ModificationType == OperationType.Create).ToList();
2529

30+
CultureInfo locale = null;
31+
32+
if (this.Locale != null)
33+
{
34+
locale = new CultureInfo(this.Locale);
35+
}
36+
2637
if (this.Parallel.IsPresent)
2738
{
28-
RmcWrapper.Client.SaveResourcesParallel(this.Resources.Select(t => t.GetResourceWithAppliedChanges()));
39+
RmcWrapper.Client.SaveResourcesParallel(this.Resources.Select(t => t.GetResourceWithAppliedChanges()), -1, locale);
2940
}
3041
else
3142
{
32-
RmcWrapper.Client.SaveResources(this.Resources.Select(t => t.GetResourceWithAppliedChanges()));
43+
RmcWrapper.Client.SaveResources(this.Resources.Select(t => t.GetResourceWithAppliedChanges()), locale);
3344
}
3445

3546
foreach(RmaObject resource in creatingObjects)

src/Lithnet.ResourceManagement.Automation/SearchResources.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.ResourceManagement.WebServices.WSEnumeration;
99
using System.Collections;
1010
using Lithnet.ResourceManagement.Client;
11-
11+
using System.Globalization;
1212

1313
namespace Lithnet.ResourceManagement.Automation
1414
{
@@ -38,9 +38,19 @@ public class SearchResources : Cmdlet
3838

3939
[Parameter]
4040
public SwitchParameter Descending { get; set; }
41-
41+
42+
[Parameter]
43+
public string Locale { get; set; }
44+
4245
protected override void ProcessRecord()
4346
{
47+
CultureInfo locale = null;
48+
49+
if (this.Locale != null)
50+
{
51+
locale = new CultureInfo(this.Locale);
52+
}
53+
4454
IEnumerable<string> attributes = null;
4555
string filter = this.GetQueryString();
4656

@@ -90,7 +100,7 @@ protected override void ProcessRecord()
90100
}
91101
}
92102

93-
foreach (ResourceObject resource in RmcWrapper.Client.GetResources(filter, pageSize, attributes, sortCriteria))
103+
foreach (ResourceObject resource in RmcWrapper.Client.GetResources(filter, pageSize, attributes, sortCriteria, locale))
94104
{
95105
this.WriteObject(new RmaObject(resource));
96106
count++;

src/Lithnet.ResourceManagement.Automation/SearchResourcesPaged.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.ResourceManagement.WebServices.WSEnumeration;
99
using System.Collections;
1010
using Lithnet.ResourceManagement.Client;
11+
using System.Globalization;
1112

1213
namespace Lithnet.ResourceManagement.Automation
1314
{
@@ -34,9 +35,19 @@ public class SearchResourcesPaged : Cmdlet
3435

3536
[Parameter]
3637
public SwitchParameter Descending { get; set; }
38+
39+
[Parameter]
40+
public string Locale { get; set; }
3741

3842
protected override void ProcessRecord()
3943
{
44+
CultureInfo locale = null;
45+
46+
if (this.Locale != null)
47+
{
48+
locale = new CultureInfo(this.Locale);
49+
}
50+
4051
IEnumerable<string> attributes = null;
4152
string filter = this.GetQueryString();
4253

@@ -71,7 +82,6 @@ protected override void ProcessRecord()
7182
pageSize = 200;
7283
}
7384

74-
7585
List<SortingAttribute> sortCriteria = new List<SortingAttribute>();
7686
if (this.SortAttributes != null)
7787
{
@@ -81,7 +91,7 @@ protected override void ProcessRecord()
8191
}
8292
}
8393

84-
this.WriteObject(new RmaSearchPager(RmcWrapper.Client.GetResourcesPaged(filter, pageSize, attributes, sortCriteria)));
94+
this.WriteObject(new RmaSearchPager(RmcWrapper.Client.GetResourcesPaged(filter, pageSize, attributes, sortCriteria, locale)));
8595
}
8696

8797
private string GetQueryString()

src/Lithnet.ResourceManagement.Automation/SetResourceManagementClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected override void EndProcessing()
5050
}
5151

5252
RmcWrapper.Client = new Client.ResourceManagementClient(baseUri, creds, this.ServicePrincipalName, !this.ForceKerberos);
53+
RmcWrapper.Client.RefreshSchema();
5354

5455
base.EndProcessing();
5556
}

src/Lithnet.ResourceManagement.Automation/XmlConfig/ResourceOperation.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.ObjectModel;
77
using System.Collections;
88
using Lithnet.ResourceManagement.Client;
9+
using System.Globalization;
910

1011
namespace Lithnet.ResourceManagement.Automation
1112
{
@@ -63,6 +64,9 @@ public List<AttributeOperation> AttributeOperations
6364
[XmlAttribute(AttributeName = "resourceType")]
6465
public string ResourceType { get; set; }
6566

67+
[XmlAttribute(AttributeName = "locale")]
68+
public string Locale { get; set; }
69+
6670
[XmlAttribute(AttributeName = "id")]
6771
public string ID { get; set; }
6872

@@ -104,7 +108,9 @@ internal void ExecuteOperation()
104108
this.RaiseLogEvent("Refreshing schema");
105109
RmcWrapper.Client.RefreshSchema();
106110
}
107-
111+
112+
this.ThrowOnLocaleSpecifiedForNonUpdate();
113+
108114
switch (this.Operation)
109115
{
110116
case ResourceOperationType.None:
@@ -137,6 +143,17 @@ internal void ExecuteOperation()
137143
}
138144
}
139145

146+
private void ThrowOnLocaleSpecifiedForNonUpdate()
147+
{
148+
if (this.Locale != null)
149+
{
150+
if (this.Operation != ResourceOperationType.Update)
151+
{
152+
throw new InvalidOperationException("Locale can only be specified for an 'Update' operation. Perform an Add-Update first with the invariant culture values, then perform an update with the culture-specific values");
153+
}
154+
}
155+
}
156+
140157
private void ProcessResourceAdd()
141158
{
142159
this.Resource = RmcWrapper.Client.CreateResource(this.ResourceType);
@@ -159,8 +176,15 @@ private void ProcessResourceUpdate()
159176
{
160177
if (this.Resource == null)
161178
{
162-
this.Resource = RmcWrapper.Client.GetResourceByKey(this.ResourceType, this.GetAnchorValues(), this.AttributesToGet);
163-
179+
CultureInfo locale = null;
180+
181+
if (!string.IsNullOrWhiteSpace(this.Locale))
182+
{
183+
locale = new CultureInfo(this.Locale);
184+
}
185+
186+
this.Resource = RmcWrapper.Client.GetResourceByKey(this.ResourceType, this.GetAnchorValues(), this.AttributesToGet, locale);
187+
164188
if (this.Resource == null)
165189
{
166190
throw new InvalidOperationException(string.Format("An update operation is not valid for the resource operation with ID {0} as the resource does not exist in the FIM service. Consider changing the operation to an 'Add Update' type", this.ID));

0 commit comments

Comments
 (0)