public void SetUp()
        {
            AuthenticationHelper.AuthenticateUser(this.AdminEmail, this.AdminPass, true);
            ServerOperationsFeather.DynamicModules().EnsureModuleIsImported(ModuleName, ModuleResource);

            Guid pageId = ServerOperations.Pages().CreatePage(PageName);

            ServerOperations.Taxonomies().CreateCategory(TaxonTitle + "0");

            for (int i = 1; i < 7; i++)
            {
                ServerOperations.Taxonomies().CreateCategory(TaxonTitle + i, TaxonTitle + (i - 1));
                var category = TaxonomyManager.GetManager().GetTaxa <HierarchicalTaxon>().SingleOrDefault(t => t.Title == TaxonTitle + i);
                ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticle(ItemsTitle + (i - 1), ItemsTitle + i + "Url", Guid.Empty, category.Id);
            }

            ServerOperationsFeather.Pages().AddDynamicWidgetToPage(pageId, "Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle", "PressArticle", "Press Articles MVC");
        }
예제 #2
0
        private List <BlendedListItem> SetBlendedListItems_dev(IResultSet results)
        {
            var resultSet       = new List <BlendedListItem>();
            var taxonomyManager = TaxonomyManager.GetManager();

            if (results != null && results.Any())
            {
                foreach (IDocument result in results)
                {
                    var item = new BlendedListItem()
                    {
                        Title = result.GetValue("Title")?.ToString() ?? "",
                    };
                }
            }

            return(resultSet);
        }
        public void NewsWidget_SelectByTagNewsFunctionalityAndNoLimit()
        {
            var newsController = new NewsController();

            newsController.Model.DisplayMode  = ListDisplayMode.All;
            newsController.Model.ItemsPerPage = 1;
            newsController.Model.LimitCount   = 1;

            string tagTitle  = "Tag1";
            string newsTitle = "News ";

            try
            {
                Guid taxonId = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle);

                Guid newsId0 = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 0);
                this.serverOperationsNews.AssignTaxonToNewsItem(newsId0, "Tags", taxonId);

                Guid newsId1 = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 1);
                this.serverOperationsNews.AssignTaxonToNewsItem(newsId1, "Tags", taxonId);

                this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 2);

                ITaxon tagTaxonomy = TaxonomyManager.GetManager().GetTaxon(taxonId);
                var    items       = newsController.Model.CreateListViewModel(tagTaxonomy, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(2), "The count of news items is not correct - no limit");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 1, StringComparison.CurrentCulture), "The news with this title was found!");
                Assert.IsTrue(items[1].Fields.Title.Equals(newsTitle + 0, StringComparison.CurrentCulture), "The news with this title was found!");

                newsController.Model.DisplayMode  = ListDisplayMode.Paging;
                newsController.Model.ItemsPerPage = 20;
                items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(3), "The count of news items is not correct - all items");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 2, StringComparison.CurrentCulture), "The news with this title was found!");
                Assert.IsTrue(items[1].Fields.Title.Equals(newsTitle + 1, StringComparison.CurrentCulture), "The news with this title was found!");
                Assert.IsTrue(items[2].Fields.Title.Equals(newsTitle + 0, StringComparison.CurrentCulture), "The news with this title was found!");
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteTags(tagTitle);
            }
        }
예제 #4
0
        private void RepublishTaxonItems(string taxonomyName, bool isFlat)
        {
            var taxonomyManager = TaxonomyManager.GetManager();

            taxonomyManager.Provider.SuppressSecurityChecks = false;
            if (isFlat)
            {
                var taxonomies = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Taxonomy.Name == taxonomyName).ToList();
                var count      = 0;

                foreach (var taxonomy in taxonomies)
                {
                    taxonomy.Title = taxonomy.Title.Trim();

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

                taxonomyManager.SaveChanges();
                taxonomyManager.Provider.SuppressSecurityChecks = true;
            }
            else
            {
                var taxonomies = taxonomyManager.GetTaxa <HierarchicalTaxon>().Where(t => t.Taxonomy.Name == taxonomyName).ToList();
                var count      = 0;

                foreach (var taxonomy in taxonomies)
                {
                    taxonomy.Title = taxonomy.Title.Trim();

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

                taxonomyManager.SaveChanges();
                taxonomyManager.Provider.SuppressSecurityChecks = true;
            }
        }
        protected void NewsExport_Click(object sender, EventArgs e)
        {
            StringBuilder   newsItems = new StringBuilder();
            NewsManager     man       = NewsManager.GetManager();
            var             tagString = string.Empty;
            List <string>   tags      = null;
            TaxonomyManager tMan      = TaxonomyManager.GetManager();

            foreach (var newsItem in man.GetNewsItems().Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master))
            {
                tags = newsItem.GetValue <TrackedList <Guid> >("Tags").ToList().Select(i => tMan.GetTaxon(i).Title.Value).ToList();

                newsItems.AppendLine(String.Format("{0}|{1}|{2}", newsItem.Title, String.Join(",", tags), newsItem.Content.Value.Replace("\n", "")));
            }
            var file = new StreamWriter(ServerPath + "\\news.txt");

            file.Write(newsItems);
            file.Close();
        }
예제 #6
0
파일: Helper.cs 프로젝트: WongMW/Demo
        public static String GetCategoryTitle(Object _cats)
        {
            Telerik.OpenAccess.TrackedList <System.Guid> cats = (Telerik.OpenAccess.TrackedList <System.Guid>)_cats;
            string[] ignoreCats = new string[]
            {
                "Chartered Accountants Ireland",
                "Accountancy Ireland",
                "RTP News",
                "CPD",
                "Public Sector",
                "enews",
                "Education",
                "Overseas Member",
                "RTP",
                "RTPeNews",
                "Student News",
                "Tax Representations"
            };

            if (cats.Count == 0)
            {
                return("");
            }

            var foundTaxon = "";

            for (var i = 0; i < cats.Count; i++)
            {
                Guid firstCat = cats[i];

                var taxonomyManager = TaxonomyManager.GetManager();
                var taxon           = taxonomyManager.GetTaxa <HierarchicalTaxon>().Where(t => t.Id.Equals(firstCat)).SingleOrDefault();

                if (taxon != null && !ignoreCats.Contains(taxon.Title.ToString()))
                {
                    foundTaxon = taxon.Title;
                    break;
                }
            }

            return(foundTaxon);
        }
예제 #7
0
        public virtual IList <FlatTaxon> GetFlatTaxons(string fieldName)
        {
            var    cahcedResultKey = this.FieldCacheKey("GetFlatTaxonNames", fieldName);
            object cachedResult;

            if (this.cachedFieldValues.TryGetValue(cahcedResultKey, out cachedResult))
            {
                return(cachedResult as IList <FlatTaxon>);
            }

            var             taxonIds = this.Fields.GetMemberValue(fieldName) as IList <Guid>;
            TaxonomyManager manager  = TaxonomyManager.GetManager();

            var taxonNames = manager.GetTaxa <FlatTaxon>()
                             .Where(t => taxonIds.Contains(t.Id) && t.Taxonomy.Name == fieldName).ToList();

            this.cachedFieldValues[cahcedResultKey] = taxonNames;

            return(taxonNames);
        }
예제 #8
0
        private IEnumerable <Classification> MapClassificationData(TrackedList <Guid> classifications)
        {
            var             classificationData = new List <Classification>();
            TaxonomyManager taxonomyManager    = TaxonomyManager.GetManager();

            if (classifications != null)
            {
                foreach (var cat in classifications)
                {
                    classificationData.Add(new Classification
                    {
                        Id    = taxonomyManager.GetTaxon(cat).Id,
                        Title = taxonomyManager.GetTaxon(cat).Title,
                        Url   = taxonomyManager.GetTaxon(cat).UrlName
                    });
                }
            }

            return(classificationData);
        }
        private void CreateLocation(LocationsManager mgr, string Title, string Address, string City, string Region, string PostalCode, string Country, string Continent)
        {
            var location = mgr.CreateLocation();

            location.Title      = Title;
            location.Address    = Address;
            location.City       = City;
            location.Region     = Region;
            location.PostalCode = PostalCode;
            location.Country    = Country;
            location.Content    = Content;
            location.UrlName    = Title.ToLower().Replace(" ", "-");

            // add taxonomy and save
            var taxonomyMgr = TaxonomyManager.GetManager();
            var taxon       = taxonomyMgr.GetTaxa <HierarchicalTaxon>().Where(t => t.Name == Continent).Select(t => t.Id).ToArray();

            location.Organizer.AddTaxa("Category", taxon);
            mgr.RecompileItemUrls <LocationItem>(location);
        }
        public void NewsWidget_SelectByCategoryNewsFunctionality()
        {
            int    newsCount      = 4;
            string newsTitle      = "Title";
            string categoryTitle  = "Category ";
            var    newsController = new NewsController();

            string[] categoryTitles = new string[newsCount + 1];

            try
            {
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "0");

                for (int i = 0; i <= newsCount; i++)
                {
                    categoryTitles[i] = categoryTitle + i;
                    this.serverOperationsTaxonomies.CreateCategory(categoryTitle + (i + 1), categoryTitle + i);
                    ServerOperationsFeather.NewsOperations().CreatePublishedNewsItem(NewsTitle + i, "Content", "AuthorName", "SourceName", new List <string> {
                        categoryTitle + i
                    }, null, null);
                }

                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();

                for (int i = 0; i < newsCount; i++)
                {
                    var    category = taxonomyManager.GetTaxa <HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + i);
                    ITaxon taxonomy = taxonomyManager.GetTaxon(category.Id);
                    var    items    = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                    for (int j = 0; j < items.Length; j++)
                    {
                        Assert.IsTrue(items[j].Fields.Title.Equals(newsTitle + i, StringComparison.CurrentCulture), "The news with this title was not found!");
                    }
                }
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteCategories(categoryTitles);
            }
        }
        private void AssignTaxonomiesToImages(List <Guid> listOfIds)
        {
            ServerOperations.Taxonomies().CreateCategory(CategoryTitle + "0");
            var taxonomyManager = TaxonomyManager.GetManager();

            for (int i = 1; i < 5; i++)
            {
                ServerOperations.Taxonomies().CreateCategory(CategoryTitle + i, CategoryTitle + (i - 1));
                var category = taxonomyManager.GetTaxa <HierarchicalTaxon>().Single(t => t.Title == CategoryTitle + i);
                ServerOperations.Taxonomies().CreateTag(TagTitle + i);
                var tag = taxonomyManager.GetTaxa <FlatTaxon>().Single(t => t.Title == TagTitle + i);
                ServerOperations.Documents().AssignTaxonToDocument(listOfIds[i - 1], "Category", category.Id);
                ServerOperations.Documents().AssignTaxonToDocument(listOfIds[i - 1], "Tags", tag.Id);
            }

            var category3 = taxonomyManager.GetTaxa <HierarchicalTaxon>().Single(t => t.Title == CategoryTitle + 3);
            var tag3      = taxonomyManager.GetTaxa <FlatTaxon>().Single(t => t.Title == TagTitle + 3);

            ServerOperations.Documents().AssignTaxonToDocument(listOfIds[0], "Category", category3.Id);
            ServerOperations.Documents().AssignTaxonToDocument(listOfIds[0], "Tags", tag3.Id);
        }
예제 #12
0
        public DynamicContent CreatePressArticleItem(string title, string url)
        {
            var providerName = string.Empty;

            if (ServerOperations.MultiSite().CheckIsMultisiteMode())
            {
                providerName = "dynamicContentProvider";
            }

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle");

            Telerik.Sitefinity.DynamicModules.Model.DynamicContent pressArticleItem = dynamicModuleManager.CreateDataItem(pressArticleType);

            // This is how values for the properties are set
            pressArticleItem.SetValue("Title", title);
            pressArticleItem.SetValue("PublishedBy", "Some PublishedBy");
            pressArticleItem.SetValue("Guid", Guid.NewGuid());

            TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
            var             tag             = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Taxonomy.Name == "Tags").FirstOrDefault();

            if (tag != null)
            {
                pressArticleItem.Organizer.AddTaxa("Tags", tag.Id);
            }

            pressArticleItem.SetString("UrlName", url);
            pressArticleItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
            pressArticleItem.SetValue("PublicationDate", DateTime.Now);
            pressArticleItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
            dynamicModuleManager.Lifecycle.Publish(pressArticleItem);

            dynamicModuleManager.RecompileDataItemsUrls(pressArticleType);

            // You need to call SaveChanges() in order for the items to be actually persisted to data store
            dynamicModuleManager.SaveChanges();

            return(pressArticleItem);
        }
        public void CreateProduct()
        {
            ProductsManager productsManager = ProductsManager.GetManager();

            var productItem = productsManager.CreateProduct(ProductsIntegrationTests.productItemId);

            productItem.Title   = "Test Product";
            productItem.Content = "<h1>Simple content goes here ...</h1>";

            var taxManager = TaxonomyManager.GetManager();

            AddTaxaToProduct(productItem, taxManager, "Colors", ProductsIntegrationTests.colorName);

            productItem.WhatIsInTheBox  = "Summary goes here...";
            productItem.QuantityInStock = 1;
            productItem.Price           = 10;

            AddImageToProductItem(productItem);

            productsManager.SaveChanges();
            var contextBag = new Dictionary <string, string>();

            contextBag.Add("ContentType", productItem.GetType().FullName);

            string workflowOperation = "Publish";

            WorkflowManager.MessageWorkflow(
                productItem.Id,
                productItem.GetType(),
                "OpenAccessDataProvider",
                workflowOperation,
                false,
                contextBag);

            var product = productsManager.GetProduct(ProductsIntegrationTests.productItemId);

            Assert.IsNotNull(product);
            Assert.IsNotNull(product.GetValue("Colors"));
        }
예제 #14
0
        public void Categories_VerifyTaxaFromContentItemIsRetrieved()
        {
            var item = NewsManager.GetManager().GetNewsItems().FirstOrDefault();

            var model = new HierarchicalTaxonomyModel();

            model.ContentId = item.Id;

            var viewModel = model.CreateViewModel();

            var itemTaxa = (IList <Guid>)item.GetValue("Category");

            Assert.AreEqual(itemTaxa.Count, viewModel.Taxa.Count);

            var taxonomyManager = TaxonomyManager.GetManager();

            for (var i = 0; i < itemTaxa.Count; i++)
            {
                var taxon = taxonomyManager.GetTaxa <HierarchicalTaxon>().FirstOrDefault(t => t.Id == itemTaxa[i]);
                Assert.AreEqual(taxon.Title.ToString(), viewModel.Taxa[i].Title);
            }
        }
예제 #15
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sfContent">The sf content.</param>
        public DepartmentModel(HierarchicalTaxon sfContent)
        {
            var manager = TaxonomyManager.GetManager();

            Id               = sfContent.Id;
            Title            = sfContent.Title;
            Description      = sfContent.Description;
            FullUrl          = sfContent.FullUrl;
            Ordinal          = sfContent.Ordinal;
            RenderAsLink     = sfContent.RenderAsLink;
            ShowInNavigation = sfContent.ShowInNavigation;
            TaxonName        = sfContent.Taxonomy.TaxonName;
            Slug             = sfContent.UrlName;
            LastModified     = sfContent.LastModified;

            //STORE PARENT DETAILS IF APPLICABLE
            if (sfContent.Parent != null)
            {
                Parent = new ParentModel
                {
                    Id          = sfContent.Parent.Id,
                    Title       = sfContent.Parent.Title,
                    Description = sfContent.Parent.Description,
                    Ordinal     = sfContent.Parent.Ordinal,
                    Slug        = sfContent.Parent.UrlName
                };
            }

            //BUILD CHILDREN CATEGORIES
            Subtaxa = new List <DepartmentModel>();
            sfContent.Subtaxa.ToList().ForEach(c =>
                                               Subtaxa.Add(new DepartmentModel(c)));

            //GET NUMBER OF ITEMS IN CATEGORY
            Count = (int)manager.GetTaxonItemsCount(sfContent.Id, ContentLifecycleStatus.Live);

            // Store original content
            OriginalContent = sfContent;
        }
예제 #16
0
        /// <summary>
        /// Gets the or create template category identifier.
        /// </summary>
        /// <param name="templateCategoryName">The template category name.</param>
        /// <param name="createIfNotExist">if set to <c>true</c> [create if not exist].</param>
        /// <returns>The id of the category.</returns>
        public virtual Guid GetOrCreateTemplateCategoryId(string templateCategoryName, bool createIfNotExist = true)
        {
            var taxonomyManager = TaxonomyManager.GetManager();

            var pageTemplatesTaxonomy = taxonomyManager.GetTaxonomy <HierarchicalTaxonomy>(SiteInitializer.PageTemplatesTaxonomyId);
            var templateCategory      = pageTemplatesTaxonomy.Taxa.SingleOrDefault(t => t.Name.Equals(templateCategoryName, StringComparison.OrdinalIgnoreCase));

            if (templateCategory == null && createIfNotExist)
            {
                templateCategory              = taxonomyManager.CreateTaxon <HierarchicalTaxon>();
                templateCategory.Name         = templateCategoryName;
                templateCategory.UrlName      = templateCategoryName;
                templateCategory.RenderAsLink = false;
                templateCategory.Title        = templateCategoryName;
                templateCategory.Description  = string.Format("Represents category for {0} page templates.", templateCategoryName);

                pageTemplatesTaxonomy.Taxa.Add(templateCategory);
                taxonomyManager.SaveChanges();
            }

            return(templateCategory.Id);
        }
예제 #17
0
        /// <summary>
        /// Gets the taxons.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="taxonomyField">The taxonomy field.</param>
        /// <returns>
        /// The taxa.
        /// </returns>
        public static List <TaxonModel> GetTaxa(this IDynamicFieldsContainer content, string taxonomyField)
        {
            var taxonomyManager = TaxonomyManager.GetManager();
            var list            = new List <TaxonModel>();

            //POPULATE CATEGORIES IF APPLICABLE
            if (content.DoesFieldExist(taxonomyField))
            {
                var ids = content.GetValue <TrackedList <Guid> >(taxonomyField);
                if (ids.Any())
                {
                    //BUILD COLLECTION OF TAXONS
                    foreach (Guid item in ids)
                    {
                        list.Add(new TaxonModel(taxonomyManager.GetTaxon(item)));
                    }
                }
            }

            //RETURN CONSTRUCTED LIST
            return(list);
        }
        public void NewsWidget_SelectByTagNewsFunctionality()
        {
            int newsCount = 2;

            Guid[] taxonId        = new Guid[newsCount];
            Guid[] newsId         = new Guid[newsCount];
            string newsTitle      = "News ";
            string tagTitle       = "Tag ";
            var    newsController = new NewsController();

            string[] tagTitles = new string[newsCount];

            try
            {
                for (int i = 0; i < newsCount; i++)
                {
                    taxonId[i]   = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle + i);
                    tagTitles[i] = tagTitle + i;
                    newsId[i]    = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + i);
                    this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Tags", taxonId[i]);
                }

                for (int i = 0; i < newsCount; i++)
                {
                    ITaxon taxonomy = TaxonomyManager.GetManager().GetTaxon(taxonId[i]);
                    var    items    = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                    for (int j = 0; j < items.Length; j++)
                    {
                        Assert.IsTrue(items[j].Fields.Title.Equals(newsTitle + i, StringComparison.CurrentCulture), "The news with this title was not found!");
                    }
                }
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteTags(tagTitles);
            }
        }
예제 #19
0
        public ActionResult Index()
        {
            List <PopularToursItemModel> popularToursItemModel = new List <PopularToursItemModel>();
            var  manager = DynamicModuleManager.GetManager();
            Type Tour    = TypeResolutionService.ResolveType(DynamicContentConstants.DynamicContent.Types.Tour);

            TaxonomyManager taxaManager      = TaxonomyManager.GetManager();
            var             adventuresTaxa   = taxaManager.GetTaxa <FlatTaxon>().Where(t => t.Taxonomy.Name == DynamicContentConstants.DynamicContent.Tours.Adventures).ToList();
            var             difficultiesTaxa = taxaManager.GetTaxa <FlatTaxon>().Where(t => t.Taxonomy.Name == DynamicContentConstants.DynamicContent.Tours.Difficulties).ToList();
            //get the selected items
            var items = manager.GetDataItems(Tour).Where(item => item.Status == ContentLifecycleStatus.Live && item.Visible).ToList();



            foreach (var item in items)
            {
                var image = item.GetRelatedItems(DynamicContentConstants.DynamicContent.Tours.ThumbnailImage).FirstOrDefault() as Image;
                var adventureTaxaTitles      = item.GetAssociatedTagNamesForContentItem(DynamicContentConstants.DynamicContent.Tours.Adventures, adventuresTaxa);
                var difficultyTaxaTitles     = item.GetAssociatedTagNamesForContentItem(DynamicContentConstants.DynamicContent.Tours.Difficulties, difficultiesTaxa);
                var accomodationChoiceFields = item.GetValue <IEnumerable <ChoiceOption> >(DynamicContentConstants.DynamicContent.Tours.Accomodation).ToList();
                var model = new PopularToursItemModel
                {
                    Title          = item.GetString(DynamicContentConstants.DynamicContent.Tours.Title),
                    Description    = item.GetString(DynamicContentConstants.DynamicContent.Tours.Description),
                    NoOfDays       = Convert.ToString(item.GetValue(DynamicContentConstants.DynamicContent.Tours.NoOfDays)),
                    SizeOfTour     = Convert.ToString(item.GetValue(DynamicContentConstants.DynamicContent.Tours.SizeOfTour)),
                    NoOfTourGuides = Convert.ToString(item.GetValue(DynamicContentConstants.DynamicContent.Tours.NoOfTourGuides)),
                    Price          = Convert.ToString(item.GetValue(DynamicContentConstants.DynamicContent.Tours.Price)),
                    AdventureTags  = adventureTaxaTitles.Any() ? string.Join(",", adventureTaxaTitles) : string.Empty,
                    DifficultyTags = difficultyTaxaTitles.Any() ? string.Join(",", difficultyTaxaTitles) : string.Empty,
                    Accomodation   = accomodationChoiceFields.Any() ? string.Join(",", accomodationChoiceFields) : string.Empty,
                    ImageUrl       = image != null ? image.MediaUrl : string.Empty
                };
                popularToursItemModel.Add(model);
            }
            model.toursItemModel = popularToursItemModel;
            return(View("Tours" + this._template, model));
        }
예제 #20
0
        /// <summary>
        /// Creates news item with tag.
        /// </summary>
        /// <param name="newsTitle">The news title.</param>
        public void AddCustomTaxonomyToNews(Guid newsItemId, string taxonomyName, IEnumerable <string> taxonNames)
        {
            var      newsManager = Telerik.Sitefinity.Modules.News.NewsManager.GetManager();
            NewsItem newsItem    = newsManager.GetNewsItem(newsItemId);

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

            TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();

            foreach (var taxonName in taxonNames)
            {
                var taxon = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Title == taxonName).FirstOrDefault();
                if (taxon != null)
                {
                    newsItem.Organizer.AddTaxa(taxonomyName, taxon.Id);
                }
            }

            newsManager.SaveChanges();
        }
예제 #21
0
        public void SetUp()
        {
            Guid pageId = ServerOperations.Pages().CreatePage(PageName);

            ServerOperationsFeather.DynamicModules().EnsureModuleIsImported(ModuleName, ModuleResource);
            ServerOperations.Taxonomies().CreateCategory(this.taxonTitleDynamic + "0");
            ServerOperations.Taxonomies().CreateCategory(this.taxonTitleNews + "0");

            for (int i = 1; i < 4; i++)
            {
                ServerOperations.Taxonomies().CreateCategory(this.taxonTitleDynamic + i, this.taxonTitleDynamic + (i - 1));
                ServerOperations.Taxonomies().CreateCategory(this.taxonTitleNews + i, this.taxonTitleNews + (i - 1));
                var category = TaxonomyManager.GetManager().GetTaxa <HierarchicalTaxon>().SingleOrDefault(t => t.Title == this.taxonTitleDynamic + i);
                ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticle(ItemsTitle + (i - 1), ItemsTitle + i + "Url", Guid.Empty, category.Id);
                ServerOperationsFeather.NewsOperations().CreatePublishedNewsItem(NewsTitle + i, NewsContent, AuthorName, SourceName, new List <string> {
                    this.taxonTitleNews + i
                }, null, null);
            }

            ServerOperationsFeather.Pages().AddDynamicWidgetToPage(pageId, "Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle", "PressArticle", "Press Articles MVC");
            ServerOperationsFeather.Pages().AddNewsWidgetToPage(pageId);
            ServerOperationsFeather.Pages().AddCategoriesWidgetToPage(pageId);
        }
        public static IQueryable <DynamicContent> GetContentByFlatTaxonomyTerm(String contentType, String term, String fieldName)
        {
            var providerName = String.Empty;

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type resourceType = TypeResolutionService.ResolveType(contentType);

            // This is how we get the resource items through filtering

            var manager = TaxonomyManager.GetManager();
            //Get the GUID of the desired category
            var category = manager.GetTaxa <FlatTaxon>().Where(t => t.Name.ToLower() == term).SingleOrDefault();

            if (category == null)
            {
                throw new InvalidProgramException("No category found");
            }
            var categoryId = category.Id;

            return(dynamicModuleManager.GetDataItems(resourceType)
                   .Where(d => d.GetValue <TrackedList <Guid> >(fieldName).Contains(categoryId) &&
                          d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live));
        }
예제 #23
0
        public void EditTag(string oldTitle, string newTitle)
        {
            var manager = TaxonomyManager.GetManager();
            var tag     = manager.GetTaxonomies <FlatTaxonomy>().Where(t => t.Name == "Tags").SingleOrDefault();

            if (tag != null)
            {
                FlatTaxon taxon = manager.GetTaxa <FlatTaxon>().Where(t => t.Title == oldTitle).SingleOrDefault();

                if (taxon != null)
                {
                    //// Code below is commented, because code below is not editing the title, which is relevant for UI tests
                    taxon.Title = newTitle;

                    //// taxon.Title = new Lstring(newTitle, CultureInfo.InvariantCulture);
                    //// taxon.Name = Regex.Replace(newTitle, " ", string.Empty);

                    taxon.UrlName  = Regex.Replace(newTitle.ToLower(CultureInfo.CurrentCulture), ArrangementConstants.UrlNameCharsToReplace, ArrangementConstants.UrlNameReplaceString);
                    taxon.Taxonomy = tag;

                    manager.SaveChanges();
                }
            }
        }
예제 #24
0
        private List <BlendedListItem> GetNewsBlendedForUrl(List <Type> dynamicContent, string url)
        {
            List <BlendedListItem> newsBlend = new List <BlendedListItem>();

            if (dynamicContent.Any())
            {
                var dynamicModuleManager = DynamicModuleManager.GetManager();
                var taxonomyManager      = TaxonomyManager.GetManager();
                log.Info("contYpe:{0}".Fmt(dynamicContent.Count));
                foreach (Type contentType in dynamicContent)
                {
                    log.Info("type of:{0} with url{1}".Fmt(contentType, url));
                    DynamicContent content = dynamicModuleManager.GetDataItems(contentType).FirstOrDefault(bp => bp.UrlName == url);
                    if (content != null)
                    {
                        log.Info("dyn content url is:{0} from {1}".Fmt(content.UrlName, url));
                        DynamicContent liveContent = dynamicModuleManager.Lifecycle.GetLive(content) as DynamicContent;
                        if (liveContent != null)
                        {
                            List <Guid> categories        = liveContent.GetValue <IList <Guid> >("Category").ToList();
                            Guid[]      contentCategories = new Guid[0];
                            int         hitCount          = 0;
                            contentCategories =
                                categories.Where(c => taxonomyManager.GetTaxon <HierarchicalTaxon>(c) != null)
                                .Select(m => m)
                                .ToArray();
                            //var resultContent = BlendedNewsHelper.GetNewsItems(Providers, _searchIndex, out hitCount, contentCategories, null, 0, this.NumberOfPosts + 10);
                            var resultContent = BlendedNewsHelper.GetNewsDocs(Providers, _searchIndex, out hitCount, contentCategories, null, 0, this.NumberOfPosts + 10);
                            List <BlendedListItem> newsResult = SetBlendedListItems(resultContent);
                            return(newsResult);
                        }
                    }
                }
            }
            return(newsBlend);
        }
예제 #25
0
 public TaxonomiesService()
 {
     manager = TaxonomyManager.GetManager();
 }
예제 #26
0
        /// <summary>
        /// Adds a custom field to Press article
        /// </summary>
        /// <param name="fieldname">Name of the field</param>
        /// <param name="isHierarchicalTaxonomy">is hierarchical taxonomy</param>
        public void AddCustomTaxonomyToContext(string fieldname, bool isHierarchicalTaxonomy)
        {
            Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle");

            if (pressArticleType == null)
            {
                throw new ArgumentException("PressArticle type can't be resolved.");
            }

            var context = new CustomFieldsContext(pressArticleType);

            TaxonomyManager manager = TaxonomyManager.GetManager();
            Guid            taxonomyId;

            if (isHierarchicalTaxonomy == true)
            {
                var taxonomy = manager.GetTaxonomies <HierarchicalTaxonomy>().Where(t => t.Title == fieldname).SingleOrDefault();
                if (taxonomy != null)
                {
                    taxonomyId = taxonomy.Id;
                }
                else
                {
                    throw new ArgumentException("The taxonomy '" + fieldname + "' does not exist in the system");
                }
            }
            else
            {
                var taxonomy = manager.GetTaxonomies <FlatTaxonomy>().Where(t => t.Title == fieldname).SingleOrDefault();
                if (taxonomy != null)
                {
                    taxonomyId = taxonomy.Id;
                }
                else
                {
                    throw new ArgumentException("The taxonomy '" + fieldname + "' does not exist in the system");
                }
            }

            UserFriendlyDataType userFriendlyDataType = UserFriendlyDataType.Classification;
            var field = new WcfField()
            {
                Name         = fieldname,
                ContentType  = "Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle",
                FieldTypeKey = userFriendlyDataType.ToString(),
                IsCustom     = true,

                // Field definition
                Definition = new WcfFieldDefinition()
                {
                    Title                  = fieldname,
                    FieldName              = fieldname.ToLower(),
                    FieldType              = isHierarchicalTaxonomy ? typeof(HierarchicalTaxonField).FullName : typeof(FlatTaxonField).FullName,
                    TaxonomyId             = taxonomyId.ToString(),
                    AllowMultipleSelection = true,
                }
            };

            var fields = new Dictionary <string, WcfField>();

            fields.Add(field.FieldTypeKey, field);

            context.AddOrUpdateCustomFields(fields, pressArticleType.Name);
            context.SaveChanges();
        }
예제 #27
0
        public void DynamicWidgets_SelectByTagAndSortFunctionality()
        {
            int tagsCount = 3;

            Guid[] taxonId       = new Guid[tagsCount];
            string sortExpession = "Title ASC";

            string[] itemsTitles  = { "Boat", "Cat", "Angel", "Kitty", "Dog" };
            string[] urls         = { "AngelUrl", "BoatUrl", "CatUrl", "KittyUrl", "DogUrl" };
            string[] sortedTitles = { "Angel", "Boat", "Cat" };

            var dynamicController = new DynamicContentController();

            dynamicController.Model.ContentType    = TypeResolutionService.ResolveType(ResolveType);
            dynamicController.Model.SortExpression = sortExpession;
            dynamicController.Model.ProviderName   = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName;

            try
            {
                for (int i = 0; i < tagsCount; i++)
                {
                    taxonId[i] = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, this.tagTitles[i]);
                }

                for (int i = 0; i < itemsTitles.Count(); i++)
                {
                    if (i <= 2)
                    {
                        ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticle(itemsTitles[i], urls[i], taxonId[0], Guid.Empty);
                    }
                    else
                    {
                        ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticle(itemsTitles[i], urls[i], taxonId[i - 2], Guid.Empty);
                    }
                }

                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();

                for (int i = 0; i < tagsCount; i++)
                {
                    var tag          = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Id == taxonId[i]).FirstOrDefault();
                    var modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: tag, page: 1);
                    var dynamicItems = modelItems.Items.ToList();
                    int itemsCount   = dynamicItems.Count;

                    if (i == 0)
                    {
                        for (int j = 0; j < itemsCount; j++)
                        {
                            Assert.IsTrue(dynamicItems[j].Fields.Title.Equals(sortedTitles[j], StringComparison.CurrentCulture), "The item with this title was not found!");
                        }
                    }
                    else
                    {
                        for (int j = 0; j < itemsCount; j++)
                        {
                            Assert.IsTrue(dynamicItems[j].Fields.Title.Equals(itemsTitles[i + 2], StringComparison.CurrentCulture), "The item with this title was not found!");
                        }
                    }
                }
            }
            finally
            {
                ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles());
                this.serverOperationsTaxonomies.DeleteTags(this.tagTitles);
            }
        }
        //***********Helper Methods***********//
        //************************************//
        //************************************//
        #region SetBlendedListItems

        private List <BlendedListItem> SetBlendedListItems(IResultSet results)
        {
            log.Info("Begin SetBlendedListItems.");
            var resultSet       = new List <BlendedListItem>();
            var taxonomyManager = TaxonomyManager.GetManager();

            log.Debug("Iterating through the results.");
            foreach (IDocument result in results)
            {
                log.Trace("Getting a new instance of BlendedListItem.");
                var newsResult = new BlendedListItem();

                log.Trace(() => String.Join("\n", result.Fields.Select(f => f.Name + ": " + f.Value)));

                if (result.Fields.Any(x => x.Name == "Title"))
                {
                    newsResult.Title = result.GetValue("Title").ToString();
                    log.Trace("Title Set.");
                }

                if (result.Fields.Any(x => x.Name == "LocationStreet"))
                {
                    newsResult.LocationStreet = result.GetValue("LocationStreet").ToString();
                    log.Trace("LocationStreet Set.");
                }

                if (result.Fields.Any(x => x.Name == "LocationState"))
                {
                    newsResult.LocationState = result.GetValue("LocationState").ToString();
                    log.Trace("LocationState Set.");
                }

                if (result.Fields.Any(x => x.Name == "LocationCity"))
                {
                    newsResult.LocationCity = result.GetValue("LocationCity").ToString();
                    log.Trace("LocationCity Set.");
                }

                if (result.Fields.Any(x => x.Name == "Summary"))
                {
                    newsResult.Summary = result.GetValue("Summary").ToString();
                    log.Trace("Summary Set.");
                }

                if (result.Fields.Any(x => x.Name == "Content"))
                {
                    newsResult.Content = result.GetValue("Content").ToString();
                    log.Trace("Content Set.");
                }

                var featured = result.GetValue("FeaturedRank").ToString() == "1" ? true : false;
                newsResult.Featured = featured;

                if (result.Fields.Any(x => x.Name == "Link"))
                {
                    newsResult.Link = result.GetValue("Link").ToString();
                    log.Trace("Link  Set.");
                }

                if (result.Fields.Any(x => x.Name == "EventStart"))
                {
                    try
                    {
                        DateTime dp = DateTime.MinValue;
                        //newsResult.EventStartDate = DateTime.ParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                        DateTime.TryParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.EventStartDate = dp;
                        //log.Trace("EventStart Set.");
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "EventEnd"))
                {
                    try
                    {
                        /*newsResult.EventEndDate = DateTime.ParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                         * log.Trace("EventStart Set.");*/
                        DateTime dp = DateTime.MinValue;
                        DateTime.TryParseExact(result.GetValue("EventEnd").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.EventEndDate = dp;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "PublishDate"))
                {
                    try
                    {
                        /*newsResult.PublicationDate = DateTime.ParseExact(result.GetValue("PublishDate").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                         * log.Trace("PublishDate Set.");*/
                        DateTime dp = DateTime.MinValue;
                        DateTime.TryParseExact(result.GetValue("PublishDate").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.PublicationDate = dp;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "CategoryIds"))
                {
                    newsResult.Categories = new List <CategoryPair>();

                    var categoryIds = result.GetValue("CategoryIds").ToString().Split(',').ToList();
                    foreach (var categoryItem in categoryIds)
                    {
                        try
                        {
                            if (!categoryItem.IsNullOrWhitespace())
                            {
                                var categoryPair = new CategoryPair();
                                if (categoryItem.IsGuid())
                                {
                                    categoryPair.Guid = categoryItem;
                                    var taxon = taxonomyManager.GetTaxon(Guid.Parse(categoryItem));
                                    categoryPair.Name = taxon.Title.Value;
                                    newsResult.Categories.Add(categoryPair);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Source: {0}", ex.Source);
                            log.Error("Stack Trace: {0}", ex.StackTrace);
                            log.Error("Message: {0}", ex.Message);
                        }
                    }
                    //newsResult.Categories = result.GetValue("CategoryList").ToString().Split(',').Select(x => x.Trim()).ToList();
                    //log.Trace("CategoryList Set.");
                }

                if (result.Fields.Any(x => x.Name == "ResourceTypesIds"))
                {
                    newsResult.ResourceTypes = new List <CategoryPair>();

                    var resourceTypesIds = result.GetValue("ResourceTypesIds").ToString().Split(',').ToList();
                    foreach (var resourceTypeItem in resourceTypesIds)
                    {
                        try
                        {
                            if (!resourceTypeItem.IsNullOrWhitespace())
                            {
                                var categoryPair = new CategoryPair();
                                if (resourceTypeItem.IsGuid())
                                {
                                    categoryPair.Guid = resourceTypeItem;
                                    var taxon = taxonomyManager.GetTaxon(Guid.Parse(resourceTypeItem));
                                    categoryPair.Name = taxon.Title.Value;
                                    newsResult.Categories.Add(categoryPair);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Source: {0}", ex.Source);
                            log.Error("Stack Trace: {0}", ex.StackTrace);
                            log.Error("Message: {0}", ex.Message);
                        }
                    }
                    //newsResult.ResourceTypes = result.GetValue("ResourceTypesList").ToString().Split(',').Select(x => x.Trim()).ToList();
                    //log.Trace("ResourceTypesList Set.");
                }

                if (result.Fields.Any(x => x.Name == "OrganizationalAuthorsIds"))
                {
                    newsResult.OrganizationalAuthors = new List <CategoryPair>();

                    var organizationalAuthorIds = result.GetValue("OrganizationalAuthorsIds").ToString().Split(',').ToList();
                    foreach (var organizationalAuthorItem in organizationalAuthorIds)
                    {
                        try
                        {
                            if (!organizationalAuthorItem.IsNullOrWhitespace())
                            {
                                var categoryPair = new CategoryPair();
                                if (organizationalAuthorItem.IsGuid())
                                {
                                    categoryPair.Guid = organizationalAuthorItem;
                                    var taxon = taxonomyManager.GetTaxon(Guid.Parse(organizationalAuthorItem));
                                    categoryPair.Name = taxon.Title.Value;
                                    newsResult.Categories.Add(categoryPair);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Source: {0}", ex.Source);
                            log.Error("Stack Trace: {0}", ex.StackTrace);
                            log.Error("Message: {0}", ex.Message);
                        }
                    }
                    //newsResult.OrganizationalAuthors = result.GetValue("OrganizationalAuthorsList").ToString().Split(',').Select(x => x.Trim()).ToList();
                    //log.Trace("OrganizationalAuthorsList Set.");
                }

                if (result.Fields.Any(x => x.Name == "DefaultLinkBase"))
                {
                    newsResult.DefaultLinkBase = result.GetValue("DefaultLinkBase").ToString();
                    log.Trace("DefaultLinkBase Set.");
                }

                if (result.Fields.Any(x => x.Name == "Selfpaced"))
                {
                    var selfPaced = result.GetValue("Selfpaced").ToString();
                    if (!selfPaced.IsNullOrWhitespace())
                    {
                        newsResult.SelfPaced = bool.Parse(result.GetValue("Selfpaced").ToString());
                        log.Trace("SelfPaced Set.");
                    }
                }

                if (result.Fields.Any(x => x.Name == "DisplayDate"))
                {
                    newsResult.DisplayDate = result.GetValue("DisplayDate").ToString();
                    log.Trace("DisplayDate Set.");
                }

                if (result.Fields.Any(x => x.Name == "DateField"))
                {
                    try
                    {
                        /*newsResult.DateField = DateTime.ParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                         * log.Trace("DateField Set.");*/
                        DateTime dp = DateTime.MinValue;
                        DateTime.TryParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.DateField = dp;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "ContentTypeDescription"))
                {
                    newsResult.ContentType = result.GetValue("ContentTypeDescription").ToString();
                    log.Trace("ContentTypeDescription Set.");
                }

                if (result.Fields.Any(x => x.Name == "ImageUrl"))
                {
                    newsResult.Image = result.GetValue("ImageUrl").ToString();
                    log.Trace("Image Set.");
                }

                if (result.Fields.Any(x => x.Name == "Protected"))
                {
                    newsResult.Protected = result.GetValue("Protected") == "1";
                    log.Trace("Protected Set.");
                }

                if (string.IsNullOrWhiteSpace(newsResult.Summary) && !string.IsNullOrWhiteSpace(newsResult.Content))
                {
                    log.Trace("The summary field is empty and the content has a value, so we will make a summary.");
                    newsResult.Summary = SummaryParser.GetSummary(newsResult.Content, new SummarySettings(SummaryMode.Words, 40, true));
                    log.Trace("Summary made and set.");
                }

                resultSet.Add(newsResult);
                log.Trace("result added to the resturn set.");
            }

            log.Info("Finishing SetBlendedListItems.");
            return(resultSet);
        }
        //**************Actions**************//
        //***********************************//
        //***********************************//
        #region HandleUnknownAction

        protected override void HandleUnknownAction(string actionName)
        {
            log.Info("Begin HandleUnknownAction.");
            var blogsManager = BlogsManager.GetManager();

            log.Trace("Got an instance of the BlogsManager.");
            var taxonomyManager = TaxonomyManager.GetManager();

            log.Trace("Got an instance of the TaxonomyManager.");
            var currentContext = System.Web.HttpContext.Current;

            log.Trace("Got the Current Context.");
            var postUrl = currentContext.Request.Url.AbsolutePath;

            if (postUrl.Contains('?'))
            {
                log.Debug("postUrl contains a '?'.");
                postUrl = postUrl.Split('?').First();
                log.Trace("postUrl: {0}", postUrl.IsNullOrEmpty() ? "There is no url available" : postUrl);
            }

            postUrl = currentContext.Request.Url.AbsolutePath.Split('/').Last();
            log.Debug("postUrl: {0}", postUrl.IsNullOrEmpty() ? "There is no url available" : postUrl);

            var item = blogsManager.GetBlogPosts().Where(bp => bp.UrlName == postUrl).FirstOrDefault();

            if (item != null)
            {
                log.Debug("item: {0}", item.Title.Value.IsNullOrEmpty() ? "There is no title set" : item.Title.Value);
                item = blogsManager.Lifecycle.GetLive(item) as BlogPost;
                log.Trace("Got the live version of the Blog Post.");
                try
                {
                    var allCategories = item.GetValue <IList <Guid> >("Category").ToArray();
                    log.Debug("Got a list of category ids for the post, {0}.", allCategories.Count());
                    List <Guid> categories = new List <Guid>();
                    log.Trace("Set the list for Blended List Query.");
                    int hitCount = 0;
                    log.Trace("Set the hitcount variable required for Sitefinity Search.");

                    foreach (var currGuid in allCategories)
                    {
                        var currTaxon = taxonomyManager.GetTaxon <HierarchicalTaxon>(currGuid);

                        if (currTaxon != null)
                        {
                            log.Debug("Got taxonomy, {0}, for the id, {1}", currTaxon.Title.Value.IsNullOrEmpty() ? "There is no title set" : currTaxon.Title.Value);
                            categories.Add(currGuid);
                            log.Trace("Taxon added to the list for the search.");
                        }
                    }

                    log.Info("Calling BlendedListHelper.GetItems.");
                    var resultListItems = BlendedNewsHelper.GetNewsItems(Providers, _searchIndex, out hitCount, categories.ToArray(), null, 0, this.NumberOfPosts + 10);
                    log.Info("Number of results: {0}", hitCount);
                    log.Info("Calling SetBlendedListItems.");
                    var blendedListItems = SetBlendedListItems(resultListItems);
                    log.Debug("Prune the current Item if it is in the list.");
                    blendedListItems = blendedListItems
                                       .Where(bli => !bli.Link.Contains(item.UrlName) &&
                                              !bli.Featured).Take(this.NumberOfPosts).ToList();

                    log.Debug("Prep the template for use.");
                    string template = _viewTemplate;
                    log.Info("Finishing HandleUnknownAction");
                    this.View(template, blendedListItems).ExecuteResult(ControllerContext);
                }
                catch (Exception ex)
                {
                    log.Error("Source: {0}", ex.Source);
                    log.Error("Stack Trace: {0}", ex.StackTrace);
                    log.Error("Message: {0}", ex.Message);
                }
            }
            else
            {
                log.Debug("There was no item for the given url, ({0}).", postUrl.IsNullOrEmpty() ? "There is no url available" : postUrl);
            }
        }
예제 #30
0
        public void DynamicWidgets_SelectByCategoryFunctionalityAndLimits()
        {
            var dynamicController = new DynamicContentController();

            dynamicController.Model.ContentType  = TypeResolutionService.ResolveType(ResolveType);
            dynamicController.Model.DisplayMode  = ListDisplayMode.Limit;
            dynamicController.Model.ProviderName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName;
            int limitCount = 3;

            dynamicController.Model.LimitCount = limitCount;
            string categoryTitle = "Category";

            string[] itemsTitles = { "Boat", "Cat", "Angel", "Kitty", "Dog" };
            string[] urls        = { "AngelUrl", "BoatUrl", "CatUrl", "KittyUrl", "DogUrl" };

            try
            {
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "0");
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "1", categoryTitle + "0");

                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
                var             category0       = taxonomyManager.GetTaxa <HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + "0");
                var             category1       = taxonomyManager.GetTaxa <HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + "1");

                for (int i = 0; i < itemsTitles.Count(); i++)
                {
                    if (i <= 3)
                    {
                        ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticle(itemsTitles[i], urls[i], Guid.Empty, category0.Id);
                    }
                    else
                    {
                        ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticle(itemsTitles[i], urls[i], Guid.Empty, category1.Id);
                    }
                }

                var modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category0, page: 1);
                var dynamicItems = modelItems.Items.ToList();
                int itemsCount   = dynamicItems.Count;

                Assert.IsTrue(itemsCount.Equals(3), "Number of items is not correct");
                for (int i = 0; i <= 2; i++)
                {
                    Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(itemsTitles[3 - i], StringComparison.CurrentCulture), "The items with this title was found!");
                }

                modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category1, page: 1);
                dynamicItems = modelItems.Items.ToList();
                itemsCount   = dynamicItems.Count;

                Assert.IsTrue(itemsCount.Equals(1), "Number of items is not correct");
                Assert.IsTrue(dynamicItems[0].Fields.Title.Equals(itemsTitles[4], StringComparison.CurrentCulture), "The items with this title was found!");

                dynamicController.Model.DisplayMode = ListDisplayMode.All;

                modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category0, page: 1);
                dynamicItems = modelItems.Items.ToList();
                itemsCount   = dynamicItems.Count;

                Assert.IsTrue(itemsCount.Equals(4), "Number of items is not correct");
                for (int i = 0; i <= 3; i++)
                {
                    Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(itemsTitles[3 - i], StringComparison.CurrentCulture), "The items with this title was found!");
                }

                modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category1, page: 1);
                dynamicItems = modelItems.Items.ToList();
                itemsCount   = dynamicItems.Count;

                Assert.IsTrue(itemsCount.Equals(1), "Number of items is not correct");
                Assert.IsTrue(dynamicItems[0].Fields.Title.Equals(itemsTitles[4], StringComparison.CurrentCulture), "The items with this title was found!");
            }
            finally
            {
                ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles());
                this.serverOperationsTaxonomies.DeleteCategories("Category0", "Category1");
            }
        }