Пример #1
0
        public static TaxonomyType GetTaxonomyType(Guid classificationId)
        {
            TaxonomyManager manager  = TaxonomyManager.GetManager();
            var             taxonomy = manager.GetTaxonomy(classificationId);
            var             type     = taxonomy.GetType();

            if (type.IsAssignableFrom(typeof(FlatTaxonomy)))
            {
                return(TaxonomyType.Flat);
            }
            else if (type.IsAssignableFrom(typeof(FacetTaxonomy)))
            {
                return(TaxonomyType.Facet);
            }
            else if (type.IsAssignableFrom(typeof(HierarchicalTaxonomy)))
            {
                return(TaxonomyType.Hierarchical);
            }
            else if (type.IsAssignableFrom(typeof(NetworkTaxonomy)))
            {
                return(TaxonomyType.Network);
            }

            throw new InvalidOperationException();
        }
Пример #2
0
        private void CreateNews(string[] values)
        {
            NewsManager man = NewsManager.GetManager();

            man.Provider.SuppressSecurityChecks = true;
            TaxonomyManager tMan = TaxonomyManager.GetManager();

            tMan.Provider.SuppressSecurityChecks = true;
            string title   = values[0],
                   tags    = values[1],
                   content = values[2];
            var newsItem   = man.GetNewsItems().FirstOrDefault(i => i.Title == title);

            if (newsItem != null)
            {
                return;
            }
            newsItem = man.CreateNewsItem();
            var newsId = newsItem.Id;

            newsItem.Title   = title;
            newsItem.Content = content;
            var tag  = tMan.GetTaxa <FlatTaxon>().FirstOrDefault(i => i.Title == tags);
            var taxa = tMan.GetTaxonomy <FlatTaxonomy>(TaxonomyManager.TagsTaxonomyId);

            if (tag == null)
            {
                tag             = tMan.CreateTaxon <FlatTaxon>(Guid.NewGuid());
                tag.Title       = tags;
                tag.Name        = tags;
                tag.Description = "This tag categorizes the Breakfast";
                tag.UrlName     = new Lstring(Regex.Replace(tags, @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-").ToLower());
                taxa.Taxa.Add(tag);
                tMan.SaveChanges();
            }

            newsItem.Organizer.AddTaxa("Tags", tag.Id);

            newsItem.DateCreated     = DateTime.UtcNow;
            newsItem.PublicationDate = DateTime.UtcNow;
            newsItem.LastModified    = DateTime.UtcNow;
            newsItem.UrlName         = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

            //Recompiles and validates the url of the news item.
            man.RecompileAndValidateUrls(newsItem);

            //Save the changes.
            man.SaveChanges();

            //Publish the news item. The published version acquires new ID.
            var bag = new Dictionary <string, string>();

            bag.Add("ContentType", typeof(NewsItem).FullName);
            WorkflowManager.MessageWorkflow(newsId, typeof(NewsItem), null, "Publish", false, bag);
            man.Lifecycle.Publish(newsItem);
            man.SaveChanges();
        }
Пример #3
0
        /// <summary>
        /// Creates the taxon.
        /// </summary>
        /// <param name="taxonomyId">The taxonomy id.</param>
        /// <param name="taxonTitle">The taxon title.</param>
        /// <returns></returns>
        private Guid CreateTaxon(Guid taxonomyId, string taxonTitle)
        {
            var taxonomyManager = new TaxonomyManager();
            var taxon           = taxonomyManager.CreateTaxon <FlatTaxon>();

            taxon.Taxonomy = taxonomyManager.GetTaxonomy <FlatTaxonomy>(taxonomyId);
            taxon.Title    = taxonTitle;
            taxon.UrlName  = new Lstring(Regex.Replace(taxonTitle, ArrangementConstants.UrlNameCharsToReplace, ArrangementConstants.UrlNameReplaceString).ToLower());
            taxonomyManager.SaveChanges();
            return(taxon.Id);
        }
Пример #4
0
        /// <summary>
        /// Get the linked Tags.
        /// </summary>
        /// <param name="item">The item to act on.</param>
        /// <returns>
        /// The tags.
        /// </returns>
        public static List <Taxon> GetTags(this DynamicContent item)
        {
            var tags = item.GetValue <TrackedList <Guid> >("Tags");

            TaxonomyManager manager = TaxonomyManager.GetManager();

            var taxonomyParent = manager.GetTaxonomy <Taxonomy>(TaxonomyManager.TagsTaxonomyId);
            var taxons         = taxonomyParent.Taxa.Where(x => tags.Contains(x.Id)).ToList();

            return(taxons);
        }
Пример #5
0
        /// <summary>
        /// Get the linked Categories.
        /// </summary>
        /// <param name="item">The item to act on.</param>
        /// <returns>
        /// The categories.
        /// </returns>
        public static List <HierarchicalTaxon> GetCategories(this DynamicContent item)
        {
            var categories = item.GetValue <TrackedList <Guid> >("Category");

            TaxonomyManager manager = TaxonomyManager.GetManager();

            var taxonomyParent = manager.GetTaxonomy <HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId);

            var taxons = taxonomyParent.Taxa.Where(x => categories.Contains(x.Id)).Select(x => (HierarchicalTaxon)x);

            return(taxons.ToList());
        }
Пример #6
0
 /// <summary>
 /// Creates the taxon.
 /// </summary>
 /// <param name="taxonomyId">The taxonomy id.</param>
 /// <param name="taxonTitle">The taxon title.</param>
 /// <returns></returns>
 private Guid CreateTaxon(Guid taxonomyId, string taxonTitle)
 {
     var taxonomyManager = new TaxonomyManager();
     var taxon = taxonomyManager.CreateTaxon<FlatTaxon>();
     taxon.Taxonomy = taxonomyManager.GetTaxonomy<FlatTaxonomy>(taxonomyId);
     taxon.Title = taxonTitle;
     taxon.UrlName = new Lstring(Regex.Replace(taxonTitle, ArrangementConstants.UrlNameCharsToReplace, ArrangementConstants.UrlNameReplaceString).ToLower());
     taxonomyManager.SaveChanges();
     return taxon.Id;
 }