private void GetUsageData() { int nodeId = Int32.Parse(Request.QueryString["id"]); var criteria = searcher.CreateSearchCriteria(IndexTypes.Content); string[] fields = PropertyTypes.Split(new[] { ',' }); var query = criteria.OrderBy("__nodeName"); query = fields.Aggregate(query, (current, field) => current.Or().Field(field, nodeId.ToString())); _results = searcher.Search(query.Compile()); queryGenerated.Value = criteria.ToString(); if (_results.Any()) { rptItemUsage.DataSource = _results; rptItemUsage.DataBind(); litMessage.Text = "The page is referenced by the pages listed below"; } else { rptItemUsage.Visible = false; litMessage.Text = NoResultstext; } }
/// <summary> /// Get the Forum Info - using examine, because that can be faster when /// there are lots and lots of posts - although i've yet to see it /// really get faster than the traverse method (yet) /// </summary> /// <param name="item"></param> /// <param name="useExamine">true to use examine</param> public static ForumCacheItem GetForumInfo(this IPublishedContent item, bool useExamine) { if (!useExamine) { return(GetForumInfo(item)); } ExamineManager.Instance.TryGetSearcher("InternalSearcher", out _); var cacheName = $"forum_{item.Id}"; var cache = Current.AppCaches.RuntimeCache; var forumInfo = cache.GetCacheItem <ForumCacheItem>(cacheName); if (forumInfo != null) { return(forumInfo); } //Stopwatch sw = new Stopwatch(); //sw.Start(); forumInfo = new ForumCacheItem(); ISearchResults searchResults = queryLastPostIndex(item, item.Name); ISearchResults updateResults = queryLastEditIndex(item, item.Name); forumInfo.Count = searchResults.ToList().Count - 1; forumInfo.latestPost = DateTime.MinValue; if (searchResults.Any()) { var lastpostdate = new DateTime(Convert.ToInt64(searchResults.First().Values["createDate"])); if (lastpostdate > DateTime.MinValue) { forumInfo.latestPost = lastpostdate; } forumInfo.lastpostAuthor = searchResults.First().Values["postCreator"]; } if (updateResults.Any()) { var latestedit = new DateTime(Convert.ToInt64(searchResults.First().Values["editDate"])); if (latestedit > DateTime.MinValue) { forumInfo.latestEdit = latestedit; } } cache.InsertCacheItem <ForumCacheItem>(cacheName, () => forumInfo); return(forumInfo); }
public static LatestUpdateList ObtainAllMessages(int pageNo = 1) { //Instantiate variables var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); LatestUpdateList lstLatestUpdates = new LatestUpdateList(); //try //{ //Get all ... BaseSearchProvider mySearcher = ExamineManager.Instance.SearchProviderCollection[Common.searchProviders.MessagesSearcher]; ISearchCriteria criteria = mySearcher.CreateSearchCriteria(IndexTypes.Content); IBooleanOperation query = criteria.Field(Common.NodeProperties.indexType, Common.NodeProperties.content); //gets all items query.And().OrderByDescending(Common.NodeProperties.publishDate); query.And().OrderBy(Common.NodeProperties.nodeName); query.And().OrderBy(Common.miscellaneous.Path); ISearchResults isResults = mySearcher.Search(query.Compile()); if (isResults.Any()) { //Instantiate variables DateTime msgDate = new DateTime(1900, 1, 1); DateTime prevDate = new DateTime(1900, 1, 1); latestUpdates latestUpdate = new latestUpdates(); visionary visionary = new visionary(); message message; IPublishedContent ipMsg; IPublishedContent ipVisionary; //Get item counts and total experiences. lstLatestUpdates.Pagination.itemsPerPage = 20; lstLatestUpdates.Pagination.totalItems = isResults.Count(); //Determine how many pages/items to skip and take, as well as the total page count for the search result. if (lstLatestUpdates.Pagination.totalItems > lstLatestUpdates.Pagination.itemsPerPage) { lstLatestUpdates.Pagination.totalPages = (int)Math.Ceiling((double)lstLatestUpdates.Pagination.totalItems / (double)lstLatestUpdates.Pagination.itemsPerPage); } else { lstLatestUpdates.Pagination.itemsPerPage = lstLatestUpdates.Pagination.totalItems; lstLatestUpdates.Pagination.totalPages = 1; } //Determine current page number if (pageNo <= 0 || pageNo > lstLatestUpdates.Pagination.totalPages) { pageNo = 1; } lstLatestUpdates.Pagination.pageNo = pageNo; //Determine how many pages/items to skip if (lstLatestUpdates.Pagination.totalItems > lstLatestUpdates.Pagination.itemsPerPage) { lstLatestUpdates.Pagination.itemsToSkip = lstLatestUpdates.Pagination.itemsPerPage * (pageNo - 1); } //Get top 'n' results and determine link structure //foreach (SearchResult srResult in isResults.Take(30)) foreach (SearchResult srResult in isResults.Skip(lstLatestUpdates.Pagination.itemsToSkip).Take(lstLatestUpdates.Pagination.itemsPerPage)) { //Obtain message's node ipMsg = umbracoHelper.TypedContent(Convert.ToInt32(srResult.Id)); if (ipMsg != null) { //Obtain date of message msgDate = ipMsg.GetPropertyValue <DateTime>(Common.NodeProperties.publishDate); //Create a new date for messages if (msgDate != prevDate) { //Update current date prevDate = msgDate; //Create new instances for updates and add to list of all updates. latestUpdate = new latestUpdates(); latestUpdate.datePublished = msgDate; lstLatestUpdates.LstLatestUpdates.Add(latestUpdate); //Reset the visionary class on every new date change. visionary = new visionary(); } //Obtain current visionary or webmaster if (ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.Visionary) != null) { if (visionary.id != ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.Visionary).Id) { //Obtain visionary node ipVisionary = ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.Visionary); //Create new visionary class and add to latest update class visionary = new visionary(); visionary.id = ipVisionary.Id; visionary.name = ipVisionary.Name; visionary.url = ipVisionary.Url; latestUpdate.lstVisionaries.Add(visionary); } } else if (ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.WebmasterMessageList) != null) { if (visionary.id != ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.WebmasterMessageList).Id) { //Obtain visionary node ipVisionary = ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.WebmasterMessageList); //Create new visionary class and add to latest update class visionary = new visionary(); visionary.id = ipVisionary.Id; visionary.name = ipVisionary.Name; visionary.url = ipVisionary.Url; latestUpdate.lstVisionaries.Add(visionary); } } //Create new message and add to existing visionary class. message = new message(); message.id = ipMsg.Id; message.title = ipMsg.Name; message.url = ipMsg.Url; visionary.lstMessages.Add(message); } } } //} //catch (Exception ex) //{ // //StringBuilder sb = new StringBuilder(); // //sb.AppendLine(@"MessageController.cs : RenderLatestMessages()"); // //sb.AppendLine("model:" + Newtonsoft.Json.JsonConvert.SerializeObject(lstLatestUpdates)); // //Common.SaveErrorMessage(ex, sb, typeof(MessageController)); // //ModelState.AddModelError("", "*An error occured while creating the latest message list."); // //return CurrentUmbracoPage(); //} //Return data to partialview return(lstLatestUpdates); }
public static List <latestUpdates> ObtainLatestMessages() { //Instantiate variables var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); List <latestUpdates> lstLatestUpdates = new List <latestUpdates>(); try { //Get all messages BaseSearchProvider mySearcher = ExamineManager.Instance.SearchProviderCollection[Common.searchProviders.MessagesSearcher]; ISearchCriteria criteria = mySearcher.CreateSearchCriteria(IndexTypes.Content); IBooleanOperation query = criteria.Field(Common.NodeProperties.indexType, Common.NodeProperties.content); //gets all items query.And().OrderByDescending(Common.NodeProperties.publishDate); query.And().OrderBy(Common.NodeProperties.nodeName); query.And().OrderBy(Common.miscellaneous.Path); ISearchResults isResults = mySearcher.Search(query.Compile()); if (isResults.Any()) { //Instantiate variables DateTime msgDate = new DateTime(1900, 1, 1); //DateTime prevDate = new DateTime(1900, 1, 1); latestUpdates latestUpdate = new latestUpdates(); visionary visionary = new visionary(); message message; IPublishedContent ipMsg; IPublishedContent ipVisionary; Boolean isFirst = true; //Get top 'n' results and determine link structure foreach (SearchResult srResult in isResults) { //Obtain message's node ipMsg = umbracoHelper.TypedContent(Convert.ToInt32(srResult.Id)); if (ipMsg != null) { if (isFirst) { //Obtain date of latest message msgDate = ipMsg.GetPropertyValue <DateTime>(Common.NodeProperties.publishDate); isFirst = false; } else { //Exit loop if a different publish date exists if (msgDate != ipMsg.GetPropertyValue <DateTime>(Common.NodeProperties.publishDate)) { break; } } //Create a new date for messages //if (msgDate != prevDate) //{ // //Update current date // prevDate = msgDate; //Create new instances for updates and add to list of all updates. latestUpdate = new latestUpdates(); latestUpdate.datePublished = msgDate; lstLatestUpdates.Add(latestUpdate); //Reset the visionary class on every new date change. visionary = new visionary(); //} //Obtain current visionary or webmaster if (ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.Visionary) != null) { if (visionary.id != ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.Visionary).Id) { //Obtain visionary node ipVisionary = ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.Visionary); //Create new visionary class and add to latest update class visionary = new visionary(); visionary.id = ipVisionary.Id; visionary.name = ipVisionary.Name; visionary.url = ipVisionary.UrlAbsolute(); latestUpdate.lstVisionaries.Add(visionary); } } else if (ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.WebmasterMessageList) != null) { if (visionary.id != ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.WebmasterMessageList).Id) { //Obtain visionary node ipVisionary = ipMsg.AncestorsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == Common.docType.WebmasterMessageList); //Create new visionary class and add to latest update class visionary = new visionary(); visionary.id = ipVisionary.Id; visionary.name = ipVisionary.Name; visionary.url = ipVisionary.UrlAbsolute(); latestUpdate.lstVisionaries.Add(visionary); } } //Create new message and add to existing visionary class. message = new message(); message.id = ipMsg.Id; message.title = ipMsg.Name; message.url = ipMsg.UrlAbsolute(); visionary.lstMessages.Add(message); } } } } catch (Exception ex) { //StringBuilder sb = new StringBuilder(); //sb.AppendLine(@"MessageController.cs : RenderLatestMessages()"); //sb.AppendLine("model:" + Newtonsoft.Json.JsonConvert.SerializeObject(lstLatestUpdates)); //Common.saveErrorMessage(ex.ToString(), sb.ToString()); //ModelState.AddModelError("", "*An error occured while creating the latest message list."); //return CurrentUmbracoPage(); } // return(lstLatestUpdates); }