Пример #1
0
        public void ListsWidget_VerifyMoreThan20Items()
        {
            var list           = this.serverOperationsLists.CreateList(ListTitle);
            int listItemsCount = 21;

            for (int i = 0; i < listItemsCount; i++)
            {
                this.serverOperationsLists.CreateListItem(list, ItemTitle + i, ItemTitle + i);
            }

            var listsController = new ListsController();

            var listsManager = ListsManager.GetManager();
            var selectedList = listsManager.GetLists().FirstOrDefault();

            listsController.Model.SerializedSelectedItemsIds = "[\"" + selectedList.Id.ToString() + "\"]";

            var lists = listsController.Model.CreateListViewModel(null, 1).Items.ToArray();

            Assert.AreEqual(1, lists.Length, "The count of lists is not as expected");

            var listItems = ((ListViewModel)lists.FirstOrDefault()).ListItemViewModel.Items.ToArray();

            for (int i = 0; i < listItemsCount; i++)
            {
                Assert.IsTrue(listItems[i].Fields.Title.Equals("Item" + i, StringComparison.CurrentCulture), "The item with this title was not found!");
            }
        }
Пример #2
0
        public string GetListItemURLById(Guid _id)
        {
            ListsManager listsManager = ListsManager.GetManager();
            ListItem     listItem     = listsManager.GetListItems().Where(i => (i.Id == _id))
                                        .FirstOrDefault();

            if (listItem != null && listItem.Urls != null && listItem.Parent != null)
            {
                var clService    = SystemManager.GetContentLocationService();
                var allLocations = clService.GetItemLocations(listItem);

                string firstUrl = string.Empty;

                foreach (var location in allLocations)
                {
                    if (firstUrl == string.Empty && location != null)
                    {
                        firstUrl = location.ItemAbsoluteUrl;
                    }
                }
                if (firstUrl != null)
                {
                    return(firstUrl);
                }
                else
                {
                    return("/");
                }
            }
            else
            {
                return("/");
            }
        }
Пример #3
0
        private void RepublishListItems(IEnumerable <string> providers)
        {
            foreach (var provider in providers)
            {
                var listsManager = ListsManager.GetManager(provider);
                listsManager.Provider.SuppressSecurityChecks = false;
                var listItems = listsManager.GetListItems().Where(n => n.Visible && n.Status == ContentLifecycleStatus.Live).ToList();
                var count     = 0;

                foreach (var listItem in listItems)
                {
                    var master = listsManager.Lifecycle.GetMaster(listItem);
                    var temp   = listsManager.Lifecycle.CheckOut(master) as ListItem;
                    temp.Title = temp.Title.Trim();
                    master     = listsManager.Lifecycle.CheckIn(temp) as ListItem;
                    listsManager.Lifecycle.Publish(master);

                    count++;
                    if (count % 200 == 0)
                    {
                        listsManager.SaveChanges();
                    }
                }

                listsManager.SaveChanges();
                listsManager.Provider.SuppressSecurityChecks = true;
            }
        }
Пример #4
0
        /// <summary>
        /// Creates list list item for given list
        /// </summary>
        /// <param name="listItemId">list item id</param>
        /// <param name="parentListId">list id</param>
        /// <param name="title">list item title</param>
        /// <param name="content">list item content</param>
        public void CreateListItem(Guid listItemId, Guid parentListId, string title, string content)
        {
            ListsManager listManager = ListsManager.GetManager();

            List parent = listManager.GetLists().Where(l => l.Id == parentListId).FirstOrDefault();

            if (parent != null)
            {
                ListItem listItem = listManager.CreateListItem(listItemId);

                listItem.Parent = parent;

                listItem.Title       = title;
                listItem.Content     = content;
                listItem.UrlName     = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                listItem.DateCreated = DateTime.Now;

                listManager.RecompileAndValidateUrls(listItem);

                listManager.SaveChanges();

                var bag = new Dictionary <string, string>();
                bag.Add("ContentType", typeof(ListItem).FullName);
                WorkflowManager.MessageWorkflow(listItemId, typeof(ListItem), null, "Publish", false, bag);
            }
        }
Пример #5
0
        /// <summary>
        /// Deletes list by given id
        /// </summary>
        /// <param name="listId">list id</param>
        public void DeleteList(Guid listId)
        {
            ListsManager listsManager = ListsManager.GetManager();

            List list = listsManager.GetLists().Where(l => l.Id == listId).FirstOrDefault();

            if (list != null)
            {
                listsManager.DeleteList(list);

                listsManager.SaveChanges();
            }
        }
Пример #6
0
        /// <summary>
        /// Deletes list item by given id
        /// </summary>
        /// <param name="masterListItemId">list item id</param>
        public void DeleteListItem(Guid masterListItemId)
        {
            ListsManager listsManager = ListsManager.GetManager();

            ListItem listItem = listsManager.GetListItems().Where(i => i.Id == masterListItemId).FirstOrDefault();

            if (listItem != null)
            {
                listsManager.DeleteListItem(listItem);

                listsManager.SaveChanges();
            }
        }
Пример #7
0
        /// <summary>
        /// Publish list item with specific date.
        /// </summary>
        /// <param name="listItemId">The list item id.</param>
        /// <param name="publicationDate">Publication datetime.</param>
        public void PublishListItemWithSpecificDate(Guid listItemId, DateTime publicationDate)
        {
            ListsManager listManager = ListsManager.GetManager();

            ListItem listItemMaster = listManager.GetListItems().Where(i => i.Id == listItemId).FirstOrDefault();

            if (listItemMaster == null)
            {
                throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "List item with id {0} was not found.", listItemId));
            }

            listManager.Lifecycle.PublishWithSpecificDate(listItemMaster, publicationDate);
            listManager.SaveChanges();
        }
Пример #8
0
        /// <summary>
        /// Creates list
        /// </summary>
        /// <param name="listId">list id</param>
        /// <param name="title">list title</param>
        /// <param name="description">list description</param>
        public void CreateList(Guid listId, string title, string description)
        {
            ListsManager listsManager = ListsManager.GetManager();

            List list = listsManager.CreateList(listId);

            list.Title       = title;
            list.Description = description;
            list.UrlName     = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            list.DateCreated = DateTime.Now;

            listsManager.RecompileAndValidateUrls(list);

            listsManager.SaveChanges();
        }
Пример #9
0
        public void AddTaxonomiesToListItem(Guid listItemId, IEnumerable <string> categories, IEnumerable <string> tags)
        {
            string       transactionName = "AddTaxonomiesToListItem";
            ListsManager listManager     = ListsManager.GetManager(string.Empty, transactionName);

            ListItem listItemMaster = listManager.GetListItems().Where(i => i.Id == listItemId).FirstOrDefault();

            if (listItemMaster == null)
            {
                throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "List item with id {0} was not found.", listItemId));
            }

            ListItem listItemTemp = listManager.Lifecycle.CheckOut(listItemMaster) as ListItem;

            var taxonomyManager = TaxonomyManager.GetManager();

            if (categories != null)
            {
                if (categories.Count() > 0)
                {
                    HierarchicalTaxon category = null;
                    foreach (var c in categories)
                    {
                        category = taxonomyManager.GetTaxa <HierarchicalTaxon>().Single(t => t.Title == c);
                        listItemTemp.Organizer.AddTaxa("Category", category.Id);
                    }
                }
            }

            if (tags != null)
            {
                if (tags.Count() > 0)
                {
                    FlatTaxon tag = null;
                    foreach (var tg in tags)
                    {
                        tag = taxonomyManager.GetTaxa <FlatTaxon>().Single(t => t.Title == tg);
                        listItemTemp.Organizer.AddTaxa("Tags", tag.Id);
                    }
                }
            }

            listItemMaster = listManager.Lifecycle.CheckIn(listItemTemp) as ListItem;
            listManager.Lifecycle.Publish(listItemMaster);
            TransactionManager.CommitTransaction(transactionName);
        }
Пример #10
0
        /// <summary>
        /// Edit title and content of list item.
        /// </summary>
        /// <param name="listItemId">The list item id.</param>
        /// <param name="newTitle">The list item title.</param>
        /// <param name="newContent">The list item content.</param>
        public void EditListItem(Guid listItemId, string newTitle, string newContent)
        {
            ListsManager listManager = ListsManager.GetManager();

            ListItem listItemMaster = listManager.GetListItems().Where(i => i.Id == listItemId).FirstOrDefault();

            if (listItemMaster == null)
            {
                throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "List item with id {0} was not found.", listItemId));
            }

            ListItem listItemTemp = listManager.Lifecycle.CheckOut(listItemMaster) as ListItem;

            listItemTemp.Title   = newTitle;
            listItemTemp.Content = newContent;

            listItemMaster = listManager.Lifecycle.CheckIn(listItemTemp) as ListItem;
            listManager.Lifecycle.Publish(listItemMaster);
            listManager.SaveChanges();
        }
Пример #11
0
        private void RepublishLists(IEnumerable <string> providers)
        {
            foreach (var provider in providers)
            {
                var listsManager = ListsManager.GetManager(provider);
                listsManager.Provider.SuppressSecurityChecks = false;
                var lists = listsManager.GetLists().ToList();
                var count = 0;

                foreach (var list in lists)
                {
                    list.Title = list.Title.Trim();

                    count++;
                    if (count % 200 == 0)
                    {
                        listsManager.SaveChanges();
                    }
                }

                listsManager.SaveChanges();
                listsManager.Provider.SuppressSecurityChecks = true;
            }
        }