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 }
public void LoadFromSeveralPartialDatabases() { { RelayTwo r1 = new RelayTwo(); TableTwo t = r1.CreateTable("Table"); t.AddField<string>("animal"); t.AddField<int>("age"); TableRow row0 = t.CreateRow(); row0.Set("animal", "rabbit"); row0.Set("age", 5); TableRow row1 = t.CreateRow(); row1.Set("animal", "salmon"); row1.Set("age", 10); TableRow row2 = t.CreateRow(); row2.Set("animal", "spider"); row2.Set("age", 1); r1.SaveAll("r1.json"); } { RelayTwo r2 = new RelayTwo(); TableTwo t = r2.CreateTable("Table"); t.AddField<string>("animal"); t.AddField<bool>("carnivore"); TableRow row0 = t.CreateRow(); row0.Set("animal", "mouse"); row0.Set("carnivore", false); TableRow row1 = t.CreateRow(); row1.Set("animal", "fox"); row1.Set("carnivore", true); r2.SaveAll("r2.json"); } { RelayTwo combined = new RelayTwo(); combined.AppendTables("r1.json"); combined.AppendTables("r2.json"); Assert.AreEqual(1, combined.tables.Count); TableTwo t = combined.GetTable("Table"); Assert.AreEqual(3, t.fieldNames.Length); Console.WriteLine("The merged table contains the following rows: "); foreach(int rowIndex in t.GetIndexesOfPopulatedRows()) { TableRow row = t[rowIndex]; Console.WriteLine("Values in row " + rowIndex); foreach(string s in row.valuesAsStrings) { Console.Write(s + ", "); } Console.WriteLine("\n"); } Assert.AreEqual(5, t.GetIndexesOfPopulatedRows().Length); TableRow rabbit = t[0]; TableRow salmon = t[1]; TableRow spider = t[2]; TableRow mouse = t[3]; TableRow fox = t[4]; Assert.AreEqual("rabbit", rabbit.Get<string>("animal")); Assert.AreEqual("salmon", salmon.Get<string>("animal")); Assert.AreEqual("spider", spider.Get<string>("animal")); Assert.AreEqual("mouse", mouse.Get<string>("animal")); Assert.AreEqual("fox", fox.Get<string>("animal")); Assert.AreEqual(5, rabbit.Get<int>("age")); Assert.AreEqual(10, salmon.Get<int>("age")); Assert.AreEqual(1, spider.Get<int>("age")); Assert.Throws<RelayException>(() => { Assert.AreEqual(0, mouse.Get<int>("age")); }); Assert.Throws<RelayException>(() => { Assert.AreEqual(0, fox.Get<int>("age")); }); Assert.AreEqual(true, fox.Get<bool>("carnivore")); } }
public void LoadFromSeveralPartialDatabases() { { RelayTwo r1 = new RelayTwo(); TableTwo t = r1.CreateTable("Table"); t.AddField <string>("animal"); t.AddField <int>("age"); TableRow row0 = t.CreateRow(); row0.Set("animal", "rabbit"); row0.Set("age", 5); TableRow row1 = t.CreateRow(); row1.Set("animal", "salmon"); row1.Set("age", 10); TableRow row2 = t.CreateRow(); row2.Set("animal", "spider"); row2.Set("age", 1); r1.SaveAll("r1.json"); } { RelayTwo r2 = new RelayTwo(); TableTwo t = r2.CreateTable("Table"); t.AddField <string>("animal"); t.AddField <bool>("carnivore"); TableRow row0 = t.CreateRow(); row0.Set("animal", "mouse"); row0.Set("carnivore", false); TableRow row1 = t.CreateRow(); row1.Set("animal", "fox"); row1.Set("carnivore", true); r2.SaveAll("r2.json"); } { RelayTwo combined = new RelayTwo(); combined.AppendTables("r1.json"); combined.AppendTables("r2.json"); Assert.AreEqual(1, combined.tables.Count); TableTwo t = combined.GetTable("Table"); Assert.AreEqual(3, t.fieldNames.Length); Console.WriteLine("The merged table contains the following rows: "); foreach (int rowIndex in t.GetIndexesOfPopulatedRows()) { TableRow row = t[rowIndex]; Console.WriteLine("Values in row " + rowIndex); foreach (string s in row.valuesAsStrings) { Console.Write(s + ", "); } Console.WriteLine("\n"); } Assert.AreEqual(5, t.GetIndexesOfPopulatedRows().Length); TableRow rabbit = t[0]; TableRow salmon = t[1]; TableRow spider = t[2]; TableRow mouse = t[3]; TableRow fox = t[4]; Assert.AreEqual("rabbit", rabbit.Get <string>("animal")); Assert.AreEqual("salmon", salmon.Get <string>("animal")); Assert.AreEqual("spider", spider.Get <string>("animal")); Assert.AreEqual("mouse", mouse.Get <string>("animal")); Assert.AreEqual("fox", fox.Get <string>("animal")); Assert.AreEqual(5, rabbit.Get <int>("age")); Assert.AreEqual(10, salmon.Get <int>("age")); Assert.AreEqual(1, spider.Get <int>("age")); Assert.Throws <RelayException>(() => { Assert.AreEqual(0, mouse.Get <int>("age")); }); Assert.Throws <RelayException>(() => { Assert.AreEqual(0, fox.Get <int>("age")); }); Assert.AreEqual(true, fox.Get <bool>("carnivore")); } }