示例#1
0
        public void Ended(object sender, EventArgs args)
        {
            Assert.IsNotNull(args, nameof(args));

            try
            {
                SitecoreEventArgs jobargs    = args as SitecoreEventArgs;
                string            index_name = jobargs.Parameters[0] as string;
                var index = ContentSearchManager.Indexes.SingleOrDefault(idx => idx.Name == index_name);

                var payload = new IndexingUpdate
                {
                    IndexName                = index.Name,
                    State                    = State.Ended,
                    IndexRebuildTime         = BuildTime(index),
                    IndexRebuildMilliseconds = IndexHealthHelper.GetIndexRebuildTime(index.Name),
                    ThroughPut               = ThroughPut(index),
                    NumberOfDocuments        = index.Summary.NumberOfDocuments
                };

                new Services.NotificationService <IndexingUpdate>().Send(payload);
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        public IHttpActionResult List()
        {
            if (!IsAuthenticated)
            {
                return(Unauthorized());
            }

            using (new UserSwitcher(Context.Site.Domain.GetFullName(this.ApiUser), false))
            {
                if (!Context.User.IsAdministrator)
                {
                    return(Unauthorized());
                }

                IList <IndexingUpdate> indexes = ContentSearchManager.Indexes.Where(index =>
                {
                    return(index.Group != IndexGroup.Experience && ContentSearchManager.Locator.GetInstance <ISearchIndexSwitchTracker>().IsIndexOn(index.Name));
                })
                                                 .Select(index =>
                {
                    StringBuilder sb = new StringBuilder();

                    sb.AppendLine(IndexingEventHandler.BuildTime(index));
                    sb.AppendLine(IndexingEventHandler.ThroughPut(index));
                    sb.AppendLine(string.Concat("Document count: ", index.Summary.NumberOfDocuments));
                    sb.AppendLine(string.Format("Last Updated: {0} (UTC)", string.Concat(index.Summary.LastUpdated.ToShortDateString(), " - ", index.Summary.LastUpdated.ToShortTimeString())));

                    var payload = new IndexingUpdate
                    {
                        IndexName                = index.Name,
                        Message                  = sb.ToString(),
                        State                    = State.UnKnown,
                        NumberOfDocuments        = index.Summary.NumberOfDocuments,
                        LastUpdated              = index.Summary.LastUpdated,
                        IndexRebuildMilliseconds = IndexHealthHelper.GetIndexRebuildTime(index.Name),
                        IndexRebuildTime         = IndexingEventHandler.BuildTime(index)
                    };

                    return(payload);
                }).ToList();

                return(new JsonResult <IList <IndexingUpdate> >(indexes, new JsonSerializerSettings(), Encoding.UTF8, this));
            }
        }
示例#3
0
        public static string ThroughPut(ISearchIndex index)
        {
            string throughput = string.Format("<p> <strong>Approximate Throughput: </strong> 0 items per second</p>");

            if (index.Summary.NumberOfDocuments > (long)0 && IndexHealthHelper.GetIndexRebuildTime(index.Name) > 0)
            {
                int indexRebuildTime = IndexHealthHelper.GetIndexRebuildTime(index.Name) / 1000;
                if (indexRebuildTime > 0)
                {
                    long num = index.Summary.NumberOfDocuments / (long)indexRebuildTime;
                    if (num > (long)0)
                    {
                        double num1 = (double)num;
                        throughput = string.Format("<p> <strong>Approximate Throughput: </strong> {0} items per second</p>", num1.ToString(CultureInfo.InvariantCulture));
                    }
                }
            }

            return(throughput);
        }
示例#4
0
        public IHttpActionResult Rebuild([FromBody] string indexname)
        {
            if (!IsAuthenticated)
            {
                return(Unauthorized());
            }

            using (new UserSwitcher(Context.Site.Domain.GetFullName(this.ApiUser), false))
            {
                if (!Context.User.IsAdministrator)
                {
                    return(Unauthorized());
                }

                var index = ContentSearchManager.Indexes.SingleOrDefault(idx => idx.Name == indexname);

                var payload = new IndexingUpdate
                {
                    IndexName                = index.Name,
                    State                    = State.Started,
                    NumberOfDocuments        = index.Summary.NumberOfDocuments,
                    LastUpdated              = index.Summary.LastUpdated,
                    IndexRebuildMilliseconds = IndexHealthHelper.GetIndexRebuildTime(index.Name),
                    IndexRebuildTime         = IndexingEventHandler.BuildTime(index)
                };

                if (index.Group == IndexGroup.Experience || !ContentSearchManager.Locator.GetInstance <ISearchIndexSwitchTracker>().IsIndexOn(index.Name))
                {
                    payload.State = State.NotStarting;
                    return(new JsonResult <IndexingUpdate>(payload, new JsonSerializerSettings(), Encoding.UTF8, this));
                }
                else
                {
                    var job = IndexCustodian.FullRebuild(index, true);
                    payload.Job   = job.DisplayName;
                    payload.State = State.Started;
                    return(new JsonResult <IndexingUpdate>(payload, new JsonSerializerSettings(), Encoding.UTF8, this));
                }
            }
        }
示例#5
0
        public static string BuildTime(ISearchIndex index)
        {
            int indexRebuildTime = IndexHealthHelper.GetIndexRebuildTime(index.Name);

            if (indexRebuildTime == 0)
            {
                return(" Never Run ");
            }
            int num = indexRebuildTime / 1000;

            if (num < 120)
            {
                return(string.Concat(indexRebuildTime / 1000, " seconds"));
            }
            if (num >= 120 && num < 3600)
            {
                return(string.Concat(indexRebuildTime / 1000 / 60, " minutes"));
            }
            if (num < 3600)
            {
                return(string.Concat(indexRebuildTime / 1000, " seconds"));
            }
            return(string.Concat(indexRebuildTime / 1000 / 60 / 60, " hours"));
        }