Microsoft.WindowsAzure.Commands.Tools.Vhd.Model.Persistence.BlockAllocationTableFactory.BeginCreate C# (CSharp) Method

BeginCreate() public method

public BeginCreate ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback
state object
return IAsyncResult
        public IAsyncResult BeginCreate(AsyncCallback callback, object state)
        {
            return AsyncMachine<BlockAllocationTable>.BeginAsyncMachine(CreateAsync, callback, state);
        }

Usage Example

Esempio n. 1
0
        private IEnumerable <CompletionPort> CreateAsync(AsyncMachine <VhdFile> machine, StreamSource streamSource)
        {
            var disposer = new Action(() => { if (streamSource.DisposeOnException)
                                              {
                                                  streamSource.Stream.Dispose();
                                              }
                                      });

            var reader        = TryCatch(() => new BinaryReader(streamSource.Stream, Encoding.Unicode), disposer);
            var dataReader    = TryCatch(() => new VhdDataReader(reader), disposer);
            var footerFactory = TryCatch(() => new VhdFooterFactory(dataReader), disposer);

            footerFactory.BeginCreateFooter(machine.CompletionCallback, null);
            yield return(CompletionPort.SingleOperation);

            var footer = TryCatch <VhdFooter>(footerFactory.EndCreateFooter, disposer, machine.CompletionResult);

            VhdHeader            header = null;
            BlockAllocationTable blockAllocationTable = null;
            VhdFile parent = null;

            if (footer.DiskType != DiskType.Fixed)
            {
                var headerFactory = new VhdHeaderFactory(dataReader, footer);

                headerFactory.BeginCreateHeader(machine.CompletionCallback, null);
                yield return(CompletionPort.SingleOperation);

                header = TryCatch <VhdHeader>(headerFactory.EndCreateHeader, disposer, machine.CompletionResult);

                var tableFactory = new BlockAllocationTableFactory(dataReader, header);
                tableFactory.BeginCreate(machine.CompletionCallback, null);
                yield return(CompletionPort.SingleOperation);

                blockAllocationTable = TryCatch <BlockAllocationTable>(tableFactory.EndCreate, disposer, machine.CompletionResult);

                if (footer.DiskType == DiskType.Differencing)
                {
                    string parentPath = GetParentPath(streamSource.VhdDirectory, header);

                    BeginCreate(parentPath, machine.CompletionCallback, null);
                    yield return(CompletionPort.SingleOperation);

                    parent = TryCatch <VhdFile>(EndCreate, disposer, machine.CompletionResult);
                }
            }
            machine.ParameterValue = new VhdFile(footer, header, blockAllocationTable, parent, streamSource.Stream);
        }