/// <summary> /// Triggered at interval to determine whether to rebuild the index. /// </summary> /// <param name="args">Event arguments (not used by this implementation)</param> internal void Handle(EventArgs args) { Assert.IsNotNull(this._index, "_index"); string path = "/sitecore/system/Settings/Rules/Indexing/Rebuilding/Rules"; using (new SC.SecurityModel.SecurityDisabler()) { SC.Data.Items.Item ruleRoot = this._ruleDatabase.GetItem(path); SC.Diagnostics.Assert.IsNotNull( ruleRoot, string.Format("ruleRoot item {0} in database {1}", path, this._ruleDatabase.Name)); SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext ruleContext = new SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext(this._index) { IndexedDatabaseName = this._indexedDatabaseName, }; SC.Rules.RuleList <SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext> ruleList = SC.Rules.RuleFactory.GetRules <SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext>(ruleRoot.Axes.GetDescendants(), "Rule"); Assert.IsNotNull(ruleList, "ruleList"); Assert.IsTrue( ruleList.Count > 0, "ruleList.Count < 1 for " + path + " in database " + this._ruleDatabase.Name); ruleList.Run(ruleContext); if (ruleContext.ShouldRebuild) { SC.ContentSearch.Diagnostics.CrawlingLog.Log.Info( this + " : rebuild " + this._index.Name); this._index.Rebuild(); } } }
// 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++; } } }