Exemplo n.º 1
0
        private void ApplyChanges(AppliedTags change, ContentItem item)
        {
            DetailCollection links = item.GetDetailCollection(Name, false);

            if (links == null)
            {
                if (change.Tags.Count == 0)
                {
                    return;
                }
                links = item.GetDetailCollection(Name, true);
            }

            List <ITag> currentTags = GetCurrentTags(change.Group, links);

            IEnumerable <string> addedTags = GetAddedTags(currentTags, change.Tags);

            foreach (string tagName in addedTags)
            {
                ITag tag = change.Group.GetOrCreateTag(tagName);
                links.Add(tag);
            }

            foreach (ContentItem tag in currentTags)
            {
                if (!change.Tags.Contains(tag.Title))
                {
                    links.Remove(tag);
                }
            }
        }
Exemplo n.º 2
0
        public void CanRemove_FromCollection()
        {
            DetailCollection collection = new DetailCollection(null, null, "hello", "world");

            collection.Remove("hello");

            Assert.That(collection.Count, Is.EqualTo(1));
            Assert.That(collection[0], Is.EqualTo("world"));
        }
Exemplo n.º 3
0
		public void CanRemove_FromCollection()
		{
			DetailCollection collection = new DetailCollection(null, null, "hello", "world");
            
			collection.Remove("hello");

			Assert.That(collection.Count, Is.EqualTo(1));
			Assert.That(collection[0], Is.EqualTo("world"));
		}
Exemplo n.º 4
0
        private void ClearMissingDetails(ContentItem source, ContentItem destination)
        {
            // remove details not present in source
            List <string> detailKeys = new List <string>(destination.Details.Keys);

            foreach (string key in detailKeys)
            {
                if (!source.Details.ContainsKey(key))
                {
                    destination.Details.Remove(key);
                }
            }

            List <string> collectionKeys = new List <string>(destination.DetailCollections.Keys);

            foreach (string key in collectionKeys)
            {
                if (source.DetailCollections.ContainsKey(key))
                {
                    // remove detail collection values not present in source
                    DetailCollection destinationCollection = destination.DetailCollections[key];
                    DetailCollection sourceCollection      = source.DetailCollections[key];
                    List <object>    values = new List <object>(destinationCollection.Enumerate <object>());
                    foreach (object value in values)
                    {
                        if (!sourceCollection.Contains(value))
                        {
                            destinationCollection.Remove(value);
                        }
                    }
                }
                else
                {
                    // remove detail collections not present in source
                    destination.DetailCollections.Remove(key);
                }
            }
        }