示例#1
0
        /// <summary>
        /// Get the records and filter by a given predicate
        /// </summary>
        /// <param name="filter">The filter to apply</param>
        /// <param name="start">The start record</param>
        /// <param name="pageSize">The page size</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The records filtered</returns>
        public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, int start, int pageSize, string ago)
        {
            bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago);

            var items = GetRecordsByFilter(CombineFilter);

            return(items.Page(start, pageSize));
        }
        /// <summary>
        /// Get the records and filter by a given predicate and time in the past
        /// </summary>
        /// <param name="filter">The filter to apply</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The records filtered</returns>
        public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, string ago)
        {
            var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero);

            bool CombineFilter(T x) => filter(x) && x.Timestamp >= utcTime;

            return(GetAllRecords().Where(CombineFilter));
        }
示例#3
0
        /// <summary>
        /// Get the records and filter by a given predicate and time in the past
        /// </summary>
        /// <param name="filter">The filter to apply</param>
        /// <param name="start">The start record</param>
        /// <param name="pageSize">The page size</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The records filterted</returns>
        public async Task <IEnumerable <T> > GetRecordsByFilterAsync(Func <T, bool> filter, int start, int pageSize, string ago)
        {
            bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago);

            var allRecords = GetAllRecords();
            var data       = allRecords.Where(CombineFilter).Page(start, pageSize);

            return(await Task.FromResult(data));
        }
        public void given_time_string_parser_get_time_ago_when_value_does_not_contain_valid_time_type_string_then_an_exception_is_thrown()
        {
            // Arrange
            // Act
            Action act = () => TimeStringParser.GetTimeAgo("1");

            // Assert
            act.Should().Throw <ArgumentException>().WithMessage("Time ago value '1' is invalid. Values must be in the format of 1m, 1h, 1d.*");
        }
示例#5
0
        public void given_time_string_parser_get_time_ago_when_value_contains_additional_characters_after_the_valid_time_then_an_exception_is_thrown()
        {
            // Arrange
            // Act
            Action act = () => TimeStringParser.GetTimeAgo("1hdfyskdhfkds");

            // Assert
            act.Should().Throw <ArgumentException>().WithMessage("Time ago value '1hdfyskdhfkds' is invalid. Values must be in the format of 1m, 1h, 1d.\r\nParameter Name: ago");
        }
示例#6
0
        /// <summary>
        /// Build the row key table query
        /// </summary>
        /// <param name="rowKey">The row key</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The table query</returns>
        private static TableQuery <T> BuildGetByRowKeyAndTimeQuery(string rowKey, string ago)
        {
            var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero);

            var query = new TableQuery <T>().Where(TableQuery.CombineFilters(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey),
                                                                             TableOperators.And,
                                                                             TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, utcTime)));

            return(query);
        }
        /// <summary>
        /// Get the records and filter by a given predicate
        /// </summary>
        /// <param name="filter">The filter to apply</param>
        /// <param name="start">The start record</param>
        /// <param name="pageSize">The page size</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The records filtered</returns>
        public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, int start, int pageSize, string ago)
        {
            var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero);

            bool CombineFilter(T x) => filter(x) && x.Timestamp >= utcTime;

            var items = GetRecordsByFilter(CombineFilter);

            return(items.Page(start, pageSize));
        }
        public async Task <IEnumerable <T> > GetByRowKeyAsync(string rowKey, string ago)
        {
            EnsureRowKey(rowKey);

            var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero);

            var queryResults = CloudTable.QueryAsync <T>(x => x.RowKey == rowKey && x.Timestamp >= utcTime);

            return(await queryResults.ToListAsync());
        }
        public void given_time_string_parser_get_time_ago_when_value_contains_additional_characters_after_the_valid_time_then_an_exception_is_thrown()
        {
            // Arrange
            var invalidAgo = "1hiudadlj";
            // Act
            Action act = () => TimeStringParser.GetTimeAgo(invalidAgo);

            // Assert
            act.Should().Throw <ArgumentException>().WithMessage($"Time ago value '{invalidAgo}' is invalid. Values must be in the format of 1m, 1h, 1d.*");
        }
        public void given_time_string_parser_get_time_ago_when_1d_then_the_result_is_1_day_in_the_past(string ago)
        {
            // Arrange
            var expected = new DateTime(2017, 12, 31, 08, 10, 00);

            // Act
            var result = TimeStringParser.GetTimeAgo(ago);

            // Assert
            result.Should().Be(expected);
        }
        public void given_time_string_parser_get_time_ago_when_30s_then_the_result_is_30_seconds_in_the_past(string ago)
        {
            // Arrange
            var expected = new DateTime(2018, 01, 01, 08, 9, 30);

            // Act
            var result = TimeStringParser.GetTimeAgo(ago);

            // Assert
            result.Should().Be(expected);
        }
        /// <summary>
        /// Get the records and filter by a given predicate and time in the past
        /// </summary>
        /// <param name="filter">The filter to apply</param>
        /// <param name="start">The start record</param>
        /// <param name="pageSize">The page size</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The records filtered</returns>
        public async Task <IEnumerable <T> > GetRecordsByFilterAsync(Func <T, bool> filter, int start, int pageSize, string ago)
        {
            var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero);

            bool CombineFilter(T x) => filter(x) && x.Timestamp >= utcTime;

            var allRecords = await GetAllRecordsAsync();

            var data = allRecords.Where(CombineFilter).Page(start, pageSize);

            return(data);
        }
示例#13
0
        /// <summary>
        /// Get the records and filter by a given predicate via observable
        /// </summary>
        /// <param name="filter">The filter to apply</param>
        /// <param name="start">The start record</param>
        /// <param name="pageSize">The page size</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The observable for the results</returns>
        public IObservable <T> GetRecordsByFilterObservable(Func <T, bool> filter, int start, int pageSize, string ago)
        {
            bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago);

            return(Observable.Create <T>(o =>
            {
                foreach (var result in GetAllRecords().Where(CombineFilter).Page(start, pageSize))
                {
                    o.OnNext(result);
                }
                return Disposable.Empty;
            }));
        }
示例#14
0
        /// <summary>
        /// Get the records and filter by a given predicate and time in the past
        /// </summary>
        /// <param name="filter">The filter to apply</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The records filtered</returns>
        public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, string ago)
        {
            bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago);

            return(GetAllRecords().Where(CombineFilter));
        }
        /// <summary>
        /// Build the row key table query
        /// </summary>
        /// <param name="rowKey">The row key</param>
        /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param>
        /// <returns>The table query</returns>
        //private static TableQuery<T> BuildGetByRowKeyAndTimeQuery(string rowKey, string ago)
        private Pageable <T> BuildGetByRowKeyAndTimeQuery(string rowKey, string ago)
        {
            var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero);

            return(CloudTable.Query <T>(x => x.RowKey == rowKey && x.Timestamp >= utcTime));
        }