Exemplo n.º 1
0
        public UploadContextDisk Create(FileInfo localVhd, PSPageBlobClient pageblob, bool overWrite)
        {
            AssertIfValidhVhd(localVhd);
            AssertIfValidVhdSize(localVhd);

            UploadContextDisk context = null;
            bool completed            = false;

            this.localVhd = localVhd;
            try
            {
                context = new UploadContextDisk
                {
                    DestinationDisk     = pageblob,
                    SingleInstanceMutex = AcquireSingleInstanceMutex(pageblob.Uri)
                };

                PopulateContextWithUploadableRanges(localVhd, context, false);
                PopulateContextWithDataToUpload(localVhd, context);

                context.Md5HashOfLocalVhd = MD5HashOfLocalVhd;
                completed = true;
            }
            finally
            {
                if (!completed && context != null)
                {
                    context.Dispose();
                }
            }
            return(context);
        }
 public DiskSynchronizer(UploadContextDisk context, int maxParallelism)
 {
     this.context             = context;
     this.md5Hash             = context.Md5HashOfLocalVhd;
     this.dataWithRanges      = context.UploadableDataWithRanges;
     this.dataToUpload        = context.UploadableDataSize;
     this.alreadyUploadedData = context.AlreadyUploadedDataSize;
     this.pageBlob            = context.DestinationDisk;
     this.maxParallelism      = maxParallelism;
 }
        protected static void PopulateContextWithUploadableRanges(FileInfo vhdFile, UploadContextDisk context, bool resume)
        {
            using (var vds = new VirtualDiskStream(vhdFile.FullName))
            {
                IEnumerable <IndexRange> ranges = vds.Extents.Select(e => e.Range).ToArray();

                var bs = new BufferedStream(vds);
                // linear still
                var uploadableRanges = IndexRangeHelper.ChunkRangesBySize(ranges, PageSizeInBytes).ToArray();

                // detecting empty data blocks line. Takes long
                var nonEmptyUploadableRanges = GetNonEmptyRanges(bs, uploadableRanges).ToArray();
                context.UploadableDataSize = nonEmptyUploadableRanges.Sum(r => r.Length);
                context.UploadableRanges   = nonEmptyUploadableRanges;
            }
        }
Exemplo n.º 4
0
        protected static IEnumerable <DataWithRange> GetDataWithRangesToUpload(FileInfo vhdFile, UploadContextDisk context)
        {
            var uploadableRanges = context.UploadableRanges;
            var manager          = BufferManager.CreateBufferManager(Int32.MaxValue, MaxBufferSize);

            using (var vds = new VirtualDiskStream(vhdFile.FullName))
            {
                foreach (var range in uploadableRanges)
                {
                    var localRange = range;
                    yield return(new DataWithRange(manager)
                    {
                        Data = ReadBytes(vds, localRange, manager),
                        Range = localRange
                    });
                }
            }
            yield break;
        }
Exemplo n.º 5
0
 protected static void PopulateContextWithDataToUpload(FileInfo vhdFile, UploadContextDisk context)
 {
     context.UploadableDataWithRanges = GetDataWithRangesToUpload(vhdFile, context);
 }