Ejemplo n.º 1
0
        /// <summary>
        /// Append all entries in all tables, source IDs will be discarded.
        /// </summary>
        public void AppendTables(string pFilename)
        {
            //Console.WriteLine("Appending table from file " + pFilename);
            RelayTwo additiveRelay = new RelayTwo(pFilename);

            AppendTables(additiveRelay);
        }
Ejemplo n.º 2
0
 public void NonExistingFieldTest()
 {
     RelayLib.RelayTwo r2 = new RelayLib.RelayTwo();
     r2.CreateTable(TingTing.Ting.TABLE_NAME);
     r2.CreateTable(TingTing.Room.TABLE_NAME);
     RoomRunner rr =  new TingTing.RoomRunner(r2);
     rr.CreateRoom<Room>(WorldCoordinate.UNDEFINED_ROOM);
     TingTing.TingRunner tr = new TingTing.TingRunner(r2,rr);
     tr.CreateTing<SomeLesserTing>("TingA", TingTing.WorldCoordinate.NONE);
     r2.GetTable(TingTing.Ting.TABLE_NAME)[0].Set<string>(TingTing.Ting.CSHARP_CLASS_FIELD_NAME, "TerreTingThongDong");
     List<TingTing.Ting> list = InstantiatorTwo.Process<TingTing.Ting>(r2.GetTable(TingTing.Ting.TABLE_NAME));
     Console.WriteLine("list length" + list.Count);
     Assert.NotNull((list[0] as TerreTingThongDong));
     Assert.AreSame("Something", (list[0] as TerreTingThongDong).funk);
 }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            RelayTwo r = obj as RelayTwo;

            if (r == null || r.tables.Count != tables.Count)
            {
                return(false);
            }
            foreach (TableTwo t in tables.Values)
            {
                if (!t.Equals(r.tables[t.name]))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        public void NonExistingFieldTest()
        {
            RelayLib.RelayTwo r2 = new RelayLib.RelayTwo();
            r2.CreateTable(TingTing.Ting.TABLE_NAME);
            r2.CreateTable(TingTing.Room.TABLE_NAME);
            RoomRunner rr = new TingTing.RoomRunner(r2);

            rr.CreateRoom <Room>(WorldCoordinate.UNDEFINED_ROOM);
            TingTing.TingRunner tr = new TingTing.TingRunner(r2, rr);
            tr.CreateTing <SomeLesserTing>("TingA", TingTing.WorldCoordinate.NONE);
            r2.GetTable(TingTing.Ting.TABLE_NAME)[0].Set <string>(TingTing.Ting.CSHARP_CLASS_FIELD_NAME, "TerreTingThongDong");
            List <TingTing.Ting> list = InstantiatorTwo.Process <TingTing.Ting>(r2.GetTable(TingTing.Ting.TABLE_NAME));

            Console.WriteLine("list length" + list.Count);
            Assert.NotNull((list[0] as TerreTingThongDong));
            Assert.AreSame("Something", (list[0] as TerreTingThongDong).funk);
        }
Ejemplo n.º 5
0
        public RelayTreeRunner(RelayTwo pRelay, string pTableName)
        {
            D.isNull(pRelay);
            if (!pRelay.tables.ContainsKey(pTableName))
            {
                pRelay.CreateTable(pTableName);
            }
            _table = pRelay.GetTable(pTableName);
            List <RelayTreeNode> nodes = InstantiatorTwo.Process <RelayTreeNode>(_table);

            foreach (RelayTreeNode t in nodes)
            {
                D.assert(t.hasSetupCells, "an object of type " + t.GetType().Name + " did not call base method of SetupCells");
                _nodes.Add(t.objectId, t);
                t.SetRunner(this);
            }
            foreach (RelayTreeNode t in nodes)
            {
                t.RestoreRelations();
            }
        }
Ejemplo n.º 6
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.º 7
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.º 8
0
        public void SaveTableSubsetSeparately(string pTableName, string pSaveFilePath)
        {
            RelayTwo subset = Subset(pTableName, (o => true));

            subset.SaveAll(pSaveFilePath);
        }
Ejemplo n.º 9
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);
                    }
                }
            }
        }