Esempio n. 1
0
        public static void TreeToBinary(String TreePath, String BinaryPath, String MainType)
        {
            var TypeName = ObjectSchemaExtensions.GetDotNetFullNameFromVersionedName(MainType);
            var a        = SchemaAssembly();
            var t        = a.GetType(TypeName);

            if (t == null)
            {
                throw new InvalidOperationException("TypeNotExist: " + TypeName);
            }
            var tbc = TreeBinaryConverter();

            var Data = TreeFile.ReadFile(TreePath);
            var b    = tbc.TreeToBinary(t, Data);
            var Dir  = FileNameHandling.GetFileDirectory(BinaryPath);

            if (Dir != "" && !Directory.Exists(Dir))
            {
                Directory.CreateDirectory(Dir);
            }
            using (var s = Streams.CreateWritable(BinaryPath))
            {
                s.Write(b);
            }
        }
Esempio n. 2
0
        public static void SaveData(Schema s, String MemoryDatabaseFile, RelationVal Value, Firefly.Mapping.Binary.BinarySerializer bs)
        {
            var rvs = new RelationValueSerializer(s);

            var Dir = FileNameHandling.GetFileDirectory(MemoryDatabaseFile);

            if (Dir != "" && !Directory.Exists(Dir))
            {
                Directory.CreateDirectory(Dir);
            }
            using (var fs = Streams.CreateWritable(MemoryDatabaseFile))
            {
                fs.WriteSimpleString("KRUSDATA", 8);
                fs.WriteUInt64(s.Hash());
                var SchemaLengthPosition = fs.Position;
                fs.WriteInt64(0);
                var SchemaPosition = fs.Position;
                bs.Write(fs, s);
                var SchemaLength       = fs.Position - SchemaPosition;
                var DataLengthPosition = fs.Position;
                fs.WriteInt64(0);
                var DataPosition = fs.Position;
                rvs.Write(fs, Value);
                var DataLength = fs.Position - DataPosition;
                fs.Position = SchemaLengthPosition;
                fs.WriteInt64(SchemaLength);
                fs.Position = DataLengthPosition;
                fs.WriteInt64(DataLength);
            }
        }
Esempio n. 3
0
        public static void TreeToBinaryWithFirefly(String TreePath, String BinaryPath)
        {
            var tbc  = new TreeBinaryConverter();
            var Data = TreeFile.ReadFile(TreePath);
            var b    = tbc.TreeToBinary <World.World>(Data);

            using (var s = Streams.CreateWritable(BinaryPath))
            {
                s.Write(b);
            }
        }
Esempio n. 4
0
        public static void ExpressionSchemaToBinary(List <String> DataDirs, String BinaryPath)
        {
            var ExpressionSchema = GetExpressionSchema();
            var eal = new ExpressionAssemblyLoader(ExpressionSchema);

            foreach (var DataDir in DataDirs)
            {
                foreach (var tf in Directory.EnumerateFiles(DataDir, "*.tree", SearchOption.AllDirectories))
                {
                    eal.LoadAssembly(tf);
                }
            }
            var a  = eal.GetResult();
            var bs = BinarySerializerWithString.Create();

            Byte[] Compiled;
            using (var ms = Streams.CreateMemoryStream())
            {
                bs.Write(a, ms);
                ms.Position = 0;
                Compiled    = ms.Read((int)(ms.Length));
            }
            if (File.Exists(BinaryPath))
            {
                Byte[] Original;
                using (var fs = Streams.OpenReadable(BinaryPath))
                {
                    Original = fs.Read((int)(fs.Length));
                }
                if (Compiled.SequenceEqual(Original))
                {
                    return;
                }
            }
            var BinaryDir = FileNameHandling.GetFileDirectory(BinaryPath);

            if (BinaryDir != "" && !Directory.Exists(BinaryDir))
            {
                Directory.CreateDirectory(BinaryDir);
            }
            using (var fs = Streams.CreateWritable(BinaryPath))
            {
                fs.Write(Compiled);
            }
        }
Esempio n. 5
0
        public static void TreeToBinary(String TreePath, String BinaryPath)
        {
            var xs = new XmlSerializer(true);
            var x  = TreeFile.ReadFile(TreePath);
            var o  = xs.Read <World.World>(x);

            Byte[] b;
            using (var s = new World.BinaryWithoutFirefly.ByteArrayStream())
            {
                World.BinaryWithoutFirefly.BinaryTranslator.WorldToBinary(s, o);
                s.Position = 0;
                b          = s.ReadBytes(s.Length);
            }
            using (var s = Streams.CreateWritable(BinaryPath))
            {
                s.Write(b);
            }
        }