Пример #1
0
 private void WriteTable(QTable t)
 {
     _writer.Write((sbyte)QType.Table);
     _writer.Write((byte)0);  // attributes
     _writer.Write((sbyte)QType.Dictionary);
     WriteObject(t.Columns);
     WriteObject(t.Data);
 }
Пример #2
0
        /// <summary>
        ///     Determines whether the specified QTable is equal to the current QTable.
        /// </summary>
        /// <param name="t">The QTable to compare with the current QTable.</param>
        /// <returns>true if the specified QTable is equal to the current QTable; otherwise, false</returns>
        public bool Equals(QTable t)
        {
            if (t == null)
            {
                return(false);
            }

            return(Utils.ArrayEquals(Columns, t.Columns) && Utils.ArrayEquals(Data, t.Data));
        }
Пример #3
0
 /// <summary>
 ///     Initializes a new instance of the Row.
 /// </summary>
 public Row(QTable table, int rowIndex)
     : this()
 {
     if (rowIndex < 0 || rowIndex > table.RowsCount)
     {
         throw new ArgumentOutOfRangeException();
     }
     _table = table;
     Index  = rowIndex;
 }
Пример #4
0
        /// <summary>
        ///     Creates new QKeyedTable instance with given keys and values arrays.
        /// </summary>
        public QKeyedTable(QTable keys, QTable values)
        {
            if (keys == null || keys.RowsCount == 0)
            {
                throw new ArgumentException("Keys table cannot be null or 0-length");
            }

            if (values == null || values.RowsCount == 0)
            {
                throw new ArgumentException("Values table cannot be null or 0-length");
            }

            if (keys.RowsCount != values.RowsCount)
            {
                throw new ArgumentException("Keys and value tables cannot have different length");
            }

            this.keys = keys;
            this.values = values;
        }
Пример #5
0
        /// <summary>
        ///     Creates new QKeyedTable instance with given keys and values arrays.
        /// </summary>
        public QKeyedTable(QTable keys, QTable values)
        {
            if (keys == null || keys.RowsCount == 0)
            {
                throw new ArgumentException("Keys table cannot be null or 0-length");
            }

            if (values == null || values.RowsCount == 0)
            {
                throw new ArgumentException("Values table cannot be null or 0-length");
            }

            if (keys.RowsCount != values.RowsCount)
            {
                throw new ArgumentException("Keys and value tables cannot have different length");
            }

            _keys   = keys;
            _values = values;
        }
Пример #6
0
        /// <summary>
        ///     Creates new QDictionary instance with given keys array and table values.
        /// </summary>
        public QDictionary(Array keys, QTable values)
        {
            if (keys == null || keys.Length == 0)
            {
                throw new ArgumentException("Keys array cannot be null or 0-length");
            }

            if (values == null || values.RowsCount == 0)
            {
                throw new ArgumentException("Values table cannot be null or 0-length");
            }

            if (keys.Length != values.RowsCount)
            {
                throw new ArgumentException("Keys and value arrays cannot have different length");
            }

            _keys = keys;
            _values = values;
            _areValuesArray = false;
        }
Пример #7
0
        /// <summary>
        ///     Creates new QDictionary instance with given keys array and table values.
        /// </summary>
        public QDictionary(Array keys, QTable values)
        {
            if (keys == null || keys.Length == 0)
            {
                throw new ArgumentException("Keys array cannot be null or 0-length");
            }

            if (values == null || values.RowsCount == 0)
            {
                throw new ArgumentException("Values table cannot be null or 0-length");
            }

            if (keys.Length != values.RowsCount)
            {
                throw new ArgumentException("Keys and value arrays cannot have different length");
            }

            _keys           = keys;
            _values         = values;
            _areValuesArray = false;
            Count           = keys.Length;
        }
Пример #8
0
        //-------------------------------------------------------------------//        
        /// <summary>
        ///     This function applies data received from Q process to in-memory cache.
        ///     All operations are structured in a way that only data that has been subscribed is kept,
        ///     i.e.: data from columns that were not requested is simply discarded.
        /// </summary>
        /// <param name="alias">alias of the connection producing the data</param>
        /// <param name="table">name of the table</param>
        /// <param name="data">table data</param>
        private static void UpdateCache(string alias, string table, QTable data)
        {
            var symIdx = data.GetColumnIndex(_symColName);
            var cols = data.Columns;
            foreach (QTable.Row row in data)
            {
                var ra = row.ToArray();
                var symName = ra[symIdx].ToString();

                var symId = GetSymbolId(alias, table, symName);
                if (WildCardMapping.ContainsKey(alias) /*&& symId != null*/)
                {
                    for (var i = 0; i < cols.Length; i++)
                    {
                        Cache.UpdateData(alias, table, symName, cols[i], Conversions.Convert2Excel(ra[i]));

                        AllSymbols[alias][table].Add(symName);
                        if (symId == null) continue;
                        if (!WildCardMapping[alias].ContainsColumn(table, symId, cols[i])) continue;

                        foreach (var ti in WildCardMapping[alias].GetTopics(table, symId, cols[i]))
                        {
                            DataOut.AddOrUpdate(ti, "", (k, v) => "");
                            var val = string.IsNullOrEmpty(ti.History)
                                ? Conversions.Convert2Excel(ra[i])
                                : Cache.GetData(alias, table, symName, cols[i], ti.History);
                            ti.Topic.UpdateValue(val ?? ExcelEmpty.Value);
                        }
                    }
                }

                if (!Mapping.ContainsKey(alias) || !Mapping[alias].ContainsSymbol(table, symName))
                {
                    continue;
                }
                for (var i = 0; i < cols.Length; i++)
                {
                    if (!Mapping[alias].ContainsColumn(table, symName, cols[i])) continue;
                    Cache.UpdateData(alias, table, symName, cols[i], Conversions.Convert2Excel(ra[i]));
                    foreach (var ti in Mapping[alias].GetTopics(table, symName, cols[i]))
                    {
                        DataOut.AddOrUpdate(ti, "", (k, v) => "");
                        var val = string.IsNullOrEmpty(ti.History)
                            ? Conversions.Convert2Excel(ra[i])
                            : Cache.GetData(alias, table, symName, cols[i], ti.History);
                        ti.Topic.UpdateValue(val ?? ExcelEmpty.Value);
                    }
                }
            }
        }
Пример #9
0
 //-------------------------------------------------------------------//
 private static object[,] QTable2Excel(QTable table)
 {
     var res = new object[table.RowsCount + 1, table.ColumnsCount];
     for (var i = 0; i < table.ColumnsCount; i++)
         for (var j = 0; j < table.RowsCount + 1; j++)
         {
             if (j == 0) //write header
             {
                 res[j, i] = table.Columns.GetValue(i).ToString();
             }
             else //write data
             {
                 res[j, i] = Convert2Excel(((Array) table.Data.GetValue(i)).GetValue(j - 1));
             }
         }
     return res;
 }
Пример #10
0
 public QTableEnumerator(QTable table)
 {
     _table   = table;
     _current = new Row(_table, _index);
 }
Пример #11
0
        /// <summary>
        ///     Initializes a new instance of the QKeyedTable with specified column names and data matrix.
        /// </summary>
        public QKeyedTable(string[] columns, string[] keyColumns, Array data)
        {
            if (columns == null || columns.Length == 0)
            {
                throw new ArgumentException("Columns array cannot be null or 0-length");
            }

            if (keyColumns == null || keyColumns.Length == 0)
            {
                throw new ArgumentException("Key columns array cannot be null or 0-length");
            }

            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("Data matrix cannot be null or 0-length");
            }

            if (columns.Length != data.Length)
            {
                throw new ArgumentException("Columns array and data matrix cannot have different length");
            }

            if (data.Cast<object>().Any(col => !col.GetType().IsArray))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            if (keyColumns.Any(keyCol => !columns.Contains(keyCol)))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            var keyIndices = new SortedSet<int>();
            for (int i = 0; i < columns.Length; i++)
            {
                if (keyColumns.Contains(columns[i]))
                {
                    keyIndices.Add(i);
                }
            }

            var keyArrays = new object[keyIndices.Count];
            var keyHeaders = new string[keyIndices.Count];
            var dataArrays = new object[data.Length - keyIndices.Count];
            var dataHeaders = new string[data.Length - keyIndices.Count];

            int ki = 0;
            int di = 0;

            for (int i = 0; i < data.Length; i++)
            {
                if (keyIndices.Contains(i))
                {
                    keyHeaders[ki] = columns[i];
                    keyArrays[ki++] = data.GetValue(i);
                }
                else
                {
                    dataHeaders[di] = columns[i];
                    dataArrays[di++] = data.GetValue(i);
                }
            }

            keys = new QTable(keyHeaders, keyArrays);
            values = new QTable(dataHeaders, dataArrays);
        }
Пример #12
0
 private void WriteTable(QTable t)
 {
     writer.Write((sbyte)QType.Table);
     writer.Write((byte)0); // attributes
     writer.Write((sbyte)QType.Dictionary);
     WriteObject(t.Columns);
     WriteObject(t.Data);
 }
Пример #13
0
 public QTableEnumerator(QTable table)
 {
     _table = table;
 }
Пример #14
0
 /// <summary>
 ///     Initializes a new instance of the Row.
 /// </summary>
 public Row(QTable table, int rowIndex)
 {
     if (rowIndex < 0 || rowIndex > table.RowsCount)
     {
         throw new ArgumentOutOfRangeException();
     }
     _table = table;
     _rowIndex = rowIndex;
 }
Пример #15
0
        /// <summary>
        ///     Determines whether the specified QTable is equal to the current QTable.
        /// </summary>
        /// <param name="t">The QTable to compare with the current QTable.</param>
        /// <returns>true if the specified QTable is equal to the current QTable; otherwise, false</returns>
        public bool Equals(QTable t)
        {
            if (t == null)
            {
                return false;
            }

            return Utils.ArrayEquals(Columns, t.Columns) && Utils.ArrayEquals(Data, t.Data);
        }
Пример #16
0
        /// <summary>
        ///     Initializes a new instance of the QKeyedTable with specified column names and data matrix.
        /// </summary>
        public QKeyedTable(IList <string> columns, ICollection <string> keyColumns, Array data)
        {
            if (columns == null || columns.Count == 0)
            {
                throw new ArgumentException("Columns array cannot be null or 0-length");
            }

            if (keyColumns == null || keyColumns.Count == 0)
            {
                throw new ArgumentException("Key columns array cannot be null or 0-length");
            }

            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("Data matrix cannot be null or 0-length");
            }

            if (columns.Count != data.Length)
            {
                throw new ArgumentException("Columns array and data matrix cannot have different length");
            }

            if (data.Cast <object>().Any(col => !col.GetType().IsArray))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            if (keyColumns.Any(keyCol => !columns.Contains(keyCol)))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            var keyIndices = new SortedSet <int>();

            for (var i = 0; i < columns.Count; i++)
            {
                if (keyColumns.Contains(columns[i]))
                {
                    keyIndices.Add(i);
                }
            }

            var keyArrays   = new object[keyIndices.Count];
            var keyHeaders  = new string[keyIndices.Count];
            var dataArrays  = new object[data.Length - keyIndices.Count];
            var dataHeaders = new string[data.Length - keyIndices.Count];

            var ki = 0;
            var di = 0;

            for (var i = 0; i < data.Length; i++)
            {
                if (keyIndices.Contains(i))
                {
                    keyHeaders[ki]  = columns[i];
                    keyArrays[ki++] = data.GetValue(i);
                }
                else
                {
                    dataHeaders[di]  = columns[i];
                    dataArrays[di++] = data.GetValue(i);
                }
            }

            _keys   = new QTable(keyHeaders, keyArrays);
            _values = new QTable(dataHeaders, dataArrays);
        }