Esempio n. 1
0
        public SqlSelectQuery <T> Take(int rows)
        {
            var clause = new SqlRowFetchNextClause(rows);

            Clauses.Add(clause);
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Add a component clause to the query.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="clause"></param>
        /// <returns></returns>
        public Q Add(string component, AbstractClause clause)
        {
            clause.Component = component;
            Clauses.Add(clause);

            return((Q)this);
        }
Esempio n. 3
0
        private void BuildQuery(string filterName, FilterClauseEnum clause, FilterConditionEnum condition, string filterValue)
        {
            FilterName  = filterName;
            Clause      = clause;
            Condition   = condition;
            FilterValue = filterValue;

            foreach (FilterClauseEnum val in Enum.GetValues(typeof(FilterClauseEnum)))
            {
                var isSelected = val == clause;

                Clauses.Add(new FilterEnumContainer {
                    Name = val.ToString(), Value = (int)val, Selected = isSelected
                });
            }

            foreach (FilterConditionEnum val in Enum.GetValues(typeof(FilterConditionEnum)))
            {
                var isSelected = val == condition;

                Conditions.Add(
                    new FilterEnumContainer {
                    Name = val.ToString(), Value = (int)val, Selected = isSelected
                });
            }
        }
Esempio n. 4
0
        public SqlSelectQuery <T> Skip(int rows)
        {
            var clause = new SqlRowOffsetClause(rows);

            Clauses.Add(clause);
            return(this);
        }
        protected TSpecification Clause(Clause <TEntity> clause)
        {
            Clauses.Add(new ClauseData(CurrentOperator, clause));

            CurrentOperator = Operator.And;
            return(this as TSpecification);
        }
Esempio n. 6
0
        /// <summary>
        /// Create a new selector from DOM elements.
        /// </summary>
        ///
        /// <param name="elements">
        /// A sequence of elements.
        /// </param>

        public Selector(IEnumerable <IDomObject> elements)
        {
            SelectorClause sel = new SelectorClause();

            sel.SelectorType   = SelectorType.Elements;
            sel.SelectElements = elements;
            Clauses.Add(sel);
        }
        protected TSpecification Clause(Expression <Func <TEntity, bool> > clauseData)
        {
            Clauses.Add(new ClauseData(CurrentOperator,
                                       new DirectClause <TEntity>(clauseData)));

            CurrentOperator = Operator.And;
            return(this as TSpecification);
        }
Esempio n. 8
0
        public ConfigurableSwitchSortClauseBuilder <TRequest, TEntity, TValue> ThenBy(string entityProperty)
        {
            var clauseBuilder = ConfigurableSwitchSortClauseBuilder <TRequest, TEntity, TValue>
                                .From(this, entityProperty);

            Clauses.Add(clauseBuilder);

            return(clauseBuilder);
        }
Esempio n. 9
0
 private void AddClause(Clause clause)
 {
     learnedClauses.Add(clause);
     Clauses.Add(clause);
     foreach (var literal in clause)
     {
         ClauseReferences[literal.index].Add(clause);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// SELECT column_name(s)
        /// FROM table_name
        /// ORDER BY column_name[ASC|DESC]
        /// </summary>
        /// <param name="customization"></param>
        /// <returns></returns>
        public OrderByClause OrderBy(Action <Target, Context> customization)
        {
            var clause = new OrderByClause(this);

            Clauses.Add(clause);
            clause.Target.Customize(customization);

            return(clause);
        }
Esempio n. 11
0
 /// <summary>
 /// Ends the current active clause, and creates a new one.
 /// </summary>
 public void CreateNewClause()
 {
     // Create new Group
     if (CurrentClause.Expressions.Count > 0)
     {
         CurrentClause = new WhereClause <SelectWhereStatement>();
         Clauses.Add(CurrentClause);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Create a new selector from a single element.
        /// </summary>
        ///
        /// <param name="element">
        /// The element to test.
        /// </param>

        public Selector(IDomObject element)
        {
            SelectorClause sel = new SelectorClause();

            sel.SelectorType   = SelectorType.Elements;
            sel.SelectElements = new List <IDomObject>();
            ((List <IDomObject>)sel.SelectElements).Add(element);
            Clauses.Add(sel);
        }
Esempio n. 13
0
        public void AddValues(object values)
        {
            var properties = values.GetType().GetProperties();

            Clauses.AddRange(new RawSqlClause("("), new ListSqlClause(properties.Select(p => new RawSqlClause(p.Name))), new RawSqlClause(")"));

            Clauses.Add(new RawSqlClause("VALUES"));

            Clauses.AddRange(new RawSqlClause("("), new ListSqlClause(properties.Select(p => new ParameterSqlClause(p.GetValue(values)))), new RawSqlClause(")"));
        }
Esempio n. 14
0
        public ConfigurableSwitchSortClauseBuilder <TRequest, TEntity, TValue> ThenBy <TProp>(
            Expression <Func <TEntity, TProp> > entityProperty)
        {
            var clauseBuilder = ConfigurableSwitchSortClauseBuilder <TRequest, TEntity, TValue>
                                .From(this, entityProperty);

            Clauses.Add(clauseBuilder);

            return(clauseBuilder);
        }
Esempio n. 15
0
        public SqlSelectQuery <T> Where(Expression <Func <T, bool> > predicate)
        {
            if (predicate == null)
            {
                return(this);
            }
            var clause = new SqlWhereClause(predicate);

            Clauses.Add(clause);
            return(this);
        }
Esempio n. 16
0
        public SqlSelectQuery <T> OrderBy(Expression <Func <T, object> > columns)
        {
            if (columns == null)
            {
                return(this);
            }
            var clause = new SqlOrderByClause(columns);

            Clauses.Add(clause);
            return(this);
        }
Esempio n. 17
0
        public void Init(string tell)

        /* This is the agents set up. It sets up:
        * - the list of all symbols
        * - all the clauses for the knowledge base
        * - the facts about the world          */
        {
            string[] sentances = tell.Split(';');
            for (int i = 0; i < sentances.Length - 1; i++)
            {
                if (!sentances[i].Contains("=>"))                  // Checks to see if its a fact. eg b;
                {
                    if (!Agenda.Contains(sentances[i]))            // If the symbol is not already in the Symbols list
                    {
                        Agenda.Add(sentances[i]);                  // Adds this symbol to the symbols list
                    }
                    if (!Facts.Contains(sentances[i]))             // Checks if Facts already contains the symbol
                    {
                        Facts.Add(sentances[i]);                   // Adds the symbol to the list of symbols that are true
                    }
                }
                else
                {
                    // If it gets here; the current string is a Clause
                    Clauses.Add(sentances[i]);
                    string[] splitImp = sentances[i].Split("=>");   // Splits clause into pre-implication and post-implecation
                    if (!splitImp[0].Contains("&"))                 // if pre-implecation does not have &
                    {
                        for (int j = 0; j < splitImp.Length; j++)   // loop through clause
                        {
                            if (!Agenda.Contains(splitImp[j]))      // if agenda doesnt contain the symbol
                            {
                                Agenda.Add(splitImp[j]);            // add symbols
                            }
                        }
                    }
                    else
                    {                                                      // Pre-imp contains &
                        string[] splitLogic = splitImp[0].Split("&");      // split by logical separators
                        for (int j = 0; j < splitLogic.Length; j++)        // loop through strings split
                        {
                            if (!Agenda.Contains(splitLogic[j]))
                            {
                                Agenda.Add(splitLogic[j]);                    // add symbols to symbols base
                            }
                            if (!Agenda.Contains(splitImp[1]))
                            {
                                Agenda.Add(splitImp[1]);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        public SqlSelectQuery <T> Having(Expression <Func <T, object> > predicate)
        {
            if (predicate == null)
            {
                return(this);
            }
            var clause = new SqlHavingClause(predicate);

            Clauses.Add(clause);
            return(this);
        }
Esempio n. 19
0
        /// <summary>
        /// Adds the clause is active between dates.
        /// </summary>
        /// <param name="logicOperator">The logic operator.</param>
        /// <param name="startColumn">The start column.</param>
        /// <param name="endColumn">The end column.</param>
        /// <param name="date">The date.</param>
        public void AddClauseIsActiveBetweenDates(LogicOperator logicOperator, string startColumn, string endColumn, DateTime date)
        {
            var whereClause = new WhereClause(logicOperator, startColumn, Comparison.Equals, null);

            whereClause.AddClause(Enums.LogicOperator.Or, startColumn, Comparison.LessOrEquals, date.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture));
            Clauses.Add(whereClause);

            whereClause = new WhereClause(logicOperator, endColumn, Comparison.Equals, null);
            whereClause.AddClause(Enums.LogicOperator.Or, endColumn, Comparison.GreaterOrEquals, date.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture));
            Clauses.Add(whereClause);
        }
Esempio n. 20
0
        /// <summary>
        /// Adds a clause to this selector.
        /// </summary>
        ///
        /// <param name="clause">
        /// The clause to insert.
        /// </param>

        public void Add(SelectorClause clause)
        {
            // TODO: We'd like to prevent duplicate clauses, but in order to do so, they need to be combined into
            // complete selectors (e.g. sets bounded by CombinatorType.Root). That really should be the definition of a
            // selector, e.g. each part separated by a comma

            //if (clause.CombinatorType == CombinatorType.Root && Clauses.Contains(clause))
            //{
            //    return;
            //}
            Clauses.Add(clause);
        }
Esempio n. 21
0
        public SqlSelectQuery <T> OrderBy(string columns)
        {
            if (columns == null)
            {
                return(this);
            }
            var exp    = Expression.Constant(columns);
            var clause = new SqlOrderByClause(exp);

            Clauses.Add(clause);
            return(this);
        }
Esempio n. 22
0
        public SqlSelectQuery <T> Select(string columns, string from)
        {
            //_selectClauseTable = from;
            if (string.IsNullOrWhiteSpace(columns))
            {
                columns = "*";
            }
            var exp = Expression.Constant(columns);

            Clauses.Add(new SqlSelectClause <T>(exp, from));
            return(this);
        }
Esempio n. 23
0
        public SqlSelectQuery <T> Where(string predicate)
        {
            if (predicate == null)
            {
                return(this);
            }
            var exp    = Expression.Constant(predicate);
            var clause = new SqlWhereClause(exp as Expression);

            Clauses.Add(clause);
            return(this);
        }
Esempio n. 24
0
 /// <summary>
 /// Adds a `Clause` to this query.
 /// Unless the clause contains the fields to be matched all fields will be matched.
 /// In addition, a default boost of 1 is applied to the clause.
 /// </summary>
 /// <param name="clause">The clause to add to this query.</param>
 /// <returns>The query.</returns>
 public Query AddClause(Clause clause)
 {
     if (!clause.Fields.Any())
     {
         Clauses.Add(clause.WithFields(AllFields));
     }
     else
     {
         Clauses.Add(clause);
     }
     return(this);
 }
Esempio n. 25
0
 public void CopyFromAll(QueryBuilderClause from, CMSDataContext Db)
 {
     foreach (var c in Clauses)
     {
         DeleteClause(c, Db);
     }
     CopyFrom(from);
     foreach (var c in from.Clauses)
     {
         Clauses.Add(c.Clone(Db));
     }
 }
        public CalculatedImmediateTmsOperand(List <object> sourceClauses, bool shiftLeft)
        {
            Clauses = sourceClauses.ToList();
            if (shiftLeft)
            {
                Clauses.Add(Z80AssemblyParsing.Operands.MathOperator.TIMES);
                Clauses.Add((ushort)0x100);
            }

            var sb = new StringBuilder();

            Clauses.ForEach(clause => sb.Append(GetString(clause)));
            DisplayValue = sb.ToString();
        }
        private void Initialize(string sqlText)
        {
            string curClause      = string.Empty;
            int    curClauseIndex = 0;

            for (int i = 0; i < sqlText.Length;)
            {
                //Find new Sql clause
                int    maxLenToSearch = sqlText.Length - i >= 10 ? 10 : sqlText.Length - i;
                string keyword        = StartsWithString(sqlText.Substring(i, maxLenToSearch), keywords, StringComparison.OrdinalIgnoreCase);
                bool   isWordStart    = i > 0 ? sqlText[i - 1] == ' ' || (i > 1 && sqlText.Substring(i - 2, 2) == "\r\n") : true;
                //Process Sql clause
                if (keyword != null && curClause != keyword && isWordStart)
                {
                    string inputText = sqlText.Substring(curClauseIndex, i - curClauseIndex);
                    if (!string.IsNullOrEmpty(curClause))
                    {
                        if (curClause == "DECLARE")
                        {
                            var       declareParts   = inputText.Substring(0, inputText.IndexOf(";")).Trim().Split(" ");
                            int       sizeStartIndex = declareParts[1].IndexOf("(");
                            string    dbTypeString   = sizeStartIndex != -1 ? declareParts[1].Substring(0, sizeStartIndex) : declareParts[1];
                            SqlDbType dbType         = (SqlDbType)Enum.Parse(typeof(SqlDbType), dbTypeString, true);
                            int       size           = sizeStartIndex != -1 ?
                                                       Convert.ToInt32(declareParts[1].Substring(sizeStartIndex).Replace(")", "")) : 0;
                            string value = declareParts[3][0] == '\'' ? declareParts[3].Substring(1, declareParts[3].Length - 2) : declareParts[3];
                            Parameters.Add(new SqlParameter(declareParts[0], dbType, size)
                            {
                                Value = value
                            });
                        }
                        else
                        {
                            Clauses.Add(SqlClause.Parse(curClause, inputText));
                        }
                    }
                    curClause      = keyword;
                    curClauseIndex = i + curClause.Length;
                    i = i + curClause.Length;
                }
                else
                {
                    i++;
                }
            }
            if (!string.IsNullOrEmpty(curClause))
            {
                Clauses.Add(SqlClause.Parse(curClause, sqlText.Substring(curClauseIndex)));
            }
        }
Esempio n. 28
0
        private void SetStatement(SqlStatement value)
        {
            if (!Clauses.Any())
            {
                Clauses.Add(value);
            }

            if (Clauses[0] is SqlStatement)
            {
                Clauses[0] = value;
            }
            else
            {
                Clauses.Insert(0, value);
            }
        }
Esempio n. 29
0
 // method which sets up initial values for forward chaining
 // takes in string representing KB and seperates symbols and
 // clauses, calculates count etc ...
 public void Init(string tell)
 {
     string[] sentances = tell.Split(';');
     for (int i = 0; i < sentances.Length; i++)
     {
         if (!sentances[i].Contains("=>"))
         {
             Agenda.Add(sentances[i]);
         }
         else
         {
             // add sentances
             Clauses.Add(sentances[i]);
             Count.Add(sentances[i].Split('&').Length);
         }
     }
 }
Esempio n. 30
0
        public override void BuildKB(string tell)
        {
            // Split tell into list of strings
            List <string> sentences = tell.Split(';').ToList();

            for (int i = 0; i < sentences.Count; i++)
            {
                //Look for Inference
                if (sentences[i].Contains("=>"))
                {
                    //If true, add to clause and count the conjuctions (A&B or Z)
                    Clauses.Add(sentences[i].ToLower());
                    Count.Add(sentences[i].Split('&').Length);
                }
                else if (!sentences[i].Trim().Equals(""))  //If false and not empty, add to agenda
                {
                    Agenda.Add(sentences[i].ToLower());
                    SingleStatement.Add(sentences[i].ToLower());
                }
            }

            //add every symbol into the agenda including the deuplicated
            //the deuplication will be remove in the next step

            for (int i = 0; i < Clauses.Count; i++)
            {
                string statement = Clauses[i];
                string aftermise = Regex.Split(statement, "=>")[1];
                AllSymbolBeenIndicated.Add(aftermise);
                //Console.WriteLine(aftermise);
                statement = statement.Replace("=>", " ").Replace("&", " ");
                string[] temp = statement.Split(' ');
                for (int j = 0; j < temp.Length; j++)
                {
                    if (!Agenda.Contains(temp[j])) //Check for Duplicates
                    {
                        Agenda.Add(temp[j]);
                    }
                }
            }

            BuildTheModels();
        }