Skip to content

Commit

Permalink
Removes support for composite saves of localized resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ryannewington committed Jul 22, 2016
1 parent 328dae1 commit 5e34c22
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 63 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
20 changes: 0 additions & 20 deletions src/Lithnet.ResourceManagement.Client.UnitTests/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ namespace Lithnet.ResourceManagement.Client.UnitTests
[TestClass]
public class GetTests
{
[TestMethod]
public void TestLocale()
{
ResourceManagementClient client = new ResourceManagementClient();

try
{
//ResourceObject resource = client.GetResourceByKey("AttributeTypeDescription", "Name", "DisplayName", UnitTestHelper.TestCulture);

ResourceObject resource = client.GetResource("7dcc83b6-8be7-4717-a1ac-62b0b1b7ce29", UnitTestHelper.TestCulture);
Assert.AreEqual(UnitTestHelper.TestCulture, resource.Locale);
//Nome visualizzato
}
finally
{

}
}


[TestMethod]
public void GetObjectByIDWithAllAttributes()
{
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
19 changes: 7 additions & 12 deletions src/Lithnet.ResourceManagement.Client/ResourceManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public void DeleteResource(string id)
/// <param name="resources">The resources to update</param>
public void SaveResources(params ResourceObject[] resources)
{
this.SaveResources(resources, null);
this.SaveResources(resources);
}

/// <summary>
Expand All @@ -385,17 +385,12 @@ public void SaveResources(params ResourceObject[] resources)
/// <param name="resources">The collection of resources to update</param>
public void SaveResources(IEnumerable<ResourceObject> resources)
{
this.SaveResources(resources, null);
}
IList<ResourceObject> resourceObjects = resources as IList<ResourceObject> ?? resources.ToList();

/// <summary>
/// Saves the specified resources in the resource management service. Updates and Adds are committed as a single composite operation.
/// </summary>
/// <param name="resources">The collection of resources to update</param>
/// <param name="locale">The localization culture to use when saving the object</param>
public void SaveResources(IEnumerable<ResourceObject> resources, CultureInfo locale)
{
IEnumerable<ResourceObject> resourceObjects = resources as IList<ResourceObject> ?? resources.ToList();
if (resourceObjects.Any(t => t.Locale != null))
{
throw new InvalidOperationException("Cannot perform a composite save on a localized resource");
}

List<ResourceObject> objectsToCreate = resourceObjects.Where(t => t.ModificationType == OperationType.Create).ToList();
if (objectsToCreate.Count > 0)
Expand All @@ -420,7 +415,7 @@ public void SaveResources(IEnumerable<ResourceObject> resources, CultureInfo loc

if (objectsToUpdate.Count > 0)
{
this.resourceClient.Put(objectsToUpdate, locale);
this.resourceClient.Put(objectsToUpdate);

foreach (ResourceObject resource in objectsToUpdate)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Lithnet.ResourceManagement.Client/ResourceObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ 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>
/// <param name="locale">The localization culture that this object is represented as</param>
private ResourceObject(OperationType opType, ResourceManagementClient client, CultureInfo locale)
{
this.ModificationType = opType;
Expand Down Expand Up @@ -215,6 +216,7 @@ 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>
/// <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)
{
Expand All @@ -226,6 +228,7 @@ 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>
/// <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)
{
Expand All @@ -237,6 +240,7 @@ 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>
/// <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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ internal static Message CreatePutMessage(ResourceObject resource, CultureInfo lo
return message;
}

internal static Message CreatePutMessage(IEnumerable<ResourceObject> resources, CultureInfo locale)
internal static Message CreatePutMessage(IEnumerable<ResourceObject> resources)
{
int count = resources.Count();
if (count == 0)
Expand All @@ -158,22 +158,16 @@ internal static Message CreatePutMessage(IEnumerable<ResourceObject> resources,
}
else if (count == 1)
{
return MessageComposer.CreatePutMessage(resources.First(), locale);
return MessageComposer.CreatePutMessage(resources.First(), null);
}

Put op = new Put();

op.Dialect = Namespaces.RMIdentityAttributeType;
List<PutFragmentType> fragments = new List<PutFragmentType>();
CultureInfo lastCulture = resources.First().Locale;

foreach (ResourceObject resource in resources)
{
if (lastCulture != resource.Locale)
{
throw new NotSupportedException();
}

foreach (PutFragmentType fragment in resource.GetPutFragements())
{
fragment.TargetIdentifier = resource.ObjectID.Value;
Expand All @@ -194,11 +188,6 @@ internal static Message CreatePutMessage(IEnumerable<ResourceObject> resources,
message.AddHeader(Namespaces.ResourceManagement, HeaderConstants.CompositeTypeOperation, null);
message.AddHeader(HeaderConstants.ResourceReferenceProperty, resources.Select(t => t.ObjectID.ToString()).ToCommaSeparatedString());

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

return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,14 @@ public void Put(ResourceObject resource, CultureInfo locale)
}
}

public void Put(IEnumerable<ResourceObject> resources, CultureInfo locale)
public void Put(IEnumerable<ResourceObject> resources)
{
if (resources == null)
{
throw new ArgumentNullException("resources");
}

if (resources.Any(t => t.Locale != null && t.Locale != locale))
{
foreach (ResourceObject resource in resources)
{
this.Put(resource, locale);
}

return;
}

using (Message message = MessageComposer.CreatePutMessage(resources, locale))

using (Message message = MessageComposer.CreatePutMessage(resources))
{
if (message == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public int CurrentIndex
/// <param name="pageSize">The page size used in the search operation</param>
/// <param name="searchClient">The client proxy used for performing the search</param>
/// <param name="client">The client used to convert response data into ResourceObjects</param>
/// <param name="locale">The localization culture that the search results are represented as</param>
internal SearchResultPager(EnumerateResponse response, int pageSize, SearchClient searchClient, ResourceManagementClient client, CultureInfo locale)
{
if (response == null)
Expand Down

0 comments on commit 5e34c22

Please sign in to comment.