Esempio n. 1
0
            protected override UpdatedItem DoUpdate(JObject target, ISourceMatch source)
            {
                var propertyName = this.GetPropertyName(source);

                if (!this.ShouldMap(target.ContainsKey(propertyName)))
                {
                    return(UpdatedItem.Notupdated);
                }

                if (this.IsArray)
                {
                    var targetProperty = target.Property(propertyName);
                    if (targetProperty == null || !(targetProperty.Value is JArray targetArray))
                    {
                        targetArray          = new JArray();
                        target[propertyName] = targetArray;
                    }

                    var targetElement = source.Element.DeepClone();
                    targetArray.Add(targetElement);
                    return(targetElement.AsUpdated());
                }

                return(Merging.MergeToProperty(target, propertyName, source.Element).AsUpdated());
            }
Esempio n. 2
0
            public static void MergeObjects(JObject target, ISourceMatch source)
            {
                if (!(source.Element is JObject sourceObj))
                {
                    throw new ApplicationException("Only an object can be merged with an object.");
                }

                MergeObjects(target, sourceObj);
            }
Esempio n. 3
0
                public string Get(ISourceMatch source)
                {
                    var builder = new StringBuilder();

                    foreach (var token in this.tokens)
                    {
                        builder.Append(
                            token.Type == TokenType.Variable
                                ? source.VariableValues[token.Value]
                                : token.Value);
                    }

                    return(builder.ToString());
                }
Esempio n. 4
0
            public bool Update(JObject target, ISourceMatch source)
            {
                var updated = this.DoUpdate(target, source);

                if (updated.WasUpdated && this.propertySetters != null && updated.Item is JObject updatedObj)
                {
                    foreach (var setter in this.propertySetters)
                    {
                        setter.Set(updatedObj, source);
                    }
                }

                return(updated.WasUpdated);
            }
Esempio n. 5
0
            protected override UpdatedItem DoUpdate(JObject target, ISourceMatch source)
            {
                var propertyName   = this.GetPropertyName(source);
                var targetProperty = target.Property(propertyName);

                if (!this.ShouldMap(targetProperty != null))
                {
                    return(UpdatedItem.Notupdated);
                }

                if (!this.IsArray && targetProperty != null && targetProperty.Value is JObject targetObj)
                {
                    return(this.next.Update(targetObj, source)
                        ? targetObj.AsUpdated()
                        : UpdatedItem.Notupdated);
                }

                // If the target does not have an object to update then create it
                // and try to map to it, if that succeeds then assign to the target
                // either as the object or into the array (if this is an array)
                targetObj = new JObject();
                if (this.next.Update(targetObj, source))
                {
                    if (!this.IsArray)
                    {
                        target[propertyName] = targetObj;
                    }
                    else
                    {
                        if (targetProperty == null || !(targetProperty.Value is JArray targetArr))
                        {
                            targetArr            = new JArray();
                            target[propertyName] = targetArr;
                        }

                        targetArr.Add(targetObj);
                    }

                    return(targetObj.AsUpdated());
                }

                return(UpdatedItem.Notupdated);
            }
Esempio n. 6
0
 public string Get(ISourceMatch source) => this.name;
Esempio n. 7
0
 protected string GetPropertyName(ISourceMatch source) => this.propertyName.Get(source);
Esempio n. 8
0
 protected abstract UpdatedItem DoUpdate(JObject target, ISourceMatch source);