Skip to content

Commit

Permalink
Merge locale-support into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ryannewington committed Jul 22, 2016
2 parents ffba62f + 5e34c22 commit 6d8c856
Show file tree
Hide file tree
Showing 10 changed files with 584 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.ResourceManagement, Version=4.1.3634.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\Microsoft.ResourceManagement.dll</HintPath>
<Reference Include="Microsoft.ResourceManagement">
<HintPath>..\Lithnet.ResourceManagement.Client\bin\Release (nuget)\Microsoft.ResourceManagement.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.ResourceManagement">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\Microsoft.ResourceManagement.dll</HintPath>
<HintPath>..\Lithnet.ResourceManagement.Client\bin\Release (nuget)\Microsoft.ResourceManagement.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
using Lithnet.ResourceManagement.Client;
using Microsoft.ResourceManagement.WebServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Globalization;

namespace Lithnet.ResourceManagement.Client.UnitTests
{
public static class UnitTestHelper
{
internal static ResourceManagementClient client = new ResourceManagementClient();

internal const string TestLocale = "it-IT";
internal static CultureInfo TestCulture = new CultureInfo(UnitTestHelper.TestLocale);

public static string TestDataString1 = "testString1";
public static string TestDataString2 = "testString2";
public static string TestDataString3 = "testString3";
Expand Down Expand Up @@ -84,6 +88,8 @@ public static class UnitTestHelper
internal const string AttributeBinaryMV = "ut_mvbinary";
internal const string AttributeBooleanSV = "ut_svboolean";



static UnitTestHelper()
{
UnitTestHelper.PrepareRMSForUnitTests();
Expand Down
535 changes: 486 additions & 49 deletions src/Lithnet.ResourceManagement.Client/ResourceManagementClient.cs

Large diffs are not rendered by default.

41 changes: 28 additions & 13 deletions src/Lithnet.ResourceManagement.Client/ResourceObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Runtime.Serialization;
using System.Collections.ObjectModel;
using Lithnet.ResourceManagement.Client;
using System.Globalization;

namespace Lithnet.ResourceManagement.Client
{
Expand All @@ -25,7 +26,7 @@ public class ResourceObject : ISerializable
/// The client object used to pass save, update, and create operations to
/// </summary>
private ResourceManagementClient client;

/// <summary>
/// The internal representation of attributes of the object
/// </summary>
Expand Down Expand Up @@ -78,6 +79,11 @@ public string ObjectTypeName
/// </summary>
public ObjectTypeDefinition ObjectType { get; private set; }

/// <summary>
/// Gets the localization culture of this object
/// </summary>
public CultureInfo Locale { get; private set; }

/// <summary>
/// Gets the collection of attributes and values associated with this object
/// </summary>
Expand Down Expand Up @@ -115,7 +121,7 @@ public UniqueIdentifier ObjectID
}

return newId;

}
}
}
Expand Down Expand Up @@ -143,11 +149,13 @@ public string DisplayName
/// </summary>
/// <param name="opType">The type of modification to set on the object</param>
/// <param name="client">The client used for further operations on this object</param>
private ResourceObject(OperationType opType, ResourceManagementClient client)
/// <param name="locale">The localization culture that this object is represented as</param>
private ResourceObject(OperationType opType, ResourceManagementClient client, CultureInfo locale)
{
this.ModificationType = opType;
this.attributes = new AttributeValueCollection();
this.client = client;
this.Locale = locale;
}

/// <summary>
Expand All @@ -166,7 +174,7 @@ protected ResourceObject(SerializationInfo info, StreamingContext context)
/// <param name="type">The object type that this object will represent</param>
/// <param name="client">The client used for further operations on this object</param>
internal ResourceObject(string type, ResourceManagementClient client)
: this(OperationType.Create, client)
: this(OperationType.Create, client, null)
{
if (!ResourceManagementSchema.ObjectTypes.ContainsKey(type))
{
Expand All @@ -188,7 +196,7 @@ internal ResourceObject(string type, ResourceManagementClient client)
/// <param name="id">The ID of the object</param>
/// <param name="client">The client used for further operations on this object</param>
internal ResourceObject(string type, UniqueIdentifier id, ResourceManagementClient client)
: this(OperationType.Update, client)
: this(OperationType.Update, client, null)
{
if (!ResourceManagementSchema.ObjectTypes.ContainsKey(type))
{
Expand All @@ -208,8 +216,9 @@ internal ResourceObject(string type, UniqueIdentifier id, ResourceManagementClie
/// </summary>
/// <param name="objectElements">An enumeration of XmlElements that make up a partial response</param>
/// <param name="client">The client used for further operations on this object</param>
internal ResourceObject(IEnumerable<XmlElement> objectElements, ResourceManagementClient client)
: this(OperationType.Update, client)
/// <param name="locale">The localization culture that this object is represented as</param>
internal ResourceObject(IEnumerable<XmlElement> objectElements, ResourceManagementClient client, CultureInfo locale)
: this(OperationType.Update, client, locale)
{
this.PopulateResourceFromPartialResponse(objectElements);
}
Expand All @@ -219,8 +228,9 @@ internal ResourceObject(IEnumerable<XmlElement> objectElements, ResourceManageme
/// </summary>
/// <param name="reader">An XmlDictionaryReader containing the full object definition</param>
/// <param name="client">The client used for further operations on this object</param>
internal ResourceObject(XmlDictionaryReader reader, ResourceManagementClient client)
: this(OperationType.Update, client)
/// <param name="locale">The localization culture that this object is represented as</param>
internal ResourceObject(XmlDictionaryReader reader, ResourceManagementClient client, CultureInfo locale)
: this(OperationType.Update, client, locale)
{
this.PopulateResourceFromFullObject(reader);
}
Expand All @@ -230,8 +240,9 @@ internal ResourceObject(XmlDictionaryReader reader, ResourceManagementClient cli
/// </summary>
/// <param name="element">An XmlElement containing definition of the object from a set of fragments obtained from an enumeration response</param>
/// <param name="client">The client used for further operations on this object</param>
internal ResourceObject(XmlElement element, ResourceManagementClient client)
: this(OperationType.Update, client)
/// <param name="locale">The localization culture that this object is represented as</param>
internal ResourceObject(XmlElement element, ResourceManagementClient client, CultureInfo locale)
: this(OperationType.Update, client, locale)
{
this.PopulateResourceFromFragment(element);
}
Expand Down Expand Up @@ -301,7 +312,7 @@ public void Save()
break;

case OperationType.Update:
this.Client.PutResource(this);
this.Client.PutResource(this, this.Locale);
break;

case OperationType.Delete:
Expand Down Expand Up @@ -534,6 +545,11 @@ private void SetInitialAttributeValues(Dictionary<string, List<string>> values)
{
this.attributes.Add(d.SystemName, new AttributeValue(d, kvp.Value.First()));
}

if (d.SystemName == AttributeNames.Locale)
{
this.Locale = new CultureInfo(kvp.Value.First());
}
}
}

Expand Down Expand Up @@ -688,7 +704,6 @@ private void DeserializeObject(SerializationInfo info)

foreach (SerializationEntry entry in info)
{

IEnumerable<string> entryValues = entry.Value as IEnumerable<string>;

if (entryValues != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ public static class AttributeNames
/// The WorkflowInstance attribute
/// </summary>
public const string WorkflowInstance = "WorkflowInstance";

/// <summary>
/// The Locale attribute
/// </summary>
public const string Locale = "Locale";
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.ResourceManagement.WebServices;
using Microsoft.ResourceManagement.WebServices.IdentityManagementOperation;
using Microsoft.ResourceManagement.WebServices.WSEnumeration;
using Microsoft.ResourceManagement.WebServices.WSResourceManagement;

namespace Lithnet.ResourceManagement.Client.ResourceManagementService
{
Expand All @@ -19,7 +20,7 @@ internal static class MessageComposer

internal static Message CreateGetMessage(UniqueIdentifier id)
{
return CreateGetMessage(id, null, CultureInfo.InvariantCulture);
return CreateGetMessage(id, null, null);
}

internal static Message CreateGetMessage(UniqueIdentifier id, IEnumerable<string> attributes, CultureInfo locale)
Expand All @@ -30,7 +31,7 @@ internal static Message CreateGetMessage(UniqueIdentifier id, IEnumerable<string
{
op = new Get();
op.Dialect = Namespaces.RMIdentityAttributeType;
op.Expressions = MessageComposer.AddMandatoryAttributes(attributes).ToArray();
op.Expressions = MessageComposer.AddMandatoryAttributes(attributes, locale).ToArray();
}

Message message;
Expand All @@ -45,7 +46,11 @@ internal static Message CreateGetMessage(UniqueIdentifier id, IEnumerable<string
message.AddHeader(Namespaces.IdMDirectoryAccess, HeaderConstants.IdentityManagementOperation, null, true);
}

message.AddHeader("Locale", locale ?? CultureInfo.InvariantCulture);
if (locale != null)
{
message.AddHeader(AttributeNames.Locale, locale);
}

message.AddHeader(HeaderConstants.ResourceReferenceProperty, id.ToString());

return message;
Expand Down Expand Up @@ -118,7 +123,7 @@ internal static Message CreateCreateMessage(IEnumerable<ResourceObject> resource
return message;
}

internal static Message CreatePutMessage(ResourceObject resource)
internal static Message CreatePutMessage(ResourceObject resource, CultureInfo locale)
{
Put op = new Put();

Expand All @@ -136,6 +141,11 @@ internal static Message CreatePutMessage(ResourceObject resource)
message.AddHeader(Namespaces.IdMDirectoryAccess, HeaderConstants.IdentityManagementOperation, null, true);
message.AddHeader(HeaderConstants.ResourceReferenceProperty, resource.ObjectID.ToString());

if (locale != null || resource.Locale != null)
{
message.AddHeader(AttributeNames.Locale, locale ?? resource.Locale);
}

return message;
}

Expand All @@ -148,13 +158,14 @@ internal static Message CreatePutMessage(IEnumerable<ResourceObject> resources)
}
else if (count == 1)
{
return MessageComposer.CreatePutMessage(resources.First());
return MessageComposer.CreatePutMessage(resources.First(), null);
}

Put op = new Put();

op.Dialect = Namespaces.RMIdentityAttributeType;
List<PutFragmentType> fragments = new List<PutFragmentType>();

foreach (ResourceObject resource in resources)
{
foreach (PutFragmentType fragment in resource.GetPutFragements())
Expand Down Expand Up @@ -218,15 +229,15 @@ internal static Message CreateDeleteMessage(IEnumerable<UniqueIdentifier> ids)
return message;
}

internal static Message CreateEnumerateMessage(string filter, int pageSize, IEnumerable<string> attributes, IEnumerable<SortingAttribute> sortingAttributes)
internal static Message CreateEnumerateMessage(string filter, int pageSize, IEnumerable<string> attributes, IEnumerable<SortingAttribute> sortingAttributes, CultureInfo locale)
{
Enumerate request = new Enumerate();
request.Filter = new FilterType(filter);
request.MaxElements = pageSize < 0 ? MessageComposer.DefaultPageSize : pageSize.ToString();

if (attributes != null)
{
request.Selection = MessageComposer.AddMandatoryAttributes(attributes).ToArray();
request.Selection = MessageComposer.AddMandatoryAttributes(attributes, locale).ToArray();
}

if (sortingAttributes != null && sortingAttributes.Any())
Expand All @@ -236,6 +247,12 @@ internal static Message CreateEnumerateMessage(string filter, int pageSize, IEnu
request.Sorting.SortingAttributes = sortingAttributes.ToArray();
}

if (locale != null)
{
request.LocalePreferences = new LocalePreferenceType[1];
request.LocalePreferences[0] = new LocalePreferenceType(locale, 1);
}

Message requestMessage = Message.CreateMessage(MessageVersion.Default, Namespaces.Enumerate, new SerializerBodyWriter(request));
requestMessage.AddHeader(Namespaces.ResourceManagement, "IncludeCount", null);

Expand Down Expand Up @@ -263,11 +280,11 @@ internal static Message CreateApprovalMessage(UniqueIdentifier workflowID, Appro
{
Message message = Message.CreateMessage(MessageVersion.Default, Namespaces.Create, new SerializerBodyWriter(response));
message.Headers.Add(new ContextHeader(workflowID.Value));

return message;
}

private static IEnumerable<string> AddMandatoryAttributes(IEnumerable<string> attributes)
private static IEnumerable<string> AddMandatoryAttributes(IEnumerable<string> attributes, CultureInfo locale)
{
HashSet<string> set = new HashSet<string>();

Expand All @@ -281,6 +298,11 @@ private static IEnumerable<string> AddMandatoryAttributes(IEnumerable<string> at
set.Add(item);
}

if (locale != null)
{
set.Add(AttributeNames.Locale);
}

return set;
}

Expand Down
Loading

0 comments on commit 6d8c856

Please sign in to comment.