Beispiel #1
0
        private static void CreateImportedTagsInSitecore(Sitecore.Data.Database master, List<WPTag> tags, XBlogTags xbTags)
        {
            Sitecore.Data.Items.TemplateItem blogTagTemplate = master.GetItem(Tag.TagTemplateId);
            foreach (WPTag wpt in tags)
            {
                try
                {
                    string tagName = ItemUtil.ProposeValidItemName(wpt.TagName);

                    Tag t = xbTags.InnerItem.Add(tagName, blogTagTemplate).CreateAs<Tag>();

                    using (new EditContext(t.InnerItem))
                    {
                        t.InnerItem.SetString(Tag.TagNameFieldId, wpt.TagName);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("failed to create tag: " + wpt.TagName + ex.Message, "XB Creator");
                }
            }
        }
        private Item AddLanguageVersionItem(string posttype, string itemName, Dictionary<string, string> fieldsToUpdate, TemplateItem template, Item newItem, Sitecore.Data.Database master, string lang, string postid) {

            Item newLanguageVersionItem = master.GetItem(newItem.Paths.Path, Sitecore.Globalization.Language.Parse(lang));

            using (new Sitecore.SecurityModel.SecurityDisabler()) {
                try {
                    if (0 == newLanguageVersionItem.Versions.Count) {
                        newLanguageVersionItem.Versions.AddVersion();
                    }

                    newLanguageVersionItem.Editing.BeginEdit();
                    // Assign values to the fields of the new item
                    foreach (var fields in fieldsToUpdate) {
                        if (fields.Key == "Content Thumbnail") {
                            MediaItem mediaItem = DownloadImage(fields.Value);

                            Sitecore.Data.Fields.ImageField image = newLanguageVersionItem.Fields[fields.Key];
                            image.Src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);
                            image.Alt = mediaItem.Alt;
                            image.MediaID = mediaItem.ID;

                        }
                        else {
                            if (fields.Key == "Page Title") {
                                Response.Write(postid + " | " + lang + " | <b>" + fields.Value + "</b><br/>");
                            }
                            newLanguageVersionItem.Fields[fields.Key].Value = fields.Value;

                        }
                        string tagids = string.Empty;
                        string source = string.Empty;
                        switch (fields.Key) {
                            case "Child Issues":
                                tagids = GetTags(posttype, "child-issue", postid, ChildIssueTemplate, "Issue Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Child Grades":
                                tagids = GetTags(posttype, "grade_level", postid, ChildGradesTemplate, "Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Child Diagnoses":
                                tagids = GetTags(posttype, "child-diagnosis", postid, ChildDiagnosesTemplate, "Diagnosis Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Complexity Levels":
                                tagids = GetTags(posttype, "content-complexity", postid, ComplexityLevelsTemplate, "Complexity Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Diagnosed Condition":
                                tagids = GetTags(posttype, "diagnosed-undiagnosed", postid, DiagnosedConditionTemplate, "Diagnosis Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Applicable Interests":
                                tagids = GetTags(posttype, "parent-interests", postid, ApplicableInterestsTemplate, "Applicable Interests");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Applicable Personalities":
                                tagids = GetTags(posttype, "personality-type", postid, ApplicablePersonalitiesTemplate, "Personality Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Other Applicable Evaluations":
                                tagids = GetTags(posttype, "other-evaluations", postid, OtherApplicableEvaluationsTemplate, "Evaluation Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;


                            //case "Reviewed by":
                            //    source = "/sitecore/content/Globals/Content Taxonomies/Article/Reviewers";
                            //    tagids = GetTags(posttype, "child-diagnosis", newLanguageVersionItem.Fields["Reviewed by"].Source, postid, source);
                            //    if(!string.IsNullOrEmpty(tagids)){
                            //        newLanguageVersionItem[fields.Key] = tagids;
                            //    }
                            //    break;
                        }
                        // newLanguageVersionItem.Fields[fields.Key].Value = fields.Value;
                    }
                    newLanguageVersionItem.Editing.EndEdit();
                    newLanguageVersionItem.Editing.AcceptChanges();

                }
                catch (Exception ex) {
                    newLanguageVersionItem.Editing.CancelEdit();

                }
            }

            return newLanguageVersionItem;
        }
Beispiel #3
0
        private static void CreateImportedAuthorsInSitecore(Sitecore.Data.Database master, List<WPAuthor> authors, XBlogAuthors xbAuthors)
        {
            Sitecore.Data.Items.TemplateItem blogAuthorTemplate = master.GetItem(Author.AuthorTemplateId);
            foreach (WPAuthor wpa in authors)
            {
                try
                {
                    string authorsName = ItemUtil.ProposeValidItemName(wpa.Name);

                    Author a = xbAuthors.InnerItem.Add(authorsName, blogAuthorTemplate).CreateAs<Author>();

                    using (new EditContext(a.InnerItem))
                    {
                        a.InnerItem.SetString(Author.AuthorFullNameFieldId, wpa.Name.Replace(".", " "));
                        a.InnerItem.SetString(Author.AuthorEmailAddressFieldId, wpa.Email);
                        a.InnerItem.SetString(Author.CreatorFieldId, wpa.Creator);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("failed to create author: " + wpa.Name + ex.Message, "XB Creator");
                }
            }
        }
Beispiel #4
0
        private static void CreateImportedCategoriesInSitecore(Sitecore.Data.Database master, List<WPCategory> categories, XBlogCategories xbCategory)
        {
            Sitecore.Data.Items.TemplateItem blogCategoryTemplate = master.GetItem(Category.CategoryTemplateId);
            foreach (WPCategory wpc in categories)
            {
                try
                {
                    string categoryName = ItemUtil.ProposeValidItemName(wpc.CategoryName);

                    Category c = xbCategory.InnerItem.Add(categoryName, blogCategoryTemplate).CreateAs<Category>();

                    using (new EditContext(c.InnerItem))
                    {
                        c.InnerItem.SetString(Category.CategoryNameFieldId, wpc.CategoryName);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("failed to create categor: " + wpc.CategoryName + ex.Message, "XB Creator");
                }
            }
        }
 private void RemoveTestTemplate(Sitecore.Data.Database db)
 {
     using (var disabler = new Sitecore.SecurityModel.SecurityDisabler())
     {
         var template = db.GetItem("/sitecore/templates/user defined/user defined item");
         template.Delete();
     }
 }
 private void RemoveTestContent(Sitecore.Data.Database db)
 {
     using (new SecurityDisabler())
     {
         db.GetItem("/sitecore/content/home/test data").Delete();
     }
 }
 private void CreateTestTemplate(Sitecore.Data.Database db)
 {
     using (var disabler = new Sitecore.SecurityModel.SecurityDisabler())
     {
         string templatexml = File.ReadAllText(System.Environment.CurrentDirectory + @"\..\..\xml\TestTemplate.xml").ToString();
         db.GetItem("/sitecore/templates/user defined").Paste(templatexml, false, PasteMode.Merge);
     }
 }
 private void CreateTestContent(Sitecore.Data.Database db)
 {
     string itemxml = File.ReadAllText(System.Environment.CurrentDirectory + @"\..\..\xml\TestItems.xml");
     Item home = db.GetItem("/sitecore/content/home");
     using (new SecurityDisabler())
     {
         home.Paste(itemxml,false,PasteMode.Merge);
     }
 }
        /// <summary>
        /// Gets the alias item.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        private Item getAliasItem(HttpRequestArgs args, Sitecore.Data.Database masterDb) 
        {
            string websitePath = Sitecore.Context.Site.RootPath.ToLower();

            if (masterDb != null && Sitecore.Context.Site != null)
            {
                if (!string.IsNullOrEmpty(args.LocalPath) && args.LocalPath.Length > 1)
                {                    
                    Item aliasItem = masterDb.GetItem(string.Format("{0}/{1}/{2}", websitePath, "settings", "aliases") + args.LocalPath);                   
                    if (aliasItem != null)
                    {                    
                        return aliasItem;
                    }
                }
            }            

            return null;
        }