Ejemplo n.º 1
0
        public void CanRemove_AtIndex()
        {
            DetailCollection collection = new DetailCollection(null, null, "hello", "world");

            collection.RemoveAt(0);

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

			collection.RemoveAt(0);

			Assert.That(collection.Count, Is.EqualTo(1));
			Assert.That(collection[0], Is.EqualTo("world"));
		}
Ejemplo n.º 3
0
        private IEnumerable <ContentItem> UpdateLinksInternal(ContentItem item, bool recursive)
        {
            logger.DebugFormat("Updating link: {0}", item);

            if (recursive)
            {
                foreach (var part in item.Children.FindParts())
                {
                    foreach (var updatedItem in UpdateLinksInternal(part, recursive))
                    {
                        yield return(updatedItem);
                    }
                }
            }

            var referencedItems    = FindLinkedObjects(item).ToList();
            DetailCollection links = item.GetDetailCollection(LinkDetailName, false);

            if (links == null && referencedItems.Count == 0)
            {
                logger.Debug("Exiting due to no links and none to update");
                yield break;
            }

            if (links == null)
            {
                links = item.GetDetailCollection(LinkDetailName, true);
            }

            logger.DebugFormat("Updating {0} links to {1} existing", referencedItems.Count, links.Count);

            // replace existing items
            for (int i = 0; i < referencedItems.Count && i < links.Count; i++)
            {
                var extracted = referencedItems[i];
                var stored    = links.Details[i];
                if (stored.StringValue == extracted.StringValue && stored.Meta == extracted.Meta && stored.IntValue == extracted.IntValue && stored.BoolValue == extracted.BoolValue)
                {
                    // this prevents clearing item references to children when moving hierarchies
                    continue;
                }
                stored.Extract(extracted);
            }
            // add any new items
            for (int i = links.Details.Count; i < referencedItems.Count; i++)
            {
                links.Add(referencedItems[i]);
            }
            // remove any extra items
            while (links.Count > referencedItems.Count)
            {
                links.RemoveAt(links.Count - 1);
            }

            yield return(item);
        }
Ejemplo n.º 4
0
        public virtual void UpdateLinks(ContentItem item)
        {
            logger.DebugFormat("Updating link: {0}", item);

            var referencedItems    = FindLinkedObjects(item).ToList();
            DetailCollection links = item.GetDetailCollection(LinkDetailName, false);

            if (links == null && referencedItems.Count == 0)
            {
                logger.Debug("Exiting due to no links and none to update");
                return;
            }

            if (links == null)
            {
                links = item.GetDetailCollection(LinkDetailName, true);
            }

            logger.DebugFormat("Updating {0} links to {1} existing", referencedItems.Count, links.Count);

            // replace existing items
            for (int i = 0; i < referencedItems.Count && i < links.Count; i++)
            {
                var extracted = referencedItems[i];
                var stored    = links.Details[i];
                if (stored.StringValue == extracted.StringValue && stored.Meta == extracted.Meta && stored.IntValue == extracted.IntValue && stored.BoolValue == extracted.BoolValue)
                {
                    // this prevents clearing item references to children when moving hierarchies
                    continue;
                }
                stored.Extract(extracted);
            }
            // add any new items
            for (int i = links.Details.Count; i < referencedItems.Count; i++)
            {
                links.Add(referencedItems[i]);
            }
            // remove any extra items
            while (links.Count > referencedItems.Count)
            {
                links.RemoveAt(links.Count - 1);
            }
        }
Ejemplo n.º 5
0
        public virtual void UpdateLinks(ContentItem item)
        {
            var referencedItems    = FindLinkedObjects(item).ToList();
            DetailCollection links = item.GetDetailCollection(LinkDetailName, false);

            if (links == null && referencedItems.Count == 0)
            {
                return;
            }

            if (links == null)
            {
                links = item.GetDetailCollection(LinkDetailName, true);
            }

            // replace existing items
            for (int i = 0; i < referencedItems.Count && i < links.Count; i++)
            {
                if (links.Details[i].StringValue == referencedItems[i].StringValue)
                {
                    // this prevents clearing item references to children when moving hierarchies
                    continue;
                }
                links.Details[i].Extract(referencedItems[i]);
            }
            // add any new items
            for (int i = links.Details.Count; i < referencedItems.Count; i++)
            {
                links.Add(referencedItems[i]);
            }
            // remove any extra items
            while (links.Count > referencedItems.Count)
            {
                links.RemoveAt(links.Count - 1);
            }
        }