Ejemplo n.º 1
0
        protected override void ExecuteSync(IContentNode content, Index index, object parameter)
        {
            var value = content.Retrieve(index);
            var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());

            object itemToAdd;

            // First, check if parameter is an AbstractNodeEntry
            var abstractNodeEntry = parameter as AbstractNodeEntry;

            if (abstractNodeEntry != null)
            {
                itemToAdd = abstractNodeEntry.GenerateValue(null);
            }
            // Otherwise, assume it's an object
            else
            {
                var elementType = collectionDescriptor.ElementType;
                itemToAdd = parameter ?? (IsReferenceType(elementType) ? null : ObjectFactoryRegistry.NewInstance(elementType));
            }

            if (index.IsEmpty)
            {
                content.Add(itemToAdd);
            }
            else
            {
                // Handle collections in collections
                // TODO: this is not working on the observable node side
                var collectionNode = content.ItemReferences[index].TargetNode;
                collectionNode.Add(itemToAdd);
            }
        }
Ejemplo n.º 2
0
        protected override void ExecuteSync(IContentNode content, Index index, object parameter)
        {
            var indices     = (Tuple <int, int>)parameter;
            var sourceIndex = new Index(indices.Item1);
            var targetIndex = new Index(indices.Item2);
            var value       = content.Retrieve(sourceIndex);

            content.Remove(value, sourceIndex);
            content.Add(value, targetIndex);
        }
Ejemplo n.º 3
0
        protected override void ExecuteSync(IContentNode content, Index index, object parameter)
        {
            var oldName       = index;
            var renamedObject = content.Retrieve(oldName);

            content.Remove(renamedObject, oldName);
            var newName = AddPrimitiveKeyCommand.GenerateStringKey(content.Value, content.Descriptor, (string)parameter);

            content.Add(renamedObject, newName);
        }
        protected override void ExecuteSync(IContentNode content, Index index, object parameter)
        {
            var    value = content.Retrieve(index);
            var    dictionaryDescriptor = (DictionaryDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
            var    newKey  = dictionaryDescriptor.KeyType != typeof(string) ? new Index(Activator.CreateInstance(dictionaryDescriptor.KeyType)) : GenerateStringKey(value, dictionaryDescriptor, parameter as string);
            object newItem = null;

            if (!IsReferenceType(dictionaryDescriptor.ValueType))
            {
                newItem = CreateInstance(dictionaryDescriptor.ValueType);
            }
            content.Add(newItem, newKey);
        }
Ejemplo n.º 5
0
 protected static bool UpdateCollection(IContentNode node, object value, Index index)
 {
     if (IsIndexExisting(node, index))
     {
         node.Update(value, index);
         return(true);
     }
     if (IsIndexValid(node, index))
     {
         node.Add(value, index);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
        public override Task Execute(IContentNode content, Index index, object parameter)
        {
            var hasIndex     = content.Indices == null || content.Indices.Contains(index);
            var currentValue = hasIndex ? content.Retrieve(index) : (content.Type.IsValueType ? Activator.CreateInstance(content.Type) : null);
            var newValue     = ChangeValue(currentValue, parameter);

            if (hasIndex)
            {
                if (!Equals(newValue, currentValue))
                {
                    content.Update(newValue, index);
                }
            }
            else
            {
                content.Add(newValue, index);
            }
            return(Task.FromResult(0));
        }