Exemple #1
0
        private IBinnerDb LoadDatabaseByVersion(BinnerDbVersion version, byte[] bytes)
        {
            IBinnerDb db;

            // Support database loading by version number
#if (NET462 || NET471)
            switch (version.Version)
            {
            case BinnerDbV1.VersionNumber:
                // Version 1
                db = _serializer.Deserialize <BinnerDbV1>(bytes, _serializationOptions);
                break;

            default:
                throw new InvalidOperationException($"Unsupported database version: {version}");
            }
#else
            db = version.Version switch
            {
                // Version 1
                BinnerDbV1.VersionNumber => _serializer.Deserialize <BinnerDbV1>(bytes, _serializationOptions),
                _ => throw new InvalidOperationException($"Unsupported database version: {version}"),
            };
#endif
            return(db);
        }
Exemple #2
0
 private void WriteDbVersion(Stream stream, BinnerDbVersion version)
 {
     using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
     {
         writer.Write(version.Version);
         writer.Write(version.Created.ToBinary());
     }
 }
Exemple #3
0
        private BinnerDbVersion ReadDbVersion(Stream stream)
        {
            BinnerDbVersion version = null;

            using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                var versionByte    = reader.ReadByte();
                var versionCreated = reader.ReadInt64();
                version = new BinnerDbVersion(versionByte, DateTime.FromBinary(versionCreated));
            }
            return(version);
        }