コード例 #1
0
        /// <summary>
        /// This method gets called from a scheduled task command.
        /// You define a scheduled task command by navigating to
        /// /System/Tasks/Commands and inserting a new command
        /// </summary>
        /// <param name="items">Items to publish</param>
        /// <param name="command">Command Info</param>
        /// <param name="schedule">Schedule Item</param>
        public void Run(Item[] items, Tasks.CommandItem command, Tasks.ScheduleItem schedule)
        {
            //DateTime dtPublishDate = DateTime.UtcNow;

            using (new SecurityDisabler())
            {
                try
                {
                    // for each existing target
                    Sitecore.Collections.ChildList publishingTargets = master.GetItem(Constants.PublishingTargetsFolder)?.Children;
                    foreach (Item publishingTarget in publishingTargets)
                    {
                        var targetDatabase = GetTargetDatabase(publishingTarget);
                        if (targetDatabase == null)
                        {
                            Log.Info("Skipping target: Could not find Database target for Publishing target: " + publishingTarget.Name, this);
                            continue;
                        }

                        PublishItems(items, publishingTarget, targetDatabase);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Error Publishing in Automated Publisher", ex, this);
                }
            }
        }
コード例 #2
0
        public static List <Item> GetAvailForms(List <string> errLog = null)
        {
            if (errLog == null)
            {
                errLog = new List <string>();
            }
            List <Item> forms       = new List <Item>();
            Item        formsFolder = Sitecore.Context.Database.GetItem("/sitecore/content/Data Components/Forms");

            if (formsFolder != null)
            {
                Sitecore.Collections.ChildList deptFolders = formsFolder.Children;
                if (deptFolders != null)
                {
                    foreach (Item dept in deptFolders)
                    {
                        foreach (Item form in dept.Children)
                        {
                            if (form.TemplateName.Contains("Form") &&
                                form.Fields.Where(f => f.Name == "Location").ToList().Count > 0 &&
                                form.Fields["Location"].Value.Length > 0)
                            {
                                forms.Add(form);
                            }
                        }
                    }
                }
            }
            else
            {
                errLog.Add("Forms folder not found. Can not get a list of available forms.");
            }
            return(forms);
        }
コード例 #3
0
        protected override void DoRender(HtmlTextWriter output)
        {
            Sitecore.Data.Items.Item root = this.GetItem();
            Sitecore.Diagnostics.Assert.IsNotNull(root, "root");
            List <Sitecore.Data.Items.Item> list = new List <Sitecore.Data.Items.Item>();

            Sitecore.Collections.ChildList years = root.Children;

            for (int y = 0; y < years.Count && list.Count < this.MaxHeadlines; y++)
            {
                Sitecore.Collections.ChildList months = years[y].Children;

                for (int m = 0; m < months.Count && list.Count < this.MaxHeadlines; m++)
                {
                    Sitecore.Collections.ChildList days = months[m].Children;

                    for (int d = 0; d < days.Count && list.Count < this.MaxHeadlines; d++)
                    {
                        Sitecore.Collections.ChildList articles = days[d].Children;

                        for (int a = 0; a < articles.Count && list.Count < this.MaxHeadlines; a++)
                        {
                            if (articles[a].Fields[this.DateField] != null)
                            {
                                list.Add(articles[a]);
                            }
                        }
                    }
                }
            }

            if (list.Count != 0)
            {
                output.Write("<ul>");

                foreach (Sitecore.Data.Items.Item item in list)
                {
                    DateTime when   = Sitecore.DateUtil.IsoDateToDateTime(item[this.DateField]);
                    string   date   = when.ToShortDateString() + " " + when.ToShortTimeString();
                    string   markup = String.Format(
                        @"<li>{0} : <a href=""{1}"">{2}</a></li>",
                        date,
                        Sitecore.Links.LinkManager.GetItemUrl(item),
                        item[this.HeadlineField]);
                    output.Write(markup);
                }

                output.Write("</ul>");
            }
        }
コード例 #4
0
        public override void Expand(List <Sitecore.Data.Items.Item> masters, Sitecore.Data.Items.Item item)
        {
            Sitecore.Data.ID id = new Sitecore.Data.ID(TEMPLATE_ID);

            Sitecore.Collections.ChildList items = item.Children;
            foreach (Sitecore.Data.Items.Item child in items)
            {
                if (child.TemplateID.Equals(id))
                {
                    for (int i = 0; i < masters.Count; i++)
                    {
                        if (masters[i].ID.Equals(id))
                        {
                            masters.RemoveAt(i);
                            break;
                        }
                    }
                    break;
                }
            }
        }
コード例 #5
0
        public void Run()
        {
            // Get the path to the message items
            string pathToMessageItems = Sitecore.Configuration.Settings.GetSetting("Messenger.ItemsPath", MessageItemsDefaultPath);

            try
            {
                Sitecore.Data.Items.Item messagesRootItem = Sitecore.Context.Database.GetItem(pathToMessageItems);

                if (messagesRootItem != null)
                {
                    // Assume that all child items are message items
                    // Remove any item whose expiration date is earlier than now
                    Sitecore.Collections.ChildList messageItems = messagesRootItem.Children;

                    foreach (Sitecore.Data.Items.Item item in messageItems)
                    {
                        if (item == null)
                        {
                            continue;
                        }

                        if (!string.IsNullOrEmpty(item["Broadcast Expiration"]))
                        {
                            DateTime expirationDate = ((Sitecore.Data.Fields.DateField)item.Fields["Broadcast Expiration"]).DateTime;

                            if (expirationDate.CompareTo(DateTime.Now) >= 0)
                            {
                                item.Delete();
                            }
                        }
                    }
                }
            }
            catch (Exception x)
            {
                Sitecore.Diagnostics.Log.Warn("Message Cleanup Agent", x, this);
            }
        }
コード例 #6
0
        /// <summary>
        /// A helper method that filters a ChildList for items that support the specified language.  This is
        /// used in navigation controls or on landing or directory pages, to ignore all items that are not available in the
        /// current language
        /// </summary>
        /// <param name="item">The set of children to filter</param>
        /// <param name="language">The language for which to filter</param>
        /// <returns>A collection of children that have versions in the current language, or null if none were available</returns>
        public static IEnumerable <Sitecore.Data.Items.Item> FilterChildListByLanguage(Sitecore.Collections.ChildList list, String language)
        {
            if (null != list && null != language)
            {
                var items = list.Where(i => HasLanguageVersion(i, language)).ToList();
                if (null != items && items.Any())
                {
                    return(items);
                }
            }

            return(null);
        }
コード例 #7
0
 /// <summary>
 /// A helper method that filters a ChildList for items that support the user's current language.  This is
 /// used in navigation controls or on landing or directory pages, to ignore all items that are not available in the
 /// current language
 /// </summary>
 /// <param name="item">The set of children to filter</param>
 /// <returns>A collection of children that have versions in the current language, or null if none were available</returns>
 public static IEnumerable <Sitecore.Data.Items.Item> FilterChildListByLanguage(Sitecore.Collections.ChildList list)
 {
     return(FilterChildListByLanguage(list, Sitecore.Context.Language.Name));
 }
コード例 #8
0
        /// <summary>
        /// This method gets called from a scheduled task command.
        /// You define a scheduled task command by navigating to
        /// /System/Tasks/Commands and inserting a new command
        /// </summary>
        /// <param name="items">Items to publish</param>
        /// <param name="command">Command Info</param>
        /// <param name="schedule">Schedule Item</param>
        public void Run(Item[] items, Tasks.CommandItem command, Tasks.ScheduleItem schedule)
        {
            DateTime dtPublishDate = DateTime.UtcNow;

            using (new SecurityDisabler())
            {
                try
                {
                    Database master = Sitecore.Configuration.Factory.GetDatabase(Constants.MasterDatabaseName);
                    Sitecore.Globalization.Language[] languages = master.Languages;

                    // for each existing target
                    Item publishingTargetsFolder = master.GetItem(Constants.PublishingTargetsFolder);
                    Sitecore.Collections.ChildList publishingTargets = publishingTargetsFolder.Children;
                    foreach (Item publishingTarget in publishingTargets)
                    {
                        if (publishingTarget != null)
                        {
                            string targetDBName = publishingTarget[Constants.TargetDatabase];
                            if (string.IsNullOrEmpty(targetDBName) == false)
                            {
                                Database targetDb = Sitecore.Configuration.Factory.GetDatabase(targetDBName);
                                if (targetDb != null)
                                {
                                    // for each existing language
                                    foreach (Sitecore.Globalization.Language language in languages)
                                    {
                                        foreach (Item actItem in items)
                                        {
                                            ID   itemToPublishId = actItem.ID;
                                            Item itemToPublish   = master.GetItem(itemToPublishId, language);
                                            bool bPublish        = false;

                                            Sitecore.Data.Fields.MultilistField targets = itemToPublish.Fields[Sitecore.FieldIDs.PublishingTargets];
                                            if (targets != null)
                                            {
                                                Item[] itemToPublishTargets = targets.GetItems();
                                                if (itemToPublishTargets.Length > 0)
                                                {
                                                    foreach (Item itemToPublishTarget in itemToPublishTargets)
                                                    {
                                                        if (string.Equals(itemToPublishTarget.Name, publishingTarget.Name, StringComparison.CurrentCultureIgnoreCase) == true)
                                                        {
                                                            bPublish = true;
                                                            break;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    bPublish = true;
                                                }
                                            }
                                            else
                                            {
                                                bPublish = true;
                                            }

                                            if (bPublish == true)
                                            {
                                                try
                                                {
                                                    string strMessage = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Item '{0}' Target '{1}' Language '{2}': Automated Publisher Schedule Item '{3}'", itemToPublish.ID.ToString(), publishingTarget.Name, language.Name, schedule.Name);
                                                    Log.Info(strMessage, this);
                                                }
                                                catch
                                                {
                                                    Log.Error(Constants.ErrorFormattingString, this);
                                                }

                                                PublishOptions publishOptions = new PublishOptions(master, targetDb, PublishMode.Full, language, dtPublishDate);
                                                publishOptions.Deep     = true;
                                                publishOptions.RootItem = itemToPublish;

                                                Publisher publisher = new Publisher(publishOptions);
                                                publisher.Publish();
                                            }
                                            else
                                            {
                                                string strMessage = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Item '{0}' Target '{1}' Language '{2}': No publishing targets were selected in Automated Publisher",
                                                                                  itemToPublish.ID.ToString(), publishingTarget.Name, language.Name);
                                                Log.Error(strMessage, this);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    schedule.Remove();
                }
                catch (Exception ex)
                {
                    Log.Error("Error Publishing in Automated Publisher", ex, this);
                }
            }
        }