From 5e34c2269248ff7b46b024ee22182e2fb3437aee Mon Sep 17 00:00:00 2001 From: ryannewington Date: Sat, 23 Jul 2016 09:46:08 +1000 Subject: [PATCH] Removes support for composite saves of localized resources --- ...urceManagement.Client.Help.Examples.csproj | 5 ++--- .../GetTests.cs | 20 ------------------- ...ResourceManagement.Client.UnitTests.csproj | 3 +-- .../ResourceManagementClient.cs | 19 +++++++----------- .../ResourceObject.cs | 4 ++++ .../ServiceImplementation/MessageComposer.cs | 15 ++------------ .../ServiceImplementation/ResourceClient.cs | 16 +++------------ .../SearchResultPager.cs | 1 + 8 files changed, 20 insertions(+), 63 deletions(-) diff --git a/src/Lithnet.ResourceManagement.Client.Help.Examples/Lithnet.ResourceManagement.Client.Help.Examples.csproj b/src/Lithnet.ResourceManagement.Client.Help.Examples/Lithnet.ResourceManagement.Client.Help.Examples.csproj index 5feb133..d3a4f9b 100644 --- a/src/Lithnet.ResourceManagement.Client.Help.Examples/Lithnet.ResourceManagement.Client.Help.Examples.csproj +++ b/src/Lithnet.ResourceManagement.Client.Help.Examples/Lithnet.ResourceManagement.Client.Help.Examples.csproj @@ -32,9 +32,8 @@ 4 - - False - ..\lib\Microsoft.ResourceManagement.dll + + ..\Lithnet.ResourceManagement.Client\bin\Release (nuget)\Microsoft.ResourceManagement.dll diff --git a/src/Lithnet.ResourceManagement.Client.UnitTests/GetTests.cs b/src/Lithnet.ResourceManagement.Client.UnitTests/GetTests.cs index 76110dd..e3288b5 100644 --- a/src/Lithnet.ResourceManagement.Client.UnitTests/GetTests.cs +++ b/src/Lithnet.ResourceManagement.Client.UnitTests/GetTests.cs @@ -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() { diff --git a/src/Lithnet.ResourceManagement.Client.UnitTests/Lithnet.ResourceManagement.Client.UnitTests.csproj b/src/Lithnet.ResourceManagement.Client.UnitTests/Lithnet.ResourceManagement.Client.UnitTests.csproj index 6815717..b69a49b 100644 --- a/src/Lithnet.ResourceManagement.Client.UnitTests/Lithnet.ResourceManagement.Client.UnitTests.csproj +++ b/src/Lithnet.ResourceManagement.Client.UnitTests/Lithnet.ResourceManagement.Client.UnitTests.csproj @@ -49,8 +49,7 @@ - False - ..\lib\Microsoft.ResourceManagement.dll + ..\Lithnet.ResourceManagement.Client\bin\Release (nuget)\Microsoft.ResourceManagement.dll diff --git a/src/Lithnet.ResourceManagement.Client/ResourceManagementClient.cs b/src/Lithnet.ResourceManagement.Client/ResourceManagementClient.cs index bab239e..782506a 100644 --- a/src/Lithnet.ResourceManagement.Client/ResourceManagementClient.cs +++ b/src/Lithnet.ResourceManagement.Client/ResourceManagementClient.cs @@ -376,7 +376,7 @@ public void DeleteResource(string id) /// The resources to update public void SaveResources(params ResourceObject[] resources) { - this.SaveResources(resources, null); + this.SaveResources(resources); } /// @@ -385,17 +385,12 @@ public void SaveResources(params ResourceObject[] resources) /// The collection of resources to update public void SaveResources(IEnumerable resources) { - this.SaveResources(resources, null); - } + IList resourceObjects = resources as IList ?? resources.ToList(); - /// - /// Saves the specified resources in the resource management service. Updates and Adds are committed as a single composite operation. - /// - /// The collection of resources to update - /// The localization culture to use when saving the object - public void SaveResources(IEnumerable resources, CultureInfo locale) - { - IEnumerable resourceObjects = resources as IList ?? resources.ToList(); + if (resourceObjects.Any(t => t.Locale != null)) + { + throw new InvalidOperationException("Cannot perform a composite save on a localized resource"); + } List objectsToCreate = resourceObjects.Where(t => t.ModificationType == OperationType.Create).ToList(); if (objectsToCreate.Count > 0) @@ -420,7 +415,7 @@ public void SaveResources(IEnumerable resources, CultureInfo loc if (objectsToUpdate.Count > 0) { - this.resourceClient.Put(objectsToUpdate, locale); + this.resourceClient.Put(objectsToUpdate); foreach (ResourceObject resource in objectsToUpdate) { diff --git a/src/Lithnet.ResourceManagement.Client/ResourceObject.cs b/src/Lithnet.ResourceManagement.Client/ResourceObject.cs index d292826..19a6187 100644 --- a/src/Lithnet.ResourceManagement.Client/ResourceObject.cs +++ b/src/Lithnet.ResourceManagement.Client/ResourceObject.cs @@ -149,6 +149,7 @@ public string DisplayName /// /// The type of modification to set on the object /// The client used for further operations on this object + /// The localization culture that this object is represented as private ResourceObject(OperationType opType, ResourceManagementClient client, CultureInfo locale) { this.ModificationType = opType; @@ -215,6 +216,7 @@ internal ResourceObject(string type, UniqueIdentifier id, ResourceManagementClie /// /// An enumeration of XmlElements that make up a partial response /// The client used for further operations on this object + /// The localization culture that this object is represented as internal ResourceObject(IEnumerable objectElements, ResourceManagementClient client, CultureInfo locale) : this(OperationType.Update, client, locale) { @@ -226,6 +228,7 @@ internal ResourceObject(IEnumerable objectElements, ResourceManageme /// /// An XmlDictionaryReader containing the full object definition /// The client used for further operations on this object + /// The localization culture that this object is represented as internal ResourceObject(XmlDictionaryReader reader, ResourceManagementClient client, CultureInfo locale) : this(OperationType.Update, client, locale) { @@ -237,6 +240,7 @@ internal ResourceObject(XmlDictionaryReader reader, ResourceManagementClient cli /// /// An XmlElement containing definition of the object from a set of fragments obtained from an enumeration response /// The client used for further operations on this object + /// The localization culture that this object is represented as internal ResourceObject(XmlElement element, ResourceManagementClient client, CultureInfo locale) : this(OperationType.Update, client, locale) { diff --git a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/MessageComposer.cs b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/MessageComposer.cs index bddfc04..d150c5e 100644 --- a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/MessageComposer.cs +++ b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/MessageComposer.cs @@ -149,7 +149,7 @@ internal static Message CreatePutMessage(ResourceObject resource, CultureInfo lo return message; } - internal static Message CreatePutMessage(IEnumerable resources, CultureInfo locale) + internal static Message CreatePutMessage(IEnumerable resources) { int count = resources.Count(); if (count == 0) @@ -158,22 +158,16 @@ internal static Message CreatePutMessage(IEnumerable 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 fragments = new List(); - 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; @@ -194,11 +188,6 @@ internal static Message CreatePutMessage(IEnumerable 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; } diff --git a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs index 3a9f5ad..42b84da 100644 --- a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs +++ b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs @@ -41,24 +41,14 @@ public void Put(ResourceObject resource, CultureInfo locale) } } - public void Put(IEnumerable resources, CultureInfo locale) + public void Put(IEnumerable 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) { diff --git a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/SearchResultPager.cs b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/SearchResultPager.cs index fd05a53..3f11cfe 100644 --- a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/SearchResultPager.cs +++ b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/SearchResultPager.cs @@ -80,6 +80,7 @@ public int CurrentIndex /// The page size used in the search operation /// The client proxy used for performing the search /// The client used to convert response data into ResourceObjects + /// The localization culture that the search results are represented as internal SearchResultPager(EnumerateResponse response, int pageSize, SearchClient searchClient, ResourceManagementClient client, CultureInfo locale) { if (response == null)