Ejemplo n.º 1
0
        // ---------[ FILTER CONTROL ]---------
        /// <summary>Sets the title filter and refreshes the view.</summary>
        public void SetNameFieldFilter(string nameFilter)
        {
            EqualToFilter <string> oldFilter = this.nameFieldFilter;

            // null-checks
            if (nameFilter == null)
            {
                nameFilter = string.Empty;
            }

            string oldFilterValue = string.Empty;

            if (oldFilter != null &&
                oldFilter.filterValue != null)
            {
                oldFilterValue = oldFilter.filterValue;
            }

            // apply filter
            if (oldFilterValue.ToUpper() != nameFilter.ToUpper())
            {
                // set
                EqualToFilter <string> newFieldFilter = null;
                if (!string.IsNullOrEmpty(nameFilter))
                {
                    newFieldFilter = new EqualToFilter <string>()
                    {
                        filterValue = nameFilter,
                    };
                }

                this.SetFieldFilters(ModIO.API.GetAllModsFilterFields.fullTextSearch,
                                     newFieldFilter);
            }
        }
Ejemplo n.º 2
0
        private static void BuildRefrenceCode(SelectBuilder select, FapColumn column, AliasedSource table, string refAlias)
        {
            string colName = column.RefCode;

            if (colName.IsPresent())
            {
                colName = "Id";
            }
            SelectBuilder inner      = new SelectBuilder();
            AliasedSource innerTable = inner.AddTable(new Table($"{column.RefTable}"), refAlias);

            inner.AddProjection(innerTable.Column($"{colName}"));
            if (column.MultiAble == 1) //是否多选
            {
            }
            FilterGroup joinFilter = new FilterGroup(Conjunction.And,
                                                     new EqualToFilter(innerTable.Column($"{column.RefID}"), table.Column(column.ColName)),
                                                     new LessThanEqualToFilter(innerTable.Column(FapDbConstants.FAPCOLUMN_FIELD_EnableDate), new ParameterLiteral(FapDbConstants.FAPCOLUMN_PARAM_CurrentDate)),
                                                     new GreaterThanEqualToFilter(innerTable.Column(FapDbConstants.FAPCOLUMN_FIELD_DisableDate), new ParameterLiteral(FapDbConstants.FAPCOLUMN_PARAM_CurrentDate)),
                                                     new EqualToFilter(innerTable.Column(FapDbConstants.FAPCOLUMN_FIELD_Dr), new ParameterLiteral(FapDbConstants.FAPCOLUMN_PARAM_Dr)));

            if (column.RefTable.EqualsWithIgnoreCase(nameof(FapColumn)))
            {
                IFilter filter = new EqualToFilter(innerTable.Column("TableName"), table.Column("TableName"));
                joinFilter.AddFilter(filter);
            }
            inner.AddWhere(joinFilter);
            select.AddProjection(inner, $"{column.ColName}MCID");
        }
        protected override void VisitEqualToFilter(EqualToFilter item)
        {
            if (this.Mode == VisitMode.Filter)
            {
                VisitOrderFilter(item);
            }
            else if (Mode == VisitMode.From)
            {
                EqualToFilter = item;

                //TODO: Tidy this up use more of visitor pattern?
                LeftColumn  = item.LeftHand as Column;
                RightColumn = item.RightHand as Column;
                // GuardOnColumn(leftColumn);
                //  GuardOnColumn(rightColumn);

                LeftTable  = LeftColumn.Source.Source as Table;
                RightTable = RightColumn.Source.Source as Table;
                //  LeftEntityName =

                //   LinkEntity.LinkFromEntityName = LeftTable.GetTableLogicalEntityName();
                //   LinkEntity.LinkToEntityName = RightTable.GetTableLogicalEntityName();
                //   LinkEntity.LinkFromAttributeName = LeftColumn.GetColumnLogicalAttributeName();
                //   LinkEntity.LinkToAttributeName = RightColumn.GetColumnLogicalAttributeName();
            }
        }
Ejemplo n.º 4
0
 protected override void VisitEqualToFilter(EqualToFilter item)
 {
     EqualToFilter          = item;
     CurrentWhereFilterPart = WhereFilterPart.LeftHand;
     item.LeftHand.Accept(this);
     CurrentWhereFilterPart = WhereFilterPart.RightHand;
     item.RightHand.Accept(this);
 }
 protected override void VisitEqualToFilter(EqualToFilter item)
 {
     EqualToFilter        = item;
     IsVisitingFilterItem = true;
     item.LeftHand.Accept(this);
     IsVisitingRightFilterItem = true;
     item.RightHand.Accept(this);
     IsVisitingRightFilterItem = false;
     IsVisitingFilterItem      = false;
 }
Ejemplo n.º 6
0
        /// <summary>Gets the title filter string.</summary>
        public string GetTitleFilter()
        {
            EqualToFilter <string> filter = this.nameFieldFilter;

            if (filter == null)
            {
                return(null);
            }
            else
            {
                return(filter.filterValue);
            }
        }
Ejemplo n.º 7
0
        // ---------[ FILTER CONTROL ]---------
        /// <summary>Sets the title filter and refreshes the view.</summary>
        public void SetNameFieldFilter(string nameFilter)
        {
            EqualToFilter <string> oldFilter = this.nameFieldFilter;

            // null-checks
            if (nameFilter == null)
            {
                nameFilter = string.Empty;
            }

            string oldFilterValue = string.Empty;

            if (oldFilter != null &&
                oldFilter.filterValue != null)
            {
                oldFilterValue = oldFilter.filterValue;
            }

            // apply filter
            if (oldFilterValue.ToUpper() != nameFilter.ToUpper())
            {
                // set
                if (String.IsNullOrEmpty(nameFilter))
                {
                    this.nameFieldFilter = null;
                }
                else
                {
                    EqualToFilter <string> newFieldFilter = new EqualToFilter <string>()
                    {
                        filterValue = nameFilter,
                    };
                    this.nameFieldFilter = newFieldFilter;
                }

                // refresh
                if (this.isActiveAndEnabled)
                {
                    this.Refresh();
                }

                // notify
                if (this.onRequestFilterChanged != null)
                {
                    this.onRequestFilterChanged.Invoke(this.m_requestFilter);
                }
            }
        }
Ejemplo n.º 8
0
            private IFilter CreateFilter(OperatorType operators, string propertyName, string propertyValue)
            {
                IFilter filter = null;

                switch (operators)
                {
                case OperatorType.eq:
                    filter = new EqualToFilter(propertyName, propertyValue);
                    break;

                case OperatorType.ne:
                    filter = new NotEqualToFilter(propertyName, propertyValue);
                    break;

                case OperatorType.startswith:
                    filter = new StartsWithFilter(propertyName, propertyValue);
                    break;

                case OperatorType.endswith:
                    filter = new EndsWithFilter(propertyName, propertyValue);
                    break;

                case OperatorType.substringof:
                    filter = new SubstringFilter(propertyName, propertyValue);
                    break;

                    /* currently not supported
                     * case OperatorType.lt:
                     *  filter = new LessThanFilter(propertyName, propertyValue);
                     *  break;
                     * case OperatorType.le:
                     *  filter = new LessThanOrEqualFilter(propertyName, propertyValue);
                     *  break;
                     * case OperatorType.gt:
                     *  filter = new GreaterThanFilter(propertyName, propertyValue);
                     *  break;
                     * case OperatorType.ge:
                     *  filter = new GreaterThanOrEqualFilter(propertyName, propertyValue);
                     *  break;
                     */
                }

                return(filter);
            }
Ejemplo n.º 9
0
        private static void BuildRefrenceName(SelectBuilder select, FapColumn column, AliasedSource table, string refAlias)
        {
            SelectBuilder inner      = new SelectBuilder();
            AliasedSource innerTable = inner.AddTable(new Table($"{column.RefTable}"), refAlias);

            inner.AddProjection(innerTable.Column($"{column.RefName}"));

            FilterGroup joinFilter = new FilterGroup(Conjunction.And,
                                                     new EqualToFilter(innerTable.Column($"{column.RefID}"), table.Column(column.ColName)),
                                                     new LessThanEqualToFilter(innerTable.Column(FapDbConstants.FAPCOLUMN_FIELD_EnableDate), new ParameterLiteral(FapDbConstants.FAPCOLUMN_PARAM_CurrentDate)),
                                                     new GreaterThanEqualToFilter(innerTable.Column(FapDbConstants.FAPCOLUMN_FIELD_DisableDate), new ParameterLiteral(FapDbConstants.FAPCOLUMN_PARAM_CurrentDate)),
                                                     new EqualToFilter(innerTable.Column(FapDbConstants.FAPCOLUMN_FIELD_Dr), new ParameterLiteral(FapDbConstants.FAPCOLUMN_PARAM_Dr)));

            if (column.RefTable.EqualsWithIgnoreCase(nameof(FapColumn)))
            {
                //fapcolumn存在重复colName,加一个去重
                IFilter filter = new EqualToFilter(innerTable.Column("TableName"), table.Column("RefTable"));
                joinFilter.AddFilter(filter);
            }
            inner.AddWhere(joinFilter);
            select.AddProjection(inner, $"{column.ColName}MC");
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Generates the text for an EqualToFilter builder.
 /// </summary>
 /// <param name="item">The EqualToFilter builder to generate the text for.</param>
 protected internal override void VisitEqualToFilter(EqualToFilter item)
 {
     visitOrderedFilter(item, "=");
 }
Ejemplo n.º 11
0
        IContentExpression ParseExpression(Queue <DslToken> q, Func <DslToken, bool> terminate)
        {
            IContentExpression exp = null;

            while (q.Count > 0)
            {
                var lookAhead = q.Peek();

                if (terminate(lookAhead))
                {
                    break;
                }

                else if (lookAhead.IsConstant())
                {
                    if (exp != null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    var token = q.DequeueAndValidate(Utils.ConstantTokens);
                    exp = CreateConstant(token);
                }

                else if (lookAhead.TokenType == TokenType.Equals)
                {
                    if (exp == null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    var token = q.DequeueAndValidate(TokenType.Equals);
                    exp = new EqualToFilter(exp,
                                            ParseExpression(q, t => t.TokenType == TokenType.And || t.TokenType == TokenType.Or || terminate(t)));
                }

                else if (lookAhead.TokenType == TokenType.Contains)
                {
                    if (exp == null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    var token = q.DequeueAndValidate(TokenType.Contains);
                    exp = new ContainsFilter(exp,
                                             ParseExpression(q, t => t.TokenType == TokenType.And || t.TokenType == TokenType.Or || terminate(t)));
                }

                else if (lookAhead.TokenType == TokenType.MatchRegex)
                {
                    if (exp == null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    var token   = q.DequeueAndValidate(TokenType.MatchRegex);
                    var pattern = q.DequeueAndValidate(TokenType.String);
                    exp = new RegexFilter(exp, pattern.Value);
                }

                else if (lookAhead.TokenType == TokenType.And)
                {
                    if (exp == null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    var token = q.DequeueAndValidate(TokenType.And);
                    if (exp is IContentFilter leftBool)
                    {
                        var right = ParseExpression(q, terminate);
                        if (right is IContentFilter rightBool)
                        {
                            exp = new AndFilter(leftBool, rightBool);
                        }
                        else
                        {
                            throw new ParserException("AND cannot have a right operand that does not yield boolean", token);
                        }
                    }
                    else
                    {
                        throw new ParserException("AND cannot have a left operand that does not yield boolean", token);
                    }
                }

                else if (lookAhead.TokenType == TokenType.Or)
                {
                    if (exp == null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    var token = q.DequeueAndValidate(TokenType.Or);
                    if (exp is IContentFilter leftBool)
                    {
                        var right = ParseExpression(q, terminate);
                        if (right is IContentFilter rightBool)
                        {
                            exp = new OrFilter(leftBool, rightBool);
                        }
                        else
                        {
                            throw new ParserException("OR cannot have a right operand that does not yield boolean", token);
                        }
                    }
                    else
                    {
                        throw new ParserException("OR cannot have a left operand that does not yield boolean", token);
                    }
                }

                else if (lookAhead.TokenType == TokenType.Path)
                {
                    if (exp == null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    var token = q.DequeueAndValidate(TokenType.Path);
                    exp = new PathExpression(exp, ContentPath.Parse($"$.{token.Value.TrimStart('.')}"));
                }

                else if (lookAhead.TokenType == TokenType.DollarSign)
                {
                    if (exp != null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    q.DequeueAndValidate(TokenType.DollarSign);
                    exp = new ScopeRootExpression();
                }

                else if (lookAhead.TokenType == TokenType.OpenCurly)
                {
                    if (exp != null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    exp = CreateObjectExpression(q);
                }

                else if (lookAhead.TokenType == TokenType.OpenSquareBracket)
                {
                    if (exp != null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    exp = CreateListExpression(q);
                }

                else if (lookAhead.TokenType == TokenType.OpenBracket)
                {
                    if (exp != null)
                    {
                        throw new ParserException($"Unexpected token", lookAhead);
                    }
                    q.DequeueAndValidate(TokenType.OpenBracket);  // open bracket (
                    exp = ParseExpression(q, t => t.TokenType == TokenType.CloseBracket);
                    q.DequeueAndValidate(TokenType.CloseBracket); // close bracket )
                }
                else
                {
                    throw new ParserException($"Unexpected token", lookAhead);
                }
            }

            if (exp == null)
            {
                throw new ParserException($"Unexpected end", null);
            }

            return(exp);
        }
Ejemplo n.º 12
0
        public void EqualToFilter()
        {
            var filter = new EqualToFilter("Name", "ShareFile");

            filter.ToString().Should().Be("Name eq 'ShareFile'");
        }