Пример #1
0
        private int?CreateItem(DefinedContentItem item)
        {
            if (item.CanCreate())
            {
                this.CreatedItems.Add(item);

                int?parentId = ResolveParent(item);

                if (!parentId.HasValue)
                //Can't create until the parent has been created / resolved.
                {
                    this.AwaitingResolution.Add(item);
                    return(null);
                }

                if (this.AwaitingResolution.Contains(item))
                {
                    this.AwaitingResolution.Remove(item);
                }

                IContent createdContent = _contentService.CreateContentWithIdentity(item.Name, parentId.Value, item.ContentTypeAlias);
                this.CreatedItems.Add(item);

                return(createdContent.Id);
            }

            throw new Exception("Not enough information provided to create item with key. Need docTypeId, name, parent and ParentType." + item.Key);
        }
Пример #2
0
        /// <summary>
        /// When a new root Articulate node is created, then create the required 2 sub nodes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void ContentService_Saved(IContentService sender, SaveEventArgs <IContent> e)
        {
            foreach (var c in e.SavedEntities.Where(c => c.IsNewEntity() && c.ContentType.Alias.InvariantEquals("Articulate")))
            {
                LogHelper.Debug <UmbracoEventHandler>(() => "Creating sub nodes (authors, archive) for new Articulate node");

                //it's a root blog node, set up the required sub nodes (archive , authors)
                var articles = sender.CreateContentWithIdentity("Archive", c, "ArticulateArchive");

                LogHelper.Debug <UmbracoEventHandler>(() => "Archive node created with name: " + articles.Name);

                var authors = sender.CreateContentWithIdentity("Authors", c, "ArticulateAuthors");

                LogHelper.Debug <UmbracoEventHandler>(() => "Authors node created with name: " + authors.Name);
            }
        }
Пример #3
0
        private void CreateUserTagsFolder()
        {
            var dataFolder = _umbracoHelper.TypedContentAtRoot().Single(el => el.DocumentTypeAlias.Equals(DocumentTypeAliasConstants.DataFolder));

            if (dataFolder.Children.Any(el => el.DocumentTypeAlias.Equals(TaggingInstallationConstants.DocumentTypeAliases.UserTagFolder)))
            {
                return;
            }

            var content = _contentService.CreateContentWithIdentity(TaggingInstallationConstants.ContentDefaultName.UserTagFolder, dataFolder.Id, TaggingInstallationConstants.DocumentTypeAliases.UserTagFolder);

            _contentService.SaveAndPublishWithStatus(content);
        }
Пример #4
0
    private bool CreateContentNode(string name, string contentType, IContent parent, string title, string body, IContentService _cs)
    {
        var exsitingNode = _cs.GetChildrenByName(parent.Id, name);

        if (exsitingNode.Any())
        {
            return(false);
        }

        var node = _cs.CreateContentWithIdentity(name, parent, contentType);

        if (node != null)
        {
            node.SetValue("title", title);
            node.SetValue("bodyText", body);
            _cs.SaveAndPublishWithStatus(node);

            return(true);
        }
        return(false);
    }
        private void CreateHomePage()
        {
            var homePage = _umbracoHelper.TypedContentAtRoot().FirstOrDefault(el => el.DocumentTypeAlias.Equals(DocumentTypeAliasConstants.HomePage));

            if (homePage != null)
            {
                return;
            }

            var content = _contentService.CreateContentWithIdentity("Home", -1, DocumentTypeAliasConstants.HomePage);

            content.SetValue(NavigationPropertiesConstants.NavigationNamePropName, "Home");

            SetGridValueAndSaveAndPublishContent(content, "homePageGrid.json");
        }
Пример #6
0
        /// <summary>
        /// When a new root Articulate node is created, then create the required 2 sub nodes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ContentService_Saved(IContentService sender, SaveEventArgs<IContent> e)
        {
            foreach (var c in e.SavedEntities.Where(c => c.IsNewEntity() && c.ContentType.Alias.InvariantEquals("Articulate")))
            {
                LogHelper.Debug<UmbracoEventHandler>(() => "Creating sub nodes (authors, archive) for new Articulate node");

                //it's a root blog node, set up the required sub nodes (archive , authors)
                var articles = sender.CreateContentWithIdentity("Archive", c, "ArticulateArchive");

                LogHelper.Debug<UmbracoEventHandler>(() => "Archive node created with name: " + articles.Name);

                var authors = sender.CreateContentWithIdentity("Authors", c, "ArticulateAuthors");

                LogHelper.Debug<UmbracoEventHandler>(() => "Authors node created with name: " + authors.Name);
            }
        }
        /// <summary>
        /// Moves pages into year/month folders
        /// </summary>
        public void MoveToDatefolder(SaveEventArgs <IContent> e, IContentService contentService, List <string> contentTypeToMove, string contentTypeOfContainer = "NewsList", bool moveToMonth = false, bool englishMonthNames = false)
        {
            foreach (var page in e.SavedEntities)
            {
                // Not interested in anything but "create" events.
                if (!page.IsNewEntity())
                {
                    return;
                }

                // Not interested if the item being added is not a news-page.
                if (!contentTypeToMove.Contains(page.ContentType.Alias))
                {
                    return;
                }

                var now   = page.ReleaseDate.HasValue ? page.ReleaseDate.Value : DateTime.Now;
                var year  = now.ToString("yyyy");
                var month = now.ToString("MM").GetMonthFromNumber(englishMonthNames);

                IContent yearDocument = null;

                // Get year-document by container (if it is a 4 digit number)
                int n;
                if (int.TryParse(page.Parent().Name, out n))
                {
                    if (n.ToString().Length == 4)
                    {
                        yearDocument = page.Parent();
                    }
                }
                // Get year-document by parent-siblings
                if (yearDocument == null)
                {
                    foreach (var child in page.Parent().Children())
                    {
                        if (child.Name == year)
                        {
                            yearDocument = child;
                            break;
                        }
                    }
                }

                // If the year folder doesn't exist, create it.
                if (yearDocument == null)
                {
                    yearDocument = contentService.CreateContentWithIdentity(year, page.ParentId, contentTypeOfContainer);
                    contentService.Publish(yearDocument);
                }

                if (moveToMonth)
                {
                    var monthDocument = yearDocument.Children().FirstOrDefault(x => x.Name == month);

                    // If the month folder doesn't exist, create it.
                    if (monthDocument == null)
                    {
                        monthDocument = contentService.CreateContentWithIdentity(month, yearDocument.Id, contentTypeOfContainer);
                        contentService.Publish(monthDocument);
                    }

                    // Move the document into the month folder
                    contentService.Move(page, monthDocument.Id);
                }
                else
                {
                    // Move the document into the year folder
                    contentService.Move(page, yearDocument.Id);
                }

                #region Sort year pages
                try
                {
                    var mainNewsPage = yearDocument.Parent();

                    // SORT year-folders by year (newest first)
                    var sortedYearPages = mainNewsPage.Children().OrderByDescending(p => p.Name).ToArray();

                    for (var i = 0; i < sortedYearPages.Count(); i++)
                    {
                        sortedYearPages[i].SortOrder = i;
                        contentService.SaveAndPublishWithStatus(sortedYearPages[i]);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error(typeof(PageOrganizer), "Could not sort year-documents for News", ex);
                }
                #endregion
            }
        }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //NOTE: REMEMBER TO SET THE CONFIG FILE FOR UDATESYFOLDER TO ENABLED AFTER THIS IS COMPLETED!!

            //
            Stopwatch sw = new Stopwatch();

            sw.Start();

            try
            {
                //Read the msg json file
                using (StreamReader r = new StreamReader("C:\\Inetpub\\vhosts\\afterthewarning.com\\dev.AfterTheWarning.com\\dev.afterthewarning.com\\tempData\\msgs.txt"))
                {
                    //Extract json and convert back to a list of message classes
                    string     json    = r.ReadToEnd();
                    List <Msg> lstMsgs = JsonConvert.DeserializeObject <List <Msg> >(json);

                    //Display a record count
                    lblRecordCount.Text = lstMsgs.Count.ToString();

                    //Create lists
                    List <Visionary> lstVisionariesInSite    = new List <Visionary>();
                    List <string>    lstVisionaryNamesInJson = new List <string>();

                    //Create list of all current visionary folders and obtain IDs if they exist
                    IPublishedContent ipMsgs = uhelper.TypedContent((int)Common.siteNode.MessagesFromHeaven);
                    foreach (IPublishedContent ipVisionary in ipMsgs.Children.ToList())
                    {
                        var nameExists = lstVisionariesInSite.Any(x => x.nodeName == ipVisionary.Name);
                        if (!nameExists)
                        {
                            Visionary visionary = new Visionary();
                            visionary.nodeName = ipVisionary.Name;
                            visionary.id       = ipVisionary.Id;
                            lstVisionariesInSite.Add(visionary);
                        }
                    }

                    //Obtain list of all visionary names within json
                    foreach (Msg msg in lstMsgs)
                    {
                        if (!lstVisionaryNamesInJson.Contains(msg.visionary))
                        {
                            lstVisionaryNamesInJson.Add(msg.visionary);
                        }
                    }

                    //Loop thru and create all missing visionaries
                    foreach (string visionaryName in lstVisionaryNamesInJson)
                    {
                        var nameExists = lstVisionariesInSite.Any(x => x.nodeName == visionaryName);
                        if (!nameExists)
                        {
                            //Add new visionary
                            IContent icMsgs      = icService.GetById((int)Common.siteNode.MessagesFromHeaven);
                            IContent icVisionary = icService.CreateContentWithIdentity(visionaryName, icMsgs, Common.docType.Visionary);
                            icVisionary.SetValue(Common.NodeProperties.visionarysName, visionaryName);
                            icService.SaveAndPublishWithStatus(icVisionary);

                            //Add visionary to list in site
                            Visionary visionary = new Visionary();
                            visionary.nodeName = visionaryName;
                            visionary.id       = icVisionary.Id;
                            lstVisionariesInSite.Add(visionary);
                        }
                    }

                    //
                    foreach (Msg msg in lstMsgs)
                    {
                        //Obtain the correct visionary folder
                        int visionaryId = (int)lstVisionariesInSite.FirstOrDefault(x => x.nodeName == msg.visionary).id;

                        //Obtain the date folder
                        IContent icDate = getDateFolder(msg.datePublished, visionaryId);

                        //Create new message and save to date folder within visionary folder
                        IContent icMsg = icService.CreateContentWithIdentity(msg.pageTitle, icDate, "message");
                        icMsg.SetValue("publishDate", msg.datePublished);
                        icMsg.SetValue("content", getContentAsJson(msg.content));
                        icMsg.SetValue("dateOfMessages", JsonConvert.SerializeObject(msg.lstDateOfMsgs).Replace("T00:00:00", ""));

                        icService.SaveAndPublishWithStatus(icMsg);
                    }

                    //Display current list of visionaries on site
                    gvVisionaryFolders.DataSource = lstVisionariesInSite;
                    gvVisionaryFolders.DataBind();

                    //Display list of all visionary names in json
                    gvVisionariesInJson.DataSource = lstVisionaryNamesInJson;
                    gvVisionariesInJson.DataBind();

                    //Display list of all data.  (Don't display this when the full version is imported
                    //gv.DataSource = lstMsgs;
                    //gv.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblErrors.Text = ex.ToString();
            }
            finally
            {
                //Display time lapsed
                sw.Stop();
                lblTimeToProcess.Text = sw.Elapsed.TotalSeconds.ToString();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //
            Stopwatch sw = new Stopwatch();

            sw.Start();

            try
            {
                //Instantiate list of scripture books
                List <Book> lstBooks = new List <Book>();

                //Obtain list of all files within folder
                List <string> lstFiles = Directory.GetFiles(@"C:\Inetpub\vhosts\afterthewarning.com\dev.AfterTheWarning.com\dev.afterthewarning.com\tempData\DouayRheimsBibleXML\").ToList();

                //Loop thru each item in list and convert to class
                foreach (string filePath in lstFiles)
                {
                    try
                    {
                        Book          book       = null;
                        XmlSerializer serializer = new XmlSerializer(typeof(Book));
                        StreamReader  reader     = new StreamReader(filePath);
                        book = (Book)serializer.Deserialize(reader);
                        reader.Close();
                        lstBooks.Add(book);
                    }
                    catch (Exception ex)
                    {
                        //lblErrors.Text = "<br />Error: " + filePath + "<br />" + ex.ToString();
                    }
                }


                //Get root folder of bible
                IContent icBible = icService.GetById((int)Common.siteNode.TheDouayRheimsBible);

                //gv1.DataSource = lstBooks.OrderBy(x => int.Parse(x.Order));
                //gv1.DataBind();

                foreach (Book book in lstBooks.OrderBy(x => int.Parse(x.Order)))
                {
                    try
                    {
                        //Add new book
                        IContent icScripture = icService.CreateContentWithIdentity(book.Name, icBible, Common.docType.Scripture);
                        string[] bookName    = book.FullName.Split('[');
                        icScripture.SetValue(Common.NodeProperties.fullName, bookName.FirstOrDefault());
                        if (bookName.Count() > 1)
                        {
                            icScripture.SetValue(Common.NodeProperties.alternateName, bookName.LastOrDefault().Replace("]", ""));
                        }
                        if (int.Parse(book.Order) < 47)
                        {
                            icScripture.SetValue(Common.NodeProperties.testament, Common.getPrevalueId(Common.miscellaneous.ScriptureTestaments, Common.miscellaneous.OldTestament));
                        }
                        else
                        {
                            icScripture.SetValue(Common.NodeProperties.testament, Common.getPrevalueId(Common.miscellaneous.ScriptureTestaments, Common.miscellaneous.NewTestament));
                        }
                        icScripture.SetValue(Common.NodeProperties.chapters, book.TotalChapters);

                        int bookId  = int.Parse(book.Order);
                        int?bookSet = 0;

                        if (bookId >= 1 && bookId <= 8)
                        {
                            bookSet = Common.getPrevalueId(Common.miscellaneous.ScriptureSet, Common.miscellaneous.ThePentateuchBooks);
                        }
                        else if (bookId >= 9 && bookId <= 21)
                        {
                            bookSet = Common.getPrevalueId(Common.miscellaneous.ScriptureSet, Common.miscellaneous.TheHistoricalBooks);
                        }
                        else if (bookId >= 22 && bookId <= 28)
                        {
                            bookSet = Common.getPrevalueId(Common.miscellaneous.ScriptureSet, Common.miscellaneous.TheWisdomBooks);
                        }
                        else if (bookId >= 29 && bookId <= 46)
                        {
                            bookSet = Common.getPrevalueId(Common.miscellaneous.ScriptureSet, Common.miscellaneous.ThePropheticBooks);
                        }
                        else if (bookId >= 47 && bookId <= 50)
                        {
                            bookSet = Common.getPrevalueId(Common.miscellaneous.ScriptureSet, Common.miscellaneous.TheGospels);
                        }
                        else if (bookId >= 51 && bookId <= 73)
                        {
                            bookSet = Common.getPrevalueId(Common.miscellaneous.ScriptureSet, Common.miscellaneous.TheEpistles);
                        }
                        icScripture.SetValue(Common.NodeProperties.bookSet, bookSet);

                        //Save node
                        icService.SaveAndPublishWithStatus(icScripture);



                        //Add chapters for book
                        foreach (Chapter chapter in book.Chapter)
                        {
                            //Add new chapter
                            IContent icChapter = icService.CreateContentWithIdentity(chapter.Number, icScripture, Common.docType.Chapter);



                            //var scriptureVerse = Serialize.ToJson(chapter.Versicle.ToArray());

                            List <ScriptureVerse> lstScriptureVerses = new List <ScriptureVerse>();
                            foreach (Versicle versicle in chapter.Versicle)
                            {
                                ScriptureVerse scriptureVerse = new ScriptureVerse();
                                scriptureVerse.Verse   = Convert.ToInt64(versicle.Number);
                                scriptureVerse.Content = versicle.Text;
                                lstScriptureVerses.Add(scriptureVerse);
                            }

                            //
                            icChapter.SetValue(Common.NodeProperties.verses, JsonConvert.SerializeObject(lstScriptureVerses));

                            //Save node
                            icService.SaveAndPublishWithStatus(icChapter);
                        }
                    }
                    catch (Exception ex)
                    {
                        lblErrors.Text = "<br />Error: " + ex.ToString() + "<br />" + JsonConvert.SerializeObject(book);
                    }
                }
            }
            catch (Exception ex)
            {
                lblErrors.Text = "Big Error: " + ex.ToString();
            }
            finally
            {
                //Display time lapsed
                sw.Stop();
                lblTimeToProcess.Text = sw.Elapsed.TotalSeconds.ToString();
            }
        }