public XrayRunModel Read()
        {
            var xrayRunModel = new XrayRunModel();
            using (var metaFileStream = File.OpenRead(Constants.MetaFileName))
            {
                var metaWriter = new MetaStreamReader(metaFileStream);
                var xrayRunStorageModel = metaWriter.Read<XRayRunStorageModel>();

                xrayRunModel.Width = xrayRunStorageModel.Width;
                xrayRunModel.Height = xrayRunStorageModel.Height;
                xrayRunModel.Images = new List<ImageModel>();

                using (var bulkFileStream = File.OpenRead(Constants.BulkFileName))
                {
                    var bulkReader = new BulkStreamReader(bulkFileStream);
                    foreach (var bulkReference in xrayRunStorageModel.Images)
                    {
                        var buffer = bulkReader.Read(bulkReference);
                        xrayRunModel.Images.Add(new ImageModel(buffer));
                    }
                }
            }

            return xrayRunModel;
        }
        public void Write(XrayRunModel xrayRunModel)
        {
            var storageModel = new XRayRunStorageModel
            {
                Height = xrayRunModel.Height,
                Width = xrayRunModel.Width,
                NumberOfImages = xrayRunModel.Images.Count,
                Images = new List<BulkReference>()
            };

            using (var fileStream = File.Create(Constants.BulkFileName))
            {
                using (var bulkWriter = new BulkStreamWriter(fileStream))
                {
                    foreach (var image in xrayRunModel.Images)
                    {
                        var bulkRef = bulkWriter.Write(image.Data);
                        storageModel.Images.Add(bulkRef);
                    }
                }
            }

            using (var fileStream = File.Create(Constants.MetaFileName))
            {
                var metaWriter = new MetaStreamWriter(fileStream);
                metaWriter.Write(storageModel);
            }
        }
Example #3
0
        public static void Main()
        {
            var xrayRunModel = new XrayRunModel
            {
                Height = 4,
                Width = 4,
                Images = new List<ImageModel>
                {
                    new ImageModel(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}),
                    new ImageModel(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}),
                    new ImageModel(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}),
                    new ImageModel(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
                }
            };

            var xrayRunWriter = new XRayRunModelWriter();
            xrayRunWriter.Write(xrayRunModel);
            xrayRunWriter.Dispose();

            var xrayRunReader = new XrayRunModelReader();
            var xrayRunModel2 = xrayRunReader.Read();
        }