Esempio n. 1
0
 public static void LoadTest()
 {
     var fileContent =
         "id\ttype\texp\thp\tattack\nint\tint\tint\tint\tint\t\n1\t1\t100\t1\t1001\n2\t2\t1000\t1\t1002\n3\t3\t2000\t1\t1003\n4\t4\t3000\t1\t1004\n5\t5\t5000\t1\t1005\n6\t6\t6000\t1\t1006\n7\t7\t7000\t1\t1007\n8\t8\t8000\t1\t1008\n9\t9\t9000\t1\t1009\n10\t10\t10000\t1\t1010\n11\t11\t20000\t1\t1010\n12\t12\t40000\t1\t1010\n13\t13\t50000\t1\t1010\n14\t14\t70000\t1\t1010\n15\t15\t80000\t1\t1010\n16\t16\t90000\t1\t1010\n17\t17\t100000\t1\t1010\n18\t18\t122000\t1\t1010\n19\t19\t136000\t1\t1010\n20\t20\t150000\t1\t1010\n21\t21\t235000\t1\t1010\n22\t22\t320000\t1\t1010\n23\t23\t405000\t1\t1010\n24\t24\t490000\t1\t1010\n25\t25\t575000\t1\t1010\n26\t26\t660000\t1\t1010\n27\t27\t745000\t1\t1010\n28\t28\t830000\t1\t1010\n29\t29\t915000\t1\t1010\n30\t30\t1000000\t1\t1010\n31\t31\t1200000\t1\t1010\n32\t32\t1400000\t1\t1010\n33\t33\t1600000\t1\t1010\n34\t34\t1800000\t1\t1010\n35\t35\t2000000\t1\t1010\n36\t36\t2200000\t1\t1010\n37\t37\t2400000\t1\t1010\n38\t38\t2600000\t1\t1010\n39\t39\t2800000\t1\t1010\n40\t40\t3000000\t1\t1010\n41\t41\t3200000\t1\t1010\n42\t42\t3400000\t1\t1010\n43\t43\t3600000\t1\t1010\n44\t44\t3800000\t1\t1010\n45\t45\t4000000\t1\t1010\n46\t46\t4200000\t1\t1010\n47\t47\t4400000\t1\t1010\n48\t48\t4800000\t1\t1010\n49\t49\t5500000\t1\t1010\n50\t50\t6500000\t1\t1010\n51\t51\t7500000\t1\t1010\n52\t52\t9000000\t1\t1010\n53\t53\t12000000\t1\t1010\n54\t54\t15000000\t1\t1010\n55\t55\t18000000\t1\t1010\n56\t56\t21000000\t1\t1010\n57\t57\t24000000\t1\t1010\n58\t58\t27000000\t1\t1010\n59\t59\t30000000\t1\t1010\n60\t60\t34000000\t1\t1010\n61\t61\t38000000\t1\t1010\n62\t62\t42000000\t1\t1010\n63\t63\t46000000\t1\t1010\n64\t64\t50000000\t1\t1010\n65\t65\t54000000\t1\t1010\n66\t66\t58000000\t1\t1010\n67\t67\t62000000\t1\t1010\n68\t68\t66000000\t1\t1010\n69\t69\t70000000\t1\t1010\n70\t70\t75000000\t1\t1010\n71\t71\t80000000\t1\t1010\n72\t72\t85000000\t1\t1010\n73\t73\t100000000\t1\t1010\n74\t74\t115000000\t1\t1010\n75\t75\t130000000\t1\t1010\n76\t76\t145000000\t1\t1010\n77\t77\t160000000\t1\t1010\n78\t78\t175000000\t1\t1010\n79\t79\t195000000\t1\t1010\n80\t80\t215000000\t1\t1010\n81\t81\t250000000\t1\t1010\n82\t82\t280000000\t1\t1010\n83\t83\t310000000\t1\t1010\n84\t84\t350000000\t1\t1010\n85\t85\t390000000\t1\t1010\n86\t86\t440000000\t1\t1010\n87\t87\t624000000\t1\t1010\n88\t88\t780000000\t1\t1010\n89\t89\t952000000\t1\t1010\n90\t90\t1064000000\t1\t1010\n91\t91\t1848000000\t1\t1010\n92\t92\t1900000000\t1\t1010\n93\t93\t2088000000\t1\t1010\n94\t94\t2208000000\t1\t1010\n95\t95\t2328000000\t1\t1010\n96\t96\t2448000000\t1\t1010\n97\t97\t2568000000\t1\t1010\n98\t98\t2750000000\t1\t1010\n99\t99\t2900000000\t1\t1010\n100\t100\t3300000000\t1\t1010\n101\t101\t3700000000\t1\t1010\n102\t102\t4100000000\t1\t1010\n103\t103\t4500000000\t1\t1010\n104\t104\t4900000000\t1\t1010\n105\t105\t5300000000\t1\t1010\n106\t1\t1\t2\t1002\n107\t2\t2\t2\t1003\n108\t3\t3\t2\t1004\n109\t4\t4\t2\t1005\n110\t5\t5\t2\t1006\n111\t6\t6\t2\t1007\n112\t7\t7\t2\t1008\n113\t8\t8\t2\t1009\n114\t9\t9\t2\t1010\n115\t10\t10\t2\t1010\n116\t11\t11\t2\t1010\n117\t12\t12\t2\t1010\n118\t13\t13\t2\t1010\n119\t14\t14\t2\t1010\n120\t15\t15\t2\t1010\n121\t16\t16\t2\t1010\n122\t17\t17\t2\t1010\n123\t18\t18\t2\t1010\n124\t19\t19\t2\t1010\n125\t20\t20\t2\t1010\n126\t21\t21\t2\t1010\n127\t22\t22\t2\t1010\n128\t23\t23\t2\t1010\n129\t24\t24\t2\t1010\n130\t25\t25\t2\t1010\n131\t26\t26\t2\t1010\n132\t27\t27\t2\t1010\n133\t28\t28\t2\t1010\n134\t29\t29\t2\t1010\n135\t30\t30\t2\t1010\n136\t31\t31\t2\t1010\n137\t32\t32\t2\t1010\n138\t33\t33\t2\t1010\n139\t34\t34\t2\t1010\n140\t35\t35\t2\t1010\n141\t36\t36\t2\t1010\n142\t37\t37\t2\t1010\n143\t38\t38\t2\t1010\n144\t39\t39\t2\t1010\n145\t40\t40\t2\t1010\n146\t41\t41\t2\t1010\n147\t42\t42\t2\t1010\n148\t43\t43\t2\t1010\n149\t44\t44\t2\t1010\n150\t45\t45\t2\t1010\n151\t46\t46\t2\t1010\n152\t47\t47\t2\t1010\n153\t48\t48\t2\t1010\n154\t49\t49\t2\t1010\n155\t50\t50\t2\t1010\n156\t51\t51\t2\t1010\n157\t52\t52\t2\t1010\n158\t53\t53\t2\t1010\n159\t54\t54\t2\t1010\n160\t55\t55\t2\t1010\n161\t56\t56\t2\t1010\n162\t57\t57\t2\t1010\n163\t58\t58\t2\t1010\n164\t59\t59\t2\t1010\n165\t60\t60\t2\t1010\n166\t61\t61\t2\t1010\n167\t62\t62\t2\t1010\n168\t63\t63\t2\t1010\n169\t64\t64\t2\t1010\n170\t65\t65\t2\t1010\n171\t66\t66\t2\t1010\n172\t67\t67\t2\t1010\n173\t68\t68\t2\t1010\n174\t69\t69\t2\t1010\n175\t70\t70\t2\t1010\n176\t71\t71\t2\t1010\n177\t72\t72\t2\t1010\n178\t73\t73\t2\t1010\n179\t74\t74\t2\t1010\n180\t75\t75\t2\t1010\n181\t76\t76\t2\t1010\n182\t77\t77\t2\t1010\n183\t78\t78\t2\t1010\n184\t79\t79\t2\t1010\n185\t80\t80\t2\t1010\n186\t81\t81\t2\t1010\n187\t82\t82\t2\t1010\n188\t83\t83\t2\t1010\n189\t84\t84\t2\t1010\n190\t85\t85\t2\t1010\n191\t86\t86\t2\t1010\n192\t87\t87\t2\t1010\n193\t88\t88\t2\t1010\n194\t89\t89\t2\t1010\n195\t90\t90\t2\t1010\n196\t91\t91\t2\t1010\n197\t92\t92\t2\t1010\n198\t93\t93\t2\t1010\n199\t94\t94\t2\t1010\n200\t95\t95\t2\t1010\n201\t96\t96\t2\t1010\n202\t97\t97\t2\t1010\n203\t98\t98\t2\t1010\n204\t99\t99\t2\t1010\n205\t100\t100\t2\t1010\n206\t101\t101\t2\t1010\n207\t102\t102\t2\t1010\n208\t103\t103\t2\t1010\n209\t104\t104\t2\t1010\n210\t105\t105\t2\t1010";
     var tab = TableFile.LoadFromString(fileContent);
     var aa  = tab;
 }
Esempio n. 2
0
        public async Task ExecuteInsertObject(TableFile tableFile, string insertStatement, Dictionary <string, string> ParameterMap, string connStr, int numStatements, int start, int total)
        {
            SqlCommand command;

            try
            {
                using (var conn = new SqlConnection(connStr))
                {
                    using (command = new SqlCommand(insertStatement, conn))
                    {
                        for (int i = start; i < start + numStatements; i++)
                        {
                            if (i > total)
                            {
                                break;
                            }
                            for (int j = 0; j < tableFile.Columns.Count; j++)
                            {
                                command.Parameters.AddWithValue("@" + i.ToString() + tableFile.Columns[j].Pseudonym.Replace("-", ""),
                                                                ((object)ParameterMap["@" + i.ToString() + tableFile.Columns[j].Pseudonym.Replace("-", "")]) ?? DBNull.Value);
                            }
                        }

                        await conn.OpenAsync();

                        await command.ExecuteNonQueryAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 3
0
        private static async Task SpeedTestSingleThreadedSearchFile()
        {
            var tempPath    = System.IO.Path.GetTempPath();
            var fileName    = System.IO.Path.Combine(tempPath, "Level1_1.trim");
            var loadedWords = await System.IO.File.ReadAllLinesAsync("words.txt");


            using (var blockCache = new ProtoBlockCache(10000))
            {
                var loadedTable = new TableFile(fileName, blockCache);
                await loadedTable.LoadAsync();

                // Check we can get the values back out

                var hash = new MurmurHash3();

                var sw = Stopwatch.StartNew();
                foreach (var word in loadedWords)
                {
                    var utf8 = Encoding.UTF8.GetBytes(word);
                    var h    = hash.ComputeHash64(utf8);

                    var result = await loadedTable.GetAsync(utf8, h);

                    var resultAsString = Encoding.UTF8.GetString(result.Value.Span);
                }
                sw.Stop();
                Console.WriteLine($"Total time taken {sw.ElapsedMilliseconds} time per key {(double)sw.ElapsedMilliseconds / loadedWords.Length}");
            }
        }
Esempio n. 4
0
        public void TestMultString()
        {
            var table = TableFile.LoadFromString(TableString1, TableString2);
            var row   = table.GetByPrimaryKey("1");

            Assert.AreEqual("hi", row["Value"]);
        }
        /// <summary>
        /// 收集StringsTalbe.bytes的字符串
        /// </summary>
        /// <param name="refItems"></param>
        static void CollectStringsTable(ref I18NItems refItems)
        {
            var compilePath = AppEngine.GetConfig("KEngine.Setting", "SettingCompiledPath");
            var ext = AppEngine.GetConfig("KEngine", "AssetBundleExt");
            var stringsTablePath = string.Format("{0}/StringsTable{1}", compilePath, ext);
            if (!File.Exists(stringsTablePath))
                return;

            string stringsTableContent;
            using (var stream = new FileStream(stringsTablePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(stream))
                {
                    stringsTableContent = reader.ReadToEnd();
                }
            }

            var tableFile = new TableFile(stringsTableContent);
            foreach (var row in tableFile)
            {
                var srcStr = row["Id"];
                refItems.Add(srcStr, stringsTablePath);
            }
            Debug.Log("[CollectStringsTable]Success!");
        }
Esempio n. 6
0
        private void createHTMLDumpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TableFile file = (tvMessageFiles.SelectedNode.Tag as TableFile);

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.InitialDirectory = Configuration.LastDataPath;
            sfd.Title            = "Save HTML dump";
            sfd.Filter           = "HTML Files (*.htm;*.html)|*.htm;*.html";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                List <TableFile> files = new List <TableFile>();
                files.Add(file);

                if (gameDataManager.Version == GameDataManager.Versions.European &&
                    MessageBox.Show("Fetch every language version of this file to dump?", "Language Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    string strippedName = Path.GetFileNameWithoutExtension(file.Filename);
                    foreach (KeyValuePair <GameDataManager.Languages, string> pair in gameDataManager.LanguageSuffixes)
                    {
                        strippedName = strippedName.Replace(pair.Value, "");
                    }

                    files.AddRange(gameDataManager.MessageFiles
                                   .Where(x => Path.GetFileNameWithoutExtension(x.Filename).StartsWith(strippedName) && x.Filename != file.Filename && x.FileNumber == file.FileNumber));
                }

                DataDumpers.DumpMessages(gameDataManager, files, sfd.FileName);
            }
        }
Esempio n. 7
0
        public void CanAddAndRemoveNewEntryInTableFile()
        {
            string[] newEntry = new string[] { "UnitTestKey", "UnitTestValue1", "UnitTestValue2" };

            TableFile tempFile = new TableFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.TABLE_FILENAME));
            {// ADD ENTRY
                Assert.IsFalse(tempFile.KeyExists(newEntry[0]));
                tempFile.Add(newEntry);
                Assert.IsTrue(tempFile.KeyExists(newEntry[0]));
            }
            {// COMMIT
                TableFile tempFile2 = new TableFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.TABLE_FILENAME));
                Assert.IsFalse(tempFile2.KeyExists(newEntry[0]));
                tempFile.Commit();
                Assert.IsTrue(tempFile.KeyExists(newEntry[0]));
                TableFile tempFile3 = new TableFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.TABLE_FILENAME));
                Assert.IsTrue(tempFile3.KeyExists(newEntry[0]));
                Assert.IsTrue(tempFile3.Data.Contains(string.Concat(newEntry[0], "|!|", newEntry[1], "|!|", newEntry[2])));
            }
            {// REMOVE ENTRY
                TableFile tempFile4 = new TableFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.TABLE_FILENAME));
                Assert.IsTrue(tempFile4.KeyExists(newEntry[0]));
                tempFile4.Remove(newEntry[0]);
                Assert.IsFalse(tempFile4.KeyExists(newEntry[0]));
                TableFile tempFile5 = new TableFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.TABLE_FILENAME));
                Assert.IsTrue(tempFile5.KeyExists(newEntry[0]));
                tempFile4.Commit();
                TableFile tempFile6 = new TableFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.TABLE_FILENAME));
                Assert.IsFalse(tempFile6.KeyExists(newEntry[0]));
            }
        }
Esempio n. 8
0
        public void TestSaveMethod()
        {
            TableFile tableFile = new TableFile();

            tableFile.Load(TEST_FILE);

            MemoryStream savedStream = new MemoryStream();

            tableFile.Save(savedStream);

            savedStream.Seek(0, SeekOrigin.Begin);

            TableFile savedTableFile = new TableFile();

            savedTableFile.Load(savedStream);

            savedStream.Close();

            Assert.AreEqual(tableFile.MaximumRange, savedTableFile.MaximumRange, "Maximum range does not match");

            for (int i = 0; i < tableFile.MaximumRange; i++)
            {
                Assert.AreEqual(tableFile.StartIndices[i], tableFile.StartIndices[i], "Start index does not match");
                Assert.AreEqual(tableFile.IndexCounts[i], tableFile.IndexCounts[i], "Index count does not match");
            }

            Assert.AreEqual(tableFile.Points.Count, savedTableFile.Points.Count, "Points count does not match");

            for (int i = 0; i < tableFile.Points.Count; i++)
            {
                Assert.AreEqual(tableFile.Points[i].X, tableFile.Points[i].X, "Points do not match");
                Assert.AreEqual(tableFile.Points[i].Y, tableFile.Points[i].Y, "Points do not match");
            }
        }
Esempio n. 9
0
        public async Task <List <TableFile> > GetTableFiles(string connStr)
        {
            try
            {
                var data = new List <TableFile>();
                using (var conn = new SqlConnection(connStr))

                    using (var command = new SqlCommand("GetTables", conn))
                    {
                        command.CommandType = CommandType.StoredProcedure;

                        await conn.OpenAsync();

                        var rdr = await command.ExecuteReaderAsync();

                        while (await rdr.ReadAsync())
                        {
                            TableFile tb = new TableFile();

                            tb.TableName    = Convert.ToString(rdr["DataSetTitle"]);
                            tb.TableGuid    = Convert.ToString(rdr["TableGuid"]);
                            tb.DataSetTitle = Convert.ToString(rdr["DataSetTitle"]);
                            tb.Description  = Convert.ToString(rdr["Description"]);

                            data.Add(tb);
                        }
                    }
                return(data);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 10
0
        public void GlobalSetup()
        {
            if (Directory.Exists(_outputFolder))
            {
                Directory.Delete(_outputFolder, true);
            }
            Directory.CreateDirectory(_outputFolder);

            var dbFolder  = "D:\\stress";
            var dbOptions = new TrimDatabaseOptions();


            _cache = dbOptions.BlockCache();
            var filenames = Directory.GetFiles(dbFolder);

            _tableFiles = new TableFile[filenames.Length];

            _storageLayer = new SortedStorageLayer(5, _outputFolder, _cache, 10 * 1024 * 1024, 100);

            for (var i = 0; i < _tableFiles.Length; i++)
            {
                var tf = new TableFile(filenames[i], _cache);
                tf.LoadAsync().Wait();
                _tableFiles[i] = tf;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 收集StringsTalbe.bytes的字符串
        /// </summary>
        /// <param name="refItems"></param>
        static void CollectStringsTable(ref I18NItems refItems)
        {
            var compilePath      = AppEngine.GetConfig("KEngine.Setting", "SettingCompiledPath");
            var ext              = AppEngine.GetConfig("KEngine", "AssetBundleExt");
            var stringsTablePath = string.Format("{0}/StringsTable{1}", compilePath, ext);

            if (!File.Exists(stringsTablePath))
            {
                return;
            }

            string stringsTableContent;

            using (var stream = new FileStream(stringsTablePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(stream))
                {
                    stringsTableContent = reader.ReadToEnd();
                }
            }

            var tableFile = new TableFile(stringsTableContent);

            foreach (var row in tableFile)
            {
                var srcStr = row["Id"];
                refItems.Add(srcStr, stringsTablePath);
            }
            Debug.Log("[CollectStringsTable]Success!");
        }
Esempio n. 12
0
        public StorageLayer(string databaseFolder, int level, BlockCache blockCache, int targetFileSize)
        {
            MaxFileSize     = targetFileSize;
            _databaseFolder = databaseFolder;
            _level          = level;
            _blockCache     = blockCache;

            var levelFiles = System.IO.Directory.GetFiles(_databaseFolder, $"Level{level}_*.trim");

            _tableFiles       = new TableFile[levelFiles.Length];
            _tableFileIndices = new int[levelFiles.Length];

            if (_tableFiles.Length > 0)
            {
                for (var i = 0; i < _tableFiles.Length; i++)
                {
                    var table = new TableFile(levelFiles[i], _blockCache);
                    if (table.FileId.Level != level)
                    {
                        throw new InvalidOperationException();
                    }
                    _tableFileIndices[i] = table.FileId.FileId;
                    _tableFiles[i]       = table;
                }

                Array.Sort(_tableFileIndices, _tableFiles);
                _maxFileIndex = _tableFileIndices[^ 1];
Esempio n. 13
0
 public File(TableFile file)
 {
     Name        = file.Name;
     Title       = file.Title;
     Description = file.Description;
     Video_Url   = file.Video_Url;
     File_Url    = file.File_Url;
 }
Esempio n. 14
0
        public void GlobalSetup()
        {
            _cache = new ProtoBlockCache(10);
            var tempPath = System.IO.Path.GetTempPath();
            var fileName = System.IO.Path.Combine(tempPath, "Level1_1.trim");

            _file = new TableFile(fileName, _cache);
            _file.LoadAsync().Wait();
        }
Esempio n. 15
0
        public void ReadCompliedTsvWithClass()
        {
            var tabFile = TableFile <TestExcelInfo> .LoadFromFile("./test_excel.bytes");

            var config = tabFile.FindByPrimaryKey(1);

            Assert.IsNotNull(config);
            Assert.AreEqual(config.Name, "Test1");
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return;
            }

            string srcDir = Utils.AbstractPath(options.InputDirectory);
            string dstDir = Utils.AbstractPath(options.OutputDirectory);

            if (!Directory.Exists(srcDir))
            {
                Console.WriteLine("目录{0}不存在!", srcDir);
                return;
            }

            try
            {
                List <TableFile> list = new List <TableFile>();
                var files             = Utils.GetAllFiles(srcDir, "*.xls");
                foreach (var file in files)
                {
                    TableFile excel = TableFile.Create(file.FullName);
                    if (excel == null)
                    {
                        break;
                    }

                    string dstFile = Path.Combine(dstDir, Path.GetFileNameWithoutExtension(file.Name)) + ".txt";
                    bool   ok      = excel.SaveToTSV(dstFile);
                    if (!ok)
                    {
                        break;
                    }
                    Console.WriteLine("输出文件:{0}", dstFile);
                    list.Add(excel);
                }
                if (!string.IsNullOrEmpty(options.SharpOutputDirectory))
                {
                    if (options.IsAnnotation)
                    {
                        Generator.Configuration.USE_ANNOTATION = true;
                    }
                    string sharpDir = Utils.AbstractPath(options.SharpOutputDirectory);
                    new Generator(list.ToArray()).DoGenerateAll(sharpDir);
                    Console.WriteLine("\n输出CSharp文件到目录 :{0} ", sharpDir);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="_f"></param>
 /// <param name="_name"></param>
 public Container_file(TableFile _f, string _name)
 {
     File     = _f;
     Name     = _name;
     Stream   = null;
     Rstream  = null;
     Cat      = null;
     Packed   = table_file_packed.unknown;
     Dynno    = -3;
     temppath = "";
 }
Esempio n. 18
0
        public void CommandLine1()
        {
            CommandProgram.Run(new string[]
            {
                "-Folder", "./*.xls"
            });
            Assert.IsTrue(File.Exists("TabConfigs.cs"));
            var table = TableFile.LoadFromFile("./test_excel.bytes");

            ReadCompliedTsv();
        }
Esempio n. 19
0
        public void TestWrite()
        {
            var tableObj = TableFile.LoadFromString(TableString1, TableString2);
            var writer   = new TableFileWriter(tableObj);

            Assert.AreEqual(true, writer.Save("write.txt"));
            var result = File.ReadAllText("write.txt");
            var expect = TableString1Plus2.Replace("\r", "");

            Assert.AreEqual(expect, result);
        }
Esempio n. 20
0
        public TableFile GetMessageFile(string filename)
        {
            filename = (Version == Versions.European ? string.Format("{0}{1}", filename, LanguageSuffixes[Language]) : filename);
            TableFile messageFile = MessageFiles.FirstOrDefault(x => x.Filename != null && Path.GetFileName(x.Filename).StartsWith(filename));

            if (messageFile == null)
            {
                throw new ArgumentException("Message file could not be found");
            }
            return(messageFile);
        }
Esempio n. 21
0
        public void ReadCompliedTsv()
        {
            var tabFile = TableFile.LoadFromFile("./test_excel.bytes");

            Assert.AreEqual <int>(3, tabFile.GetColumnCount());

            var headerNames = tabFile.HeaderNames.ToArray();

            Assert.AreEqual("Id", headerNames[0]);
            Assert.AreEqual("Name", headerNames[1]);
            Assert.AreEqual("StrArray", headerNames[2]);
        }
Esempio n. 22
0
        /// <summary>
        /// 通过SettingModule拥有缓存与惰式加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="useCache">是否缓存起来?还是单独创建新的</param>
        /// <returns></returns>
        public TableFile GetTableFile(string path, bool useCache = false)
        {
            object tableFile;

            if (!useCache || !_tableFilesCache.TryGetValue(path, out tableFile))
            {
                var fileContent = LoadSetting(path);
                var tab         = TableFile.LoadFromString(fileContent);
                _tableFilesCache[path] = tableFile = tab;
                return(tab);
            }

            return(tableFile as TableFile);
        }
Esempio n. 23
0
        /// <summary>
        /// Do reload the dataTable file: Test
        /// </summary>
        void _ReloadAll(bool throwWhenDuplicatePrimaryKey, string customContent = null)
        {
            for (var j = 0; j < TabFilePaths.Length; j++)
            {
                var       tabFilePath = TabFilePaths[j];
                TableFile tableFile;
                if (customContent == null)
                {
                    tableFile = DataTableModule.Get(tabFilePath, false);
                }
                else
                {
                    tableFile = TableFile.LoadFromString(customContent);
                }

                using (tableFile)
                {
                    foreach (var row in tableFile)
                    {
                        var           pk = TestDataTable.ParsePrimaryKey(row);
                        TestDataTable dataTable;
                        if (!_dict.TryGetValue(pk, out dataTable))
                        {
                            dataTable           = new TestDataTable(row);
                            _dict[dataTable.Id] = dataTable;
                        }
                        else
                        {
                            if (throwWhenDuplicatePrimaryKey)
                            {
                                throw new System.Exception(string.Format("DuplicateKey, Class: {0}, File: {1}, Key: {2}", this.GetType().Name, tabFilePath, pk));
                            }
                            else
                            {
                                dataTable.Reload(row);
                            }
                        }
                    }
                }
            }

            if (OnReload != null)
            {
                OnReload();
            }

            ReloadCount++;
            UnityEngine.Debug.LogFormat("Reload dataTables: {0}, Row Count: {1}, Reload Count: {2}", GetType(), Count, ReloadCount);
        }
Esempio n. 24
0
        /// <summary>
        /// Do reload the setting file: GameConfig
        /// </summary>
        void _ReloadAll(bool throwWhenDuplicatePrimaryKey, string customContent = null)
        {
            for (var j = 0; j < TabFilePaths.Length; j++)
            {
                var       tabFilePath = TabFilePaths[j];
                TableFile tableFile;
                if (customContent == null)
                {
                    tableFile = SettingModule.Get(tabFilePath, false);
                }
                else
                {
                    tableFile = TableFile.LoadFromString(customContent);
                }

                using (tableFile)
                {
                    foreach (var row in tableFile)
                    {
                        var pk = GameConfigSetting.ParsePrimaryKey(row);
                        GameConfigSetting setting;
                        if (!_dict.TryGetValue(pk, out setting))
                        {
                            setting           = new GameConfigSetting(row);
                            _dict[setting.Id] = setting;
                        }
                        else
                        {
                            if (throwWhenDuplicatePrimaryKey)
                            {
                                throw new System.Exception(string.Format("DuplicateKey, Class: {0}, File: {1}, Key: {2}", this.GetType().Name, tabFilePath, pk));
                            }
                            else
                            {
                                setting.Reload(row);
                            }
                        }
                    }
                }
            }

            if (OnReload != null)
            {
                OnReload();
            }

            ReloadCount++;
            Log.Info("Reload settings: {0}, Row Count: {1}, Reload Count: {2}", GetType(), Count, ReloadCount);
        }
Esempio n. 25
0
        public void TestRemoveRowTableFile1()
        {
            var tabFileWrite = new TabFileWriter <TestWrite>();
            var newRow       = tabFileWrite.NewRow();

            newRow.TestColumn1 = "Test String";
            newRow.TestColumn2 = 123123;
            tabFileWrite.RemoveRow(newRow.RowNumber);  // remove row 1
            tabFileWrite.Save("./test_write.bytes");


            var tabFileRead = TableFile <TestWrite> .LoadFromFile("./test_write.bytes");

            Assert.AreEqual(tabFileRead.GetHeight(), 0);
        }
Esempio n. 26
0
        public async Task WriteAndReadFile()
        {
            using var allocator = new NativeAllocator64(4096 * 10_000, 25);
            var memoryTable = new SkipList64(allocator);

            var loadedWords = CommonData.Words;

            foreach (var word in loadedWords)
            {
                if (string.IsNullOrEmpty(word))
                {
                    continue;
                }
                var utf8  = Encoding.UTF8.GetBytes(word);
                var value = Encoding.UTF8.GetBytes($"VALUE={word}");
                memoryTable.Put(utf8, value);
            }

            var tempPath = System.IO.Path.GetTempPath();
            var fileName = System.IO.Path.Combine(tempPath, "Level1_1.trim");

            System.IO.File.Delete(fileName);

            var fw = new TableFileWriter(fileName);
            await fw.SaveMemoryTable(memoryTable);

            using (var blockCache = new MMapBlockCache())
            {
                var loadedTable = new TableFile(fileName, blockCache);
                await loadedTable.LoadAsync();

                // Check we can get the values back out

                var hash = new MurmurHash3();
                foreach (var word in loadedWords)
                {
                    var utf8  = Encoding.UTF8.GetBytes(word);
                    var value = Encoding.UTF8.GetBytes($"VALUE={word}");
                    var h     = hash.ComputeHash64(utf8);

                    var result = await loadedTable.GetAsync(utf8, h);

                    Assert.Equal(SearchResult.Found, result.Result);
                    Assert.Equal(value, result.Value.ToArray());
                }
            }
            System.IO.File.Delete(fileName);
        }
Esempio n. 27
0
        /// <summary>
        /// 通过SettingModule拥有缓存与惰式加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="useCache">是否缓存起来?还是单独创建新的</param>
        /// <returns></returns>
        public static TableFile Get(string path, bool useCache = true)
        {
            object tableFile;

            if (!useCache || !_tableFilesCache.TryGetValue(path, out tableFile))
            {
                var fileContentAsset = Resources.Load("Setting/" + Path.GetFileNameWithoutExtension(path)) as TextAsset;
                var fileContent      = Encoding.UTF8.GetString(fileContentAsset.bytes);

                var tab = TableFile.LoadFromString(fileContent);
                _tableFilesCache[path] = tableFile = tab;
                return(tab);
            }

            return(tableFile as TableFile);
        }
Esempio n. 28
0
        public void TestWriteTableFile2()
        {
            var tabFile = TableFile <TestWrite> .LoadFromFile("./test_write.bytes");

            var tabFileWrite = new TabFileWriter <TestWrite>(tabFile);

            var newRow = tabFileWrite.NewRow();

            newRow.TestColumn1 = Path.GetRandomFileName();
            newRow.TestColumn2 = new Random().Next();


            // 两个方法执行后
            Assert.AreEqual(tabFile.GetHeight(), 2);

            tabFileWrite.Save("./test_write.bytes");
        }
Esempio n. 29
0
        public void TableLine2Matches()
        {
            string    expectedLine = "\"SecondRowValue1\"|!|\"SecondRowValue2\"|!|\"SecondRowValue3\"";
            TableFile file         = new TableFile(string.Concat(Constants.TestData.DBFILEPATHS[2]));

            Assert.AreEqual(expectedLine, file.Data[1]);

            IList <string> expectedCellValues = new List <string> {
                "SecondRowValue1", "SecondRowValue2", "SecondRowValue3"
            };

            Assert.AreEqual(expectedCellValues.Count, file.TableRows[1].Count);
            for (int i = 0; i < expectedCellValues.Count; i++)
            {
                Assert.AreEqual(expectedCellValues[i], file.TableRows[1][i]);
            }
        }
Esempio n. 30
0
        private void ParseTsv(string filePath)
        {
            _tableFile   = TableFile.LoadFromFile(filePath, Encoding.GetEncoding("GBK"));
            _columnCount = _tableFile.GetColumnCount();


            // 通过TableFile注册头信息
            var commentRow = _tableFile.GetRow(1);

            foreach (var kv in _tableFile.Headers)
            {
                var header = kv.Value;
                ColName2Index[header.HeaderName]     = header.ColumnIndex;
                Index2ColName[header.ColumnIndex]    = header.HeaderName;
                ColName2Statement[header.HeaderName] = header.HeaderMeta;
                ColName2Comment[header.HeaderName]   = commentRow[header.ColumnIndex];
            }
        }
Esempio n. 31
0
        private Dictionary <ushort, string> GenerateStringDictionary(string filename, int tableNo)
        {
            loadWaitWorker.ReportProgress(-1, string.Format("Generating dictionary for {0}, table {1}...", filename, tableNo));

            Dictionary <ushort, string> dict = new Dictionary <ushort, string>();

            dict.Add(0, "(None)");

            TableFile    messageFile  = GetMessageFile(filename);
            MessageTable messageTable = (messageFile.Tables[tableNo] as MessageTable);

            for (ushort number = 1; number <= messageTable.NumMessages; number++)
            {
                dict.Add(number, messageTable.Messages[number - 1].ConvertedString);
            }

            return(dict);
        }
Esempio n. 32
0
        /// <summary>
        /// Ensure the CEngineConfig file loaded.
        /// </summary>
        public static TableFile<CCosmosEngineInfo> EnsureConfigTab(bool reload = false)
        {
            if (_configsTable == null || reload)
            {
                string configContent;
                if (Application.isEditor && !Application.isPlaying)
                {
                    // prevent Resources.Load fail on Batch Mode
                    configContent = System.IO.File.ReadAllText("Assets/Resources/KEngineConfig.txt");
                }
                else
                {
                    var textAsset = Resources.Load<TextAsset>("KEngineConfig");
                    Logger.Assert(textAsset);
                    configContent = textAsset.text;
                }

                _configsTable = new TableFile<CCosmosEngineInfo>(new TableFileConfig
                {
                    Content = configContent, 
                    OnExceptionEvent = (ex, args) =>
                    {
                        if (ex != TableFileExceptionType.DuplicatedKey)
                        {
                            var sb = new StringBuilder();
                            sb.Append(ex.ToString());
                            sb.Append(": ");
                            foreach (var s in args)
                            {
                                sb.Append(s);
                                sb.Append(", ");
                            }
                            throw new Exception(sb.ToString());
                        }
                    },
                });
            }
            return _configsTable;
        }
Esempio n. 33
0
 public TabFileWriter()
 {
     TabFile = new TableFile();
 }
Esempio n. 34
0
 public TabFileWriter(TableFile tabFile)
 {
     TabFile = tabFile;
 }
Esempio n. 35
0
        /// <summary>
        /// Ensure the CEngineConfig file loaded.
        /// </summary>
        public static TableFile<CCosmosEngineInfo> EnsureConfigTab(bool reload = false)
        {
            if (_configsTable == null || reload)
            {
                TextAsset textAsset;
                textAsset = Resources.Load<TextAsset>("CEngineConfig");

                CDebug.Assert(textAsset);
                _configsTable = new TableFile<CCosmosEngineInfo>(new TableFileConfig
                {
                    Content = textAsset.text,
                    OnExceptionEvent = (ex, args) =>
                    {
                        if (ex != TableFileExceptionType.DuplicatedKey)
                        {
                            throw new Exception(ex.ToString());
                        }
                    },

                });
            }
            return _configsTable;
        }
Esempio n. 36
0
        /// <summary>
        /// Ensure the CEngineConfig file loaded.
        /// </summary>
        static void EnsureConfigTab()
        {
            if (Confs == null)
            {
                TextAsset textAsset;
                textAsset = Resources.Load<TextAsset>("CEngineConfig");

                CDebug.Assert(textAsset);
                Confs = new TableFile<CCosmosEngineConfig>(new TableFileConfig
                {
                    Content = textAsset.text,
                    OnExceptionEvent = (ex, args) =>
                    {
                        if (ex != TableFileExceptionType.DuplicatedKey)
                        {
                            throw new Exception(ex.ToString());
                        }
                    },

                });
            }
        }