Beispiel #1
0
        public Item AddFolder(String name, Item Parent)
        {
            Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");

            if (Parent == null)
            {
                return(null);
            }
            Item mediaFolder = null;

            try
            {
                Sitecore.Data.Items.TemplateItem FolderTemplate = masterDb.GetTemplate(TemplateIDs.MediaFolder);
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    mediaFolder = Parent.Add(name, FolderTemplate);
                }
                string str = string.Concat("Processed ", Context.Job.Status.Processed, " items");
                Log.Info(str, this);
                JobStatus status = Context.Job.Status;
                status.Processed = status.Processed + (long)1;
                Context.Job.Status.Messages.Add(str);
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(mediaFolder);
        }
        private void InitializeButtonViewRendering()
        {
            DisplayItem = Rendering.Item;

            var generalLinkParameter = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.GeneralLink] ?? null;

            var buttonText   = (string)null;
            var buttonLink   = (string)null;
            var buttonTarget = (string)null;


            if (!string.IsNullOrEmpty(generalLinkParameter))
            {
                var generalLinkXml = HttpUtility.HtmlDecode(generalLinkParameter);

                var renderingParameterTemplateField       = Rendering.RenderingItem.InnerItem.Fields[MobileFieldNames.ViewRenderingFields.ParametersTemplate];
                var renderingParameterTemplateLookupField = new Sitecore.Data.Fields.LookupField(renderingParameterTemplateField);
                var renderingParameterTemplateItem        = new Sitecore.Data.Items.TemplateItem(renderingParameterTemplateLookupField.TargetItem);

                var standardValuesGeneralLinkField = renderingParameterTemplateItem.StandardValues.Fields[MobileFieldNames.ButtonViewRenderingParameters.GeneralLink];

                var generalLinkField = new Sitecore.Data.Fields.LinkField(standardValuesGeneralLinkField, generalLinkXml);

                buttonText   = generalLinkField.Text;
                buttonTarget = !string.IsNullOrEmpty(generalLinkField.Target) ? generalLinkField.Target : null;

                if (!string.IsNullOrEmpty(generalLinkField.Anchor))
                {
                    buttonLink = string.Format("#{0}", generalLinkField.Anchor);
                }
                else
                {
                    buttonLink = generalLinkField.Url;
                }
            }

            ButtonModel = new SitecoreMobile.Models.ButtonModel()
            {
                Item               = DisplayItem,
                ButtonText         = buttonText,
                ButtonLink         = buttonLink,
                ButtonTarget       = buttonTarget,
                LinkFieldName      = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.LinkFieldName] ?? null,
                TextFieldName      = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.TextFieldName] ?? null,
                ButtonIcon         = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonIcon],
                ButtonTheme        = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonTheme],
                ButtonInline       = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonInline] == "1" ? true : false,
                ButtonMini         = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonMini] == "1" ? true : false,
                ButtonIconPosition = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonIconPosition],
                ButtonIconShadow   = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonIconShadow] == "1" || string.IsNullOrEmpty(Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonIconShadow]) ? true : false,
                ButtonCorners      = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonCorners] == "1" || string.IsNullOrEmpty(Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonCorners]) ? true : false,
                ButtonShadow       = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonShadow] == "1" || string.IsNullOrEmpty(Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonShadow]) ? true : false,
                ButtonPopupOverlay = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonPopupOverlay] == "1" || string.IsNullOrEmpty(Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonPopupOverlay]) ? true : false,
                ButtonTransition   = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonTransition] ?? null,
                ButtonMode         = Rendering.Parameters[MobileFieldNames.ButtonViewRenderingParameters.ButtonMode] ?? null
            };
        }
        private bool mapMediaItemToSharedContent(Sitecore.Data.Database database, Item allocationItem, string title, MediaItem mediaItem, out ID itemId)
        {
            bool bOk = false;

            itemId = null;

            try
            {
                Item docs = allocationItem.Children["Documents"];
                if (docs == null)
                {
                    Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Folder Types/Investment Folders/Investment Document Folder");
                    docs = allocationItem.Add("Documents", docsTemplateItem);
                }

                Item performanceItem = docs.Children[title];
                if (performanceItem == null)
                {
                    Sitecore.Data.Items.TemplateItem performanceTemplateItem = database.GetItem("/sitecore/templates/Genworth/Document Types/Investments/Portfolio Information/Monthly Strategist Performance Report");
                    performanceItem = docs.Add(title, performanceTemplateItem);
                }

                itemId = performanceItem.ID;

                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    performanceItem.Editing.BeginEdit();

                    Sitecore.Data.Fields.FileField fileField = performanceItem.Fields["File"];
                    fileField.MediaID = mediaItem.ID;
                    fileField.Src     = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);

                    if (dictCategories.ContainsKey("Performance"))
                    {
                        performanceItem["Category"] = dictCategories["Performance"].ToString();
                    }

                    if (dictSources.ContainsKey("AssetMark"))
                    {
                        performanceItem["Source"] = dictSources["AssetMark"].ToString();
                    }

                    performanceItem["Date"] = Sitecore.DateUtil.ToIsoDate(DateTime.Now);

                    performanceItem.Editing.EndEdit();
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapMediaItemToSharedContent, allocation: {1}, title {2}, exception: {3}", allocationItem["Title"], title, ex.ToString()), this);
            }

            return(bOk);
        }
 private void InjectTheNeededTemplate(MediaItem currentItem)
 {
     using (new SecurityModel.SecurityDisabler())
     {
         Sitecore.Data.Items.TemplateItem baseImageTemplate = currentItem.InnerItem.Template;
         baseImageTemplate.InnerItem.Editing.BeginEdit();
         baseImageTemplate.InnerItem["__Base Template"] = $"{baseImageTemplate.InnerItem.Fields["__Base Template"].Value}|{ImageCompressionConstants.TemplateIDs.RelatedImageTemplateId}";
         baseImageTemplate.InnerItem.Editing.EndEdit();
     }
 }
        private bool mapMediaItemToSharedContent(Sitecore.Data.Database database, Item managerItem, string title, MediaItem mediaItem)
        {
            bool bOk = false;

            try
            {
                Item docs = managerItem.Children["Documents"];
                if (docs == null)
                {
                    Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Folder Types/Investment Folders/Investment Document Folder");
                    docs = managerItem.Add("Documents", docsTemplateItem);
                }

                Item commentaryItem = docs.Children[title];
                if (commentaryItem == null)
                {
                    Sitecore.Data.Items.TemplateItem commentaryTemplateItem = database.GetItem("/sitecore/templates/Genworth/Document Types/Investments/Product Commentary/Product Commentary");
                    commentaryItem = docs.Add(title, commentaryTemplateItem);
                }

                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    commentaryItem.Editing.BeginEdit();

                    Sitecore.Data.Fields.FileField fileField = commentaryItem.Fields["File"];
                    fileField.MediaID = mediaItem.ID;
                    fileField.Src     = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);

                    if (dictCategories.ContainsKey("Commentary"))
                    {
                        commentaryItem["Category"] = dictCategories["Commentary"].ToString();
                    }

                    if (dictSources.ContainsKey("AssetMark"))
                    {
                        commentaryItem["Source"] = dictSources["AssetMark"].ToString();
                    }

                    commentaryItem["Date"] = Sitecore.DateUtil.ToIsoDate(DateTime.Now);

                    commentaryItem.Editing.EndEdit();
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.ExpenseRatioImporter:mapMediaItemToSharedContent, allocation: {1}, title {2}, exception: {3}", managerItem["Name"], title, ex.ToString()), this);
            }

            return(bOk);
        }
Beispiel #6
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");
                }
            }
        }
Beispiel #7
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");
                }
            }
        }
Beispiel #8
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");
                }
            }
        }
        private bool mapMediaItemToSharedContent(Sitecore.Data.Database database, string strategist, Item allocationItem, string title, MediaItem mediaItem, out ID itemId)
        {
            bool bOk = false;

            itemId = null;
            string allocation = string.Empty;

            if (allocationItem != null)
            {
                allocation = allocationItem["Title"];
            }

            try
            {
                // Sitecore/content/Shared Content/Investments/Strategists/<strategist>/<allocation approach>/Documents/<fact sheet>
                string sharedPath     = "/sitecore/content/Shared Content/Investments/Strategists/" + strategist;
                Item   strategistItem = database.GetItem(sharedPath);

                if (strategistItem == null)
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:mapMediaItemToSharedContent, shared content folder for strategist {0} does not exist, skipping. Path: {1}", strategist, sharedPath), this);
                    return(false);
                }

                if (!String.IsNullOrEmpty(allocation))
                {
                    allocationItem = strategistItem.Children[allocation];
                    if (allocationItem == null)
                    {
                        Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Data/Strategy");
                        allocationItem = strategistItem.Add(allocation, docsTemplateItem);
                    }
                }
                else // GPS & GPS Select-only scenario (no allocation approach)
                {
                    allocationItem = strategistItem;
                }

                //Item docs = allocationItem.Children["Documents"];
                Item docs = strategistItem.Children["Documents"];
                if (docs == null)
                {
                    Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Folder Types/Investment Folders/Investment Document Folder");
                    //docs = allocationItem.Add("Documents", docsTemplateItem);
                    docs = strategistItem.Add("Documents", docsTemplateItem);
                }

                Item commentaryItem = docs.Children[title];
                if (commentaryItem == null)
                {
                    Sitecore.Data.Items.TemplateItem commentaryTemplateItem = database.GetItem("/sitecore/templates/Genworth/Document Types/Investments/Product Commentary/Product Commentary");
                    commentaryItem = docs.Add(title, commentaryTemplateItem);
                }

                itemId = commentaryItem.ID;

                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    commentaryItem.Editing.BeginEdit();

                    Sitecore.Data.Fields.FileField fileField = commentaryItem.Fields["File"];
                    fileField.MediaID = mediaItem.ID;
                    fileField.Src     = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);

                    if (dictCategories.ContainsKey("Commentary"))
                    {
                        commentaryItem["Category"] = dictCategories["Commentary"].ToString();
                    }

                    if (dictSources.ContainsKey("AssetMark"))
                    {
                        commentaryItem["Source"] = dictSources["AssetMark"].ToString();
                    }

                    commentaryItem["Date"] = Sitecore.DateUtil.ToIsoDate(DateTime.Now);

                    commentaryItem.Editing.EndEdit();
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:mapMediaItemToSharedContent, strategist: {0}, allocation: {1}, title {2}, exception: {3}", strategist, allocation, title, ex.ToString()), this);
            }

            return(bOk);
        }
        public BaseDataMap(Database db, string connectionString, Item importItem)
        {
            //instantiate log
            log = new StringBuilder();

            //setup import details
            SitecoreDB = db;
            DatabaseConnectionString = connectionString;
            //get query
            Query = importItem.Fields["Query"].Value;
            if (string.IsNullOrEmpty(Query))
            {
                Log("Error", "the 'Query' field was not set");
            }
            //get parent and store it
            string parentID = importItem.Fields["Import To Where"].Value;

            if (!string.IsNullOrEmpty(parentID))
            {
                Item parent = SitecoreDB.Items[parentID];
                if (parent.IsNotNull())
                {
                    Parent = parent;
                }
                else
                {
                    Log("Error", "the 'To Where' item is null");
                }
            }
            else
            {
                Log("Error", "the 'To Where' field is not set");
            }
            //get new item template
            string templateID = importItem.Fields["Import To What Template"].Value;

            if (!string.IsNullOrEmpty(templateID))
            {
                Item templateItem = SitecoreDB.Items[templateID];
                if (templateItem.IsNotNull())
                {
                    if ((BranchItem)templateItem != null)
                    {
                        NewItemTemplate = (BranchItem)templateItem;
                    }
                    else
                    {
                        NewItemTemplate = (TemplateItem)templateItem;
                    }
                }
                else
                {
                    Log("Error", "the 'To What Template' item is null");
                }
            }
            else
            {
                Log("Error", "the 'To What Template' field is not set");
            }
            //more properties
            ItemNameDataField = importItem.Fields["Pull Item Name from What Fields"].Value;
            ItemNameMaxLength = int.Parse(importItem.Fields["Item Name Max Length"].Value);
            Item iLang = SitecoreDB.GetItem(importItem.Fields["Import To Language"].Value);

            ImportToLanguage = LanguageManager.GetLanguage(iLang.Name);
            if (ImportToLanguage == null)
            {
                Log("Error", "The 'Import Language' field is not set");
            }

            //foldering information
            FolderByDate = ((CheckboxField)importItem.Fields["Folder By Date"]).Checked;
            FolderByName = ((CheckboxField)importItem.Fields["Folder By Name"]).Checked;
            DateField    = importItem.Fields["Date Field"].Value;
            if (FolderByName || FolderByDate)
            {
                //setup a default type to an ordinary folder
                Sitecore.Data.Items.TemplateItem FolderItem = SitecoreDB.Templates["{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}"];
                //if they specify a type then use that
                string folderID = importItem.Fields["Folder Template"].Value;
                if (!string.IsNullOrEmpty(folderID))
                {
                    FolderItem = SitecoreDB.Templates[folderID];
                }
                FolderTemplate = FolderItem;
            }

            //start handling fields
            Item Fields = GetItemByTemplate(importItem, FieldsFolderID);

            if (Fields.IsNotNull())
            {
                ChildList c = Fields.GetChildren();
                if (c.Any())
                {
                    foreach (Item child in c)
                    {
                        //create an item to get the class / assembly name from
                        BaseMapping bm = new BaseMapping(child);
                        if (!string.IsNullOrEmpty(bm.HandlerAssembly))
                        {
                            if (!string.IsNullOrEmpty(bm.HandlerClass))
                            {
                                //create the object from the class and cast as base field to add it to field definitions
                                IBaseField bf = null;
                                try {
                                    bf = (IBaseField)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child });
                                } catch (FileNotFoundException fnfe) {
                                    Log("Error", string.Format("the field:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly));
                                }
                                if (bf != null)
                                {
                                    FieldDefinitions.Add(bf);
                                }
                                else
                                {
                                    Log("Error", string.Format("the field: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass));
                                }
                            }
                            else
                            {
                                Log("Error", string.Format("the field: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass));
                            }
                        }
                        else
                        {
                            Log("Error", string.Format("the field: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly));
                        }
                    }
                }
                else
                {
                    Log("Warn", "there are no fields to import");
                }
            }
            else
            {
                Log("Warn", "there is no 'Fields' folder");
            }
        }
Beispiel #11
0
        public static bool CreateBlogStructure(string blogName, BlogType.Tech currentBlogType, bool hasImportFile, string blogHomePath, string fileLocation)
        {
            Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master");

            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                #region Create high level blog structure

                TemplateItem folder = master.GetItem("{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}");

                //Check to see if a Data folder already exists, if not create one.
                Item blogDataParentItem = master.GetItem("/sitecore/content/Data");

                if (blogDataParentItem == null)
                {
                    Item contentHome = master.GetItem("/sitecore/content");
                    blogDataParentItem = contentHome.Add("Data", folder);
                }

                //Where all new templates should be created
                Item pageTemplateHome = master.GetItem("/sitecore/templates/XBlog/Page");
                if (pageTemplateHome == null)
                {
                    return(false);
                }

                //Add an instance of this blog to pageTemplateHome
                Item blogPageTemplateHomeFolder = pageTemplateHome.Add(blogName, folder);
                #endregion

                #region Create Templates (Blog Home, Author Listing, and Blog Post) specific to blog type technology

                Item userCreatedBlogBaseTemplate = null;
                Item userCreatedAuthorTemplate   = null;
                Item userBlogPostTemplate        = null;

                try
                {
                    if (currentBlogType == BlogType.Tech.MVC)
                    {
                        //Creates template for MVC Author Home
                        Item mvcAuthorHome     = master.GetItem("/sitecore/templates/XBlog/Page/MVC/Blog Author");
                        Item userMvcAuthorHome = mvcAuthorHome.CopyTo(blogPageTemplateHomeFolder, "Blog Author");
                        userCreatedAuthorTemplate = userMvcAuthorHome;

                        //TODO if I could get the standard values and set the datasource location of the author listing to the imported authors.... would be pretty sweet.

                        //Creates template for MVC Blog Post
                        Item mvcBlogPost     = master.GetItem("/sitecore/templates/XBlog/Page/MVC/Blog Post");
                        Item userMvcBlogPost = mvcBlogPost.CopyTo(blogPageTemplateHomeFolder, "Blog Post");
                        userBlogPostTemplate = userMvcBlogPost;

                        //Creates template for MVC Blog Home
                        Item mvcBlogHome     = master.GetItem("/sitecore/templates/XBlog/Page/MVC/Blog Home");
                        Item userMvcBlogHome = mvcBlogHome.CopyTo(blogPageTemplateHomeFolder, "Blog Home");
                        userCreatedBlogBaseTemplate = userMvcBlogHome;

                        //Get the standard values for the newly created Blog Home and update its insert options to include the newly created Blog Post
                        Item userMvcBlogHomeStandarValues = master.GetItem(userMvcBlogHome.Paths.FullPath + "/__Standard Values");

                        //Change the insert options to use the newly created templates instead of the "shipped" MVC / WF
                        using (new EditContext(userMvcBlogHomeStandarValues))
                        {
                            userMvcBlogHomeStandarValues.SetValue("{1172F251-DAD4-4EFB-A329-0C63500E4F1E}", userMvcBlogPost.ID);
                        }
                    }
                    else if (currentBlogType == BlogType.Tech.WebForm)
                    {
                        //Creates template for WebForms Author Home
                        Item wfAuthorHome     = master.GetItem("/sitecore/templates/XBlog/Page/WF/Blog Author");
                        Item userWfAuthorHome = wfAuthorHome.CopyTo(blogPageTemplateHomeFolder, "Blog Author");
                        userCreatedAuthorTemplate = userWfAuthorHome;

                        //Creates template for WebForms Blog Post
                        Item wfBlogPost     = master.GetItem("/sitecore/templates/XBlog/Page/WF/Blog Post");
                        Item userWfBlogPost = wfBlogPost.CopyTo(blogPageTemplateHomeFolder, "Blog Post");
                        userBlogPostTemplate = userWfBlogPost;

                        //Creates template for MVC Blog Home
                        Item wfBlogHome     = master.GetItem("/sitecore/templates/XBlog/Page/WF/Blog Home");
                        Item userWfBlogHome = wfBlogHome.CopyTo(blogPageTemplateHomeFolder, "Blog Home");
                        userCreatedBlogBaseTemplate = userWfBlogHome;

                        //Get the standard values for the newly created Blog Home and update its insert options to include the newly created Blog Post
                        Item userWfBlogHomeStandarValues = master.GetItem(userWfBlogHome.Paths.FullPath + "/__Standard Values");

                        //Change the insert options to use the newly created templates instead of the "shipped" MVC / WF
                        using (new EditContext(userWfBlogHomeStandarValues))
                        {
                            userWfBlogHomeStandarValues.SetValue("{1172F251-DAD4-4EFB-A329-0C63500E4F1E}", userWfBlogPost.ID);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Failed to create Blog Templates: " + ex.Message, "BlogCreator");
                    return(false);
                }

                #endregion

                #region Create Data and Settings
                //create new XBlog Data node
                Sitecore.Data.Items.TemplateItem blogDataTemplate = master.GetItem(XBlogData.XBlogDataTemplateId);
                XBlogData xdata = blogDataParentItem.Add(blogName, blogDataTemplate).CreateAs <XBlogData>();

                //Create new Settings node under the XBlog Data node
                Sitecore.Data.Items.TemplateItem settingsTemplate = master.GetItem(BlogSettings.BlogSettingsTemplateId);
                BlogSettings blogSettings = xdata.InnerItem.Add("Settings", settingsTemplate).CreateAs <BlogSettings>();
                #endregion

                #region Create Author Structure and import authors if needed
                //Create new Authors node under the new XBlog Data node
                Sitecore.Data.Items.TemplateItem blogAuthorsTemplate = master.GetItem(XBlogAuthors.XBlogAuthorsTemplateId);
                XBlogAuthors xbAuthors = xdata.InnerItem.Add("Authors", blogAuthorsTemplate).CreateAs <XBlogAuthors>();

                //Links author Parent in settings
                using (new EditContext(blogSettings.InnerItem))
                {
                    blogSettings.InnerItem.SetValue(BlogSettings.AuthorFolderFieldId, xbAuthors.InnerItem.ID);
                }

                //Import authors
                if (hasImportFile && !string.IsNullOrEmpty(fileLocation))
                {
                    List <WPAuthor> authors = ImportManager.ImportAuthors(fileLocation);
                    if (authors.Any())
                    {
                        CreateImportedAuthorsInSitecore(master, authors, xbAuthors);
                    }
                }

                #endregion

                #region Create Tags Structure and import tags if needed

                //Create new Tags node under the XBlog Data node
                Sitecore.Data.Items.TemplateItem blogTagsTemplate = master.GetItem(XBlogTags.XBlogTagsTemplateId);
                XBlogTags xbTags = xdata.InnerItem.Add("Tags", blogTagsTemplate).CreateAs <XBlogTags>();

                //Links tag Parent in settings
                using (new EditContext(blogSettings.InnerItem))
                {
                    blogSettings.InnerItem.SetValue(BlogSettings.TagFolderFieldId, xbTags.InnerItem.ID);
                }

                //Import tags
                if (hasImportFile && !string.IsNullOrEmpty(fileLocation))
                {
                    List <WPTag> tags = ImportManager.ImportTags(fileLocation);
                    if (tags.Any())
                    {
                        CreateImportedTagsInSitecore(master, tags, xbTags);
                    }
                }


                #endregion

                #region Create Categories Structure and import categories if needed

                //Create new Categories node under the XBlog Data node
                Sitecore.Data.Items.TemplateItem blogCategoriesTemplate = master.GetItem(XBlogCategories.XBlogCategoriesTemplateId);
                XBlogCategories xbCategories = xdata.InnerItem.Add("Categories", blogCategoriesTemplate).CreateAs <XBlogCategories>();

                //Links category Parent in settings
                using (new EditContext(blogSettings.InnerItem))
                {
                    blogSettings.InnerItem.SetValue(BlogSettings.CategoryFolderFieldId, xbCategories.InnerItem.ID);
                }

                //Import categories
                if (hasImportFile && !string.IsNullOrEmpty(fileLocation))
                {
                    List <WPCategory> categories = ImportManager.ImportCategories(fileLocation);
                    if (categories.Any())
                    {
                        CreateImportedCategoriesInSitecore(master, categories, xbCategories);
                    }
                }

                #endregion

                #region Create Author Home, Blog Home and import blog posts if needed
                //Use the template created based on the base template - containes correct insert options
                TemplateItem blogHomeTemplate = master.GetItem(userCreatedBlogBaseTemplate.ID);//(BlogHome.BlogPostParentTemplateId);
                TemplateItem authorTemplate   = master.GetItem(userCreatedAuthorTemplate.ID);

                //TODO give the user the option of where the Blog Home should be created
                Item blogPostParentItem = master.GetItem(blogHomePath);
                Item bh         = blogPostParentItem.Add(blogName, blogHomeTemplate);
                Item authorPage = blogPostParentItem.Add("Authors of " + blogName, authorTemplate);

                //Links author Parent in settings
                using (new EditContext(blogSettings.InnerItem))
                {
                    blogSettings.InnerItem.SetValue(BlogSettings.AuthorViewPageFieldId, authorPage.ID);
                }

                using (new EditContext(bh))
                {
                    bh.SetValue(BlogHome.BlogSettingsFieldId, blogSettings.InnerItem.ID);
                    bh.SetString(BlogHome.BlogNameFieldId, blogName);
                }

                if (hasImportFile)
                {
                    //IMPORTS BLOG POSTS
                    List <WPPost> listWordpressPosts = ImportManager.Import(fileLocation, false, false, false);
                    if (listWordpressPosts.Any())
                    {
                        ImportManager.ImportPosts(bh, listWordpressPosts.ToList(), blogName, userBlogPostTemplate);
                    }
                }

                return(true);

                #endregion
            }
        }