public async Task Append(string streamName, byte[] data, long expectedStreamVersion = -1) { int retry = 0; try { var azurehelper = new AzureBlobAppenderHelper(this.storage, this.container, this.options); await azurehelper.WriteContent(streamName, data, expectedStreamVersion); } catch (ConcurrentIndexException) { while (retry < retrypolicy.Length) { await Task.Delay(retrypolicy[retry]); await this.Append(streamName, data, expectedStreamVersion); retry++; } throw; } catch (StorageException ex) { var requestInformation = ex.RequestInformation; var extended = requestInformation.ExtendedErrorInformation; throw; } }
public async Task Append(string streamName, byte[] data, long expectedStreamVersion = -1) { int retry = 0; try { var azurehelper = new AzureBlobAppenderHelper(this.storage, this.container, this.options); await azurehelper.WriteContent(streamName, data, expectedStreamVersion); } catch (ConcurrentIndexException) { while (retry < retrypolicy.Length) { await Task.Delay(retrypolicy[retry]); await this.Append(streamName, data, expectedStreamVersion); retry++; } throw; } catch (StorageException ex) { var requestInformation = ex.RequestInformation; var extended = requestInformation.ExtendedErrorInformation; throw; } }
public async Task<DataWithVersion[]> ReadRecords(string streamName, long afterVersion, int maxCount) { try { var azurehelper = new AzureBlobAppenderHelper(this.storage, this.container, this.options); var items = await azurehelper.ReadStreamCache(streamName); return items.Where(x => x.Version > afterVersion && x.Version <= maxCount).Select(x => new DataWithVersion(x.Version, x.Bytes)).ToArray(); } catch (StorageException ex) { var requestInformation = ex.RequestInformation; var extended = requestInformation.ExtendedErrorInformation; throw; } }
public async Task <DataWithVersion[]> ReadRecords(string streamName, long afterVersion, int maxCount) { try { var azurehelper = new AzureBlobAppenderHelper(this.storage, this.container, this.options); var items = await azurehelper.ReadStreamCache(streamName); return(items.Where(x => x.Version > afterVersion && x.Version <= maxCount).Select(x => new DataWithVersion(x.Version, x.Bytes)).ToArray()); } catch (StorageException ex) { var requestInformation = ex.RequestInformation; var extended = requestInformation.ExtendedErrorInformation; throw; } }
public async Task <DataWithName[]> ReadRecords(long afterVersion, int maxCount) { try { var azurehelper = new AzureBlobAppenderHelper(this.storage, this.container, this.options); var items = await azurehelper.ReadMasterCache(); return(items.Where(x => x.Version > afterVersion && x.Version <= maxCount).Select(x => new DataWithName(x.Name, x.Bytes)).ToArray()); } catch (StorageException ex) { if (ex.HResult == 404) { return(new DataWithName[0]); } var requestInformation = ex.RequestInformation; var extended = requestInformation.ExtendedErrorInformation; throw; } }
public async Task WriteAll() { var helper = new AzureBlobAppenderHelper(storage, container, options); var master = helper.GetMasterCache(); master.StreamWriteSizeInBytes = 1024 * 1024 * 4; using (var masterindex = new MemoryStream()) { var writer = new StreamWriter(masterindex); using (var stream = new MemoryStream()) { foreach (var record in records) { record.WriteContentToStream(stream); var hashhex = string.Join(String.Empty, record.Hash.Select(x => x.ToString("x2"))); writer.WriteLine(String.Join("\t", record.Name, record.Version, hashhex, this.options.NamingPolicy.GetStreamPath(record.Name))); } await writer.FlushAsync(); stream.Position = 0; masterindex.Position = 0; await master.CreateOrReplaceAsync(); await master.AppendFromStreamAsync(stream); var indexblob = storage.CreateCloudBlobClient().GetContainerReference(container).GetAppendBlobReference(this.options.NamingPolicy.GetIndexPath()); await indexblob.CreateOrReplaceAsync(); await indexblob.AppendFromStreamAsync(masterindex); var streams = GetNamedStreams(helper); await Task.WhenAll(streams); } } }
private IEnumerable <Task> GetNamedStreams(AzureBlobAppenderHelper helper) { foreach (var name in names) { yield return(Task.Run(async() => { using (var indexstream = new MemoryStream()) { var writer = new StreamWriter(indexstream); using (var s = new MemoryStream()) { var blobstream = helper.GetStreamCache(name); blobstream.StreamWriteSizeInBytes = 1024 * 1024 * 3; foreach (var record in this.records.Where(x => x.Name.Equals(name)).OrderBy(x => x.Version)) { record.WriteContentToStream(s); var hashhex = string.Join(String.Empty, record.Hash.Select(x => x.ToString("x2"))); writer.WriteLine(String.Join("\t", record.Name, record.Version, hashhex, blobstream.Name)); } await writer.FlushAsync(); s.Position = 0; indexstream.Position = 0; var indexblob = storage.CreateCloudBlobClient().GetContainerReference(container).GetAppendBlobReference(this.options.NamingPolicy.GetIndexPath(name)); await indexblob.CreateOrReplaceAsync(); await indexblob.AppendFromStreamAsync(indexstream); await blobstream.CreateOrReplaceAsync(); await blobstream.AppendFromStreamAsync(s); } } })); } }
public async Task WriteAll() { var helper = new AzureBlobAppenderHelper(storage, container, options); var master = helper.GetMasterCache(); master.StreamWriteSizeInBytes = 1024 * 1024 * 4; using (var masterindex = new MemoryStream()) { var writer = new StreamWriter(masterindex); using (var stream = new MemoryStream()) { foreach (var record in records) { record.WriteContentToStream(stream); var hashhex = string.Join(String.Empty, record.Hash.Select(x => x.ToString("x2"))); writer.WriteLine(String.Join("\t", record.Name, record.Version, hashhex, this.options.NamingPolicy.GetStreamPath(record.Name))); } await writer.FlushAsync(); stream.Position = 0; masterindex.Position = 0; await master.CreateOrReplaceAsync(); await master.AppendFromStreamAsync(stream); var indexblob = storage.CreateCloudBlobClient().GetContainerReference(container).GetAppendBlobReference(this.options.NamingPolicy.GetIndexPath()); await indexblob.CreateOrReplaceAsync(); await indexblob.AppendFromStreamAsync(masterindex); var streams = GetNamedStreams(helper); await Task.WhenAll(streams); } } }
public async Task<DataWithName[]> ReadRecords(long afterVersion, int maxCount) { try { var azurehelper = new AzureBlobAppenderHelper(this.storage, this.container, this.options); var items = await azurehelper.ReadMasterCache(); return items.Where(x => x.Version > afterVersion && x.Version <= maxCount).Select(x => new DataWithName(x.Name, x.Bytes)).ToArray(); } catch (StorageException ex) { if (ex.HResult == 404) { return new DataWithName[0]; } var requestInformation = ex.RequestInformation; var extended = requestInformation.ExtendedErrorInformation; throw; } }
private IEnumerable<Task> GetNamedStreams(AzureBlobAppenderHelper helper) { foreach (var name in names) { yield return Task.Run(async () => { using (var indexstream = new MemoryStream()) { var writer = new StreamWriter(indexstream); using (var s = new MemoryStream()) { var blobstream = helper.GetStreamCache(name); blobstream.StreamWriteSizeInBytes = 1024*1024*3; foreach (var record in this.records.Where(x => x.Name.Equals(name)).OrderBy(x => x.Version)) { record.WriteContentToStream(s); var hashhex = string.Join(String.Empty, record.Hash.Select(x => x.ToString("x2"))); writer.WriteLine(String.Join("\t", record.Name, record.Version, hashhex, blobstream.Name)); } await writer.FlushAsync(); s.Position = 0; indexstream.Position = 0; var indexblob = storage.CreateCloudBlobClient().GetContainerReference(container).GetAppendBlobReference(this.options.NamingPolicy.GetIndexPath(name)); await indexblob.CreateOrReplaceAsync(); await indexblob.AppendFromStreamAsync(indexstream); await blobstream.CreateOrReplaceAsync(); await blobstream.AppendFromStreamAsync(s); } } }); } }