Example #1
0
        public string PublishPostings(string channelPath)
        {
            string retval;

            // get the current cms application context
            using (CmsApplicationContext cac = CmsUtilities.GetAdminContext(PublishingMode.Update))
            {
                var currentChannel = cac.Searches.GetByUrl(channelPath) as Channel;
                try
                {
                    foreach (Posting posting in currentChannel.Postings)
                    {
                        if (posting.StartDate > DateTime.Now)
                        {
                            posting.StartDate = DateTime.Now;
                            posting.Approve();
                        }

                        if (posting.State == PostingState.Saved | posting.State == PostingState.WaitingForEditorApproval)
                        {
                            posting.StartDate = DateTime.Now;
                            posting.Approve();
                        }
                    }
                    cac.CommitAll();
                    retval = "Channel postings have been approved and published.";
                }
                catch (Exception ex)
                {
                    retval = ex.Message;
                }
            }
            return(retval);
        }
Example #2
0
        public CmsResourceGallery RootResourceGallery()
        {
            string rootGuid = String.Empty;

            using (var cms = CmsUtilities.GetAdminContext(PublishingMode.Published))
            {
                rootGuid = cms.RootResourceGallery.Guid;
            }
            return(ResourceGallery(new Guid(rootGuid)));
        }
Example #3
0
 private void ExtendChannel(DateTime newExpiry, Guid channelGuid)
 {
     using (CmsContext cms = CmsUtilities.GetAdminContext(PublishingMode.Update))
     {
         Channel channelToExtend = cms.Searches.GetByGuid(channelGuid.ToString("B")) as Channel;
         foreach (Posting posting in channelToExtend.Postings)
         {
             if (this.updateExpired || posting.State != PostingState.Expired)
             {
                 posting.ExpiryDate = newExpiry;
                 posting.Approve();
             }
         }
         cms.CommitAll();
     }
 }
Example #4
0
        public string SetExpiryDate(string channelPath, string months, bool includeSubchannels, bool updateExpiredPages)
        {
            this.newExpiry = (String.IsNullOrEmpty(months)) ? CmsUtilities.NeverExpires : DateTime.Now.AddMonths(Convert.ToInt32(months));
            string retval = String.Empty;
            // get the current cms application context
            string channelGuid = null;

            this.updateExpired = updateExpiredPages;

            using (CmsApplicationContext cac = CmsUtilities.GetAdminContext(PublishingMode.Published))
            {
                // we need to authenticate against a cms mode and MUST do this before using searches to get he current channel
                Channel currentChannel = CmsUtilities.ParseChannelUrl(channelPath, cac);
                if (currentChannel == null)
                {
                    retval = "Channel not found";
                }
                else
                {
                    channelGuid = currentChannel.Guid;
                }
            }

            if (channelGuid != null)
            {
                try
                {
                    if (includeSubchannels)
                    {
                        CmsTraverser traverser = new CmsTraverser();
                        traverser.TraversingChannel += new CmsEventHandler(traverser_TraversingChannel);
                        traverser.TraverseChannel(PublishingMode.Update, true, new Guid(channelGuid));
                    }
                    else
                    {
                        ExtendChannel(newExpiry, new Guid(channelGuid));
                    }
                    retval = "Channel posting expiry dates have been delayed until " + newExpiry;
                }
                catch (Exception ex)
                {
                    retval = ex.Message;
                }
            }

            return(retval);
        }
Example #5
0
        public CmsResourceGallery ResourceGallery(Guid guid)
        {
            using (var cms = CmsUtilities.GetAdminContext(PublishingMode.Published))
            {
                var gallery = cms.Searches.GetByGuid("{" + guid.ToString() + "}") as ResourceGallery;
                if (gallery == null)
                {
                    return(null);
                }

                // Get the requested gallery and its child galleries. Only go one level, not recursive,
                // because otherwise this method would take a long time to execute and build up a massive string.
                var cmsGallery = BuildGallery(gallery);
                foreach (ResourceGallery child in gallery.ResourceGalleries)
                {
                    cmsGallery.Galleries.Add(BuildGallery(child));
                }
                foreach (Resource child in gallery.Resources)
                {
                    cmsGallery.Resources.Add(BuildResource(child));
                }
                return(cmsGallery);
            }
        }