Esempio n. 1
0
        protected bool CheckRenderingCounts(
            ArrayList devices,
            SC.Rules.RuleContext ruleContext)
        {
            // note: this applies for all devices - you couldn't allow 3 renderings
            // in a placeholder for one device but only 1 for another device.
            // you could add another property to the condition to specify a single device
            foreach (SC.Layouts.DeviceDefinition device in devices)
            {
                if (String.IsNullOrEmpty(device.Layout) ||
                    device.Renderings == null)
                {
                    continue;
                }

                int count = 0;

                // I find this more readable without LINQ
                foreach (SC.Layouts.RenderingDefinition rendering in device.Renderings)
                {
                    if (String.IsNullOrEmpty(rendering.Placeholder))
                    {
                        continue;
                    }

                    if (rendering.Placeholder.EndsWith(
                            this.PlaceholderKey,
                            StringComparison.OrdinalIgnoreCase))
                    {
                        count++;
                    }
                }

                if (count <= this.MaxRenderings)
                {
                    continue;
                }

                //       ruleContext.Parameters["Validation Message"] = count
                ruleContext.Parameters["Validation Message"] = count
                                                               + " renderings bound to placeholder "
                                                               + this.PlaceholderKey
                                                               + " (limit "
                                                               + this.MaxRenderings +
                                                               ")";
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        // agent body
        public void Run()
        {
            // database containing items to process
            SC.Data.Database db = this.GetDatabase();
            SC.Diagnostics.Assert.IsNotNull(db, "db");

            // ids of items to process
            SC.Data.ID[] itemIDs = this.GetItemIDs(db);
            SC.Diagnostics.Assert.IsNotNull(itemIDs, "itemIDs");

            if (SC.Context.Job != null)
            {
                SC.Context.Job.Status.Total = itemIDs.Length;
            }

            // rules to invoke
            SC.Rules.RuleList <SC.Rules.RuleContext> rules = this.GetRules(db);
            SC.Diagnostics.Assert.IsNotNull(rules, "rules");

            // execute rules against each item
            foreach (SC.Data.ID id in itemIDs)
            {
                SC.Data.Items.Item[] versions = this.GetVersionsToProcess(
                    db,
                    id);

                if (SC.Context.Job != null && versions.Length > 0)
                {
                    SC.Context.Job.Status.Messages.Add(
                        "Processing " + versions[0].Paths.FullPath);
                }

                foreach (SC.Data.Items.Item version in versions)
                {
                    SC.Rules.RuleContext ruleContext = new SC.Rules.RuleContext();
                    ruleContext.Item = version;
                    rules.Run(ruleContext);
                }

                if (SC.Context.Job != null)
                {
                    SC.Context.Job.Status.Processed++;
                }
            }
        }