/// <summary>Deserializes a foreign table.</summary>
        /// <remarks>
        ///     This can only deserialize rows written with layout. (Requires use of <see cref="Flags.WithLayout" /> when
        ///     serializing.)
        /// </remarks>
        /// <param name="reader">The reader to read from.</param>
        /// <returns>The deserialized table instance.</returns>
        public static ITable DeserializeForeignTable(this DataReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var flags = (Flags)reader.Read7BitEncodedInt32();

            if ((flags & Flags.WithLayout) == 0)
            {
                throw new NotSupportedException(
                          "For DeserializeForeignX() functions the layout has to be written by the sender! The current decoded data does not contain a layout!");
            }

            var layout = RowLayout.Load(reader);
            var result = MemoryTable.Create(layout);
            var count  = reader.Read7BitEncodedInt64();

            for (long l = 0; l < count; l++)
            {
                var row = DeserializeData(reader, layout);
                result.Insert(row);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>Caches the whole table into memory and provides a new ITable instance.</summary>
        /// <param name="table">The table.</param>
        /// <returns>Returns a new memory table.</returns>
        public static MemoryTable ToMemory(this ITable table)
        {
            Trace.TraceInformation("Copy {0} rows to memory table", table.RowCount);
            var result = MemoryTable.Create(table.Layout);

            result.LoadTable(table);
            return(result);
        }
Beispiel #3
0
        /// <summary>Caches the whole table into memory and provides a new ITable{TStruct} instance.</summary>
        /// <typeparam name="TKey">Key identifier type.</typeparam>
        /// <typeparam name="TStruct">Row structure type.</typeparam>
        /// <param name="table">The table.</param>
        /// <returns>Returns a new memory table.</returns>
        public static ITable <TKey, TStruct> ToMemory <TKey, TStruct>(this ITable <TKey, TStruct> table)
            where TKey : IComparable <TKey>
            where TStruct : struct
        {
            var result = MemoryTable.Create(table.Layout);

            result.LoadTable(table);
            return(new Table <TKey, TStruct>(result));
        }
Beispiel #4
0
        /// <summary>Caches the whole table into memory and provides a new ITable{TStruct} instance.</summary>
        /// <typeparam name="TStruct">Structure type.</typeparam>
        /// <param name="table">The table.</param>
        /// <returns>Returns a new memory table.</returns>
        public static ITable <TStruct> ToMemory <TStruct>(this ITable <TStruct> table)
            where TStruct : struct
        {
            Trace.TraceInformation("Copy {0} rows to memory table", table.RowCount);
            var result = MemoryTable.Create(table.Layout);

            result.LoadTable(table);
            return(new Table <TStruct>(result));
        }
Beispiel #5
0
        /// <summary>Caches the whole table into memory and provides a new ITable instance.</summary>
        /// <param name="table">The table.</param>
        /// <returns>Returns a new memory table.</returns>
        public static MemoryTable ToMemory(this ITable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            Trace.TraceInformation("Copy {0} rows to memory table", table.RowCount);
            var result = MemoryTable.Create(table.Layout);

            result.LoadTable(table);
            return(result);
        }
Beispiel #6
0
        /// <summary>Caches the whole table into memory and provides a new ITable{TStruct} instance.</summary>
        /// <typeparam name="TKey">Key identifier type.</typeparam>
        /// <typeparam name="TStruct">Row structure type.</typeparam>
        /// <param name="table">The table.</param>
        /// <returns>Returns a new memory table.</returns>
        public static ITable <TKey, TStruct> ToMemory <TKey, TStruct>(this ITable <TKey, TStruct> table)
            where TKey : IComparable <TKey>
            where TStruct : struct
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            var result = MemoryTable.Create(table.Layout);

            result.LoadTable(table);
            return(new Table <TKey, TStruct>(result));
        }
Beispiel #7
0
        /// <summary>Caches the whole table into memory and provides a new ITable{TStruct} instance.</summary>
        /// <typeparam name="TStruct">Structure type.</typeparam>
        /// <param name="table">The table.</param>
        /// <returns>Returns a new memory table.</returns>
        public static ITable <TStruct> ToMemory <TStruct>(this ITable <TStruct> table)
            where TStruct : struct
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            Trace.TraceInformation("Copy {0} rows to memory table", table.RowCount);
            var result = MemoryTable.Create(table.Layout);

            result.LoadTable(table);
            return(new Table <TStruct>(result));
        }
        /// <inheritdoc />
        public override ITable CreateTable(RowLayout layout, TableFlags flags = default)
        {
            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            if (tables.ContainsKey(layout.Name))
            {
                throw new InvalidOperationException($"Table '{layout.Name}' already exists!");
            }

            var table = MemoryTable.Create(layout);

            tables[layout.Name] = table;
            return(table);
        }
 /// <inheritdoc/>
 public RowCacheBuilder(ITable table)
 {
     Table = table;
     Cache = MemoryTable.Create(table.Layout);
 }