Exemplo n.º 1
0
    public bool Contains(T x)
    {
        int          count = 0;
        ListPart <T> p     = head;

        while (p != null)
        {
            if (p.val.Equals(x))
            {
                count++;
                break;
            }

            p = p.next;
        }
        switch (count)
        {
        case 0:
            Console.WriteLine("False");
            return(false);

        default:
            Console.WriteLine("True");
            return(true);
        }
    }
Exemplo n.º 2
0
        private ListPartSettings GetSettings(ListPart listPart)
        {
            var contentTypeDefinition     = _contentDefinitionManager.GetTypeDefinition(listPart.ContentItem.ContentType);
            var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => String.Equals(x.PartDefinition.Name, "ListPart"));

            return(contentTypePartDefinition?.GetSettings <ListPartSettings>());
        }
Exemplo n.º 3
0
    public void AddFirst(T x)
    {
        ListPart <T> placeholder = new ListPart <T>(x);

        placeholder.next = head;
        head             = placeholder;
    }
Exemplo n.º 4
0
    public void IndexOf(T x)
    {
        int          pos = 0;
        ListPart <T> p   = head;

        while (p != null)
        {
            if (p.val.Equals(x))
            {
                break;
            }
            pos++;
            p = p.next;
        }
        switch (p)
        {
        case null:
            Console.WriteLine("null");
            break;

        default:
            Console.WriteLine(pos);
            break;
        }
    }
Exemplo n.º 5
0
    public void Remove(T value)
    {
        if (head == null)
        {
            return;
        }

        if (head.val.Equals(value))
        {
            head = head.next;
            return;
        }

        ListPart <T> n = head;

        while (n.val != null)
        {
            if (n.next.val.Equals(value))
            {
                n.next = n.next.next;
                return;
            }

            n = n.next;
        }
    }
Exemplo n.º 6
0
        private static Expression ParseListComprehension(Parser parser, Token token, Expression firstExpression)
        {
            ComprehensionPart root = null;
            ComprehensionPart prev = null;

            while (true)
            {
                ComprehensionPart curr;

                if (parser.Match(TokenType.Identifier) && parser.Match(TokenType.In, 1))
                {
                    var identifier = parser.Take(TokenType.Identifier).Contents;

                    parser.Take(TokenType.In);

                    var list = parser.ParseExpession();

                    curr = new ListPart(token, identifier, list);
                }
                else
                {
                    var filter = parser.ParseExpession();
                    curr = new FilterPart(token, filter);
                }

                if (root == null)
                {
                    root = curr;
                }

                if (prev != null)
                {
                    prev.Next = curr;
                }

                prev = curr;

                if (!parser.Match(TokenType.Comma))
                {
                    break;
                }

                parser.Take(TokenType.Comma);
            }

            parser.Take(TokenType.RightSquare);

            prev.Next = new YieldPart(token, firstExpression);

            var body = new BlockExpression(new List <Expression>
            {
                root.Compile()
            });

            return(new ListComprehensionExpression(token, body));
        }
Exemplo n.º 7
0
    public int Count()
    {
        int          n = 0;
        ListPart <T> p = head;

        while (p != null)
        {
            n++;
            p = p.next;
        }
        return(n);
    }
Exemplo n.º 8
0
    public void Reverse()
    {
        ListPart <T> prev, cur, next;

        prev = null;
        cur  = head;
        while (cur != null)
        {
            next     = cur.next;
            cur.next = prev;
            prev     = cur;
            cur      = next;
        }
        head = prev;
    }
Exemplo n.º 9
0
    public void AddLast(T x)
    {
        ListPart <T> it;
        ListPart <T> temp = new ListPart <T>(x);

        if (head == null)
        {
            head = temp;
            return;
        }

        it = head;
        while (it.next != null)
        {
            it = it.next;
        }

        it.next = temp;
    }
 public override IDisplayResult Display(ListPart part, BuildPartDisplayContext context)
 {
     return(Combine(
                Initialize <ListPartViewModel>(GetDisplayShapeType(context), async model =>
     {
         await BuildViewModel(context, part, model, new ContainedItemOptions());
     })
                .Location("Detail", "Content:10"),
                Initialize <ListPartViewModel>("ListPart", async model =>
     {
         var listPartFilterViewModel = new ListPartFilterViewModel();
         var containedItemOptions = new ContainedItemOptions();
         await _updateModelAccessor.ModelUpdater.TryUpdateModelAsync(listPartFilterViewModel, Prefix);
         containedItemOptions.DisplayText = listPartFilterViewModel.DisplayText;
         containedItemOptions.Status = listPartFilterViewModel.Status;
         model.ListPartFilterViewModel = listPartFilterViewModel;
         await BuildViewModel(context, part, model, containedItemOptions);
     })
                .Location("DetailAdmin", "Content:10")
                ));
 }
        private async ValueTask BuildViewModel(BuildPartDisplayContext context, ListPart part, ListPartViewModel model, ContainedItemOptions options)
        {
            var settings = context.TypePartDefinition.GetSettings <ListPartSettings>();
            var pager    = new PagerParameters()
            {
                Page = 1, PageSize = settings.PageSize
            };
            await context.Updater.TryUpdateModelAsync <PagerParameters>(pager);

            var count = (pager.Page - 1) * pager.PageSize;
            var query = _session.Query <ContentItem, ContainedPartIndex>(x => x.ListContentItemId == part.ContentItem.ContentItemId);

            if (settings.EnableOrdering)
            {
                query.OrderBy(x => x.Order);
            }
            var searchQuery = query.With <ContentItemIndex>();

            ApplyContainedItemOptionsFilter(options, searchQuery);
            if (settings.EnableOrdering == false)
            {
                searchQuery.OrderByDescending(x => x.CreatedUtc);
            }

            var totalCount = await searchQuery.CountAsync();

            var items = await searchQuery.Skip(Math.Max(0, count.Value)).Take(pager.PageSize.Value).ListAsync();

            var contentTypes = settings.ContainedContentTypes ?? Enumerable.Empty <string>();

            model.ContainedContentTypeDefinitions = contentTypes.Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType));
            model.ContentItems   = items;
            model.ListPart       = part;
            model.Context        = context;
            model.EnableOrdering = settings.EnableOrdering;
            model.Pager          = (await context.New.Pager(pager)).TotalItemCount(totalCount);
        }
Exemplo n.º 12
0
        private long CreateContent2()
        {
            // assure storage is empty
            Assert.AreEqual(0, Storage.GetItems().Count());

            // create some content
            root = CreateOneItem<TestItem>(1, "root", null);
            item1 = CreateOneItem<TestItem>(11, "item1", root);
            item2 = CreateOneItem<TestItem>(12, "item2", root);
            list = CreateOneItem<ListPart>(1000, "listitem", item1);
            CreateOneChild(91, "listitem1", list);
            CreateOneChild(92, "listitem2", list);
            CreateOneChild(93, "listitem3", list);
            item1a = CreateOneItem<TestItem>(111, "item1a", item1);
            item1b = CreateOneItem<TestItem>(112, "item1b", item1);

            repository.SaveOrUpdate(root, item1, item1a, item1b, item2, list);
            return 5; // # of pages 
        }
Exemplo n.º 13
0
 protected ListItem CreateOneChild(int id, string name, ListPart parent)
 {
     ListItem item = (ListItem)Activator.CreateInstance(typeof(ListItem), true);
     item.ID = id;
     item.Name = name;
     item.Title = name;
     item.AncestralTrail = N2.Utility.GetTrail(parent);
     item.SortOrder = parent.Children.Count;
     item.LinkText = "Test_" + name;
     item.Title = "Title_" + name;
     item.AddTo(parent);
     return item;
 }
Exemplo n.º 14
0
 public LinkedList()
 {
     head = null;
 }
Exemplo n.º 15
0
 public ListPart(T i)
 {
     val  = i;
     next = null;
 }