コード例 #1
0
ファイル: UpdateEngin.cs プロジェクト: Adel-dz/Hub
        public static IEnumerable <TableUpdate> LoadTablesUpdate(string filePath, IDatumFactory dataFactory)
        {
            using (FileStream fs = File.OpenRead(filePath))
            {
                var    reader = new RawDataReader(fs, Encoding.UTF8);
                byte[] sign   = Encoding.UTF8.GetBytes(TABLES_UPDATE_SIGNATURE);

                for (int i = 0; i < sign.Length; ++i)
                {
                    if (reader.ReadByte() != sign[i])
                    {
                        throw new CorruptedFileException(filePath);
                    }
                }

                int tableCount = reader.ReadInt();
                var lst        = new List <TableUpdate>(tableCount);

                for (int i = 0; i < tableCount; ++i)
                {
                    lst.Add(LoadTableUpdate(reader, dataFactory));
                }

                return(lst);
            }
        }
コード例 #2
0
ファイル: UpdateEngin.cs プロジェクト: Adel-dz/Hub
        //private:
        static TableUpdate LoadTableUpdate(IReader reader, IDatumFactory dataFactory)
        {
            uint idTable     = reader.ReadUInt();
            uint preGen      = reader.ReadUInt();
            uint postGen     = reader.ReadUInt();
            int  szDatum     = reader.ReadInt();
            int  actionCount = reader.ReadInt();

            var lst = new List <IUpdateAction>(actionCount);

            for (int i = 0; i < actionCount; ++i)
            {
                var code = (ActionCode_t)reader.ReadByte();

                switch (code)
                {
                case ActionCode_t.ResetTable:
                    lst.Add(new ResetTable());
                    break;

                case ActionCode_t.DeleteRow:
                {
                    var delAction = new DeleteRow(0);
                    delAction.Read(reader);
                    lst.Add(delAction);
                }
                break;

                case ActionCode_t.ReplaceRow:
                {
                    var repAction = new ReplaceRow(dataFactory.CreateDatum(idTable));
                    repAction.Read(reader);
                    lst.Add(repAction);
                }
                break;

                case ActionCode_t.AddRow:
                {
                    var addAction = new AddRow(dataFactory.CreateDatum(idTable));
                    addAction.Read(reader);
                    lst.Add(addAction);
                }
                break;

                default:
                    Assert(false);
                    break;
                }
            }

            return(new TableUpdate(idTable, lst, szDatum, preGen, postGen));
        }