Exemple #1
0
        public void CanCreateIndexOnFilledTable()
        {
            var recordFile = new RecordFile(tableInfo, _transaction);

            recordFile.BeforeFirst();
            for (int i = 0; i < 10; ++i)
            {
                recordFile.Insert();
                recordFile.SetInt("Id", i - 1);
            }
            recordFile.Close();

            metadataManager = new MetadataManager(_fileManager, tableManager, viewManager, indexManager, statisticsManager);

            Assert.DoesNotThrow(() =>
            {
                metadataManager.CreateIndex(RandomFilename, tableName, "Id", _transaction);
            });

            var index = metadataManager.GetIndexInfo(tableName, _transaction);

            Assert.IsNotNull(index);
            Assert.AreEqual(0, index["Id"].BlocksAccessed());
            Assert.AreEqual(2, index["Id"].RecordsOutput());
        }
Exemple #2
0
        public void CanGetStatisticsFromNewTableInTheSameTransaction()
        {
            manager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 1);


            var newTableName = RandomFilename;

            var schema = new Schema();

            schema.AddIntField("Id");
            schema.AddStringField("Guid", 40);

            var newTableInfo = new TableInfo(newTableName, schema);

            tableManager.CreateTable(newTableName, schema, _transaction);

            var recordFile = new RecordFile(newTableInfo, _transaction);

            recordFile.BeforeFirst();

            for (int i = 0; i < 50; ++i)
            {
                recordFile.Insert();
                recordFile.SetInt("Id", i + 10);
                recordFile.SetString("Guid", Guid.NewGuid().ToString());
            }

            var updatedData = manager.GetStatisticalInfo(newTableName, _transaction);

            Assert.AreEqual(50, updatedData.RecordsOutput);
            Assert.AreEqual(3, updatedData.BlocksAccessed);
            Assert.AreEqual(17, updatedData.DistinctValues("Id"));
        }
        private void JudgeSelect()
        {
            IList <RecordFile> files = (IList <RecordFile>)gridControl1.DataSource;

            if (files == null)
            {
                wizardPage1.AllowNext = false;
                return;
            }
            bool selectOne = false;

            for (int i = 0; i < files.Count; i++)
            {
                RecordFile f = files[i];
                selectOne = f.Select;

                if (selectOne)
                {
                    break;
                }
            }
            if (string.IsNullOrEmpty(textEdit1.Text))
            {
                wizardPage1.AllowNext = false;
            }
            else
            {
                wizardPage1.AllowNext = selectOne;
            }
        }
Exemple #4
0
        public void CanGetStatisticsFromTableFilledWithValuesInTheSameTransaction()
        {
            manager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 1);

            var data = manager.GetStatisticalInfo(tableName, _transaction);

            var recordFile = new RecordFile(tableInfo, _transaction);

            recordFile.BeforeFirst();

            for (int i = 0; i < 30; ++i)
            {
                recordFile.Insert();
                recordFile.SetInt("Id", i + 10);
            }

            //Before update

            Assert.AreEqual(1, data.BlocksAccessed);
            Assert.AreEqual(0, data.RecordsOutput);

            Assert.AreEqual(1, data.DistinctValues("Id"));

            //After update
            var updatedData = manager.GetStatisticalInfo(tableName, _transaction);

            Assert.AreEqual(30, updatedData.RecordsOutput);
            Assert.AreEqual(1, updatedData.BlocksAccessed);
            Assert.AreEqual(11, updatedData.DistinctValues("Id"));
        }
Exemple #5
0
 public TableScan(
     TableInfo tableInfo,
     Transaction transaction)
 {
     _recordFile = new RecordFile(tableInfo, transaction);
     _schema     = tableInfo.Schema;
 }
Exemple #6
0
        private StatisticalInfo RefreshTableStatistics(string tableName, Transaction transaction)
        {
            var recordsCount = 0;

            var tableInfo = _tableManager.GetTableInfo(tableName, transaction);

            if (tableInfo == null)
            {
                return(null);
            }

            var recordFile = new RecordFile(tableInfo, transaction);

            recordFile.BeforeFirst();

            while (recordFile.Next())
            {
                recordsCount++;
            }

            int blockNumber = recordFile.CurrentRID.BlockNumber;

            recordFile.Close();

            int blocksCount = 1 + blockNumber;
            var statInfo    = new StatisticalInfo(blocksCount, recordsCount);

            _tableStats.Add(tableName, statInfo);
            return(statInfo);
        }
Exemple #7
0
        public void CanCreateViewDefinition()
        {
            var viewMetadataStorageFilename = RandomFilename;

            viewManager = new ViewManager(true, tableManager, _transaction, viewMetadataStorageFilename);

            viewManager.CreateView("view1", "viewDefinition1", _transaction);

            _transaction.Commit();

            var schema = new Schema();

            schema.AddStringField("viewname", ViewManager.MAX_VIEW_LENGTH);
            schema.AddStringField("viewdef", ViewManager.MAX_VIEW_LENGTH);

            var viewTableInfo = tableManager.GetTableInfo(viewMetadataStorageFilename, _transaction);
            var viewTableCatalogRecordPage = new RecordFile(viewTableInfo, _transaction);

            viewTableCatalogRecordPage.BeforeFirst();
            viewTableCatalogRecordPage.Next();

            var viewName       = viewTableCatalogRecordPage.GetString("viewname");
            var viewDefinition = viewTableCatalogRecordPage.GetString("viewdef");

            Assert.AreEqual("view1", viewName);
            Assert.AreEqual("viewDefinition1", viewDefinition);
        }
        public SelectChannel(RecordDisk disk, int channel, int index)
        {
            this.file        = disk.RecordList[index - 1];
            this.channel     = channel;
            this.RecordIndex = index;
            this.BeginTime   = file.BeginTime.ToString("yyyy-MM-dd HH:mm:ss");
            this.EndTime     = file.EndTime.ToString("yyyy-MM-dd HH:mm:ss");

            int seconds = 0;

            if (file.EndTime > file.BeginTime)
            {
                seconds        = (int)((file.EndTime - file.BeginTime).TotalSeconds);
                this.RecordSec = seconds;
                int h = seconds / (3600);
                int m = (seconds - h * (3600)) / 60;
                int s = seconds - h * (3600) - m * 60;

                this.TimeLength = h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
            }
            else
            {
                this.TimeLength = "---";
            }


            this.Channel     = channel;
            this.ChannelName = file.Channels[channel - 1].ChannelName;
            this.ModuleID    = file.RecordDevice.DeviceInfo.DevCode + ":" + file.RecordDevice.DeviceInfo.ID;
            this.TimeCal     = file.Channels[channel - 1].Time;
        }
Exemple #9
0
        public void createTable(string tblname, Schema sch, Transaction tx)
        {//创建一个新表,有指定的表名称、模式信息
            TableInfo ti = new TableInfo(tblname, sch);
            //往tblcat表中插入一条记录
            RecordFile tcatfile = new RecordFile(tcatInfo, tx);

            tcatfile.insert();
            tcatfile.setString("tblname", tblname);
            tcatfile.setInt("reclength", ti.recordLength());
            tcatfile.close();

            //往fldcat表中插入记录:每个字段的信息
            RecordFile fcatfile = new RecordFile(fcatInfo, tx);

            foreach (string fldname in sch.fields())
            {
                fcatfile.insert();
                fcatfile.setString("tblname", tblname);
                fcatfile.setString("fldname", fldname);
                fcatfile.setInt("type", sch.type(fldname));
                fcatfile.setInt("length", sch.length(fldname));
                fcatfile.setInt("offset", ti.offset(fldname));
            }
            fcatfile.close();
        }
Exemple #10
0
        public void CanDeleteRecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

            schema.AddIntField("field");
            _tableInfo = new TableInfo(tableFile, schema);

            _recordFile = new RecordFile(_tableInfo, _transaction);

            _recordFile.BeforeFirst();

            _recordFile.Insert();
            _recordFile.SetInt("field", 10);

            _recordFile.Delete();

            _transaction.Commit();

            var block = new IO.Primitives.Block(tableFile + ".tbl", 0);
            var page  = _fileManager.ResolvePage(block);

            page.Read(block);

            page.GetInt(0, out var used);
            Assert.AreEqual(0, used);
        }
Exemple #11
0
        public TableInfo getTableInfo(string tblname, Transaction tx)
        {
            RecordFile tcatfile = new RecordFile(tcatInfo, tx);
            int        reclen   = -1;

            while (tcatfile.next())
            {
                if (tcatfile.getString("tblname").Equals(tblname))
                {//获取到指定表名称的一条记录长度
                    reclen = tcatfile.getInt("reclength");
                    break;
                }
            }
            tcatfile.close();

            RecordFile fcatfile = new RecordFile(fcatInfo, tx);
            Schema     sch      = new Schema();
            Dictionary <string, int> offsets = new Dictionary <string, int>();

            while (fcatfile.next())
            {//每次取fcatfile中的一条记录
                if (fcatfile.getString("tblname").Equals(tblname))
                {
                    string fldname = fcatfile.getString("fldname");
                    int    fldtype = fcatfile.getInt("type");
                    int    fldlen  = fcatfile.getInt("length");
                    int    offset  = fcatfile.getInt("offset");
                    offsets.Add(fldname, offset);           //获取一张表中每个字段名称的偏移量
                    sch.addField(fldname, fldtype, fldlen); //获取一张表的模式信息
                }
            }
            fcatfile.close();
            return(new TableInfo(tblname, sch, offsets, reclen));
        }
Exemple #12
0
        public void CanInsertMoreThanForOnePage()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

            schema.AddIntField("field");
            _tableInfo = new TableInfo(tableFile, schema);

            _recordFile = new RecordFile(_tableInfo, _transaction);

            _recordFile.BeforeFirst();

            for (int i = 0; i < 12; ++i)
            {
                _recordFile.Insert();
            }

            // And this folk would go to the next page
            _recordFile.Insert();

            var rid = _recordFile.CurrentRID;

            Assert.AreEqual(1, rid.BlockNumber);
            Assert.AreEqual(0, rid.Id);
        }
        public Task <Stream> Download(RecordFile file)
        {
            var path   = GetFileLocation(file);
            var stream = File.OpenRead(path);

            return(Task.FromResult((Stream)stream));
        }
Exemple #14
0
        public void CanReadWrittenDateRecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

            schema.AddDateField("field");
            _tableInfo = new TableInfo(tableFile, schema);

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetDate("field", new DateTime(2020, 1, 1));
            _recordFile.Close();

            _transaction.Commit();

            var cm    = new ConcurrencyManager();
            var newTr = new Transaction(_dispatcher, _bufferManager, cm, _fileManager, _logManager);

            var rf = new RecordFile(_tableInfo, newTr);

            rf.MoveToRID(new RID(0, 0));
            var value = rf.GetDate("field");

            Assert.AreEqual(new DateTime(2020, 1, 1), value);
        }
        AbsoluteUri IRepository <T> .ToUrn(AlphaDecimal key)
        {
            var file = GetFile(key);

            return(null == file
                       ? null
                       : RecordFile.Load(file).ToRecord <T>().Urn);
        }
        AlphaDecimal? IRepository <T> .ToKey(AbsoluteUri urn)
        {
            var file = GetFile(urn);

            return(null == file
                       ? null
                       : RecordFile.Load(file).ToRecord <T>().Key);
        }
        IRecord <T> IRepository <T> .Select(AlphaDecimal key)
        {
            var file = GetFile(key);

            return(null == file
                       ? null
                       : RecordFile.Load(file).ToRecord <T>());
        }
        IRecord <T> IRepository <T> .Select(AbsoluteUri urn)
        {
            var file = GetFile(urn);

            return(null == file
                       ? null
                       : RecordFile.Load(file).ToRecord <T>());
        }
        bool IRepository <T> .Match(AlphaDecimal key,
                                    EntityTag etag)
        {
            var file = GetFile(key);

            return(null != file &&
                   string.Equals(etag, RecordFile.Load(file).ToRecord <T>().Etag, StringComparison.OrdinalIgnoreCase));
        }
Exemple #20
0
 public bool StartDownload(DateTime startTime, DateTime stopTime, string localFileName)
 {
     if (RecordFile != null)
     {
         return(RecordFile.Download(Config.Channel, startTime, stopTime, localFileName));
     }
     return(false);
 }
Exemple #21
0
 public bool StartDownload(string localFileName)
 {
     if (RecordFile != null)
     {
         return(RecordFile.Download(localFileName));
     }
     return(false);
 }
Exemple #22
0
 public bool StopDownLoad()
 {
     if (RecordFile != null)
     {
         return(RecordFile.Stop());
     }
     return(false);
 }
        public void toSendFormatTest()
        {
            RecordFile rf = new RecordFile("C:\\ciao.txt", "abcdefghabcdefghabcdefghabcdefgh", 15, new DateTime(1970, 1, 1, 1, 0, 0));
            string     s  = rf.toSendFormat();
            string     rs = "C:\\ciao.txt\r\n00000000000Fabcdefghabcdefghabcdefghabcdefgh0000000000000000\r\n";

            Assert.AreEqual(s, rs);
        }
Exemple #24
0
        public static void UploadRecordFiles(Dictionary <string, string> recordConfigs, View.Progress progress, int startLine, int endLine)
        {
            var currentFileIndex = startLine / 16384;
            var offset           = (startLine % 16384);
            var files            = Directory.GetFiles(recordConfigs["Directory"], "*.HEX", SearchOption.AllDirectories);
            var currentLine      = startLine;
            var fileList         = new List <Dictionary <string, int> >();
            var fileName         = 0;

            while (currentLine < endLine)
            {
                fileList.Add(new Dictionary <string, int>
                {
                    { "file", currentFileIndex },
                    { "offset", offset },
                    { "fileName", fileName }
                });
                fileName++;
                offset       = 0;
                currentLine += 16384;
            }
            _fileCount     = (endLine - startLine) / 16384;
            _fileProcessed = 0;
            var fileNameList = new List <string>();

            foreach (var uploadFile in fileList)
            {
                var file = new RecordFile
                {
                    FileName = uploadFile["fileName"].ToString("D8"),
                    Configs  = recordConfigs
                };
                fileNameList.Add(uploadFile["fileName"].ToString("D8"));
                using (var reader = new BinaryReader(new FileStream(files[uploadFile["fileName"]], FileMode.Open)))
                {
                    file.FileDataBytes = new byte[(int)(reader.BaseStream.Length - uploadFile["offset"] * 16)];
                    reader.BaseStream.Seek(uploadFile["offset"] * 16, SeekOrigin.Begin);
                    reader.Read(file.FileDataBytes, 0, (int)(reader.BaseStream.Length - uploadFile["offset"] * 16));
                }

                var response = string.Empty;
                var tryTimes = 0;
                while (response != "255")
                {
                    if (tryTimes > 10)
                    {
                        return;
                    }
                    response = new PostClient($"{ServerAddr}RecordFile").Post(JsonConvert.SerializeObject(file));
                    tryTimes++;
                }

                _fileProcessed++;
                progress.UpdateProgressBar((_fileProcessed / (_fileCount * 1.0)) * 100);
            }
            StartRecordProcess(recordConfigs, progress, fileNameList);
        }
Exemple #25
0
        public void CanCreateRecordFile()
        {
            _tableInfo = new TableInfo(RandomFilename, new Schema());

            Assert.DoesNotThrow(() =>
            {
                _recordFile = new RecordFile(_tableInfo, _transaction);
            });
        }
    void Start()
    {
        switch (m_GameType)
        {
        case GameType.Jigsaw:
            break;

        case GameType.Racing:
            break;

        case GameType.Survival:
            m_GameMode = new SurvivalGameMode();
            break;

        default:
            break;
        }
        m_Players = new List <Player>();
        for (int i = 0; i < m_PlayerNum; i++)
        {
            m_Players.Add(new Player());
        }

        //绑定方块掉落事件
        if (m_GameMode is SurvivalGameMode)
        {
            m_Players[0].OnBrickFallOut += (m_GameMode as SurvivalGameMode).BrickFalloutEvent;
            //绑定更新生命值事件
            (m_GameMode as SurvivalGameMode).OnFalloutCountChange += uiView.ChangeHeartCount;
        }

        //绑定UI事件
        uiView.OnMoveLeft  += this.MoveLeft;
        uiView.OnMoveRight += this.MoveRight;
        uiView.OnSpeedUp   += this.SpeedUp;
        uiView.OnSpeedDown += this.SpeedDown;
        uiView.OnRotate    += this.Rotate;

        uiView.OnRestart         += this.Restart;
        uiView.OnLookRecordClick += this.StartLookRecord;

        OnGameEnd     += uiView.HandleGameEnd;
        OnGameRestart += uiView.GameEndMenuMoveOut;
        OnScoreChange += uiView.HandleScoreChange;
        m_Players[0].OnChangeNextBrickView += uiView.ChangeNextBrickIcon;

        //开始游戏
        m_Players[0].StartGame();

        //播放音乐
        AudioManager.instance.StopAllMusic();
        AudioManager.instance.PlayMusic("Music_SurvivalGame");

        m_RecordFile            = new RecordFile();
        m_RecordFile.randomSeed = m_Players[0].RandomSeed;
    }
Exemple #27
0
        public void createView(string vname, string vdef, Transaction tx)
        {//创建视图,在内存中创建RecordFile读取类往里面写信息
            TableInfo  ti = tblMgr.getTableInfo("viewcat", tx);
            RecordFile rf = new RecordFile(ti, tx);

            rf.insert();
            rf.setString("viewname", vname);
            rf.setString("viewdef", vdef);
            rf.close();
        }
Exemple #28
0
        public void CreateIndex(string indexName, string tableName, string fieldName, Transaction transaction)
        {
            var recordFile = new RecordFile(_tableInfo, transaction);

            recordFile.Insert();
            recordFile.SetString("idxname", indexName);
            recordFile.SetString("tblname", tableName);
            recordFile.SetString("fldname", fieldName);
            recordFile.Close();
        }
Exemple #29
0
        public void CreateView(string viewName, string viewDefinition, Transaction transaction)
        {
            var tableInfo  = _tableManager.GetTableInfo(_viewTableName, transaction);
            var recordFile = new RecordFile(tableInfo, transaction);

            recordFile.Insert();
            recordFile.SetString("viewname", viewName);
            recordFile.SetString("viewdef", viewDefinition);
            recordFile.Close();
        }
Exemple #30
0
        public void createIndex(string idxname, string tblname, string fldname, Transaction tx)
        {//在指定表、指定字段上创造一个指定名称的索引
            RecordFile rf = new RecordFile(ti, tx);

            rf.insert();
            rf.setString("indexname", idxname);
            rf.setString("tablename", tblname);
            rf.setString("fieldname", fldname);
            rf.close();
        }
        public RecordFile Create(int id)
        {
            var recordFile = new RecordFile
            {
                DateUpdated = DateTime.UtcNow,
                RecordId = id
            };

            this.data.RecordFiles.Add(recordFile);
            this.data.SaveChanges();

            return recordFile;
        }
Exemple #32
0
        public void op_ToRecordOfT()
        {
            var expected = new Record<int>
                               {
                                   Cacheability = "public",
                                   Created = new DateTime(1999, 12, 31, 01, 00, 00, 00),
                                   Etag = "\"xyz\"",
                                   Expiration = "P1D",
                                   Key = AlphaDecimal.Random(),
                                   Modified = new DateTime(2001, 12, 31, 01, 00, 00, 00),
                                   Status = 200,
                                   Urn = "urn://example.com/abc",
                                   Value = 123
                               };

            var obj = new RecordFile(expected);

            var actual = obj.ToRecord<int>();

            Assert.Equal(expected, actual);
        }
Exemple #33
0
        public void op_ToString_whenRecordNullXml()
        {
            var key = AlphaDecimal.Random();
            var record = new Record<string>
                             {
                                 Cacheability = "public",
                                 Created = new DateTime(1999, 12, 31, 01, 00, 00, 00),
                                 Etag = "\"xyz\"",
                                 Expiration = "P1D",
                                 Key = key,
                                 Modified = new DateTime(2001, 12, 31, 01, 00, 00, 00),
                                 Status = 200,
                                 Urn = "urn://example.com/abc",
                                 Value = null
                             };

            var obj = new RecordFile(record);

            var expected = new StringBuilder();
            expected.AppendLine("urn: urn://example.com/abc");
            expected.AppendLine("key: " + key);
            expected.AppendLine("etag: \"xyz\"");
            expected.AppendLine("created: 1999-12-31T01:00:00Z");
            expected.AppendLine("modified: 2001-12-31T01:00:00Z");
            expected.AppendLine("cacheability: public");
            expected.AppendLine("expiration: P1D");
            expected.AppendLine("status: 200");
            expected.AppendLine(string.Empty);

            var actual = obj.ToString();

            Assert.Equal(expected.ToString(), actual);
        }
Exemple #34
0
        public void op_ToXml()
        {
            const string expected = "<root />";

            var obj = new RecordFile
                          {
                              Body = expected
                          };

            var actual = obj.ToXml().CreateNavigator().OuterXml;

            Assert.Equal(expected, actual);
        }
Exemple #35
0
        public void op_Save_FileSystemInfo()
        {
            var record = new Record<int>
                             {
                                 Cacheability = "public",
                                 Created = new DateTime(1999, 12, 31, 01, 00, 00, 00),
                                 Etag = "\"xyz\"",
                                 Expiration = "P1D",
                                 Key = AlphaDecimal.Random(),
                                 Modified = new DateTime(2001, 12, 31, 01, 00, 00, 00),
                                 Status = 200,
                                 Urn = "urn://example.com/abc",
                                 Value = 123
                             };

            var expected = new StringBuilder();
            expected.AppendLine("urn: urn://example.com/abc");
            expected.AppendLine("key: " + record.Key);
            expected.AppendLine("etag: \"xyz\"");
            expected.AppendLine("created: 1999-12-31T01:00:00Z");
            expected.AppendLine("modified: 2001-12-31T01:00:00Z");
            expected.AppendLine("cacheability: public");
            expected.AppendLine("expiration: P1D");
            expected.AppendLine("status: 200");
            expected.AppendLine(string.Empty);
            expected.Append("<int>123</int>");

            string actual;
            using (var root = new TempDirectory())
            {
                var obj = new RecordFile(record);
                obj.Save(root.Info);

                actual = new FileInfo(obj.Location.FullName).ReadToEnd();
            }

            Assert.Equal(expected.ToString(), actual);
        }
Exemple #36
0
        public void op_ToString_whenNullBody()
        {
            var obj = new RecordFile();
            obj.Headers["urn"] = "urn://example.com/abc";
            obj.Headers["etag"] = "\"xyz\"";

            var expected = new StringBuilder();
            expected.AppendLine("urn: urn://example.com/abc");
            expected.AppendLine("key: ");
            expected.AppendLine("etag: \"xyz\"");
            expected.AppendLine("created: ");
            expected.AppendLine("modified: ");
            expected.AppendLine("cacheability: ");
            expected.AppendLine("expiration: ");
            expected.AppendLine("status: ");
            expected.AppendLine(string.Empty);

            var actual = obj.ToString();

            Assert.Equal(expected.ToString(), actual);
        }
 public void SetPath(RecordFile recordFile, string savePath)
 {
     recordFile.Path = savePath;
     this.data.SaveChanges();
 }