/// <summary> /// Parse the arguments for the programme and start either the reporting or deleting process /// </summary> /// <param name="args">The args.</param> static void Main(string[] args) { try { // Is the delete action specified as a parameter? bool delete = false; var len = args.Length; for (var i = 0; i < len; i++) { if (args[i].ToUpperInvariant() == "/DELETE" || args[i].ToUpperInvariant() == "-DELETE") { delete = true; args[i] = String.Empty; } } // Is a specific gallery specified as a parameter? ResourceGallery startGallery = null; using (var cmsContext = new CmsApplicationContext()) { cmsContext.AuthenticateAsCurrentUser(delete ? PublishingMode.Update : PublishingMode.Published); for (var i = 0; i < len; i++) { if (!String.IsNullOrEmpty(args[i])) { startGallery = CmsUtilities.ParseResourceGalleryUrl(args[i], cmsContext); // If gallery was specified but not found, tell the user and finish if (startGallery == null) { Console.WriteLine(String.Format(CultureInfo.CurrentCulture, Properties.Resources.ErrorGalleryNotFound, args[i])); return; } } } // If method hasn't returned and there's no gallery yet, none was specified, so default to root if (startGallery == null) { startGallery = cmsContext.RootResourceGallery; } // Based on arguments, either delete resources from the gallery or just report what would be deleted if (delete) { DeleteResources(cmsContext, startGallery); } else { ReportResources(startGallery); } } } catch (Exception ex) { ExceptionManager.Publish(ex); log.Error(ex.Message); } }
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); }
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); }