コード例 #1
0
        /// <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();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Rules engine condition to determine whether the number of items updated
        /// since the last commit of changes to the search index to disk exceeds
        /// a given threshold.
        /// </summary>
        /// <param name="ruleContext">Rule processing context.</param>
        /// <returns>True if the number of indexed items updated since the last commit
        /// exceeds the given threshold.</returns>
        protected override bool Execute(T ruleContext)
        {
            Assert.IsTrue(this.Threshold > 0, "Threshold: " + this.Threshold);
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            bool result = ruleContext.UpdatesSinceLastCommit > this.Threshold;

            return(result);
        }
        /// <summary>
        /// Rules engine condition to determine whether a given number
        /// of milliseconds has elapsed since the last commit of changes
        /// to a search engine to disk.
        /// </summary>
        /// <param name="ruleContext">Rule context type.</param>
        /// <returns>True if the number of milliseconds has updates </returns>
        protected override bool Execute(T ruleContext)
        {
            Assert.IsTrue(this.Threshold > 0, "Threshold: " + this.Threshold);
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            bool result = DateTime.Now.CompareTo(ruleContext.LastCommitted.AddMilliseconds(this.Threshold)) > 0;

            return(result);
        }
コード例 #4
0
        protected override void Render(HtmlTextWriter writer)
        {
            string itemId = S.Web.WebUtil.GetQueryString("id");

            Assert.IsNotNullOrEmpty(itemId, "itemId");
            string dbName = S.Web.WebUtil.GetQueryString("database");

            Assert.IsNotNullOrEmpty(dbName, "dbName");
            S.Data.Database db = S.Configuration.Factory.GetDatabase(dbName);
            Assert.IsNotNull(db, "db: " + dbName);
            S.Data.Items.Item item = db.GetItem(itemId);
            Assert.IsNotNull(item, "item: " + itemId + " in " + dbName);
            string value = item["Type"];

            Assert.IsNotNullOrEmpty(value, "value: Type of " + item.Paths.FullPath);
            string name  = string.Empty;
            string dll   = string.Empty;
            int    comma = value.IndexOf(',');

            if (comma >= 0)
            {
                name = value.Substring(0, comma).Trim();
                dll  = value.Substring(comma + 1).Trim();
            }

            Assembly assembly = S.Reflection.ReflectionUtil.LoadAssembly(dll);

            Assert.IsNotNull(assembly, "assembly: " + dll);
            Type type = assembly.GetType(name, false, true);

            if (type == null)
            {
                type = assembly.GetType(name + "`1");
            }

            Assert.IsNotNull(type, "Type : " + name);
            dll = S.IO.FileUtil.MapPath("/bin/" + dll + ".dll");
            Assert.IsTrue(File.Exists(dll), "dll.Exists(): " + dll);
            string tempFile = string.Format(
                "{0}.{1}.il",
                type,
                DateTime.Now.ToString("yyyyMMddTHHmmssffff"));

            S.IO.TempFolder.EnsureFolder();
            tempFile = S.IO.FileUtil.MapPath(
                S.IO.FileUtil.MakePath(S.IO.TempFolder.Folder, tempFile, '/'));
            S.Sharedsource.Diagnostics.CommandLineTool clt =
                new S.Sharedsource.Diagnostics.CommandLineTool(
                    "c:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.0A\\bin\\NETFX 4.0 Tools\\x64\\ildasm.exe");
            clt.Execute(
                true /*log*/,
                "/source /html /linenum /item=" + type + " /out=" + tempFile + " " + dll); // /pubonly
            Assert.IsTrue(File.Exists(tempFile), "tempFile.Exists(): " + tempFile);
            this.Response.Output.Write(S.IO.FileUtil.ReadFromFile(tempFile));
            this.Response.End();
            File.Delete(tempFile);
        }
コード例 #5
0
        // rewrite the Source property
        // set selectFirstItem now rather than parsing again later
        protected void ProcessSource(string originalSource)
        {
            if ((!string.IsNullOrEmpty(originalSource)) &&
                this.Source.Contains("{itemfield:"))
            {
                MatchCollection matches = Regex.Matches(
                    originalSource,
                    "(?<match>\\{itemfield\\:(?<field>[^\\}]+)})");
                Assert.IsTrue(matches.Count > 0, "matches > 0");

                foreach (Match match in matches)
                {
                    foreach (Group group in match.Groups)
                    {
                        originalSource = originalSource.Replace(
                            match.Groups["match"].Value,
                            this.CurrentItem[match.Groups["field"].Value]);
                    }
                }
            }

            // If the Source contains a single value, convert it to a
            // key=value pair.
            if (originalSource.StartsWith("query:") ||
                originalSource.StartsWith("~") ||
                originalSource.StartsWith("/") ||
                originalSource.StartsWith("."))
            {
                originalSource = "DataSource=" + originalSource;
            }

            SC.Collections.SafeDictionary <string> parameters =
                SC.Web.WebUtil.ParseQueryString(originalSource);
            string databaseName = parameters["DatabaseName"];

            if (String.IsNullOrEmpty(databaseName))
            {
                this.database = this.CurrentItem.Database;
            }
            else
            {
                this.database = SC.Configuration.Factory.GetDatabase(databaseName);
                SC.Diagnostics.Assert.IsNotNull(this.database, "database");
            }

            string dataSource = parameters["DataSource"];

            if (!(string.IsNullOrEmpty(dataSource) || dataSource.StartsWith("~")))
            {
                parameters["DataSource"] = this.ExpandDataSource(dataSource);
            }

            string sortBy = parameters["SortBy"];

            if (!string.IsNullOrEmpty(sortBy))
            {
                this.SortBy = sortBy;
                parameters.Remove("SortBy");
            }

            string display = parameters["Display"];

            if (!string.IsNullOrEmpty(display))
            {
                this.Display = display;
                parameters.Remove("Display");
            }

            string displayInTree = parameters["DisplayInTree"];

            if (displayInTree != null)
            {
                this.DisplayFieldName = displayInTree;
                parameters.Remove("DisplayInTree");
            }

            string includeItemsForDisplay = parameters["IncludeItemsForDisplay"];

            if ((!string.IsNullOrEmpty(includeItemsForDisplay) &&
                 includeItemsForDisplay.StartsWith("query:")))
            {
                parameters["IncludeItemsForDisplay"] =
                    this.CalculateIncludeItemsForDisplay(includeItemsForDisplay);
            }

            this.selectFirstItem = parameters["SelectFirstItem"];
            this.Source          = SC.Web.WebUtil.BuildQueryString(parameters, false);
        }