/// <summary> /// Updates all messages in the list view to show only those meeting the /// selection criteria. /// </summary> private void RefreshMessages() { //Check if we have a task if (Task == null) { return; } //Check if we have any session selected if (filterSessionCombobox.SelectedIndex == -1) { return; } Application.UseWaitCursor = true; LogSinkBase sink = Task.Log[filterSessionCombobox.SelectedIndex]; EntryCache.Clear(); SelectedEntries.Clear(); EntryCache.AddRange(sink.Where(MeetsCriteria)); //Set the list view size and update all the control states log.VirtualListSize = EntryCache.Count; log.Refresh(); EnableButtons(); Application.UseWaitCursor = false; }
public void OnEventLogged(object sender, LogEventArgs e) { if (IsDisposed || !IsHandleCreated) { return; } if (InvokeRequired) { Invoke((EventHandler <LogEventArgs>)OnEventLogged, sender, e); return; } //Check whether the current entry meets the criteria for display. if (filterSessionCombobox.SelectedItem == null || !MeetsCriteria(e.LogEntry)) { return; } //Add it to the cache and increase our virtual list size. EntryCache.Add(e.LogEntry); ++log.VirtualListSize; //Enable the clear and copy log buttons only if we have entries to copy. EnableButtons(); }
private void clear_Click(object sender, EventArgs e) { //Clear the backing store Task.Log.Clear(); //Reset the list of sessions filterSessionCombobox.Items.Clear(); //And reset the list-view control log.VirtualListSize = 0; SelectedEntries.Clear(); EntryCache.Clear(); //Finally update the UI state. EnableButtons(); }
/// <summary> /// Gets blog entries for the given blog which meet the criteria. /// </summary> /// <param name="blogRootItem">The root item of the blog to retrieve the entries for.</param> /// <param name="criteria">The criteria the entries should meet.</param> /// <param name="resultOrder">The ordering of the results.</param> /// <returns>The entries matching the criteria.</returns> public virtual SearchResults <Entry> GetBlogEntries(Item blogRootItem, EntryCriteria criteria, ListOrder resultOrder) { if (blogRootItem == null || criteria == null || criteria.PageNumber <= 0 || criteria.PageSize <= 0) { return(SearchResults <Entry> .Empty); } var cachedEntries = EntryCache?.Get(criteria, resultOrder); if (cachedEntries != null) { return(cachedEntries); } var customBlogItem = (from templateId in Settings.BlogTemplateIds where TemplateManager.TemplateIsOrBasedOn(blogRootItem, templateId) select(BlogHomeItem) blogRootItem).FirstOrDefault(); if (customBlogItem == null) { customBlogItem = (from templateId in Settings.BlogTemplateIds let item = blogRootItem.FindAncestorByTemplate(templateId, TemplateManager) where item != null select(BlogHomeItem) item).FirstOrDefault(); } if (customBlogItem == null) { return(SearchResults <Entry> .Empty); } var blogSettings = BlogSettingsResolver.Resolve(customBlogItem); using (var context = CreateSearchContext(blogRootItem)) { var builder = PredicateBuilder.Create <EntryResultItem>(searchItem => searchItem.TemplateId == blogSettings.EntryTemplateID && searchItem.Paths.Contains(customBlogItem.ID) && searchItem.Language.Equals(customBlogItem.InnerItem.Language.Name, StringComparison.InvariantCulture) ); // Tag if (!string.IsNullOrEmpty(criteria.Tag)) { builder = builder.And(i => i.Tags.Contains(criteria.Tag)); } // Categories if (!string.IsNullOrEmpty(criteria.Category)) { var categoryItem = ManagerFactory.CategoryManagerInstance.GetCategory(customBlogItem, criteria.Category); // If the category is unknown, don't return any results. if (categoryItem == null) { return(SearchResults <Entry> .Empty); } builder = builder.And(i => i.Category.Contains(categoryItem.ID)); } if (criteria.MinimumDate != null) { builder = builder.And(i => i.EntryDate >= criteria.MinimumDate); } if (criteria.MaximumDate != null) { builder = builder.And(i => i.EntryDate <= criteria.MaximumDate); } var indexresults = context.GetQueryable <EntryResultItem>().Where(builder); if (resultOrder == ListOrder.Descending) { indexresults = indexresults.OrderByDescending(item => item.EntryDate) .ThenByDescending(item => item.CreatedDate) .ThenByDescending(item => item.Title); } else { indexresults = indexresults.OrderBy(item => item.EntryDate) .ThenBy(item => item.CreatedDate) .ThenBy(item => item.Title); } indexresults = indexresults.Skip(criteria.PageSize * (criteria.PageNumber - 1)) .Take(criteria.PageSize < int.MaxValue ? criteria.PageSize + 1 : criteria.PageSize); var entries = indexresults.Select(resultItem => // Keep field access inline so the query analyzer can see which fields will be used. new Entry { Uri = resultItem.Uri, Title = string.IsNullOrWhiteSpace(resultItem.Title) ? resultItem.Name : resultItem.Title, Tags = resultItem.Tags != null ? resultItem.Tags : Enumerable.Empty <string>(), EntryDate = resultItem.EntryDate } ).ToList(); var hasMore = entries.Count > criteria.PageSize; var entriesPage = entries.Take(criteria.PageSize).ToList(); var results = new SearchResults <Entry>(entriesPage, hasMore); EntryCache?.Set(criteria, resultOrder, results); return(results); } }
public LinkAndInfo ResolveLink(LinkToResolve link) { string absoluteUri = link.Link.AbsoluteUri; Match z0rMatch = Z0rUrlPattern.Match(absoluteUri); if (!z0rMatch.Success) { // can't handle this return(null); } // obtain the ID long z0rID; if (!long.TryParse(z0rMatch.Groups["id"].Value, NumberStyles.None, CultureInfo.InvariantCulture, out z0rID)) { // unparseable ID, probably too many digits return(null); } Z0rEntry entry; if (EntryCache.TryGetValue(z0rID, out entry)) { // fast-path return(link.ToResult(FetchErrorLevel.Success, FormatEntry(entry))); } Z0rRange range = RangeForID(z0rID); if (!MaxPage.HasValue) { MaxPage = ObtainMaxPageValue(); } if (!MaxPage.HasValue) { // bad return(link.ToResult( FetchErrorLevel.TransientError, string.Format(CultureInfo.InvariantCulture, "z0r #{0}; fetching index page list failed", z0rID) )); } if (range.Page > MaxPage) { // the index does not contain this page entry = new Z0rEntry(z0rID, null, null, null, null); return(link.ToResult(FetchErrorLevel.Success, FormatEntry(entry))); } LoadFromPage(range.Page); if (EntryCache.TryGetValue(z0rID, out entry)) { return(link.ToResult(FetchErrorLevel.Success, FormatEntry(entry))); } return(link.ToResult( FetchErrorLevel.TransientError, string.Format(CultureInfo.InvariantCulture, "z0r #{0}; fetching failed", z0rID) )); }