Esempio n. 1
0
        public void inserting_sould_work_properly()
        {
            QList <Person> list = new QList <Person>();

            Int32 count = 100;

            for (var i = 0; i < count; i++)
            {
                list.Add(PersonHelper.CreateTestPerson());
            }

            Person firstPerson = PersonHelper.CreateTestPerson();

            list.Insert(0, firstPerson);

            Person lastPerson = PersonHelper.CreateTestPerson();

            list.Insert(list.Count, lastPerson);

            Person middlePerson = PersonHelper.CreateTestPerson();

            list.Insert(50, middlePerson);

            Assert.IsTrue(list.IndexOf(firstPerson) >= 0);
            Assert.IsTrue(list.IndexOf(lastPerson) >= 0);
            Assert.IsTrue(list.IndexOf(middlePerson) >= 0);
            Assert.AreEqual(count + 3, list.Items.Count());
        }
Esempio n. 2
0
        public void adding_few_item_sould_work_properly()
        {
            QList <Person> list    = new QList <Person>();
            Person         person1 = PersonHelper.CreateTestPerson();
            Person         person2 = PersonHelper.CreateTestPerson();
            Person         person3 = PersonHelper.CreateTestPerson();
            Person         person4 = PersonHelper.CreateTestPerson();
            Person         person5 = PersonHelper.CreateTestPerson();

            list.Add(person1);
            list.Add(person2);
            list.Add(person3);
            list.Add(person4);
            list.Add(person5);

            Assert.AreEqual(5, list.Count);
            Assert.AreEqual(person1, list[0]);
            Assert.AreEqual(person1, list.FirstOrDefault());


            Assert.AreEqual(person2, list[1]);
            Assert.AreEqual(person3, list[2]);
            Assert.AreEqual(person4, list[3]);

            Assert.AreEqual(person5, list[4]);
            Assert.AreEqual(person5, list.LastOrDefault());
        }
Esempio n. 3
0
        void RankTablesByAffinity(string affinityTableName, int ct, double weight)
        {
            QList <string> top  = GetTop(affinityTableName, ct);
            int            rank = ct;

            foreach (string t in top.Each())
            {
                tables[t].importance += T.Normalize(rank--, 0, ct, weight);
            }
        }
Esempio n. 4
0
        public void adding_one_item_sould_work_properly()
        {
            QList <Person> list      = new QList <Person>();
            Person         newPerson = PersonHelper.CreateTestPerson();

            list.Add(newPerson);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(newPerson, list[0]);
            Assert.AreEqual(newPerson, list.FirstOrDefault());
        }
Esempio n. 5
0
        QList <string> GetTop(string table, int ct)
        {
            QList <string> list = new QList <string>(QListSort.Descending);

            foreach (DbTable t in tables.Values)
            {
                list.Add(t.objectName, t.affinities.Get(table));
            }
            LogTop(table, list, ct);
            return(list);
        }
Esempio n. 6
0
        public void AddAllColumnsInQuery()
        {
            QList <Column> list = new QList <Column>(QListSort.Descending);

            foreach (Column c in Query.rootQuery.allColumns.tokens)
            {
                list.Add(c, c.significance);
            }
            foreach (Column c in list.Each())
            {
                AddColumn(c);
            }
        }
Esempio n. 7
0
        public string GetTableNameForTableAlias(string alias)
        {
            QList <Column> list = new QList <Column>(QListSort.Descending);

            foreach (Column c in tokens)
            {
                if (alias == c.columnAlias)
                {
                    list.Add(c, c.significance);
                }
            }

            return(list.Count > 0 ? list[0].tableName : null);
        }
Esempio n. 8
0
        public static void LogTop(string table, QList <string> list, int ct)
        {
            Log("top " + table);

            int i = 0;

            foreach (string t in list.Each())
            {
                Log(" " + t + " " + list.GetPosition(t));
                i++;
                if (i >= ct)
                {
                    break;
                }
            }
        }
Esempio n. 9
0
        public async Task <IEnumerable <Pos> > List(int CompanyId)
        {
            IEnumerable <Pos> list;
            IQueryable <Pos>  QList;
            IQueryable <Pos>  QResult;

            try
            {
                QList   = _dbContex.Pos.AsQueryable();
                QResult = QList.Where(x => x.CompanyId == CompanyId);
                return(await QResult.ToListAsync());
            }
            catch (Exception e)
            {
                throw;
            }
        }
Esempio n. 10
0
        public virtual void AnalyzeSummarize()
        {
            if (analyzeTableColumnAffinities)
            {
                foreach (DbTable t in tables.Values)
                {
                    t.FindAffinities();
                    t.AnalyzeAffinities();
                }
            }

            if (rankTables)
            {
                QDict <string, DbTable> rankList = new QDict <string, DbTable>(QListSort.Descending);

                QList <string> list = new QList <string>(QListSort.Descending);
                foreach (DbTable t in tables.Values)
                {
                    rankList.Add(t.name, t);
                    t.affinities.Add("rowCount", t.rowCount);
                    if (t.references.Count > 0)
                    {
                        t.affinities.Add("references", t.references.Count);
                    }
                }

                RankTablesByAffinity("references", 5, 7);
                RankTablesByAffinity("important", 5, 3);
                RankTablesByAffinity("descriptive", 5, 3);
                RankTablesByAffinity("label", 5, 3);
                //RankTablesByAffinity("quantity", 5, 2);
                RankTablesByAffinity("rowCount", 5, 2);
                foreach (DbTable t in tables.Values)
                {
                    rankList.SetPosition(t.objectName, Convert.ToInt32(1000 * t.importance));
                }

                Log("table rank");
                foreach (string nam in rankList.Keys)
                {
                    Log(" " + nam);
                }
            }
        }
Esempio n. 11
0
 public void addQueueVariable(int queue, double tcurr)
 {
     QList.Add(queue);
     QInterval.Add(tcurr - lastQMove);
     lastQMove = tcurr;
 }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var    count  = 10000;
            object tmpObj = null;

            var items_to_add = new List <Person>();

            for (var i = 0; i < count; i++)
            {
                items_to_add.Add(PersonHelper.CreateTestPerson());
            }

            var list1 = new List <Person>(count);
            var list2 = new QList <Person>();

            Stopwatch st_create_1 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                list1.Add(item);
            }
            st_create_1.Stop();


            Stopwatch st_create_2 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                list2.Add(item);
            }
            st_create_2.Stop();


            Stopwatch st_read_1 = Stopwatch.StartNew();

            for (var i = 0; i < count; i++)
            {
                tmpObj = list1[i];
            }
            st_read_1.Stop();


            Stopwatch st_read_2 = Stopwatch.StartNew();

            for (var i = 0; i < count; i++)
            {
                tmpObj = list2[i];
            }
            st_read_2.Stop();


            Stopwatch st_enumerator_1 = Stopwatch.StartNew();

            foreach (var item in list1)
            {
                tmpObj = item;
            }
            st_enumerator_1.Stop();


            Stopwatch st_enumerator_2 = Stopwatch.StartNew();

            foreach (var item in list2)
            {
                tmpObj = item;
            }
            st_enumerator_2.Stop();


            Stopwatch st_indexof_1 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list1.IndexOf(item);
            }
            st_indexof_1.Stop();


            Stopwatch st_indexof_2 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list2.IndexOf(item);
            }
            st_indexof_2.Stop();



            Stopwatch st_Contains_1 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list1.Contains(item);
            }
            st_Contains_1.Stop();


            Stopwatch st_Contains_2 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list2.Contains(item);
            }
            st_Contains_2.Stop();



            var rand            = new Random(DateTime.Now.Millisecond);
            var items_to_remove = items_to_add.OrderBy(i => rand.Next(0, count)).ToList();

            Stopwatch st_remove_1 = Stopwatch.StartNew();

            foreach (var item in items_to_remove)
            {
                list1.Remove(item);
            }
            st_remove_1.Stop();


            Stopwatch st_remove_2 = Stopwatch.StartNew();

            foreach (var item in items_to_remove)
            {
                list2.Remove(item);
            }
            st_remove_2.Stop();

            list2.Clear();
            foreach (var item in items_to_add)
            {
                list2.Add(item);
            }

            list1.Clear();
            foreach (var item in items_to_add)
            {
                list1.Add(item);
            }


            Stopwatch st_remove2_1 = Stopwatch.StartNew();

            for (var i = count - 1; i >= 0; i--)
            {
                list1.RemoveAt(i);
            }
            st_remove2_1.Stop();


            Stopwatch st_remove2_2 = Stopwatch.StartNew();

            for (var i = count - 1; i >= 0; i--)
            {
                list2.RemoveAt(i);
            }
            st_remove2_2.Stop();



            var index = 0;

            foreach (var item2 in list2)
            {
                var item1 = list1[index];

                if (item1 != item2 || list1.Count != list2.Count)
                {
                    throw new NotImplementedException();
                }

                index++;
            }

            var c = 4;

            Console.WriteLine($"         |  Insert  |  Delete  |    Read  |  IndexOf  |  RemoveAt  |  Contains   |  Enumerator ");
            Console.WriteLine($" List<>  |  {format(st_create_1.ElapsedMilliseconds, c)}ms  |  {format(st_remove_1.ElapsedMilliseconds, c)}ms  |  {format(st_read_1.ElapsedMilliseconds, c)}ms  |   {format(st_indexof_1.ElapsedMilliseconds, c)}ms  |    {format(st_remove2_1.ElapsedMilliseconds, c)}ms  |  {format(st_Contains_1.ElapsedMilliseconds, c)}ms  |  {format(st_enumerator_1.ElapsedMilliseconds, c)}ms");
            Console.WriteLine($"QList<>  |  {format(st_create_2.ElapsedMilliseconds, c)}ms  |  {format(st_remove_2.ElapsedMilliseconds, c)}ms  |  {format(st_read_2.ElapsedMilliseconds, c)}ms  |   {format(st_indexof_2.ElapsedMilliseconds, c)}ms  |    {format(st_remove2_2.ElapsedMilliseconds, c)}ms  |  {format(st_Contains_2.ElapsedMilliseconds, c)}ms  |  {format(st_enumerator_2.ElapsedMilliseconds, c)}ms");
            Console.ReadKey();
        }
Esempio n. 13
0
 protected QList <Client> clients;//All connected clients
 public Server()
 {
     clients = new QList <Client>();
 }
Esempio n. 14
0
        public override void GetSuggestions(SuggestionList s)
        {
            if (parentQuery.select == null)
            {
                return;
            }

            SuggestionContext sc = s.suggestionContext;

            Table rightTable = null;
            Table leftTable  = null;

            if (sc.last == null)
            {
                sc.suggestTables = true;
            }
            else
            {
                rightTable = sc.lastTable.token != null ? sc.lastTable.token as Table : null;
                leftTable  = rightTable == null ? null : sc.tokens.GetNearestTokenBefore(rightTable, TokenType.Table) as Table;

                if (rightTable == null)
                {
                    sc.suggestTables = true;
                }
                else if (sc.last.type.IsOneOf("conjunction"))
                {
                    sc.suggestColumns = true;
                }
                else if (sc.last.type == "operator")
                {
                    sc.suggestColumns = true;
                    if (sc.lastColumn.token != null)
                    {
                        Column c = sc.lastColumn.token as Column;
                        sc.suggestColumnsDataType = c.dbColumn.dataType;
                    }
                }
                else if (sc.last.type.IsOneOf("identifier", "column", "literal"))
                {
                    sc.suggestOperators       = sc.lastOperator.pos < sc.lastConjunction.pos;
                    sc.suggestPrimaryKeywords = sc.suggestConjunctions = sc.lastOperator.pos == 0 || sc.lastOperator.pos > sc.lastConjunction.pos;
                    sc.suggestJoin            = sc.lastOperator.pos > sc.lastKeyword.pos;
                }
                else if (sc.last.type == "table")
                {
                    sc.suggestPrimaryKeywords = (sc.lastKeyword.isJoin == false);
                    if (sc.last.hasComma)
                    {
                        sc.suggestTables = true;
                    }
                    else
                    {
                        sc.suggestAlias          = true;
                        sc.suggestJoin           = sc.lastKeyword.isJoin == false;
                        sc.suggestJoinExpression = sc.suggestOn = !sc.suggestJoin;
                    }
                }
                else if (sc.last.isOn)
                {
                    sc.suggestColumns        = true;
                    sc.suggestJoinExpression = true;
                }
                else if (sc.last.isJoin)
                {
                    sc.suggestTables = true;
                }
            }

            if (sc.suggestJoinExpression && s.enableSuggestJoins && rightTable != null && leftTable != null)
            {
                string join = leftTable.dbTable.RenderJoinCols(rightTable.name, s.includeAliases);
                if (join != null)
                {
                    if (sc.suggestOn)
                    {
                        join = "on " + join;
                    }
                    s.Add(new Suggestion(TokenType.Expression, join));
                }
            }

            if (sc.suggestJoin && s.enableSuggestKeywords)
            {
                s.AddKeyword("inner join", true);
            }
            if (sc.suggestOn && s.enableSuggestKeywords)
            {
                s.AddKeyword("on", true);
            }

            if (sc.suggestAlias && s.enableSuggestAliases && rightTable != null && rightTable.dbTable != null)
            {
                foreach (string alias in rightTable.dbTable.aliases.Keys)
                {
                    s.Add(new Suggestion(TokenType.Identifier, alias));
                }
                s.Add(new Suggestion(TokenType.Identifier, Db.GetAliasForTable(rightTable.dbTable.name, false)));
            }

            if (sc.suggestColumns && s.enableSuggestColumns)
            {
                if (rightTable != null && rightTable.dbTable != null)
                {
                    sc.AddColumnsInTable(leftTable, true);
                    sc.AddColumnsInTable(rightTable, true);
                    sc.AddColumnsInTable(leftTable);
                    sc.AddColumnsInTable(rightTable);
                    sc.AddColumnsInFromTables();
                }
            }

            if (sc.suggestTables && s.enableSuggestTables)
            {
                QList <string> names = new QList <string>();
                QList <string> list  = new QList <string>();
                foreach (Column c in parentQuery.select.columns.tokens)
                {
                    if (c.table != null && c.table.dbTable != null && (c.columnType == Column.ColumnType.Db))
                    {
                        list.AddIfNotExists(c.table.dbTable.name);
                    }
                    sc.AddTable(c.tableName);
                }
                foreach (DbColumn c in Query.columnHints)
                {
                    sc.AddTable(c.table.name);
                }

                if (rightTable != null && rightTable.dbTable != null)
                {
                    /*
                     * if (rightTable.tableAlias != null)
                     *  aliasFound = true;
                     * // need to sort these tables by most recently used
                     * names.MergeRange(Db.relationships.GetRelatedTables(rightTable.dbTable.name));
                     * foreach (string name in names.Each())
                     *  sc.AddTable(name, aliasFound ? Db.GetAliasForTable(name, true) : "");
                     * names.Clear();
                     */
                }

                if (s.textEntered.Trim() != "")
                {
                    foreach (Column c in parentQuery.select.columns.tokens)
                    {
                        if ((c.tableAlias == null || c.columnType == Column.ColumnType.Proposed) &&
                            c.tableName != null && Db.tables.ContainsKey(c.tableName))
                        {
                            list.AddIfNotExists(c.tableName);
                            names.AddIfNotExists(c.tableName);
                        }
                    }

                    foreach (string srcTable in list.Each())
                    {
                        names.MergeRange(Db.TableNamesSortedByUsage(Db.tables[srcTable].accessibleTableNames));
                    }
                    names.MergeRange(Db.tables.Keys);
                    foreach (string name in names.Each())
                    {
                        sc.AddTable(name);
                    }
                }
            }
        }
Esempio n. 15
0
        public int FindInferredRelationships()
        {
            DbColumn primaryKeyColumn = GetSinglePrimaryKeyColumn();

            if (primaryKeyColumn == null)
            {
                return(0);
            }

            QList <DbColumn> references = new QList <DbColumn>(QListSort.Descending);

            foreach (DbColumn c in DbColumn.allNames.Each(name.ToLower()))
            {
                references.Add(c, 10);
            }
            foreach (DbColumn c in DbColumn.allNameStems.Each(name.Stem().ToLower()))
            {
                references.Add(c, 7);
            }
            foreach (DbColumn c in DbColumn.allWords.Each(name.ToLower()))
            {
                if (c.likeIdentifier)
                {
                    references.Add(c, 4 - c.objectNameWords.Count);
                }
            }
            foreach (DbColumn c in DbColumn.allWordStems.Each(name.Stem().ToLower()))
            {
                if (c.likeIdentifier)
                {
                    references.Add(c, 3 - c.objectNameWords.Count);
                }
            }

            /*
             * if (!primaryKeyColumn.objectName.In("id,code,name,label"))
             * {
             *  if (primaryKeyColumn.dataType == typeof(int) || primaryKeyColumn.dataType == typeof(string))
             *  {
             *      foreach (DbColumn c in DbColumn.allNames.Each(primaryKeyColumn.objectName.ToLower()))
             *          references.Add(c, 5);
             *  }
             * }
             */


            // todo: should these fields have zero empty values?

            int ct = 0;

            List <string> tablesAdded = new List <string>();

            foreach (DbColumn c in references.Each())
            {
                if (c != primaryKeyColumn && !tablesAdded.Contains(c.objectName))
                {
                    if (c.dataType == primaryKeyColumn.dataType && c.columnLength == primaryKeyColumn.columnLength)
                    {
                        if (c.table.GetForeignKey(objectName, primaryKeyColumn.objectName) == null)
                        {
                            DbTableConstraint constraint = c.table.GetOrAddConstraint("inferred" + objectName, "inferred");
                            constraint.AddInferredRelationship(c.objectName, this, primaryKeyColumn);
                            tablesAdded.Add(c.table.name);
                            ct++;
                        }
                    }
                }
            }

            return(ct);
        }