Skip to content

Commit

Permalink
#128 Moves the Value element of a pre-value into the element value
Browse files Browse the repository at this point in the history
moves it from attribute Value , also has legacy support so old syncs
where value is an attribute will still work (but a new sync is always
recommended on a version bump)
  • Loading branch information
KevinJump committed May 20, 2017
1 parent d72ed4a commit 9d1753e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Jumoo.uSync.Core/Helpers/uSyncValueMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public string MapToId(XElement valueNode, PreValue preVal)

// at the end we remove the zzusync
Regex regx = new Regex(@"\d+");
var value = regx.Replace(valueNode.Attribute("Value").Value, "$0:zzusync");
var value = regx.Replace(valueNode.Value, "$0:zzusync");

var mapGuid = valueNode.Attribute("MapGuid");
if (mapGuid == null)
Expand Down
20 changes: 13 additions & 7 deletions Jumoo.uSync.Core/Serializers/DataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ internal override SyncAttempt<IDataTypeDefinition> DesearlizeSecondPassCore(IDat

private XElement DeserializeGetMappedValues(XElement node, IDictionary<string, PreValue> preValues )
{

XElement nodeCopy = new XElement(node);
var id = nodeCopy.Attribute("Id").ValueOrDefault(string.Empty);

Expand All @@ -188,6 +187,12 @@ private XElement DeserializeGetMappedValues(XElement node, IDictionary<string, P

var preValuesElements = nodeCopy.Element("PreValues");

// value use to be an attrib - now it's a value
foreach (var legacyElement in preValuesElements.Descendants().Where(x => x.Attribute("Value") != null))
{
legacyElement.Value = legacyElement.Attribute("Value").Value;
}

if (mapper != null && preValuesElements != null && preValuesElements.HasElements)
{
foreach (var preValueNode in preValuesElements.Descendants()
Expand All @@ -203,7 +208,8 @@ private XElement DeserializeGetMappedValues(XElement node, IDictionary<string, P
if (!string.IsNullOrEmpty(value))
{
LogHelper.Debug<DataTypeSerializer>("Setting Mapped Value: {0}", () => value);
preValueNode.Attribute("Value").Value = value;
preValueNode.Value = value;
// preValueNode.Attribute("Value").Value = value;
}

preValueNode.Attribute("MapGuid").Remove();
Expand Down Expand Up @@ -239,9 +245,9 @@ private void DeserializeUpdatePreValues(IDataTypeDefinition item, XElement node)
if (preValNode != null)
{
// set the value of preValue value to the value of the value attribute :)
if (preValue.Value.Value != preValNode.Attribute("Value").Value)
if (preValue.Value.Value != preValNode.Value)
{
preValue.Value.Value = preValNode.Attribute("Value").Value;
preValue.Value.Value = preValNode.Value;
}
}
else
Expand All @@ -268,7 +274,7 @@ private void DeserializeUpdatePreValues(IDataTypeDefinition item, XElement node)
foreach (var nodeValue in preValueRootNode.Elements("PreValue"))
{
var alias = nodeValue.Attribute("Alias").ValueOrDefault(string.Empty);
var value = nodeValue.Attribute("Value").ValueOrDefault(string.Empty);
var value = nodeValue.ValueOrDefault(string.Empty);

if (!string.IsNullOrEmpty(alias))
{
Expand Down Expand Up @@ -333,8 +339,8 @@ private XElement SerializePreValues(IDataTypeDefinition item, XElement node)
var preValueValue = preValue.Value;

XElement preValueNode = new XElement("PreValue",
new XAttribute("Id", preValue.Id.ToString()),
new XAttribute("Value", String.IsNullOrEmpty(preValueValue) ? "" : preValueValue));
new XAttribute("Id", preValue.Id.ToString()));
preValueNode.Add(new XCData(String.IsNullOrEmpty(preValueValue) ? "" : preValueValue));

if (!itemPreValuePair.Key.StartsWith("zzzuSync"))
preValueNode.Add(new XAttribute("Alias", itemPreValuePair.Key));
Expand Down

0 comments on commit 9d1753e

Please sign in to comment.