Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <summary>
        /// Returns all topics in given host and exchange.
        /// </summary>
        /// <param name="host">Host.</param>
        /// <param name="exc">Exchange.</param>
        /// <returns>Topics.</returns>
        public SysColl.List <string> GetTopics(string host, string exc)
        {
            ExpectNotDisposed(); // throws ObjectDisposedException

            var items = m_messageContext.DbMetadataItem
                        .Where(m => m.Host == host && m.Exchange == exc)
                        .Select(m => new { m.Topic })
                        .Distinct()
                        .OrderBy(m1 => m1.Topic);

            // Convert to strings
            var retval = new SysColl.List <string>();

            foreach (var i in items)
            {
                retval.Add(i.Topic);
            }

            return(retval);
        }