/// <summary> /// Gets message metadata. /// </summary> /// <param name="query">Query.</param> /// <param name="maxItems">The maximum number of items to return.</param> /// <returns>Metadata.</returns> /// <exception cref="ArgumentException">Thrown if DateTime kind is not UTC.</exception> /// <exception cref="ObjectDisposedException">Thrown if disposed.</exception> public SysColl.List <Metadata> Get(MetadataQuery query, int maxItems) { ExpectNotDisposed(); // throws ObjectDisposedException var retval = new SysColl.List <Metadata>(); // Setting query defaults for the timestamps var startForQuery = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc); var endForQuery = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc); // Getting the actual datetime values in the query if (query.TimeWindowStart.HasValue) { startForQuery = query.TimeWindowStart.Value; } if (query.TimeWindowEnd.HasValue) { endForQuery = query.TimeWindowEnd.Value; } // Requiring UTC as the DateTime kind ExpectUtc(startForQuery); ExpectUtc(endForQuery); var discoveredItems = from md in m_messageContext.DbMetadataItem select md; // Filtering by host and exchange; // filtering by start and end time discoveredItems = discoveredItems.Where(md => md.Host == query.Host && md.Exchange == query.Exchange && md.ReceivedAt >= startForQuery.Ticks && md.ReceivedAt <= endForQuery.Ticks ); // Filtering by topic if specified if (!string.IsNullOrEmpty(query.Topic)) { discoveredItems = discoveredItems.Where(md => md.Topic == query.Topic); } // Limiting the number of items discoveredItems = discoveredItems.Take(maxItems); // Converting to the Entify-Framework-independent format foreach (var efMeta in discoveredItems.ToList()) // ToList() requires System.Linq { var metadata = ConvertForOutput(efMeta); retval.Add(metadata); } return(retval); }
private AppLogic.MetadataState GetMetadataUsingFilters() { // Clear any previous filter status and messages FiltersExpander.Header = "Filters"; SetStatusText(FiltersHintTextBlock, "", isProblem: false); TimeWindowBuilder timeWindow; // Trying to build time window for the query try { timeWindow = GetTimeWindowForFilter(); } catch (ArgumentException e) { SetStatusText(FiltersHintTextBlock, e.Message, isProblem: true); return(null); } // Create query object var query = new MetadataQuery(m_host, m_exchange) { TimeWindowStart = timeWindow.TimeWindowStart, TimeWindowEnd = timeWindow.TimeWindowEnd }; // Adding topic for filtering if selected if (FilterTopicComboBox.SelectedValue != null) { var selectedValue = (string)FilterTopicComboBox.SelectedValue; query.Topic = selectedValue; } // Getting metadata and topics var metadataState = m_appLogic.GetMetadataState(query); // Refreshing message count FiltersExpander.Header = string.Format("Filters (showing {0} messages out of {1})", metadataState.Items.Count, metadataState.TotalItemCount); // Is the item limit applied? Set hint if yes. if (metadataState.IsLimitApplied) { SetStatusText(FiltersHintTextBlock, "Too many items found. Not showing all.", isProblem: false); } return(metadataState); }
/// <summary> /// Returns information about the currently stored metadata. /// </summary> /// <param name="query">Query for the metadata items to return.</param> /// <returns>Information about metadata.</returns> public MetadataState GetMetadataState(MetadataQuery query) { const int MaxItemsToReturn = 200; using (var metadataMgr = new MetadataManager(m_exeFolder)) { var items = metadataMgr.Get(query, MaxItemsToReturn); return(new MetadataState() { Items = items, Topics = metadataMgr.GetTopics(host: query.Host, exc: query.Exchange), TotalItemCount = metadataMgr.GetTotalCount(host: query.Host, exc: query.Exchange), IsLimitApplied = items.Count >= MaxItemsToReturn // Max item count reached? }); } }