Ejemplo n.º 1
0
        private void AddFieldsToTable(TableTwo pTable, string[] pFieldNames, string[] pDataTypeNames)
        {
            D.assert(pFieldNames.Length == pDataTypeNames.Length, "field definitions does not match");

            for (int i = 0; i < pFieldNames.Length; i++)
            {
                Type   genericType  = typeof(TableField <>);
                string dataTypeName = pDataTypeNames[i];
                //Console.WriteLine(dataTypeName);
                Type[] typeArgs = null;

                // Check through all assemblies for the type arguemnts
                foreach (Assembly assm in AppDomain.CurrentDomain.GetAssemblies())
                {
                    typeArgs = new Type[] { assm.GetType(dataTypeName) };
                    if (typeArgs[0] != null)
                    {
                        break; //found type
                    }
                }

                D.isNull(typeArgs[0], dataTypeName + " was not found ");
                Type repositoryType = genericType.MakeGenericType(typeArgs);

                ITableField result = (ITableField)Activator.CreateInstance(repositoryType, pFieldNames[i]);
                pTable.AddField(result);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Append all entries in all tables, source IDs will be discarded.
        /// </summary>
        public void AppendTables(RelayTwo pRelay)
        {
            RelayTwo additiveRelay = pRelay;

            // Cycle through all new tables in the loaded relay
            foreach (String tableName in additiveRelay.tables.Keys)
            {
                TableTwo fromTable = additiveRelay.tables[tableName];
                // If the table already exists, append the entries from the new table.
                if (tables.ContainsKey(tableName))
                {
                    TableTwo toTable = tables[tableName];
                    // Ensure that all fields exists in the old table.
                    foreach (ITableField f in fromTable.fields)
                    {
                        if (!toTable.fieldNames.Contains(f.name))
                        {
                            toTable.AddField(f.GetEmptyCopy());
                        }
                    }
                    foreach (TableRow fromRow in fromTable)
                    {
                        TableRow toRow = toTable.CreateRow();
                        foreach (ITableField fromField in fromTable.fields)
                        {
                            ITableField toField = toTable.GetField(fromField.name);
                            toField.SetValueFromString(toRow.row, fromField.GetValueAsString(fromRow.row));
                        }
                    }
                }
                else
                {
                    this.tables[fromTable.name] = fromTable;
                }
            }
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }