Exemplo n.º 1
0
        /// <summary>
        /// Gets a list of ranking illusts.
        /// </summary>
        /// <param name="mode">The ranking mode to use.</param>
        /// <param name="date">The date to get ranking illusts for.</param>
        /// <param name="filter">The filter to use.</param>
        /// <returns><seealso cref="IllustSearchResult"/> for ranking illusts.</returns>
        public async Task <IllustSearchResult> RankingIllustsAsync(RankingMode mode  = RankingMode.Day, DateTime?date = null,
                                                                   FilterType?filter = null)
        {
            // Converts time to the correct timezone and produces a date string in correct format
            Stream   response;
            DateTime dateValue  = date ?? DateTime.Now.AddDays(-1);
            string   dateString = dateValue.Year.ToString("0000") + "-" + dateValue.Month.ToString("00")
                                  + "-" + dateValue.Day.ToString("00");

            Dictionary <string, string> parameters = new Dictionary <string, string>()
            {
                { "mode", mode.JsonValue() },
                { "date", dateString }
            };

            // Adds filter if required
            if ((filter ?? Filter) != FilterType.None)
            {
                parameters.Add("filter", filter.JsonValue() ?? Filter.JsonValue());
            }

            FormUrlEncodedContent encodedParams = new FormUrlEncodedContent(parameters);

            response = await RequestClient.RequestAsync(PixivUrls.RankingIllusts, encodedParams)
                       .ConfigureAwait(false);

            return(Json.DeserializeJson <IllustSearchResult>(response));
        }
Exemplo n.º 2
0
        private static IEnumerable <QueryToken> AggregateTokens(QueryToken token, QueryDescription qd)
        {
            if (token == null)
            {
                yield return(new AggregateToken(AggregateFunction.Count, qd.QueryName));
            }
            else if (!(token is AggregateToken))
            {
                FilterType?ft = QueryUtils.TryGetFilterType(token.Type);

                if (ft == FilterType.Integer || ft == FilterType.Decimal || ft == FilterType.Boolean)
                {
                    yield return(new AggregateToken(AggregateFunction.Average, token));

                    yield return(new AggregateToken(AggregateFunction.Sum, token));

                    yield return(new AggregateToken(AggregateFunction.Min, token));

                    yield return(new AggregateToken(AggregateFunction.Max, token));
                }
                else if (ft == FilterType.DateTime) /*ft == FilterType.String || */
                {
                    yield return(new AggregateToken(AggregateFunction.Min, token));

                    yield return(new AggregateToken(AggregateFunction.Max, token));
                }
            }
        }
Exemplo n.º 3
0
 internal ServiceBusRuleData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, FilterAction action, FilterType?filterType, SqlFilter sqlFilter, CorrelationFilter correlationFilter) : base(id, name, resourceType, systemData)
 {
     Action            = action;
     FilterType        = filterType;
     SqlFilter         = sqlFilter;
     CorrelationFilter = correlationFilter;
 }
Exemplo n.º 4
0
        protected override string PropertyValidation(PropertyInfo pi)
        {
            if (token != null && token.ParseException == null)
            {
                if (pi.Name == nameof(Token))
                {
                    return(QueryUtils.CanFilter(token.Token));
                }

                if (pi.Name == nameof(Operation))
                {
                    FilterType?filterType = QueryUtils.TryGetFilterType(Token.Token.Type);

                    if (filterType == null)
                    {
                        return(UserQueryMessage._0IsNotFilterable.NiceToString().FormatWith(token));
                    }

                    if (!QueryUtils.GetFilterOperations(filterType.Value).Contains(Operation))
                    {
                        return(UserQueryMessage.TheFilterOperation0isNotCompatibleWith1.NiceToString().FormatWith(Operation, filterType));
                    }
                }

                if (pi.Name == nameof(ValueString))
                {
                    return(FilterValueConverter.TryParse(ValueString, Token.Token.Type, out object val, Operation.IsList()));
                }
            }

            return(null);
        }
Exemplo n.º 5
0
 private string FilterTypeToString(FilterType?filterType)
 {
     if (filterType.HasValue && FilterTypeNameMapper.TryGetValue(filterType.Value, out var res))
     {
         return(res);
     }
     throw new InvalidOperationException();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the Rule class.
 /// </summary>
 /// <param name="id">Resource Id</param>
 /// <param name="name">Resource name</param>
 /// <param name="type">Resource type</param>
 /// <param name="action">Represents the filter actions which are
 /// allowed for the transformation of a message that have been matched
 /// by a filter expression.</param>
 /// <param name="filterType">Filter type that is evaluated against a
 /// BrokeredMessage. Possible values include: 'SqlFilter',
 /// 'CorrelationFilter'</param>
 /// <param name="sqlFilter">Properties of sqlFilter</param>
 /// <param name="correlationFilter">Properties of
 /// correlationFilter</param>
 public Rule(string id = default(string), string name = default(string), string type = default(string), Action action = default(Action), FilterType?filterType = default(FilterType?), SqlFilter sqlFilter = default(SqlFilter), CorrelationFilter correlationFilter = default(CorrelationFilter))
     : base(id, name, type)
 {
     Action            = action;
     FilterType        = filterType;
     SqlFilter         = sqlFilter;
     CorrelationFilter = correlationFilter;
     CustomInit();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Set filter type.
        /// </summary>
        /// <param name="filterType">Filter type.</param>
        public void FilterType(FilterType filterType)
        {
            if (_complexFilter != null)
            {
                throw new InvalidOperationException("Cannot specify filter type when complex filter expression is used.");
            }

            _filterType = filterType;
        }
Exemplo n.º 8
0
        private static IEnumerable <QueryToken> AggregateTokens(QueryToken token, QueryDescription qd)
        {
            if (token == null)
            {
                yield return(new AggregateToken(AggregateFunction.Count, qd.QueryName));
            }
            else if (!(token is AggregateToken))
            {
                FilterType?ft = QueryUtils.TryGetFilterType(token.Type);

                if (ft == FilterType.Integer || ft == FilterType.Decimal || ft == FilterType.Boolean)
                {
                    yield return(new AggregateToken(AggregateFunction.Average, token));

                    yield return(new AggregateToken(AggregateFunction.Sum, token));

                    yield return(new AggregateToken(AggregateFunction.Min, token));

                    yield return(new AggregateToken(AggregateFunction.Max, token));
                }
                else if (ft == FilterType.DateTime) /*ft == FilterType.String || */
                {
                    yield return(new AggregateToken(AggregateFunction.Min, token));

                    yield return(new AggregateToken(AggregateFunction.Max, token));
                }

                if (ft != null)
                {
                    yield return(new AggregateToken(AggregateFunction.Count, token, FilterOperation.DistinctTo, null));

                    yield return(new AggregateToken(AggregateFunction.Count, token, FilterOperation.EqualTo, null));
                }

                if (token.IsGroupable)
                {
                    yield return(new AggregateToken(AggregateFunction.Count, token, distinct: true));
                }

                if (ft == FilterType.Enum)
                {
                    foreach (var v in Enum.GetValues(token.Type.UnNullify()))
                    {
                        yield return(new AggregateToken(AggregateFunction.Count, token, FilterOperation.EqualTo, v));

                        yield return(new AggregateToken(AggregateFunction.Count, token, FilterOperation.DistinctTo, v));
                    }
                }

                if (ft == FilterType.Boolean)
                {
                    yield return(new AggregateToken(AggregateFunction.Count, token, FilterOperation.EqualTo, true));

                    yield return(new AggregateToken(AggregateFunction.Count, token, FilterOperation.EqualTo, false));
                }
            }
        }
Exemplo n.º 9
0
        public static FilterType GetFilterType(Type type)
        {
            FilterType?filterType = TryGetFilterType(type);

            if (filterType == null)
            {
                throw new NotSupportedException("Type {0} not supported".FormatWith(type));
            }

            return(filterType.Value);
        }
Exemplo n.º 10
0
        private void ComboBoxType_SelectedIndexChanged(object sender, EventArgs e)
        {
            FilterType?type = (FilterType?)comboBoxType.SelectedItem;

            if (type == FilterType.Highlight)
            {
                UpdateColor();
            }

            labelColor.Enabled  = type == FilterType.Highlight;
            buttonColor.Enabled = type == FilterType.Highlight;
        }
Exemplo n.º 11
0
        public async Task <IActionResult> List([FromQuery] string keyword = null, [FromQuery] FilterType?filterType = FilterType.Student, [FromQuery] int pageNo = 1, [FromQuery] int pageSize = 10)

        {
            try
            {
                if (pageNo <= 0)
                {
                    pageNo = 1;
                }

                if (pageSize > 50)
                {
                    pageSize = 50;
                }
                else if (pageSize <= 0)
                {
                    pageSize = 10;
                }

                keyword = keyword?.ToLower();

                var skip = (pageNo - 1) * pageSize;
                var take = pageSize;


                var query    = _DbContext.tbl_Marks.Where(x => (filterType == FilterType.Student && (string.IsNullOrWhiteSpace(keyword) || x.StudentID.ToString() == keyword || x.tbl_Student.FirstName.Contains(keyword) || x.tbl_Student.LastName.Contains(keyword))) || (filterType == FilterType.Class && x.tbl_Student.Class.ToString() == keyword) || (filterType == FilterType.Subject && x.tbl_Subject.Name.ToString() == keyword));
                var newquery = query.Select(x => new { x.ID, x.StudentID, x.StudentMark, x.tbl_Student.Class, x.tbl_Student.FirstName, x.tbl_Student.LastName, x.tbl_Subject.Name });
                var totalFilteredResultCount = await newquery.CountAsync();


                if (skip > totalFilteredResultCount)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new ApiResponse {
                        message = "invalid request", data = "no more file found."
                    }));
                }

                var totalFilteredResult = await newquery.Skip(skip).Take(take).ToListAsync();

                return(StatusCode(StatusCodes.Status200OK, new ApiResponse {
                    success = true, message = "success", data = new { total = totalFilteredResultCount, pageNo = pageNo, pageSize = pageSize, records = totalFilteredResult }
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse {
                    message = "unexpected error", data = ex.Message
                }));
            }
        }
Exemplo n.º 12
0
        public ColumnDescriptionTS(ColumnDescription a, object queryName)
        {
            var token = new ColumnToken(a, queryName);

            this.name          = a.Name;
            this.type          = new TypeReferenceTS(a.Type, a.Implementations);
            this.filterType    = QueryUtils.TryGetFilterType(a.Type);
            this.typeColor     = token.TypeColor;
            this.niceTypeName  = token.NiceTypeName;
            this.isGroupable   = token.IsGroupable;
            this.unit          = a.Unit;
            this.format        = a.Format;
            this.displayName   = a.DisplayName;
            this.propertyRoute = token.GetPropertyRoute()?.ToString();
        }
Exemplo n.º 13
0
        public ColumnDescriptionTS(ColumnDescription a, object queryName)
        {
            var token = new ColumnToken(a, queryName);

            this.name            = a.Name;
            this.type            = new TypeReferenceTS(a.Type, a.Implementations);
            this.filterType      = QueryUtils.TryGetFilterType(a.Type);
            this.typeColor       = token.TypeColor;
            this.niceTypeName    = token.NiceTypeName;
            this.isGroupable     = token.IsGroupable;
            this.hasOrderAdapter = QueryUtils.OrderAdapters.ContainsKey(token.Type);
            this.preferEquals    = token.Type == typeof(string) &&
                                   token.GetPropertyRoute() is PropertyRoute pr &&
                                   typeof(Entity).IsAssignableFrom(pr.RootType) &&
                                   Schema.Current.HasSomeIndex(pr);
            this.unit          = a.Unit;
            this.format        = a.Format;
            this.displayName   = a.DisplayName;
            this.propertyRoute = token.GetPropertyRoute()?.ToString();
        }
Exemplo n.º 14
0
        public static string GetUrl(string ext            = null,
                                    bool fromEditor       = false,
                                    FolderType?root       = null,
                                    bool?thirdParty       = null,
                                    FilterType?filterType = null,
                                    bool multiple         = false,
                                    string successButton  = null)
        {
            var args = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(ext = (ext ?? "").Trim().ToLower()))
            {
                args.Add(FilterExtParam, ext);
            }
            if (fromEditor)
            {
                args.Add(FromEditorParam, "true");
            }
            if (root.HasValue)
            {
                args.Add(RootParam, root.ToString());
            }
            if (thirdParty.HasValue)
            {
                args.Add(ThirdPartyParam, thirdParty.Value.ToString().ToLower());
            }
            if (filterType.HasValue)
            {
                args.Add(FileTypeParam, filterType.Value.ToString());
            }
            if (multiple)
            {
                args.Add(MultiSelectParam, "true");
            }
            if (!string.IsNullOrEmpty(successButton = (successButton ?? "").Trim()))
            {
                args.Add(SuccessButtonParam, successButton);
            }

            return(Location + "?" + string.Join("&", args.Select(arg => HttpUtility.HtmlEncode(arg.Key) + "=" + HttpUtility.HtmlEncode(arg.Value))));
        }
Exemplo n.º 15
0
        public FilterParameters
        (
            FilterType?type = null,
            float?frequency = null,
            float?oneOverQ  = null
        ) : this()
        {
            if (type is not null)
            {
                Type = type.Value;
            }

            if (frequency is not null)
            {
                Frequency = frequency.Value;
            }

            if (oneOverQ is not null)
            {
                OneOverQ = oneOverQ.Value;
            }
        }
Exemplo n.º 16
0
 internal static string ToSerializedValue(this FilterType?value)
 {
     return(value == null ? null : ((FilterType)value).ToSerializedValue());
 }
Exemplo n.º 17
0
        public ColumnDescriptionTS(ColumnDescription a, object queryName)
        {
            var token = new ColumnToken(a, queryName);

            this.name = a.Name;
            this.type = new TypeReferenceTS(a.Type, a.Implementations);
            this.filterType = QueryUtils.TryGetFilterType(a.Type);
            this.typeColor = token.TypeColor;
            this.niceTypeName = token.NiceTypeName;
            this.isGroupable = token.IsGroupable;
            this.unit = a.Unit;
            this.format = a.Format;
            this.displayName = a.DisplayName;
            this.propertyRoute = token.GetPropertyRoute()?.ToString();
        }
        public override IFilter Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            if (reader.TokenType != JsonTokenType.StartObject)
            {
                throw new JsonException();
            }

            FilterType?    filterType = null;
            bool           and        = false;
            string         path       = null;
            object         value      = null;
            List <IFilter> filters    = null;

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    break;
                }

                if (reader.TokenType != JsonTokenType.PropertyName)
                {
                    continue;
                }

                var propertyName = reader.GetString().ToLower();
                reader.Read();

                switch (propertyName)
                {
                case "path":
                    path = reader.GetString();
                    break;

                case "type":
                    filterType = GetFilterType(ref reader);
                    break;

                case "and":
                    and = reader.GetBoolean();
                    break;

                case "value":
                    value = GetValue(JsonSerializer.Deserialize <JsonElement>(ref reader, options));
                    break;

                case "filters":
                    var elm = JsonSerializer.Deserialize <JsonElement>(ref reader, options);
                    filters = JsonSerializer.Deserialize <List <IFilter> >(elm.GetRawText(), options);
                    break;
                }
            }

            if (filterType == null)
            {
                throw new JsonException("filterType error");
            }

            // ICompositeFilter
            if (filterType == FilterType.Composite)
            {
                var compositeFilter = GetService <ICompositeFilter>();
                compositeFilter.And     = and;
                compositeFilter.Type    = filterType.Value;
                compositeFilter.Filters = filters;
                return(compositeFilter);
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new JsonException("path error");
            }

            // ISimpleFilter
            var simpleFilter = GetService <ISimpleFilter>();

            simpleFilter.And   = and;
            simpleFilter.Type  = filterType.Value;
            simpleFilter.Path  = path;
            simpleFilter.Value = value;
            return(simpleFilter);
        }
Exemplo n.º 19
0
        private static Tuple <FilterType, FilterType?, SecondaryFilterCondition> GetFilterTypes(JsonElement element)
        {
            var        filterType          = FilterType.Unknown;
            FilterType?secondaryFilterType = null;
            var        secondaryConfition  = SecondaryFilterCondition.NotSet;

            var typeProperty = element.GetPropertyString(ReportLayoutDocument.Type);

            if (typeProperty == null)
            {
                return(Tuple.Create <FilterType, FilterType?, SecondaryFilterCondition>
                           (filterType, secondaryFilterType, secondaryConfition));
            }

            if (string.Compare(typeProperty, "Categorical", true) == 0)
            {
                filterType = FilterType.BasicCategorical;
            }
            else if (string.Compare(typeProperty, "TopN", true) == 0)
            {
                filterType = FilterType.TopN;
            }
            else if (string.Compare(typeProperty, "Advanced", true) == 0)
            {
                var whereArray = element.GetChild(ReportLayoutDocument.Filter)
                                 ?.GetChild(ReportLayoutDocument.FilterWhere);

                if (whereArray != null && whereArray.Value.ValueKind == JsonValueKind.Array)
                {
                    var whereEnumerator = whereArray.Value.EnumerateArray();
                    whereEnumerator.MoveNext();

                    var conditionalAnd = whereEnumerator.Current
                                         .GetChild(ReportLayoutDocument.FilterCondition)
                                         ?.GetChild("And");

                    var conditionalOr = whereEnumerator.Current
                                        .GetChild(ReportLayoutDocument.FilterCondition)
                                        ?.GetChild("Or");

                    if (conditionalAnd.HasValue || conditionalOr.HasValue)
                    {
                        var conditionalElement = conditionalAnd ?? conditionalOr;

                        //main
                        var leftCondition = conditionalElement?.GetChild("Left");
                        if (leftCondition.HasValue)
                        {
                            filterType = ReadAdvancedFilterType(leftCondition.Value);
                        }

                        var rightCondition = conditionalElement?.GetChild("Right");
                        if (rightCondition.HasValue)
                        {
                            secondaryFilterType = ReadAdvancedFilterType(rightCondition.Value);
                        }

                        secondaryConfition = conditionalAnd.HasValue
                            ? SecondaryFilterCondition.And
                            : SecondaryFilterCondition.Or;
                    }
                    else
                    {
                        filterType = ReadAdvancedFilterType(whereEnumerator.Current);
                    }
                }
            }

            return(Tuple.Create <FilterType, FilterType?, SecondaryFilterCondition>
                       (filterType, secondaryFilterType, secondaryConfition));
        }
 public IEnumerable <SymbolByFilterMessage> GetSymbolsByFilter(FieldToSearch fieldToSearch, string searchString, FilterType?filterType,
                                                               IEnumerable <int> filterValues, string requestId = null)
 {
     return(GetSymbolsByFilterAsync(fieldToSearch, searchString, filterType, filterValues, requestId)
            .SynchronouslyAwaitTaskResult());
 }
        public Task <IEnumerable <SymbolByFilterMessage> > GetSymbolsByFilterAsync(FieldToSearch fieldToSearch, string searchString, FilterType?filterType, IEnumerable <int> filterValues, string requestId = null)
        {
            var request = _symbolRequestFormatter.ReqSymbolsByFilter(fieldToSearch, searchString, filterType, filterValues, requestId);

            return(string.IsNullOrEmpty(requestId)
                ? GetMessagesAsync(request, _symbolMessageHandler.GetSymbolByFilterMessages)
                : GetMessagesAsync(request, _symbolMessageHandler.GetSymbolByFilterMessagesWithRequestId));
        }
Exemplo n.º 22
0
        public string ReqSymbolsByFilter(FieldToSearch fieldToSearch, string searchString, FilterType?filterType, IEnumerable <int> filterValues, string requestId = null)
        {
            // SBF,[Field To Search],[Search String],[Filter Type],[Filter Value],[RequestID]<CR><LF>
            var fieldToSearchFormat = ((char)fieldToSearch).ToString();
            var filterTypeFormat    = filterType.HasValue ? ((char)filterType).ToString() : string.Empty;
            var filterValuesFormat  = filterType.HasValue ? string.Join(" ", filterValues) : string.Empty;
            var request             = $"SBF,{fieldToSearchFormat},{searchString},{filterTypeFormat},{filterValuesFormat},{requestId}{IQFeedDefault.ProtocolTerminatingCharacters}";

            return(request);
        }