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(); } }
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); } }
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); }
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); }
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; }
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; }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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; }
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); }
public bool Add(Content content) { int i = 0; i = icontent.Add(content); if (i != 0) { return(true); } else { return(false); } }
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); }
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)); }
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(); } }
/// <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(); } } }
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); } }
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); } }
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 })); } }
public void AddContent(IContent content) { content.Add(); AppState.TriggerNotification(content.Name + " content added"); }