Exemple #1
0
        public void MergeSavesWithDifferentFields()
        {
            {
                RelayTwo relay = new RelayTwo();

                TableTwo table = relay.CreateTable("Table");

                table.AddField <string>("oldField");

                TableRow row1 = table.CreateRow();
                TableRow row2 = table.CreateRow();
                TableRow row3 = table.CreateRow();

                row1.Set("oldField", "kottar");
                row2.Set("oldField", "stenar");
                row3.Set("oldField", "gräs");

                relay.Subset("Table", (o => o.row == 0)).SaveAll("s0.json");
                relay.Subset("Table", (o => o.row == 1)).SaveAll("s1.json");
                relay.Subset("Table", (o => o.row == 2)).SaveAll("s2.json");

                table.AddField <int>("newField");

                TableRow row4 = table.CreateRow();
                TableRow row5 = table.CreateRow();

                row4.Set("newField", 500);
                row5.Set("newField", 1000);

                relay.Subset("Table", (o => o.row == 3)).SaveAll("s3.json");
                relay.Subset("Table", (o => o.row == 4)).SaveAll("s4.json");
            }
            {
                RelayTwo relay = new RelayTwo();

                relay.MergeWith(new RelayTwo("s4.json"));
                relay.MergeWith(new RelayTwo("s0.json"));
                relay.MergeWith(new RelayTwo("s1.json"));
                relay.MergeWith(new RelayTwo("s2.json"));
                relay.MergeWith(new RelayTwo("s3.json"));


                TableTwo table = relay.GetTable("Table");
                Assert.AreEqual(5, table.GetRows().Length);

                Assert.AreEqual("kottar", table.GetRow(0).Get <string>("oldField"));
                Assert.AreEqual("stenar", table.GetRow(1).Get <string>("oldField"));
                Assert.AreEqual("gräs", table.GetRow(2).Get <string>("oldField"));

                Assert.AreEqual(500, table.GetRow(3).Get <int>("newField"));
                Assert.AreEqual(1000, table.GetRow(4).Get <int>("newField"));
            }
        }
Exemple #2
0
        public void MergeSaves()
        {
            {
                RelayTwo relay = new RelayTwo();

                TableTwo table = relay.CreateTable("Table");

                table.AddField <string>("name");

                TableRow row1 = table.CreateRow();
                TableRow row2 = table.CreateRow();
                TableRow row3 = table.CreateRow();

                row1.Set("name", "a");
                row2.Set("name", "b");
                row3.Set("name", "c");

                Assert.AreEqual(3, table.GetRows().Length);
                Assert.AreEqual("a", table.GetRow(0).Get <string>("name"));
                Assert.AreEqual("b", table.GetRow(1).Get <string>("name"));
                Assert.AreEqual("c", table.GetRow(2).Get <string>("name"));

                RelayTwo save1 = relay.Subset("Table", (o => o.Get <string>("name") == "a"));
                RelayTwo save2 = relay.Subset("Table", (o => o.Get <string>("name") == "b"));
                RelayTwo save3 = relay.Subset("Table", (o => o.Get <string>("name") == "c"));

                Assert.AreEqual(1, save1.GetTable("Table").GetRows().Length);
                Assert.AreEqual(1, save2.GetTable("Table").GetRows().Length);
                Assert.AreEqual(1, save3.GetTable("Table").GetRows().Length);

                save1.SaveAll("PartialSave1.json");
                save2.SaveAll("PartialSave2.json");
                save3.SaveAll("PartialSave3.json");
            }
            {
                RelayTwo relay = new RelayTwo();
                relay.MergeWith(new RelayTwo("PartialSave1.json"));
                relay.MergeWith(new RelayTwo("PartialSave2.json"));
                relay.MergeWith(new RelayTwo("PartialSave3.json"));

                TableTwo table = relay.GetTable("Table");
                Assert.AreEqual(3, table.GetRows().Length);

                Assert.AreEqual("a", table.GetRow(0).Get <string>("name"));
                Assert.AreEqual("b", table.GetRow(1).Get <string>("name"));
                Assert.AreEqual("c", table.GetRow(2).Get <string>("name"));
            }
        }
Exemple #3
0
        public void MergeTwoSubsets()
        {
            RelayTwo relay = new RelayTwo();

            TableTwo table = relay.CreateTable("Table1");

            table.AddField <string>("name");
            table.AddField <bool>("1337");

            TableRow row1 = table.CreateRow();
            TableRow row2 = table.CreateRow();
            TableRow row3 = table.CreateRow();

            row1.Set("name", "Arne");
            row1.Set("1337", false);

            row2.Set("name", "Björn");
            row2.Set("1337", true);

            row3.Set("name", "Charlie");
            row3.Set("1337", false);

            Assert.AreEqual(3, table.GetRows().Length);

            RelayTwo subsetA = relay.Subset("Table1", (o => o.Get <bool>("1337") == true));
            RelayTwo subsetB = relay.Subset("Table1", (o => o.Get <bool>("1337") == false));

            subsetA.MergeWith(subsetB);
            Assert.Throws <RelayTwo.RelayMergeException>(() => subsetB.MergeWith(relay));
            Assert.AreEqual(true, subsetA.Equals(relay));
            Assert.AreEqual(false, subsetB.Equals(relay));
        }
Exemple #4
0
        private void FoundFile(string pFilepath, bool pOnlyLoadTingsAndRooms)
        {
            //logger.Log("Found file with path '" + pFilepath + "'");

            if (pFilepath.Contains(".svn"))
            {
                return;
            }

                        #if PROFILE
            Stopwatch sw = new Stopwatch();
            sw.Start();
                        #endif

            if (pFilepath.EndsWith(".dia") && !pOnlyLoadTingsAndRooms)
            {
                //logger.Log("Loading it as Dialogue");
                _dialogueScriptLoader.LoadDialogueNodesFromFile(pFilepath);
            }
            else if (pFilepath.EndsWith(".tings"))
            {
                _relay.AppendTables(pFilepath);
            }
            else if (pFilepath.EndsWith(".json") /* && !pOnlyLoadTingsAndRooms*/)
            {
                //logger.Log("Loading " + pFilepath + " as Relay Database");
                _relay.MergeWith(new RelayTwo(pFilepath));
            }
            else if (pFilepath.EndsWith(".sprak") && !pOnlyLoadTingsAndRooms)
            {
                //logger.Log("Loading it as Program");
                _sourceCodeDispenser.LoadSourceCode(pFilepath);
            }
            else if (pFilepath.EndsWith(".ttt") && !pOnlyLoadTingsAndRooms)
            {
                _timetableRunner.LoadTimetableFromFile(pFilepath);
            }

                        #if PROFILE
            sw.Stop();
            if (sw.Elapsed.TotalSeconds > 0.1f)
            {
                //Console.WriteLine("\nOBS! Loading " + pFilepath + " took " + sw.Elapsed.TotalSeconds + " s.");
            }
                        #endif
        }
Exemple #5
0
        public void MergeSavesWithDifferentFields()
        {
			{
	            RelayTwo relay = new RelayTwo();
				
				TableTwo table = relay.CreateTable("Table");
	
	            table.AddField<string>("oldField");
	
	            TableRow row1 = table.CreateRow();
	            TableRow row2 = table.CreateRow();
				TableRow row3 = table.CreateRow();
	
	            row1.Set("oldField", "kottar");
	            row2.Set("oldField", "stenar");
				row3.Set("oldField", "gräs");
				
				relay.Subset("Table", (o => o.row == 0)).SaveAll("s0.json");
				relay.Subset("Table", (o => o.row == 1)).SaveAll("s1.json");
				relay.Subset("Table", (o => o.row == 2)).SaveAll("s2.json");
	
				table.AddField<int>("newField");
				
	            TableRow row4 = table.CreateRow();
				TableRow row5 = table.CreateRow();		
				
				row4.Set("newField", 500);
				row5.Set("newField", 1000);
				
				relay.Subset("Table", (o => o.row == 3)).SaveAll("s3.json");
				relay.Subset("Table", (o => o.row == 4)).SaveAll("s4.json");
			}
			{
				RelayTwo relay = new RelayTwo();
				
				relay.MergeWith(new RelayTwo("s4.json"));
				relay.MergeWith(new RelayTwo("s0.json"));
				relay.MergeWith(new RelayTwo("s1.json"));
				relay.MergeWith(new RelayTwo("s2.json"));
				relay.MergeWith(new RelayTwo("s3.json"));
				
				
				TableTwo table = relay.GetTable("Table");
				Assert.AreEqual(5, table.GetRows().Length);
				
				Assert.AreEqual("kottar", table.GetRow(0).Get<string>("oldField"));
				Assert.AreEqual("stenar", table.GetRow(1).Get<string>("oldField"));
				Assert.AreEqual("gräs", table.GetRow(2).Get<string>("oldField"));
				
				Assert.AreEqual(500, table.GetRow(3).Get<int>("newField"));
				Assert.AreEqual(1000, table.GetRow(4).Get<int>("newField"));
			}
        }
Exemple #6
0
        public void MergeSaves()
        {
			{
	            RelayTwo relay = new RelayTwo();
				
				TableTwo table = relay.CreateTable("Table");
	
	            table.AddField<string>("name");
	
	            TableRow row1 = table.CreateRow();
	            TableRow row2 = table.CreateRow();
	            TableRow row3 = table.CreateRow();
	
	            row1.Set("name", "a");
	            row2.Set("name", "b");
				row3.Set("name", "c");
	
	            Assert.AreEqual(3, table.GetRows().Length);
				Assert.AreEqual("a", table.GetRow(0).Get<string>("name"));
				Assert.AreEqual("b", table.GetRow(1).Get<string>("name"));
				Assert.AreEqual("c", table.GetRow(2).Get<string>("name"));
	
	            RelayTwo save1 = relay.Subset("Table", (o => o.Get<string>("name") == "a"));
	            RelayTwo save2 = relay.Subset("Table", (o => o.Get<string>("name") == "b"));
				RelayTwo save3 = relay.Subset("Table", (o => o.Get<string>("name") == "c"));
				
				Assert.AreEqual(1, save1.GetTable("Table").GetRows().Length);
				Assert.AreEqual(1, save2.GetTable("Table").GetRows().Length);
				Assert.AreEqual(1, save3.GetTable("Table").GetRows().Length);
				
				save1.SaveAll("PartialSave1.json");
				save2.SaveAll("PartialSave2.json");
				save3.SaveAll("PartialSave3.json");
			}
			{
				RelayTwo relay = new RelayTwo();
				relay.MergeWith(new RelayTwo("PartialSave1.json"));
				relay.MergeWith(new RelayTwo("PartialSave2.json"));
				relay.MergeWith(new RelayTwo("PartialSave3.json"));
				
				TableTwo table = relay.GetTable("Table");
				Assert.AreEqual(3, table.GetRows().Length);
				
				Assert.AreEqual("a", table.GetRow(0).Get<string>("name"));
				Assert.AreEqual("b", table.GetRow(1).Get<string>("name"));
				Assert.AreEqual("c", table.GetRow(2).Get<string>("name"));
			}
        }