Пример #1
0
        protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
        {
            var value = content.Retrieve();
            var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
            object itemToAdd = null;
            // TODO: Find a better solution for ContentSerializerAttribute that doesn't require to reference Core.Serialization (and unreference this assembly)
            if (collectionDescriptor.ElementType.IsAbstract || collectionDescriptor.ElementType.IsNullable() || collectionDescriptor.ElementType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
            {
                // If the parameter is a type instead of an instance, try to construct an instance of this type
                var type = parameter as Type;
                if (type?.GetConstructor(Type.EmptyTypes) != null)
                    itemToAdd = Activator.CreateInstance(type);
            }
            else if (collectionDescriptor.ElementType == typeof(string))
            {
                itemToAdd = parameter ?? "";
            }
            else
            {
                itemToAdd = parameter ?? ObjectFactory.NewInstance(collectionDescriptor.ElementType);
            }
            content.Add(itemToAdd);

            return null;
        }
        /// <inheritdoc/>
        protected override void UndoAction()
        {
            switch (ChangeType)
            {
            case ContentChangeType.ValueChange:
                var previousValue = Content.Retrieve(Index);
                Content.Update(PreviousValue, Index);
                PreviousValue = previousValue;
                break;

            case ContentChangeType.CollectionAdd:
                PreviousValue = Content.Retrieve(Index);
                Content.Remove(Index);
                ChangeType = ContentChangeType.CollectionRemove;
                break;

            case ContentChangeType.CollectionRemove:
                Content.Add(Index, PreviousValue);
                PreviousValue = null;
                ChangeType    = ContentChangeType.CollectionAdd;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #3
0
 protected override void ExecuteSync(IContent content, Index index, object parameter)
 {
     var value = content.Retrieve(index);
     var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
     object itemToAdd = null;
     // TODO: Find a better solution for ContentSerializerAttribute that doesn't require to reference Core.Serialization (and unreference this assembly)
     if (collectionDescriptor.ElementType.IsAbstract || collectionDescriptor.ElementType.IsNullable() || collectionDescriptor.ElementType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
     {
         // If the parameter is a type instead of an instance, try to construct an instance of this type
         var type = parameter as Type;
         if (type?.GetConstructor(Type.EmptyTypes) != null)
             itemToAdd = Activator.CreateInstance(type);
     }
     else if (collectionDescriptor.ElementType == typeof(string))
     {
         itemToAdd = parameter ?? "";
     }
     else
     {
         itemToAdd = parameter ?? ObjectFactory.NewInstance(collectionDescriptor.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.Reference.AsEnumerable[index].TargetNode;
         collectionNode.Content.Add(itemToAdd);
     }
 }
        protected override void ExecuteSync(IContent content, Index index, object parameter)
        {
            var value = content.Retrieve(index);
            var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());

            object itemToAdd = null;
            var elementType = collectionDescriptor.ElementType;
            if (CanAddNull(elementType) || IsReferenceType(elementType))
            {
                // If the parameter is a type instead of an instance, try to construct an instance of this type
                var type = parameter as Type;
                if (type?.GetConstructor(Type.EmptyTypes) != null)
                    itemToAdd = ObjectFactoryRegistry.NewInstance(type);
            }
            else if (collectionDescriptor.ElementType == typeof(string))
            {
                itemToAdd = parameter ?? "";
            }
            else
            {
                itemToAdd = parameter ?? ObjectFactoryRegistry.NewInstance(collectionDescriptor.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.Reference.AsEnumerable[index].TargetNode;
                collectionNode.Content.Add(itemToAdd);
            }
        }
Пример #5
0
        protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable <IDirtiable> dirtiables)
        {
            var    value = content.Retrieve();
            var    collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
            object itemToAdd            = null;

            // TODO: Find a better solution for ContentSerializerAttribute that doesn't require to reference Core.Serialization (and unreference this assembly)
            if (collectionDescriptor.ElementType.IsAbstract || collectionDescriptor.ElementType.IsNullable() || collectionDescriptor.ElementType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
            {
                // If the parameter is a type instead of an instance, try to construct an instance of this type
                var type = parameter as Type;
                if (type?.GetConstructor(Type.EmptyTypes) != null)
                {
                    itemToAdd = Activator.CreateInstance(type);
                }
            }
            else if (collectionDescriptor.ElementType == typeof(string))
            {
                itemToAdd = parameter ?? "";
            }
            else
            {
                itemToAdd = parameter ?? ObjectFactory.NewInstance(collectionDescriptor.ElementType);
            }
            content.Add(itemToAdd);

            return(null);
        }
 protected override void ExecuteSync(IContent 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);
 }
Пример #7
0
 protected override void ExecuteSync(IContent content, Index index, object parameter)
 {
     var oldName = index;
     var newName = new Index(parameter);
     var renamedObject = content.Retrieve(oldName);
     content.Remove(renamedObject, oldName);
     content.Add(renamedObject, newName);
 }
Пример #8
0
 protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var oldName = (string)index;
     var newName = (string)parameter;
     var removedObject = content.Retrieve(oldName);
     content.Remove(oldName);
     content.Add(newName, removedObject);
     return null;
 }
Пример #9
0
 protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var indices = (Tuple<int, int>)parameter;
     var sourceIndex = indices.Item1;
     var targetIndex = indices.Item2;
     content.Remove(sourceIndex);
     content.Add(targetIndex);
     return null;
 }
Пример #10
0
        public override void Execute(IContent content, object index, object parameter)
        {
            var oldName       = (string)index;
            var newName       = (string)parameter;
            var renamedObject = content.Retrieve(oldName);

            content.Remove(oldName, renamedObject);
            content.Add(newName, renamedObject);
        }
Пример #11
0
        public override void Execute(IContent content, Index index, object parameter)
        {
            var oldName       = index;
            var newName       = new Index(parameter);
            var renamedObject = content.Retrieve(oldName);

            content.Remove(renamedObject, oldName);
            content.Add(renamedObject, newName);
        }
Пример #12
0
 protected override void ExecuteSync(IContent 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);
 }
Пример #13
0
        public override void Execute(IContent content, object index, object parameter)
        {
            var indices     = (Tuple <int, int>)parameter;
            var sourceIndex = indices.Item1;
            var targetIndex = indices.Item2;
            var value       = content.Retrieve(sourceIndex);

            content.Remove(sourceIndex, value);
            content.Add(targetIndex, value);
        }
Пример #14
0
        protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable <IDirtiable> dirtiables)
        {
            var oldName       = (string)index;
            var newName       = (string)parameter;
            var removedObject = content.Retrieve(oldName);

            content.Remove(oldName);
            content.Add(newName, removedObject);
            return(null);
        }
Пример #15
0
        protected override void ExecuteSync(IContent 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);
        }
Пример #16
0
        protected override void ExecuteSync(IContent 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);
        }
Пример #17
0
        protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable <IDirtiable> dirtiables)
        {
            var indices     = (Tuple <int, int>)parameter;
            var sourceIndex = indices.Item1;
            var targetIndex = indices.Item2;
            var value       = content.Retrieve(sourceIndex);

            content.Remove(sourceIndex);
            content.Add(targetIndex, value);
            return(null);
        }
 protected override void ExecuteSync(IContent 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;
     // TODO: Find a better solution that doesn't require to reference Core.Serialization (and unreference this assembly)
     if (!dictionaryDescriptor.ValueType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
         newItem = CreateInstance(dictionaryDescriptor.ValueType);
     content.Add(newItem, newKey);
 }
Пример #19
0
 protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable<IDirtiable> dirtiables)
 {
     var value = content.Retrieve(index);
     var dictionaryDescriptor = (DictionaryDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
     var newKey = dictionaryDescriptor.KeyType != typeof(string) ? Activator.CreateInstance(dictionaryDescriptor.KeyType) : GenerateStringKey(value, dictionaryDescriptor, parameter as string);
     object newItem = null;
     // TODO: Find a better solution that doesn't require to reference Core.Serialization (and unreference this assembly)
     if (!dictionaryDescriptor.ValueType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
         newItem = !dictionaryDescriptor.ValueType.IsAbstract ? Activator.CreateInstance(dictionaryDescriptor.ValueType) : null;
     content.Add(newKey, newItem);
     return null;
 }
Пример #20
0
        protected override void ExecuteSync(IContent 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;

            // TODO: Find a better solution that doesn't require to reference Core.Serialization (and unreference this assembly)
            if (!dictionaryDescriptor.ValueType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
            {
                newItem = CreateInstance(dictionaryDescriptor.ValueType);
            }
            content.Add(newItem, newKey);
        }
Пример #21
0
        public bool Add(Content content)
        {
            int i = 0;

            i = icontent.Add(content);
            if (i != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #22
0
        protected override IActionItem ExecuteSync(IContent content, object index, object parameter, IEnumerable <IDirtiable> dirtiables)
        {
            var    value = content.Retrieve(index);
            var    dictionaryDescriptor = (DictionaryDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());
            var    newKey  = dictionaryDescriptor.KeyType != typeof(string) ? Activator.CreateInstance(dictionaryDescriptor.KeyType) : GenerateStringKey(value, dictionaryDescriptor, parameter as string);
            object newItem = null;

            // TODO: Find a better solution that doesn't require to reference Core.Serialization (and unreference this assembly)
            if (!dictionaryDescriptor.ValueType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
            {
                newItem = !dictionaryDescriptor.ValueType.IsAbstract ? Activator.CreateInstance(dictionaryDescriptor.ValueType) : null;
            }
            content.Add(newKey, newItem);
            return(null);
        }
 public override Task Execute(IContent 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);
 }
Пример #24
0
        public override Task Execute(IContent 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));
        }
Пример #25
0
        protected void ApplyUndo(object oldValue, object newValue, ContentChangeType type)
        {
            switch (type)
            {
            case ContentChangeType.ValueChange:
                Content.Update(oldValue, Index);
                break;

            case ContentChangeType.CollectionAdd:
                Content.Remove(Index, newValue);
                break;

            case ContentChangeType.CollectionRemove:
                Content.Add(Index, oldValue);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #26
0
        /// <summary>
        /// Agrega contenido al documento en la posición especificada.
        /// Si el documento no existe, se crea automáticamente.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="position"></param>
        public void AddContent(IContent content, DocumentPosition position = DocumentPosition.BOTTOM)
        {
            WordprocessingDocument wordDocument = null;

            try {
                Body docBody;

                if (File.Exists(this.path))
                {
                    wordDocument = WordprocessingDocument.Open(
                        this.path,
                        true
                        );

                    docBody = wordDocument.MainDocumentPart.Document.Body;
                }
                else
                {
                    wordDocument = WordprocessingDocument.Create(
                        this.path,
                        WordprocessingDocumentType.Document,
                        true
                        );

                    MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
                    mainPart.Document      = new DocumentFormat.OpenXml.Wordprocessing.Document();
                    docBody                = new Body();
                    mainPart.Document.Body = docBody;
                }

                content.Add(docBody, position);
            }
            finally
            {
                if (wordDocument != null)
                {
                    wordDocument.Dispose();
                }
            }
        }
Пример #27
0
        protected override void ExecuteSync(IContent content, Index index, object parameter)
        {
            var value = content.Retrieve(index);
            var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());

            object itemToAdd = null;

            // TODO: Find a better solution for ContentSerializerAttribute that doesn't require to reference Core.Serialization (and unreference this assembly)
            // TODO: Fix this for asset part types that are also references
            if (collectionDescriptor.ElementType.IsAbstract || collectionDescriptor.ElementType.IsNullable() || collectionDescriptor.ElementType.GetCustomAttributes(typeof(ContentSerializerAttribute), true).Any())
            {
                // If the parameter is a type instead of an instance, try to construct an instance of this type
                var type = parameter as Type;
                if (type?.GetConstructor(Type.EmptyTypes) != null)
                {
                    itemToAdd = Activator.CreateInstance(type);
                }
            }
            else if (collectionDescriptor.ElementType == typeof(string))
            {
                itemToAdd = parameter ?? "";
            }
            else
            {
                itemToAdd = parameter ?? ObjectFactory.NewInstance(collectionDescriptor.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.Reference.AsEnumerable[index].TargetNode;
                collectionNode.Content.Add(itemToAdd);
            }
        }
Пример #28
0
        protected override void ExecuteSync(IContent content, Index index, object parameter)
        {
            var value = content.Retrieve(index);
            var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType());

            object itemToAdd   = null;
            var    elementType = collectionDescriptor.ElementType;

            if (CanAddNull(elementType) || IsReferenceType(elementType))
            {
                // If the parameter is a type instead of an instance, try to construct an instance of this type
                var type = parameter as Type;
                if (type?.GetConstructor(Type.EmptyTypes) != null)
                {
                    itemToAdd = ObjectFactoryRegistry.NewInstance(type);
                }
            }
            else if (collectionDescriptor.ElementType == typeof(string))
            {
                itemToAdd = parameter ?? "";
            }
            else
            {
                itemToAdd = parameter ?? ObjectFactoryRegistry.NewInstance(collectionDescriptor.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.Reference.AsEnumerable[index].TargetNode;
                collectionNode.Content.Add(itemToAdd);
            }
        }
Пример #29
0
        public IActionResult Add(string content, string id, string returnUrl, string subjectid)
        {
            if (!string.IsNullOrEmpty(content) && !string.IsNullOrEmpty(id))
            {
                Content model = new Content
                {
                    Subjectid   = Convert.ToInt32(id),
                    ContentName = content
                };

                _content.Add(model);
                _content.Save();
            }


            if (returnUrl == "contentlist")
            {
                return(RedirectToAction(returnUrl, "Content", new { id = id }));
            }
            else
            {
                return(RedirectToAction(returnUrl, "lesson", new { id = subjectid }));
            }
        }
Пример #30
0
 public void AddContent(IContent content)
 {
     content.Add();
     AppState.TriggerNotification(content.Name + " content added");
 }