Beispiel #1
0
        public IEnumerable <float> Load(string pFilename)
        {
#if PRINT_TIME_DATA
            DateTime startTime = DateTime.Now;
#endif

            FileStream   f  = new FileStream(pFilename, FileMode.Open);
            StreamReader sw = new StreamReader(f);

            while (!sw.EndOfStream)
            {
                string   tableName  = sw.ReadLine();
                int      tableCount = Convert.ToInt32(sw.ReadLine());
                string[] fieldNames = JsonConvert.DeserializeObject <string[]>(sw.ReadLine());
                string[] typeNames  = JsonConvert.DeserializeObject <string[]>(sw.ReadLine());

                TableTwo newTable = new TableTwo(tableName);
                AddFieldsToTable(newTable, fieldNames, typeNames);

                for (int i = 0; i < tableCount; i++)
                {
                    SerializableTableRow r = JsonConvert.DeserializeObject <SerializableTableRow>(sw.ReadLine());
                    if (r.row >= newTable.capacity)
                    {
                        newTable.SetCapacity(r.row + 1);
                    }
                    r.InsertToTable(newTable);
                }

                tables.Add(newTable.name, newTable);
                yield return(((float)sw.BaseStream.Position) / ((float)sw.BaseStream.Length));
            }

            f.Flush();
            f.Close();
            f.Dispose();

#if PRINT_TIME_DATA
            TimeSpan span = DateTime.Now - startTime;
            Console.WriteLine("Loading " + pFilename + " took " + span.TotalSeconds + " seconds");
#endif
        }
Beispiel #2
0
        public RelayTwo Subset(string pTableName, Func <TableRow, bool> pPredicate)
        {
            RelayTwo relaySubset = new RelayTwo();
            TableTwo tableSubset = relaySubset.CreateTable(pTableName);
            TableTwo sourceTable = tables[pTableName];

            foreach (ITableField f in sourceTable.fields)
            {
                tableSubset.AddField(f.GetEmptyCopy());
            }

            tableSubset.SetCapacity(sourceTable.capacity);

            foreach (TableRow sourceRow in sourceTable.Where(pPredicate))
            {
                SerializableTableRow newRow = sourceRow.GetSerializableTableRow();
                newRow.InsertToTable(tableSubset);
                //Console.WriteLine("added row " + newRow.row);
            }

            return(relaySubset);
        }
Beispiel #3
0
        public void MergeWith(RelayTwo pSource)
        {
            foreach (TableTwo targetTable in tables.Values)
            {
                if (pSource.tables.ContainsKey(targetTable.name))
                {
                    TableTwo sourceTable = pSource.tables[targetTable.name];

                    // Add missing fields to targetTable
                    foreach (ITableField field in sourceTable.fields)
                    {
                        if (!targetTable.fieldNames.Contains(field.name))
                        {
                            targetTable.AddField(field.GetEmptyCopy());
                        }
                    }

                    // Add missing fields to sourceTable
                    foreach (ITableField field in targetTable.fields)
                    {
                        if (!sourceTable.fieldNames.Contains(field.name))
                        {
                            sourceTable.AddField(field.GetEmptyCopy());
                        }
                    }

                    if (sourceTable.capacity > targetTable.capacity)
                    {
                        targetTable.SetCapacity(sourceTable.capacity);
                    }

                    foreach (TableRow r in sourceTable)
                    {
                        SerializableTableRow sr = r.GetSerializableTableRow();

                        if (targetTable.ContainsRow(sr.row))
                        {
                            throw new RelayMergeException("table " + targetTable.name + " does already contain row " + sr.row);
                        }

                        sr.InsertToTable(targetTable);
                    }
                }
            }

            // Copy complete tables from subsetB if they don't exist in this relay
            foreach (TableTwo tableB in pSource.tables.Values)
            {
                if (!tables.ContainsKey(tableB.name))
                {
                    TableTwo newTable = CreateTable(tableB.name);

                    // Add fields to the new table
                    foreach (ITableField field in tableB.fields)
                    {
                        newTable.AddField(field.GetEmptyCopy());
                    }

                    newTable.SetCapacity(tableB.capacity);

                    foreach (TableRow r in tableB)
                    {
                        SerializableTableRow sr = r.GetSerializableTableRow();
                        sr.InsertToTable(newTable);
                    }
                }
            }
        }