예제 #1
0
            public static void CreateHierarchicalTaxonomyAndTaxon()
            {
                //gets an instance of the taxonomy manager
                TaxonomyManager manager = TaxonomyManager.GetManager();

                //creates hierarchical taxonomy - Language family
                var taxonomy = manager.CreateTaxonomy <HierarchicalTaxonomy>();

                taxonomy.Title     = "Language family";
                taxonomy.Name      = "Language family";
                taxonomy.TaxonName = "Language family";

                //creates a new taxon and adds it to the taxonomy - Language Groups
                var rootTaxonCateg = manager.CreateTaxon <HierarchicalTaxon>();

                rootTaxonCateg.Title       = "Language Groups";
                rootTaxonCateg.Name        = "Language Groups";
                rootTaxonCateg.UrlName     = new Lstring(Regex.Replace("Language Groups", @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-").ToLower());
                rootTaxonCateg.Description = "Language groups description";
                rootTaxonCateg.Taxonomy    = taxonomy;
                taxonomy.Taxa.Add(rootTaxonCateg);

                //creates two sub-taxa and adds them to the Language Groups taxon.
                //1
                var taxonSubCateg = manager.CreateTaxon <HierarchicalTaxon>();

                taxonSubCateg.Title       = "Languages";
                taxonSubCateg.Name        = "Languages";
                taxonSubCateg.UrlName     = new Lstring(Regex.Replace("Languages", @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-").ToLower());
                taxonSubCateg.Description = "Languages description";
                taxonSubCateg.Parent      = rootTaxonCateg;
                taxonSubCateg.Taxonomy    = taxonomy;
                rootTaxonCateg.Subtaxa.Add(taxonSubCateg);

                //2
                var taxonChildSubCateg = manager.CreateTaxon <HierarchicalTaxon>();

                taxonChildSubCateg.Title       = "Dialects";
                taxonChildSubCateg.Name        = "Dialects";
                taxonChildSubCateg.UrlName     = new Lstring(Regex.Replace("Dialects", @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-").ToLower());
                taxonChildSubCateg.Description = "Dialects description";
                taxonChildSubCateg.Parent      = taxonSubCateg;
                taxonChildSubCateg.Taxonomy    = taxonomy;
                taxonSubCateg.Subtaxa.Add(taxonChildSubCateg);

                //Save all changes done up to now.
                manager.SaveChanges();
            }
예제 #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
        private static Taxon GetTagIfItExsistsOrCreateOneIfItDoesnt(string tagName, FlatTaxonomy tags, TaxonomyManager taxonomyManager)
        {
            Taxon tag = tags.Taxa.Where(t => t.Title.ToLower() == tagName.ToLower()).FirstOrDefault();

            if (tag == null)
            {
                tag = taxonomyManager.CreateTaxon<FlatTaxon>();

                SetTagProperties(tag, tagName);

                tag.Taxonomy = tags;

                taxonomyManager.SaveChanges();
            }

            return tag;
        }
        private static Taxon GetDepartmentIfItExsistsOrCreateOneIfItDoesnt(string departmentName, HierarchicalTaxonomy departments, TaxonomyManager taxonomyManager)
        {
            Taxon department = departments.Taxa.Where(t => t.Title.ToLower() == departmentName.ToLower()).FirstOrDefault();

            if (department == null)
            {
                department = taxonomyManager.CreateTaxon<HierarchicalTaxon>();

                SetDepartmentProperties(department, departmentName);

                department.Taxonomy = departments;

                taxonomyManager.SaveChanges();
            }

            return department;
        }
        private void migrateTags(Entry post, BlogPost blogPost, BlogsManager blogsManager)
        {
            TaxonomyManager taxonomyManager = new TaxonomyManager();
            var tax = taxonomyManager.GetTaxonomies<FlatTaxonomy>().Where(t => t.Name == "Tags").SingleOrDefault();

            foreach (Category tag in post.Categories.Where(c => c.CategoryType == CategoryType.Unknown))
            {
                var taxon = taxonomyManager.GetTaxa<FlatTaxon>().Where(t => t.Title == tag.Term).FirstOrDefault();
                if (taxon == null)
                {
                    taxon = taxonomyManager.CreateTaxon<FlatTaxon>();
                    taxon.Name = tag.Term;
                    taxon.Title = tag.Term;

                    tax.Taxa.Add(taxon);
                    taxonomyManager.SaveChanges();
                }

                blogPost.Organizer.AddTaxa("Tags", taxon.Id);
                blogsManager.SaveChanges();
            }
        }
예제 #7
0
        private void migrateTags(Entry post, BlogPost blogPost, BlogsManager blogsManager)
        {
            TaxonomyManager taxonomyManager = new TaxonomyManager();
            var             tax             = taxonomyManager.GetTaxonomies <FlatTaxonomy>().Where(t => t.Name == "Tags").SingleOrDefault();

            foreach (Category tag in post.Categories.Where(c => c.CategoryType == CategoryType.Unknown))
            {
                var taxon = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Title == tag.Term).FirstOrDefault();
                if (taxon == null)
                {
                    taxon       = taxonomyManager.CreateTaxon <FlatTaxon>();
                    taxon.Name  = tag.Term;
                    taxon.Title = tag.Term;

                    tax.Taxa.Add(taxon);
                    taxonomyManager.SaveChanges();
                }

                blogPost.Organizer.AddTaxa("Tags", taxon.Id);
                blogsManager.SaveChanges();
            }
        }
예제 #8
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;
 }