示例#1
0
        public void TestQKeyedTable()
        {
            var columns = new[] { "pos", "dates", "eid" };
            var keyColumns = new[] { "eid" };
            var data = new object[] { new[] { "d1", "d2", "d3" }, new[] { new QDate(366), new QDate(121), new QDate(int.MinValue) }, new[] { 1001, 1002, 1003 } };

            var kt = new QKeyedTable(columns, keyColumns, data);
            Assert.AreEqual(kt, new QKeyedTable(columns, keyColumns, data));

            Assert.IsTrue(kt.HasColumn("pos"));
            Assert.IsFalse(kt.HasColumn("unknown"));

            Assert.AreEqual(0, kt.GetColumnIndex("eid"));
            Assert.AreEqual(1, kt.GetColumnIndex("pos"));
            Assert.AreEqual(2, kt.GetColumnIndex("dates"));
            Assert.Throws<NullReferenceException>(() => kt.GetColumnIndex("unknown"));

            int i = 0;
            var e = kt.GetEnumerator();

            while (e.MoveNext())
            {
                var ktp = e.Current;
                Assert.AreEqual(kt.Keys[i], ktp.Key);
                Assert.AreEqual(kt.Values[i], ktp.Value);
                i++;
            }

            Assert.AreEqual(i, kt.RowsCount);
        }
示例#2
0
        //-------------------------------------------------------------------//
        private static object[,] QKeyedTable2Excel(QKeyedTable table)
        {
            var res = new object[table.Values.RowsCount + 1, table.Values.ColumnsCount + table.Keys.ColumnsCount];

            for (var i = 0; i < table.Keys.ColumnsCount + table.Values.ColumnsCount; i++)
            {
                for (var j = 0; j < table.Values.RowsCount + 1; j++)
                {
                    if (j == 0) //write colnames
                    {
                        res[j, i] = (i < table.Keys.ColumnsCount)
                            ? table.Keys.Columns.GetValue(i).ToString()
                            : table.Values.Columns.GetValue(i - table.Keys.ColumnsCount).ToString();
                    }
                    else //write data
                    {
                        res[j, i] = (i < table.Keys.ColumnsCount)
                            ? Convert2Excel(((Array)table.Keys.Data.GetValue(i)).GetValue(j - 1))
                            : Convert2Excel(
                            ((Array)table.Values.Data.GetValue(i - table.Keys.ColumnsCount)).GetValue(
                                j - 1));
                    }
                }
            }
            return(res);
        }
示例#3
0
        public void TestQKeyedTable()
        {
            var columns    = new[] { "pos", "dates", "eid" };
            var keyColumns = new[] { "eid" };
            var data       = new object[] { new[] { "d1", "d2", "d3" }, new[] { new QDate(366), new QDate(121), new QDate(int.MinValue) }, new[] { 1001, 1002, 1003 } };

            var kt = new QKeyedTable(columns, keyColumns, data);

            Assert.AreEqual(kt, new QKeyedTable(columns, keyColumns, data));

            Assert.IsTrue(kt.HasColumn("pos"));
            Assert.IsFalse(kt.HasColumn("unknown"));

            Assert.AreEqual(0, kt.GetColumnIndex("eid"));
            Assert.AreEqual(1, kt.GetColumnIndex("pos"));
            Assert.AreEqual(2, kt.GetColumnIndex("dates"));
            Assert.Throws <NullReferenceException>(() => kt.GetColumnIndex("unknown"));

            int i = 0;
            var e = kt.GetEnumerator();

            while (e.MoveNext())
            {
                var ktp = e.Current;
                Assert.AreEqual(kt.Keys[i], ktp.Key);
                Assert.AreEqual(kt.Values[i], ktp.Value);
                i++;
            }

            Assert.AreEqual(i, kt.RowsCount);
        }
示例#4
0
        private static T[] FromQKeyedTable <T>(MappingContext cxt, QKeyedTable keyedTable)
        {
            var result = new T[keyedTable.RowsCount];

            for (int row = 0; row < result.Length; ++row)
            {
                result[row] = Activator.CreateInstance <T>();
                AssignToPropertyFromQColumn(cxt, keyedTable.Keys, result, row);
                AssignToPropertyFromQColumn(cxt, keyedTable.Values, result, row);
            }
            return(result);
        }
示例#5
0
 public void TestQKeyedTableConstruction()
 {
     var kt1 = new QKeyedTable(new QTable(new[] {"eid"}, new object[] {new[] {1001, 1002, 1003}}),
                               new QTable(new[] {"pos", "dates"},
                                          new object[]
                                              {
                                                  new[] {"d1", "d2", "d3"},
                                                  new[] {new QDate(366), new QDate(121), new QDate(int.MinValue)}
                                              }));
     var kt2 = new QKeyedTable(new[] {"pos", "dates", "eid"}, new[] {"eid"},
                               new object[]
                                   {
                                       new[] {"d1", "d2", "d3"},
                                       new[] {new QDate(366), new QDate(121), new QDate(int.MinValue)},
                                       new[] {1001, 1002, 1003}
                                   });
     Assert.IsTrue(kt1.Equals(kt2));
 }
示例#6
0
        public void TestQKeyedTableConstruction()
        {
            var kt1 = new QKeyedTable(new QTable(new[] { "eid" }, new object[] { new[] { 1001, 1002, 1003 } }),
                                      new QTable(new[] { "pos", "dates" },
                                                 new object[]
            {
                new[] { "d1", "d2", "d3" },
                new[] { new QDate(366), new QDate(121), new QDate(int.MinValue) }
            }));
            var kt2 = new QKeyedTable(new[] { "pos", "dates", "eid" }, new[] { "eid" },
                                      new object[]
            {
                new[] { "d1", "d2", "d3" },
                new[] { new QDate(366), new QDate(121), new QDate(int.MinValue) },
                new[] { 1001, 1002, 1003 }
            });

            Assert.IsTrue(kt1.Equals(kt2));
        }
示例#7
0
        // ReSharper disable InconsistentNaming
        public object[] qTable(object columnNames, object values, object types, object keys)
        // ReSharper restore InconsistentNaming
        {
            var array = values as Array;

            if (array != null && (array.Rank != 2 && !(columnNames is Array)))
            {
                values = new[] { values }
            }
            ;

            if (!(columnNames is Array) && columnNames != null)
            {
                columnNames = new[] { columnNames }
            }
            ;

            if (keys != null && keys.GetType() == typeof(ExcelMissing))
            {
                keys = null;
            }

            var array1 = columnNames as Array;

            if (array1 != null && array1.Rank == 2) //thats how it comes from worksheet.
            {
                var k = columnNames as Array;
                if (k.GetLength(0) == 1 || k.GetLength(1) == 1)
                {
                    columnNames = Utils.Com2DArray2Array(k);
                }
            }
            var res = qList(values, types, true);

            if (res[2] != null) //there was an exception converting values,so no point to attempt table creation.
            {
                return(res);
            }

            var array2 = columnNames as Array;
            var array3 = Conversions[res[0].ToString()] as Array;

            if (array3 != null && (array2 != null && array2.Length != array3.Length))
            {
                res[2] = ErrCol2ValMismatch;
                return(res);
            }

            if (keys != null)
            {
                if (!(keys is Array))
                {
                    keys = new[] { keys }
                }
                ;

                if (columnNames == null)
                {
                    return(res);
                }
                var tab = new QKeyedTable((columnNames as Array).OfType <string>().ToArray(),
                                          (keys as Array).OfType <string>().ToArray(), array3);

                Conversions[res[0].ToString()] = tab;
            }
            else
            {
                if (columnNames == null)
                {
                    return(res);
                }
                var tab = new QTable((columnNames as Array).OfType <string>().ToArray(), array3);

                Conversions[res[0].ToString()] = tab;
            }
            return(res);
        }